Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
715 changes: 580 additions & 135 deletions active_plugins/runcellpose.py

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dockerfiles/RunCellpose_Cellposev3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM pytorch/pytorch:1.13.0-cuda11.6-cudnn8-runtime

RUN pip install numpy==1.26.4 cellpose==3.1.1.2

# Include if you wish the image to contain Cellpose pretrained models
COPY download_cellpose_models.py /
RUN python /download_cellpose_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import cellpose
from cellpose.models import MODEL_NAMES

for model in MODEL_NAMES:
for model_index in range(4):
model_name = cellpose.models.model_path(model, model_index)
if model in ("cyto", "nuclei", "cyto2"):
size_model_name = cellpose.models.size_model_path(model)
7 changes: 7 additions & 0 deletions dockerfiles/RunCellpose_Cellposev4/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM pytorch/pytorch:1.13.0-cuda11.6-cudnn8-runtime

RUN pip install numpy==1.26.4 cellpose==4.0.6

# Include if you wish the image to contain Cellpose pretrained models
COPY download_cellpose_models.py /
RUN python /download_cellpose_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import cellpose
from cellpose.models import MODEL_NAMES

for model in MODEL_NAMES:
for model_index in range(4):
model_name = cellpose.models.model_path(model, model_index)
108 changes: 92 additions & 16 deletions documentation/CP-plugins-documentation/runcellpose.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,114 @@
# RunCellpose

RunCellpose is one of the modules that has additional dependencies that are not packaged with the built CellProfiler.
Therefore, you must additionally download RunCellpose's dependencies.
See [Using Plugins](using_plugins.md) for more information.
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.
See [Using plugins - Using Docker](using_plugins.md/#using-docker-to-bypass-installation-requirements) for more information on using Docker with CellProfiler.

You can also this module using Cellpose installed to the same Python environment as CellProfiler.
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.

## Troubleshooting

If you are running RunCellpose in a docker and you get an error like this:
`No such file or directory: '/Users/eweisbar/Documents/CPoutput/.cellprofiler_temp/c564a507-17e5-4256-837d-6e1d59892524/img/c564a507-17e5-4256-837d-6e1d59892524_seg.npy`
It is likely an issue with running out of memory in the Docker.
See [this Github issue](https://github.com/CellProfiler/CellProfiler-plugins/issues/243) for more information.

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.

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.
Please select one of the updated Docker image names in your pipeline.

## Installing Cellpose in the same Python environment as CellProfiler

We provide some information below about installations that have worked for us.
If you are having challenges with installing Cellpose in your CellProfiler environment, please reach out on the [forum](https://forum.image.sc/).

### Omnipose (Cellpose 1)

In an environment that has Cellprofiler installed, run the following commands to install Omnipose and Cellpose 1:

```bash
pip install omnipose
pip install cellpose==1.0.2
```

### Cellpose 2

In an environment that has Cellprofiler installed, run the following commands to install Cellpose 2:

```bash
pip install cellpose==2.3.2
```

If you have an older version of Cellpose, run the following command to reinstall Cellpose 2:

```bash
python -m pip install --force-reinstall -v cellpose==2.3.2
```

### Cellpose 3

On Mac M1/M2, to create a new environment with CellProfiler and Cellpose 4, run the following commands:

```bash
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
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
conda activate cellpose3_cellprofiler
pip install cellpose==3.1.1.2
pip install mysqlclient==1.4.6 cellprofiler
```

### Cellpose-SAM (Cellpose 4)

On Mac M1/M2, to create a new environment with CellProfiler and Cellpose 4, run the following commands:

```bash
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
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
conda activate cellposeSAM_cellprofiler
pip install cellpose==4.0.6
pip install mysqlclient==1.4.6 cellprofiler
```

## Using RunCellpose with a GPU

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.
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.
General instructions are available at this [link](https://pytorch.org/get-started/locally/).

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


2. To test whether the GPU is configured correctly:
* Run `python` on the command line (i.e., in Command Prompt or Terminal) to start an interactive session
* Then run the following
```

* Run `python` on the command line (i.e., in Command Prompt or Terminal) to start an interactive session
* Then run the following

```bash
import torch
torch.cuda.is_available()
```
* If this returns `True`, you're all set
* If this returns `False`, you likely need to install/reinstall torch. See [here](https://pytorch.org/get-started/locally/) for your exact command.
* Exit the session with `exit()` then install torch if necessary
```

* If this returns `True`, you're all set
* If this returns `False`, you likely need to install/reinstall torch. See [here](https://pytorch.org/get-started/locally/) for your exact command.
* Exit the session with `exit()` then install torch if necessary

```bash
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
```
If you have a previous version of torch installed, make sure to run `pip uninstall torch` first.

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

**NOTE**: You might get a warning like this:
```

```bash
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
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.
```
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.

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.
6 changes: 4 additions & 2 deletions documentation/CP-plugins-documentation/supported_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Those plugins that do have extra documentation contain links below.
| CalculateMoments | CalculateMoments extracts moments statistics from a given distribution of pixel values. | No | | N/A |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| FilterObjects_StringMatch| FilterObjects_StringMatch allows filtering of objects using exact or partial string matching in a manner similar to FilterObjects. | No | | N/A |
| 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 |
| 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 |
| PixelShuffle | PixelShuffle takes the intensity of each pixel in an image and randomly shuffles its position. | No | | N/A |
| [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 |
| [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 |
| 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 |
| 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 |
| RunOmnipose | RunOmnipose allows you to run Omnipose within CellProfiler. Omnipose is a general image segmentation tool that builds on Cellpose. | Yes | `omnipose` | No |
| 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 |
| 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 |
| RunVista2D | This module uses a pre-trained VISTA2D model to detect cell objects in an image. | No | | N/A |
| 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 |
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]

cellpose_deps = [
"cellpose>=1.0.2,<3.0"
"cellpose>=1.0.2,<5.0"
]

omnipose_deps = [
Expand Down