Giter VIP home page Giter VIP logo

atomai's Introduction

pycroscopy

Downloads GitHub Actions PyPI coverage conda-forge License DOI Notebook

pycroscopy is a python package for generic (domain-agnostic) microscopy data anlaysis. More specialized or domain-specific analysis routines are contained within some of the other packages within the pycroscopy ecosystem.

Please visit our homepage for more information and installation instructions.

If you use pycroscopy for research, we would appreciate if you could cite our Arxiv paper titled "USID and Pycroscopy - Open frameworks for storing and analyzing spectroscopic and imaging data"

atomai's People

Contributors

aghosh92 avatar ahoust17 avatar arpanbiswas52 avatar codacy-badger avatar miguel-fc avatar ziatdinovmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atomai's Issues

change learning rate in `.fit()` call?

Amazing package! Thanks so much for the development!

Is it possible to change learning rate within the .fit call on a atomai model? For example:

from atomai.models import rVAE

rvae = rVAE( input_dim, latent_dim = 2, conv_encoder = True, numlayers_encoder = 3, numlayers_decoder = 3 )
rvae.fit( training_stack, training_cycles = 100, batch_size = 100, **lr = 0.0005** )

I am unsure how to pass the correct params to torch.optim.Adam() in .compile_trainer(). Should it look something like?:

from atomai.models import rVAE
import torch

rvae = rVAE( input_dim, latent_dim = 2, conv_encoder = True, numlayers_encoder = 3, numlayers_decoder = 3 )
rvae.compile_trainer( imstack_train, optimizer = torch.optim.Adam( params = ??, lr = 0.0005 ), training_cycles = 100, batch_size = 100)
rvae.fit()

Thanks!

requirements.txt needs chardet added

I installed atomai in a conda python 3.11 environment, and I got the following when attempting to import the package:

Python 3.11.5 (main, Sep 11 2023, 13:54:46) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import atomai as aoi
Traceback (most recent call last):
  File "/home/may/.conda/envs/intersect/lib/python3.11/site-packages/requests/compat.py", line 11, in <module>
    import chardet
ModuleNotFoundError: No module named 'chardet'

Manually installing chardet package fixed the problem, so hopefully updating requirements.txt will fix the problem.

Use kornia library for data augmentation

Currently, we have rather archaic data augmentation pipelines, which employ a combination of scikit-learn and open-cv image processing functions. This leads to a significant slow down of the training with on-the-fly data augmentation. It would be nice if we can instead use kornia computer vision library that was specifically designed for applications in deep learning.

Custom dataloaders for AtomAI models

Passing a custom data loader in AtomAI models can be a useful feature. This would allow using e.g. Kornia data augmentation pipelines. It could look like this

segmodel = aoi.models.Segmentor(nb_classes=3)
segmodel.fit(train_loader=custom_train_loader, test_loader=custom_test_loader). # instead of passing X_train, y_train, X_test, y_test

It will also be helpful to have a utility function that builds a dataloader with Kornia data augmentation functions.

AtomAI initialization error

After pip installing atomai, on my windows laptop we get the following error that causes the python kernel to crash

Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import atomai
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

rvae.decode() fails to decode

Below code expect a 2 dimensional z_mean (like the vanilla vae case)

z_mean, z_std = rvae.encode(norm_patches)
rvae.decode(z_mean)
  • when tried with last two latent variables: rvae.decode(z_mean[:, 1:]) -> the decoded patches look very different

Tried a hacky way to decode following: forward_compute_elbo

z_mean, z_std = rvae.encode(norm_patches)
z1, z2, z3 = z_mean[:,0], z_mean[:, 1:3], z_mean[:, 3:]
x_coord_ = rvae.x_coord.expand(norm_patches.shape[0], *rvae.x_coord.size()).cpu()
phi = torch.tensor(z1) # angle
dx = torch.tensor(z2)  # translation
dx = (dx * rvae.dx_prior).unsqueeze(1)
x_coord_ = utils.transform_coordinates(x_coord_, phi, dx)
decoded_patches = rvae.decoder_net(x_coord_.to("cuda"), torch.tensor(z3).to("cuda"))

It will be useful to have this functionality directly using vae.decode(z_mean)

Gaussian of coordinates close an edge can extend past the image boundary and cause an error.

Function: create_lattice_mask
File: imgen.py
Issue: XY coordinates close an edge can cause an error if their gaussian extends past the boundary.

Potential Solution:
This can be avoided by including cases for the edges to remove the sections of the mask which extend beyond the image boundary and limit the indices to within the image width and height.

Additionally, the previous values of the mask are added to the new mask to allow smoother transitions between overlapping gaussians.

This sort of a solution can be seen in the image below.

image

Numpy deprecation error

I installed atomai 0.7.4 and numpy 1.26.0. Im running the tutorial to make sure everything works and ran into an error.

For multivariate analysis you run this line:
imstack = aoi.stat.imlocal(nn_output, coordinates, window_size=32, coord_class=1)

With numpy 1.26.0 this outputs the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[28], line 1
----> 1 imstack = aoi.stat.imlocal(nn_output, coordinates, window_size=32, coord_class=1)

File /opt/tljh/user/envs/atomai/lib/python3.10/site-packages/atomai/stat/multivar.py:87, in imlocal.__init__(self, network_output, coord_class_dict_all, window_size, coord_class)
     85 self.nb_classes = network_output.shape[-1]
     86 self.coord_all = coord_class_dict_all
---> 87 self.coord_class = np.float(coord_class)
     88 self.r = window_size
     89 (self.imgstack,
     90  self.imgstack_com,
     91  self.imgstack_frames) = self.extract_subimages_()

File /opt/tljh/user/envs/atomai/lib/python3.10/site-packages/numpy/__init__.py:324, in __getattr__(attr)
    319     warnings.warn(
    320         f"In the future `np.{attr}` will be defined as the "
    321         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    323 if attr in __former_attrs__:
--> 324     raise AttributeError(__former_attrs__[attr])
    326 if attr == 'testing':
    327     import numpy.testing as testing

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

The fix is easy but needs to be implemented.

gpu_usage @ trainer.py

Line 357 in trainer.py
gpu_usage = gpu_usage_map(torch.cuda.current_device())
may result in FileNotFoundError.

Work-around is to just use Try Except block to bypass error.
Windows may view as unsafe command.

NaN VAE training toss when using convolutional encoder and decoder

Training a VAE on grayscale image data when the "conv_encoder" and "conv_decoder" arguments of the VAE constructor method are set to True results in NaN values for the reported training loss. Printing the train loss history also shows an array filled with nan values.

I have attached an image which shows an example of the input data and the report training loss:

VAE nan training loss

Does AtomAI support GPU acceleration?

Dear Maxim,

Thanks for sharing this amazing package. I am trying out the r-VAE module after the workshop and I found it runs significantly slower than the VAE. First, I am wondering if this is usually the case and second, I am wondering if I can use GPU to accelerate the training.

Thanks,
Leixin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.