Git Product home page Git Product logo

devolearn's Introduction

Build Status codecov Open In Colab

Contents

Installation

pip install devolearn

Example notebooks

Segmenting the Cell Membrane in C. elegans embryo

  • Importing the model
from devolearn import cell_membrane_segmentor
segmentor = cell_membrane_segmentor()
  • Running the model on an image and viewing the prediction
seg_pred = segmentor.predict(image_path = "sample_data/images/seg_sample.jpg")
plt.imshow(seg_pred)
plt.show()
  • Running the model on a video and saving the predictions into a folder
filenames = segmentor.predict_from_video(video_path = "sample_data/videos/seg_sample.mov", centroid_mode = False, save_folder = "preds")
  • Finding the centroids of the segmented features
seg_pred, centroids = segmentor.predict(image_path = "sample_data/images/seg_sample.jpg", centroid_mode = True)
plt.imshow(seg_pred)
plt.show()
  • Saving the centroids from each frame into a CSV
df = segmentor.predict_from_video(video_path = "sample_data/videos/seg_sample.mov", centroid_mode = True, save_folder = "preds")
df.to_csv("centroids.csv")

Segmenting the Cell Nucleus in C. elegans embryo

  • Importing the model
from devolearn import cell_nucleus_segmentor
segmentor = cell_nucleus_segmentor()
  • Running the model on an image and viewing the prediction
seg_pred = segmentor.predict(image_path = "sample_data/images/nucleus_seg_sample.jpg")
plt.imshow(seg_pred)
plt.show()

Generating synthetic images of embryos with a Pre-trained GAN

  • Importing the model
from devolearn import Generator, embryo_generator_model
generator = embryo_generator_model()
  • Generating a picture and viewing it with matplotlib
gen_image = generator.generate()  
plt.imshow(gen_image)
plt.show()
  • Generating n images and saving them into foldername with a custom size
generator.generate_n_images(n = 5, foldername= "generated_images", image_size= (700,500))

Predicting populations of cells within the C. elegans embryo

  • Importing the population model for inferences
from devolearn import lineage_population_model
  • Loading a model instance to be used to estimate lineage populations of embryos from videos/photos.
model = lineage_population_model(device = "cpu")
  • Making a prediction from an image
print(model.predict(image_path = "sample_data/images/embryo_sample.png"))
  • Making predictions from a video and saving the predictions into a CSV file
results = model.predict_from_video(video_path = "sample_data/videos/embryo_timelapse.mov", save_csv = True, csv_name = "video_preds.csv", ignore_first_n_frames= 10, ignore_last_n_frames= 10, postprocess = False)
  • Plotting the model's predictions from a video
plot = model.create_population_plot_from_video(video_path = "sample_data/videos/embryo_timelapse.mov", save_plot= True, plot_name= "plot.png", ignore_last_n_frames= 0, postprocess = False)
plot.show()

Links to Datasets

Model Data source
Segmenting the cell membrane in C. elegans embryo 3DMMS: robust 3D Membrane Morphological Segmentation of C. elegans embryo
Segmenting the nucleus in C. elegans embryo C. elegans Cell-Tracking-Challenge dataset
Cell lineage population prediction + embryo GAN EPIC dataset

Links to HuggingFace spaces

Model Huggingface
Segmenting the cell membrane in C. elegans embryo Cell Membrane segmentor
Segmenting the nucleus in C. elegans embryo C. elegans Nucleus segmentor
Cell lineage population prediction Lineage population

Authors/maintainers:

Feel free to join our Slack workspace!

devolearn's People

Contributors

abtaha avatar alon1samuel avatar devoworm avatar iammarco11 avatar jainal09 avatar jesparent avatar joel-hanson avatar kingjuno avatar mainakdeb avatar mayukhdeb avatar orthogonal-research-lab avatar pakhi07 avatar ravikarrii avatar rtharungowda avatar rudrajit1729 avatar s0mnaths avatar shruti-raj-vansh-singh avatar sushmanthreddy avatar sushumereddy avatar ujjwalll avatar vrutikrabadia avatar watarungurunnn 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

devolearn's Issues

__init__.py: reformat __all__

The list __all__ currently looks like:

__all__ = ["lineage_populaton_model",
            "embryo_generator_model",
            "embryo_segmentor",
            "tests"]

But we want it to look like the one shown below:

__all__ = [
    "lineage_populaton_model",
    "embryo_generator_model",
    "embryo_segmentor",
    "tests"
]

tests: deprecation warning when importing collections

After cloning the repo, running python setup.py test throws a warning as follows:

 DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working

tests: unit tests do not check the outputs of models

While the unit tests do cover the output types, they do not check if the outputs themselves are correct/incorrect.

To do:

  • Use some loss function w.r.t ideal outputs and make sure the losses are low enough
  • Make sure the output dtype matches the original (int, float32, float64)

devolearn: add links to documentation in comments

Someone has to add link(s) to the documentation within the function comments.

It is fine to add only one link to only one function to make a PR. We do not require for you to add all the links for all the functions.

Please see the example below:

I'll be referring to line 58 in the lineage_population_model.py

The snippet there currently looks like this:

    def predict(self, image_path):

        """
        input{
            image path <str>
        }
        output{
            dictionary containing the cell population values <dict>
        }

But we want somehting like:

    def predict(self, image_path):

        """
        reference{
            https://github.com/DevoLearn/devolearn#predicting-populations-of-cells-within-the-c-elegans-embryo
        } 
        input{
            image path <str>
        }
        output{
            dictionary containing the cell population values <dict>
        }

build a base InferenceEngine class

the models in devolearn have different architectures, and different purposes. But it would be great if all of the models come under one single base class like:

class InferenceEngine():
    def __init__self(model, checkpoint, preprocess, deprocess, device = 'cuda'):
        self.model = model
        self.model.load_state_dict(torch.load(checkpoint))
        self.model.to(device)

    def inference(self, x):
        x = self.preprocess(x)
        pred = self.model(x)
        return self.deprocess(pred)

    ...other methods...

    def __repr__(self):
        return self.model

devolearn: long term vision

This issue would be a tracker/conversation space for devolearn's core long term goals.

Here are some of the key goals to work on:

  • every model should be a subclass of devolearn.base_inference_engine.InferenceEngine
  • InferenceEngine would contain some predefined (but overrideable) methods to:
    • Download model checkpoints from github source
    • Preprocess images for inference
    • Postprocess predictions for readability/saving
  • devolearn.IoPipeline would contain some standardized media tools for reading and writng videos/images (might use decord/imageio for videos and cv2 for images)
  • a docker based fastAPI endpoint could be created (only after the above objectives are complete). This would help us deploy the models into servers/webapps/GUIs

The picture attached below is the layout of how we want to see it ⬇️

devolearn_vision

If you have any suggestions/ideas, feel free to discuss below :)

cc: @balicea @ujjwalll

setup.py: change description

The current description on line 11 looks like:

description="Accelerate data driven research on embryos with deep learning models",

But we want it to be like:

description="Accelerate data driven research in developmental biology with deep learning models",

Try to integrate streamlit

Streamlit seems to be an amazing option for deploying python backends with a clean GUI. We should definitely explore possibilities of building a GUI with streamlit for devolearn

CI: move to pytest+codecov

Currently devolearn uses a relatively simple testing suite i.e python3 setup.py test. But a much cleaner alternative would be to use pytest for testing and codecov for coverage reports.

Why use coverage reports ?
They help us see how much of the code is being tested after each push, this'll help us find the pieces of code that are important but remain untested.

Why pytest ?
From my own personal experience, python3 setup.py test crashes without an error message when the user tries to access a CUDA device (GPU) on the github actions runtime. This error would've been impossible to fix if I hadn't moved to using pytest (which showed me the proper error message).

changes are needed in main.yml file about python versions

@Mayukhdeb In main.yml file whenever it was testing with python versions ,it was testing with previous versions of python 3.8 and 3.7 ,and most these versions are almost deprecated and most of the libraries which are installed through requirements.txt are latest version, which are not compatible with old version , this is causing some issues when we are testing .It needs to be changed ,I think so, and these should updated for new python version

Missing tqdm.notebook mode

For now, devolearn works with tqdm.tqdm and not tqdm.notebook, but that's not suitable for jupyter notebook environments

should make something like notebook_mode = True for the functions that use tqdm

Colab demo requires multiple upgrades

  1. Devolearn requires torch==1.7, but I think it would also work with the latest versions of torch. Using the latets version of torch would make the installation much faster on google colab notebooks because the latest version of torch is already installed there.
  2. The URL for the weights to the embryo segmentation model is most likely broken, throws an HTTP error.
  3. arg mode = 'cpu' should be replaced with device = 'cpu'
  4. optionally, we can also let the user decide the GPU ID like device = 'cuda:0'
  5. move the run tests cell to the bottom

Note that this is a beginner friendly issue, all the changes are to be done on this notebook. Feel free to reply to this if you're willing to take this up.

generate docstrings

Docstrings make our code much more usable and adds useful information which can be useful when debugging. Check out this link if you want to know more and generate docstrings for devolearn.

setup: installation on colab initiates reinstallation of PyTorch

Devolearn was written with Pytorch 1.7.0. but it might as well work on most of the more the other Pytorch versions (like the one on colab). If that is true, then we might not need this long reinstallation on google colab every time we do pip install devolearn

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.