Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose additional cellpose options in the task #649

Closed
jluethi opened this issue Jan 31, 2024 · 2 comments · Fixed by #650
Closed

Expose additional cellpose options in the task #649

jluethi opened this issue Jan 31, 2024 · 2 comments · Fixed by #650

Comments

@jluethi
Copy link
Collaborator

jluethi commented Jan 31, 2024

Some users need advanced options when running Cellpose tasks. We should expose more of them (& figure out how to separate between regular options and advanced options).

A few options that have come up that would be good to expose:
Normalization/Quantile rescaling. This leads to issues in sparse images when not turned off otherwise.

Main parameters I'd like to expose:

  • normalize: bool (optional, default True) normalize data so 0.0=1st percentile and 1.0=99th percentile of image intensities in each channel

Other parameters that we could also expose, just to have all options available:

  • batch_size (int, default 8): Patches that are processed in parallel on the GPI. Description: int (optional, default 8) number of 224x224 patches to run simultaneously on the GPU (can make smaller or bigger depending on GPU memory usage)
  • invert: bool (optional, default False) invert image pixel intensity before running network (if True, image is also normalized) => does not hurt to expose
  • tile: bool (optional, default True) tiles image to ensure GPU/CPU memory usage limited (recommended) => not hurt in exposing this
  • tile_overlap: float (optional, default 0.1) fraction of overlap of tiles when computing flows => no hurt in exposing this
  • resample: bool (optional, default True) run dynamics at original image size (will be slower but create more accurate boundaries) => no hurt in exposing this
  • interp: bool (optional, default True) interpolate during 2D dynamics (not available in 3D) (in previous versions it was False) => no hurt in exposing this
  • stitch_threshold: float (optional, default 0.0) if stitch_threshold>0.0 and not do_3D and equal image sizes, masks are stitched in 3D to return volume segmentation

Parameters we shouldn't currently expose:

  • channel_axis: We manually handle the order of channels via channel1, channel2 input
  • z_axis: I don't understand what that would do. See documentation: int (optional, default None) if None, z dimension is attempted to be automatically determined
  • rescale: float (optional, default None) if diameter is set to None, and rescale is not None, then rescale is used instead of diameter for resizing image: We enforce a diameter being passed, thus this option is not relevant

Open questions
Can we provide other rescaling strategies? One idea is letting the user provide the rescaling quantiles (e.g. so they could set them to 0.0, 0.99999). The Cellpose API doesn't seem to provide one. One approach would be that Fractal itself performs some form of rescaling before passing the image to the Cellpose API. Cellpose rescales the image to be a float32 between 0 & 1.
The open questions would be: What statistics are used to determine this rescaling values. Fixed-values, quantiles or statistics of a whole dataset?
(cc @fstur for discussions we've been having on this recently)

All these options are in the model.eval call: https://github.com/MouseLand/cellpose/blob/4f5661983c3787efa443bbbd3f60256f4fd8bf53/cellpose/models.py#L109

And would need to be added here in Fractal:

@jluethi
Copy link
Collaborator Author

jluethi commented Jan 31, 2024

Only exposing the options does not deal with the sparsity issue we were having. In my tests, setting normalize = False with our existing (underexposed) 16bit images just leads to Cellpose not finding any objects.

I suspect we'd really have to implement rescaling of the data outside of cellpose to make this work. Will take a bit of experimentation on whether it makes sense to pass float32 normalized datasets to cellpose or not. And if that's the correct way, would need to think about the best way to expose this in the task

@jluethi
Copy link
Collaborator Author

jluethi commented Feb 6, 2024

See this issue in the Cellpose repo for more context: MouseLand/cellpose#795

The hard-set normalization to either nothing (basically always seems to result in an empty segmentation) or 1st to 99th percentile (can be too harsh on sparse images) has been shown to be an issue by others.

I'm currently working on an option to the Fractal task to normalize the images pass to the cellpose model beforehand. That seems to do the trick. I'll investigate a bit more in #650

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant