anatomical segmentation algorithm
Project description
Cellpose
A generalist algorithm for cell and nucleus segmentation (v1.0) that can be optimized for your own data (v2.0) and (NEW) perform image restoration (v3.0).
Cellpose was written by Carsen Stringer and Marius Pachitariu. To learn about Cellpose3 (image restoration), read the paper. To learn about Cellpose 2.0 (human-in-the-loop), read the paper or watch the talk. To learn about Cellpose 1.0, read the paper or watch the talk. For support, please open an issue.
Please see install instructions below, and also check out the detailed documentation at cellpose.readthedocs.io for more information.
:star2: v3 (Feb 2024) :star2:
Cellpose3 enables image restoration in the GUI, API and CLI (saved to _seg.npy
). To learn more...
- Check out the paper.
- API documentation here
- Example google colab notebook for image restoration: , using new
CellposeDenoiseModel
. - Example google colab notebook with new super-generalist "cyto3" model: . Try out the new
cyto3
super-generalist Cellpose model withmodel_type="cyto3"
.
denoising | deblurring | upsampling |
---|---|---|
CITATION
If you use Cellpose 1, 2 or 3, please cite the Cellpose 1.0 paper:
Stringer, C., Wang, T., Michaelos, M., & Pachitariu, M. (2021). Cellpose: a generalist algorithm for cellular segmentation. Nature methods, 18(1), 100-106.
If you use the human-in-the-loop training, please also cite the Cellpose 2.0 paper:
Pachitariu, M. & Stringer, C. (2022). Cellpose 2.0: how to train your own model. Nature methods, 1-8.
If you use the new image restoration models or cyto3, please also cite the Cellpose3 paper:
Stringer, C. & Pachitariu, M. (2024). Cellpose3: one-click image restoration for improved segmentation. bioRxiv.
:triangular_flag_on_post: All models in Cellpose, except yeast_BF_cp3
, yeast_PhC_cp3
, and deepbacs_cp3
, are trained on some amount of data that is CC-BY-NC. The Cellpose annotated dataset is also CC-BY-NC.
:star2: v2.0 (April 2022) :star2:
Cellpose 2.0 allows human-in-the-loop training of models! To learn more...
- Check out the twitter thread for an overview.
- Check out the paper for more details on the algorithm and the performance. Also, there's a short review of the paper available here.
- Watch the short overview talk and watch the longer tutorial talk which goes through running Cellpose 2.0 in the GUI and a jupyter notebook.
- Check out the full human-in-the-loop video.
- Check out the colab notebook to get cloud access to a GPU to train your models or run your custom models: .
- See how to use it yourself in the docs and also check out the help info in the
Models
menu in the GUI.
Mxnet is no longer supported in cellpose. To use mxnet, please use v1.0.2 (not recommended).
Installation
You can install cellpose using conda or with native python if you have python3.8+ on your machine.
Local installation (< 2 minutes)
System requirements
Linux, Windows and Mac OS are supported for running the code. For running the graphical interface you will need a Mac OS later than Yosemite. At least 8GB of RAM is required to run the software. 16GB-32GB may be required for larger images and 3D volumes. The software has been heavily tested on Windows 10 and Ubuntu 18.04 and less well-tested on Mac OS. Please open an issue if you have problems with installation.
Dependencies
cellpose relies on the following excellent packages (which are automatically installed with conda/pip if missing):
Option 1: Installation Instructions with conda
If you have an older cellpose
environment you can remove it with conda env remove -n cellpose
before creating a new one.
If you are using a GPU, make sure its drivers and the cuda libraries are correctly installed.
- Install an Anaconda distribution of Python. Note you might need to use an anaconda prompt if you did not add anaconda to the path.
- Open an anaconda prompt / command prompt which has
conda
for python 3 in the path - Create a new environment with
conda create --name cellpose python=3.8
. We recommend python 3.8, but python 3.9 and 3.10 will likely work as well. - To activate this new environment, run
conda activate cellpose
- To install the minimal version of cellpose, run
python -m pip install cellpose
. - To install cellpose and the GUI, run
python -m pip install cellpose[gui]
. If you're on a zsh server, you may need to use ' ' around the cellpose[gui] call:python -m pip install 'cellpose[gui]'
.
To upgrade cellpose (package here), run the following in the environment:
python -m pip install cellpose --upgrade
Note you will always have to run conda activate cellpose
before you run cellpose. If you want to run jupyter notebooks in this environment, then also python -m pip install notebook
and python -m pip install matplotlib
.
You can also try to install cellpose and the GUI dependencies from your base environment using the command
python -m pip install cellpose[gui]
If you have issues with installation, see the docs for more details. You can also use the cellpose environment file included in the repository and create a cellpose environment with conda env create -f environment.yml
which may solve certain dependency issues.
If these suggestions fail, open an issue.
Option 2: Installation Instructions with python's venv
Venv (tutorial, for those interested) is a built-in tool in python for creating virtual environments. It is a good alternative if you don't want to install conda and already have python3 on your machine. The main difference is that you will need to choose where to install the environment and the packages. Cellpose will then live in this environment and not be accessible from other environments. You will need to navigate to the environment directory and activate it each time before running cellpose. The steps are similar to the conda installation:
If you are using a GPU, make sure its drivers and the cuda libraries are correctly installed.
- Install python3.8 or later from python.org. This will be the version of python that will be used in the environment. You can check your python version with
python --version
. - Navigate to the directory where you want to create the environment and run
python3 -m venv cellpose
to create a new environment calledcellpose
. - Activate the environment with
source cellpose/bin/activate
on Mac/Linux orcellpose\Scripts\activate
on Windows. A prefix(cellpose)
should appear in the terminal. - Install cellpose into the
cellpose
venv using pip withpython -m pip install cellpose
. - Install the cellpose GUI, with
python -m pip install cellpose[gui]
. Depending on your terminal software, you may need to use quotes like this:python -m pip install 'cellpose[gui]'
. - You can now run cellpose from this environment with
python -m cellpose
orcellpose
if you are in the cellpose directory. - To deactivate the environment, run
deactivate
.
GPU version (CUDA) on Windows or Linux
If you plan on running many images, you may want to install a GPU version of torch (if it isn't already installed).
To use your NVIDIA GPU with python, you will first need to install the NVIDIA driver for your GPU, check out this website to download it. You can also install the CUDA toolkit, or use the pytorch cudatoolkit (installed below with conda). If you have trouble with the below install, we recommend installing the CUDA toolkit yourself, choosing one of the 11.x releases here.
Next we need to remove the CPU version of torch:
pip uninstall torch
To install the GPU version of torch, follow the instructions here. The conda install is strongly recommended, and then choose the CUDA version that is supported by your GPU (newer GPUs may need newer CUDA versions > 10.2). For instance this command will install the 11.6 version on Linux and Windows (note the torchvision
and torchaudio
commands are removed because cellpose doesn't require them):
conda install pytorch pytorch-cuda=11.6 -c pytorch -c nvidia
If the latest CUDA versions don't work, try an older version like cuda 11.3:
conda install pytorch==1.12.0 cudatoolkit=11.3 -c pytorch
Info on how to install several older versions is available here. After install you can check conda list
for pytorch
, and its version info should have cuXX.X
, not cpu
.
Installation of github version
Follow steps from above to install the dependencies. Then run
pip install git+https://www.github.com/mouseland/cellpose.git
If you want edit ability to the code, in the github repository folder, run pip install -e .
. If you want to go back to the pip version of cellpose, then say pip install cellpose
.
Run cellpose 1.0 without local python installation
You can quickly try out Cellpose on the website first (many features disabled).
You can also run Cellpose in google colab with a GPU:
- a code-based notebook:
- a more user-friendly notebook for 2D segmentation written by @pr4deepr:
- a user-friendly ZeroCostDL4Mic notebook that includes training cellpose models, written by @guijacquemet:
The colab notebooks are recommended if you have issues with MKL or run speed on your local computer (and are running 3D volumes). Colab does not allow you to run the GUI, but you can save *_seg.npy
files in colab that you can download and open in the GUI.
Executable file: You can download an executable file for Windows 10 or for Mac OS (High Sierra or greater) that were made using PyInstaller on Intel processors (MKL acceleration works, but no GPU support). Note in both cases it will take a few seconds to open.
- The Mac OS file will download as
cellpose_mac
ORcellpose_mac.dms
. You will need to make it into an executable file and run it through the terminal:
- Open a terminal and run
cd ~/Downloads/
. - Run
chmod 777 cellpose_mac
ORchmod 777 cellpose_mac.dms
to make the file executable. - Run
./cellpose_mac
OR./cellpose_mac.dms
to open the cellpose GUI. Messages from cellpose will be printed in the terminal. - You can also run using the command line interface, e.g. as
./cellpose_mac --dir ~/Pictures/ --chan 2 --save_png
.
- The Windows 10 file is an exe and you can click on it to run the GUI. You can also run using the command line interface, e.g. as
cellpose.exe --dir Pictures/ --chan 2 --save_png
Run cellpose locally
The quickest way to start is to open the GUI from a command line terminal. You might need to open an anaconda prompt if you did not add anaconda to the path:
python -m cellpose
The first time cellpose runs it downloads the latest available trained model weights from the website.
You can now drag and drop any images (*.tif, *.png, *.jpg, *.gif) into the GUI and run Cellpose, and/or manually segment them. When the GUI is processing, you will see the progress bar fill up and during this time you cannot click on anything in the GUI. For more information about what the GUI is doing you can look at the terminal/prompt you opened the GUI with. For example data, see website or this google drive folder. For best accuracy and runtime performance, resize images so cells are less than 100 pixels across.
For 3D data, with multi-Z, please use the 3D version of the GUI with:
python -m cellpose --Zstack
Step-by-step demo
- Download this folder of images and unzip it. These are a subset of the test images from the paper.
- Start the GUI with
python -m cellpose
. - Drag an image from the folder into the GUI.
- Set the model (in demo all are
cyto
) and the channel you want to segment (in demo all aregreen
). Optionally set the second channel if you are segmentingcyto
and have an available nucleus channel. - Click the
calibrate
button to estimate the size of the objects in the image. Alternatively (RECOMMENDED) you can set thecell diameter
by hand and press ENTER. You will see the size you set as a red disk at the bottom left of the image. - Click the
run segmentation
button. If MASKS ON is checked, you should see masks drawn on the image. - Now you can click the LEFT/RIGHT arrow keys to move through the folder and segment another image.
To draw ROIs on the image you can right-click then hover to complete the ROI (do not right-click and drag). To remove ROIs left-click while holding down CTRL. See more details here.
On the demo images each of these steps should run in less than a few seconds on a standard laptop or desktop (with mkl working).
3D segmentation
For multi-channel, multi-Z tiff's, the expected format is Z x channels x Ly x Lx.
Download of pretrained models
The models will be downloaded automatically from the website when you first run a pretrained model in cellpose. If you are having issues with the downloads, you can download them from this google drive zip file, unzip the file and put the models in your home directory under the path .cellpose/models/, e.g. on Windows this would be C:/Users/YOUR_USERNAME/.cellpose/models/ or on Linux this would be /home/YOUR_USERNAME/.cellpose/models/, so /home/YOUR_USERNAME/.cellpose/models/cyto_0 is the full path to one model for example. If you cannot access google drive, the models are also available on baidu: Link:https://pan.baidu.com/s/1CARpRGCBHIYaz7KeyoX-fg ; Fetch code:pose ; thanks to @qixinbo!
Older software releases
UPDATE v1.0 (Jan 2022)
Cellpose has been relatively stable for a while now. Small bugs will continue to be fixed, but we are now releasing a reference 1.0 version. Larger updates to Cellpose will go towards a new 2.0 candidate version to be released soon.
This update fixes bugs in GUI and plotting. It also stops model weight reloading to improve speed. resample=True
is default again as in earlier releases, turn off with --no_resample
. Now logging is turned off by default. Turn on in CLI with --verbose
flag or in a script/notebook by
from cellpose.io import logger_setup
logger_setup();
To install this version please use
pip install cellpose==1.0.2
UPDATE v0.7 (Nov 2021)
Check out Omnipose, an extension of Cellpose for long filamentous bacteria. Omnipose was written by Kevin Cutler (@kevinjohncutler). To learn about Omnipose, read the paper.
UPDATE v0.6 (Dec 2020)
Pytorch is now the default deep neural network software for cellpose. Mxnet will still be supported. To install mxnet (CPU), run pip install mxnet-mkl
. To use mxnet in a notebook, declare torch=False
when creating a model, e.g. model = models.Cellpose(torch=False)
. To use mxnet on the command line, add the flag --mxnet
, e.g. python -m cellpose --dir ~/images/ --mxnet
. The pytorch implementation is 20% faster than the mxnet implementation when running on the GPU and 20% slower when running on the CPU.
Dynamics are computed using bilinear interpolation by default instead of nearest neighbor interpolation. Set interp=False
in model.eval
to turn off. The bilinear interpolation will be slightly slower on the CPU, but it is faster than nearest neighbor if using torch and the GPU is enabled.
Timing (v0.6)
You can check if cellpose is running the MKL version (if you are using the CPU not the GPU) by adding the flag --check_mkl
. If you are not using MKL cellpose will be much slower. Here are Cellpose run times divided into the time it takes to run the deep neural network (DNN) and the time for postprocessing (gradient tracking, segmentation, quality control etc.). The DNN runtime is shown using either a GPU (Nvidia GTX 1080Ti) or a CPU (Intel 10-core 7900X), with or without network ensembling (4net vs 1net). The postprocessing runtime is similar regardless of ensembling or CPU/GPU version. Runtime is shown for different image sizes, all with a cell diameter of 30 pixels (the average from our training set).
256 pix | 512 pix | 1024 pix | |
---|---|---|---|
DNN (1net, GPU) | 0.054 s | 0.12 s | 0.31 s |
DNN (1net, CPU) | 0.30 s | 0.65 s | 2.4 s |
DNN (4net, GPU) | 0.23 s | 0.41 s | 1.3 s |
DNN (4net, CPU) | 1.3 s | 2.5 s | 9.1 s |
Postprocessing (CPU) | 0.32 s | 1.2 s | 6.1 s |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cellpose-3.0.10.tar.gz
.
File metadata
- Download URL: cellpose-3.0.10.tar.gz
- Upload date:
- Size: 23.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02ea4fd752b89bf23393d17a1c55a16de45dd162e77604613789f7fe3d8a84b3 |
|
MD5 | a6f42fac8826cbd71f5f91bdacf8a715 |
|
BLAKE2b-256 | 02f052273f961f5763c985a412eec64420df9c0f738e7f5c165884ce2680143e |
File details
Details for the file cellpose-3.0.10-py3-none-any.whl
.
File metadata
- Download URL: cellpose-3.0.10-py3-none-any.whl
- Upload date:
- Size: 205.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3beeb084187bf4404f024818af6fd1f4c57cd8517d4c16a657797850f9961a3 |
|
MD5 | 36efb83adc062e7c8f689d0496056b7c |
|
BLAKE2b-256 | d75444848abea93aaa788d4a0970d79fb0e5476f8b6d9b656ec8fa1f044d15fa |