angelolab / Nimbus

Other
12 stars 1 forks source link

Prediction notebook #65

Closed JLrumberger closed 1 year ago

JLrumberger commented 1 year ago

What is the purpose of this PR?

This PR closes #64 and adds the class Nimbus which extends the class deepcell.applications.Application and gives an interface for all things inference. The class first checks its inputs, loads the model, then prepares the normalization dictionary and does predictions. In addition, the class NimbusViewer implements a viewer widget, than can be used to scroll through FOVs and show input channels and output predictions side by side for visual inspection of the results. Both classes are used in the predict.ipynb to first predict model confidence scores and then inspect them.

How did you implement your changes

  1. I added several functions to inference.py that implement a functional interface for inference. The following functions are there

    • prepare_normalization_dict: iterates through FoVs and calculates the normalization quantile. Has the option to run parallel via joblib.
    • prepare_input_data: turns the segmentation map to a binary representation with eroded edges
    • segment_mean: takes instance segmentation map and another image and returns mean per cell expression profiles.
    • test_time_aug: Does inference over a batch of flipped and 90°-rotated images and returns the average over these transformations. This is known to improve results slightly.
    • predict_fovs: iterates through fovs and predicts
  2. I added the class Nimbus that extends deepcell.applications.Application and gives a class-based interface to the above mentioned inference functions.

    • check_input: Checks the input for correctness
    • initialize_model: Initializes ML model and loads the model checkpoint
    • prepare_normalization_dict: does what it says :)
    • predict_fovs: iteratives through fovs, predicts and stores them
  3. NimbusViewer is a class that implements an ipywidget to view multiplexed channels and predicted model confidence scores side-by-side and allows the user to choose which FOV and channels to look at.

Remaining issues NimbusViewer does not have tests yet. I'll look into the Pixie repo to see how widgets can be tested.

review-notebook-app[bot] commented 1 year ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

JLrumberger commented 1 year ago

I'll add a few more tests for the viewer widget tomorrow and then will merge this PR before the workshop. Is that okay @ngreenwald ?