Skip to content

Commit 9036c78

Browse files
authored
Update RunCellpose to support v3 and v4 (#276)
* get started * make dictionaries * abstract custom models, support v3/v4 * working display, dockers 3 and 4 * support cp4, explicitly support omnipose * update docs * support cellpose 1-4 * intuitive visible settings, finish saving denoise image * fix denoise display, install instruction * debug GPU * add troubleshooting * variable revision number * only check for cellpose import if using python * RunCellpose troubleshooting * support omnipose in docker * clarify diam * add clear cache * fix custom model use v3 * cleanup
1 parent b117374 commit 9036c78

File tree

10 files changed

+705
-154
lines changed

10 files changed

+705
-154
lines changed

active_plugins/runcellpose.py

Lines changed: 580 additions & 135 deletions
Large diffs are not rendered by default.
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM pytorch/pytorch:1.13.0-cuda11.6-cudnn8-runtime
2+
3+
RUN pip install numpy==1.26.4 cellpose==3.1.1.2
4+
5+
# Include if you wish the image to contain Cellpose pretrained models
6+
COPY download_cellpose_models.py /
7+
RUN python /download_cellpose_models.py
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cellpose
2+
from cellpose.models import MODEL_NAMES
3+
4+
for model in MODEL_NAMES:
5+
for model_index in range(4):
6+
model_name = cellpose.models.model_path(model, model_index)
7+
if model in ("cyto", "nuclei", "cyto2"):
8+
size_model_name = cellpose.models.size_model_path(model)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM pytorch/pytorch:1.13.0-cuda11.6-cudnn8-runtime
2+
3+
RUN pip install numpy==1.26.4 cellpose==4.0.6
4+
5+
# Include if you wish the image to contain Cellpose pretrained models
6+
COPY download_cellpose_models.py /
7+
RUN python /download_cellpose_models.py
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cellpose
2+
from cellpose.models import MODEL_NAMES
3+
4+
for model in MODEL_NAMES:
5+
for model_index in range(4):
6+
model_name = cellpose.models.model_path(model, model_index)
Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,114 @@
11
# RunCellpose
22

3-
RunCellpose is one of the modules that has additional dependencies that are not packaged with the built CellProfiler.
4-
Therefore, you must additionally download RunCellpose's dependencies.
5-
See [Using Plugins](using_plugins.md) for more information.
3+
You can run RunCellpose using Cellpose in a Docker that the module will automatically download for you so you do not have to perform any installation yourself.
4+
See [Using plugins - Using Docker](using_plugins.md/#using-docker-to-bypass-installation-requirements) for more information on using Docker with CellProfiler.
5+
6+
You can also this module using Cellpose installed to the same Python environment as CellProfiler.
7+
See [Using plugins - Installing dependencies](using_plugins.md/#installing-plugins-with-dependencies-using-cellprofiler-from-source) for more information on installing dependencies for CellProfiler plugins.
8+
9+
## Troubleshooting
10+
11+
If you are running RunCellpose in a docker and you get an error like this:
12+
`No such file or directory: '/Users/eweisbar/Documents/CPoutput/.cellprofiler_temp/c564a507-17e5-4256-837d-6e1d59892524/img/c564a507-17e5-4256-837d-6e1d59892524_seg.npy`
13+
It is likely an issue with running out of memory in the Docker.
14+
See [this Github issue](https://github.com/CellProfiler/CellProfiler-plugins/issues/243) for more information.
15+
16+
If you open a saved pipeline that contains the RunCellpose module and your saved settings are not parsed properly, we recommend you add a new RunCellpose module to your pipeline and copy the settings from the old module to the new module.
17+
18+
If you get an error message indicating the Docker selected in your pipeline is not available, this is likely because we updated the Docker image names to more explicitly indicate which version of Cellpose they are using.
19+
Please select one of the updated Docker image names in your pipeline.
20+
21+
## Installing Cellpose in the same Python environment as CellProfiler
22+
23+
We provide some information below about installations that have worked for us.
24+
If you are having challenges with installing Cellpose in your CellProfiler environment, please reach out on the [forum](https://forum.image.sc/).
25+
26+
### Omnipose (Cellpose 1)
27+
28+
In an environment that has Cellprofiler installed, run the following commands to install Omnipose and Cellpose 1:
29+
30+
```bash
31+
pip install omnipose
32+
pip install cellpose==1.0.2
33+
```
34+
35+
### Cellpose 2
36+
37+
In an environment that has Cellprofiler installed, run the following commands to install Cellpose 2:
38+
39+
```bash
40+
pip install cellpose==2.3.2
41+
```
42+
43+
If you have an older version of Cellpose, run the following command to reinstall Cellpose 2:
44+
45+
```bash
46+
python -m pip install --force-reinstall -v cellpose==2.3.2
47+
```
48+
49+
### Cellpose 3
50+
51+
On Mac M1/M2, to create a new environment with CellProfiler and Cellpose 4, run the following commands:
52+
53+
```bash
54+
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
55+
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
56+
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
57+
conda create -y --force -n cellpose3_cellprofiler python=3.9 h5py=3.6.0 python.app scikit-learn==0.24.2 scikit-image==0.18.3 openjdk --platform osx-arm64
58+
conda activate cellpose3_cellprofiler
59+
pip install cellpose==3.1.1.2
60+
pip install mysqlclient==1.4.6 cellprofiler
61+
```
62+
63+
### Cellpose-SAM (Cellpose 4)
64+
65+
On Mac M1/M2, to create a new environment with CellProfiler and Cellpose 4, run the following commands:
66+
67+
```bash
68+
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
69+
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
70+
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
71+
conda create -y --force -n cellposeSAM_cellprofiler python=3.9 h5py=3.6.0 python.app scikit-learn==0.24.2 scikit-image==0.18.3 openjdk --platform osx-arm64
72+
conda activate cellposeSAM_cellprofiler
73+
pip install cellpose==4.0.6
74+
pip install mysqlclient==1.4.6 cellprofiler
75+
```
676

777
## Using RunCellpose with a GPU
878

9-
If you want to use a GPU to run the model (this is recommended for speed), you'll need a compatible version of PyTorch and a supported GPU.
79+
If you want to use a GPU to run the model (this is recommended for speed), you'll need a compatible version of PyTorch and a supported GPU.
1080
General instructions are available at this [link](https://pytorch.org/get-started/locally/).
1181

12-
1. Your GPU should be visible in Device Manager under Display Adaptors.
82+
1. Your GPU should be visible in Device Manager under Display Adaptors.
1383
If your GPU isn't there, you likely need to install drivers.
1484
[Here](https://www.nvidia.com/Download/Find.aspx) is where you can find NVIDIA GPU drivers if you need to install them.
1585

16-
1786
2. To test whether the GPU is configured correctly:
18-
* Run `python` on the command line (i.e., in Command Prompt or Terminal) to start an interactive session
19-
* Then run the following
20-
```
87+
88+
* Run `python` on the command line (i.e., in Command Prompt or Terminal) to start an interactive session
89+
* Then run the following
90+
91+
```bash
2192
import torch
2293
torch.cuda.is_available()
2394
```
24-
* If this returns `True`, you're all set
25-
* If this returns `False`, you likely need to install/reinstall torch. See [here](https://pytorch.org/get-started/locally/) for your exact command.
26-
* Exit the session with `exit()` then install torch if necessary
27-
```
95+
96+
* If this returns `True`, you're all set
97+
* If this returns `False`, you likely need to install/reinstall torch. See [here](https://pytorch.org/get-started/locally/) for your exact command.
98+
* Exit the session with `exit()` then install torch if necessary
99+
100+
```bash
28101
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
29102
```
30-
If you have a previous version of torch installed, make sure to run `pip uninstall torch` first.
31103

104+
If you have a previous version of torch installed, make sure to run `pip uninstall torch` first.
32105

33106
**NOTE**: You might get a warning like this:
34-
```
107+
108+
```bash
35109
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
36110
2022-05-26 20:24:21.906286: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
37111
```
38-
If you don't have a GPU, this is not a problem. If you do, your configuration is incorrect and you need to try reinstalling drivers and the correct version of CUDA for your system.
112+
113+
If you don't have a GPU, this is not a problem.
114+
If you do, your configuration is incorrect and you need to try reinstalling drivers and the correct version of CUDA for your system.

documentation/CP-plugins-documentation/supported_plugins.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ Those plugins that do have extra documentation contain links below.
1515
| CalculateMoments | CalculateMoments extracts moments statistics from a given distribution of pixel values. | No | | N/A |
1616
| CallBarcodes | CallBarcodes is used for assigning a barcode to an object based on the channel with the strongest intensity for a given number of cycles. It is used for optical sequencing by synthesis (SBS). | No | | N/A |
1717
| CompensateColors | CompensateColors determines how much signal in any given channel is because of bleed-through from another channel and removes the bleed-through. It can be performed across an image or masked to objects and provides a number of preprocessing and rescaling options to allow for troubleshooting if input image intensities are not well matched. | No | | N/A |
18+
| ConvertObjectsToOutlines | ConvertObjectsToOutlines takes in black images with white object outlines and uses them to predict objects. See [Ask Erin Dear Beth video podcast](https://youtu.be/qWYyp_a0IHM) for a walkthrough of using the module. | No | | N/A |
1819
| DistanceTransform | DistanceTransform computes the distance transform of a binary image. The distance of each foreground pixel is computed to the nearest background pixel and the resulting image is then scaled so that the largest distance is 1. | No | | N/A |
1920
| EnforceObjectsOneToOne| EnforceObjectsOneToOne generates Primary and Secondary object relationships for any pair of objects in a similar manner to the relationships established by IdentifyPrimaryObjects and IdentifySecondaryObjects. It is particularly useful for relating objects identified using Deep Learning. | No | | N/A |
2021
| EnhancedMeasureTexture| EnhancedMeasureTexture measures the degree and nature of textures within an image or objects in a more comprehensive/tuneable manner than the MeasureTexture module native to CellProfiler. | No | | N/A |
2122
| FilterObjects_StringMatch| FilterObjects_StringMatch allows filtering of objects using exact or partial string matching in a manner similar to FilterObjects. | No | | N/A |
2223
| HistogramEqualization | HistogramEqualization increases the global contrast of a low-contrast image or volume. Histogram equalization redistributes intensities to utilize the full range of intensities, such that the most common frequencies are more distinct. This module can perform either global or local histogram equalization. | No | | N/A |
2324
| HistogramMatching | HistogramMatching manipulates the pixel intensity values an input image and matches them to the histogram of a reference image. It can be used as a way to normalize intensities across different 2D or 3D images or different frames of the same 3D image. It allows you to choose which frame to use as the reference. | No | | N/A |
2425
| PixelShuffle | PixelShuffle takes the intensity of each pixel in an image and randomly shuffles its position. | No | | N/A |
25-
| [RunCellpose](RunCellPose.md) | RunCellpose allows you to run Cellpose within CellProfiler. Cellpose is a generalist machine-learning algorithm for cellular segmentation and is a great starting point for segmenting non-round cells. You can use pre-trained Cellpose models or your custom model with this plugin. You can use a GPU with this module to dramatically increase your speed/efficiency. | Yes | `cellpose` | Yes |
26+
| [RunCellpose](RunCellPose.md) | RunCellpose allows you to run Cellpose within CellProfiler. Cellpose is a generalist machine-learning algorithm for cellular segmentation and is a great starting point for segmenting non-round cells. You can use pre-trained Cellpose models or your custom model with this plugin. You can use a GPU with this module to dramatically increase your speed/efficiency. It currently supports Cellpose 1-4. | Yes | `cellpose` | Yes |
2627
| Runilastik | Runilasitk allows to run ilastik within CellProfiler. You can use pre-trained ilastik projects/models to predict the probability of your input images. The plugin supports two types of ilastik projects: Pixel Classification and Autocontext (2-stage).| Yes | | Yes |
2728
| RunImageJScript | RunImageJScript allows you to run any supported ImageJ script directly within CellProfiler. It is significantly more performant than RunImageJMacro, and is also less likely to leave behind temporary files. | Yes | `imagejscript` , though note that conda installation may be preferred, see [this link](https://py.imagej.net/en/latest/Install.html#installing-via-pip) for more information | No |
28-
| RunOmnipose | RunOmnipose allows you to run Omnipose within CellProfiler. Omnipose is a general image segmentation tool that builds on Cellpose. | Yes | `omnipose` | No |
29+
| RunOmnipose | RunOmnipose allows you to run Omnipose within CellProfiler. Omnipose is a general image segmentation tool that builds on Cellpose. Omnipose usage is also supported from within the RunCellpose module. | Yes | `omnipose` | No |
2930
| RunStarDist | RunStarDist allows you to run StarDist within CellProfiler. StarDist is a machine-learning algorithm for object detection with star-convex shapes making it best suited for nuclei or round-ish cells. You can use pre-trained StarDist models or your custom model with this plugin. You can use a GPU with this module to dramatically increase your speed/efficiency. RunStarDist is generally faster than RunCellpose. | Yes | `stardist` | No |
31+
| RunVista2D | This module uses a pre-trained VISTA2D model to detect cell objects in an image. | No | | N/A |
3032
| VarianceTransform | This module allows you to calculate the variance of an image, using a determined window size. It also has the option to find the optimal window size from a predetermined range to obtain the maximum variance of an image. | No | | N/A |

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
]
1212

1313
cellpose_deps = [
14-
"cellpose>=1.0.2,<3.0"
14+
"cellpose>=1.0.2,<5.0"
1515
]
1616

1717
omnipose_deps = [

0 commit comments

Comments
 (0)