11Models
2- ------------------------------
2+ -------------------------------
33
44``from cellpose import models ``
55
6- Each model will be downloaded automatically to your ``models.MODELS_DIR ``
7- (see Installation instructions for more details on MODELS_DIR).
8- You can also directly download a model by going to the URL, e.g.:
6+ Each model will be downloaded automatically to your ``models.MODELS_DIR `` (see
7+ Installation instructions for more details on MODELS_DIR). You can also directly
8+ download a model by going to the URL, e.g.:
99
1010``https://www.cellpose.org/models/MODEL_NAME ``
1111
1212All built-in models were trained with the ROIs resized to a diameter of 30.0
13- (``diam_mean = 30 ``),
14- except the `'nuclei' ` model which was trained with a diameter of 17.0
15- (``diam_mean = 17 ``). User-trained models will be trained with the same ``diam_mean ``
16- as the model they are initalized with.
17- The models will internally take care of rescaling the images given a
18- user-provided diameter (or with the diameter from
19- auto-diameter estimation in full models).
13+ (``diam_mean = 30 ``), except the `'nuclei' ` model which was trained with a
14+ diameter of 17.0 (``diam_mean = 17 ``). User-trained models will be trained with
15+ the same ``diam_mean `` as the model they are initalized with. The models will
16+ internally take care of rescaling the images given a user-provided diameter (or
17+ with the diameter from auto-diameter estimation in full models).
2018
2119Full built-in models
22- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2321
24- These models have Cellpose model weights and a size model. This means you can
25- run with ``diameter=0 `` or ``--diameter 0 `` and the model can estimate the ROI size.
26- However, we recommend that you set the diameter for your ROIs rather than having Cellpose
27- guess the diameter.
22+ These models have Cellpose model weights and a size model. This means you can
23+ run with ``diameter=0 `` or ``--diameter 0 `` and the model can estimate the ROI
24+ size. However, we recommend that you set the diameter for your ROIs rather than
25+ having Cellpose guess the diameter.
2826
29- These models can be loaded and used in the notebook with ``models.Cellpose(model_type='cyto3') ``
30- or in the command line with ``python -m cellpose --pretrained_model cyto3 ``.
27+ These models can be loaded and used in the notebook with
28+ ``models.Cellpose(model_type='cyto3') `` or in the command line with ``python -m
29+ cellpose --pretrained_model cyto3 ``.
3130
32- We have a ``nuclei `` model and a super-generalist ``cyto3 `` model. There are also two
33- older models, ``cyto ``, which is trained on only the Cellpose training set, and `` cyto2 ``,
34- which is also trained on user-submitted images.
31+ We have a ``nuclei `` model and a super-generalist ``cyto3 `` model. There are
32+ also two older models, ``cyto ``, which is trained on only the Cellpose training
33+ set, and `` cyto2 ``, which is also trained on user-submitted images.
3534
36- FYI we are no longer using the 4 different versions and ``--net_avg `` is deprecated.
35+ FYI we are no longer using the 4 different versions and ``--net_avg `` is
36+ deprecated.
3737
3838Cytoplasm model (``'cyto3' ``, ``'cyto2' ``, ``'cyto' ``)
39- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040
41- The cytoplasm models in cellpose are trained on two-channel images, where
42- the first channel is the channel to segment, and the second channel is
43- an optional nuclear channel. Here are the options for each:
44- 1. 0=grayscale, 1=red, 2=green, 3=blue
45- 2. 0=None (will set to zero), 1=red, 2=green, 3=blue
41+ The cytoplasm models in cellpose are trained on two-channel images, where the
42+ first channel is the channel to segment, and the second channel is an optional
43+ nuclear channel. Here are the options for each: 1. 0=grayscale, 1=red, 2=green,
44+ 3=blue 2. 0=None (will set to zero), 1=red, 2=green, 3=blue
4645
47- Set channels to a list with each of these elements, e.g.
48- `` channels = [0,0] `` if you want to segment cells in grayscale or for single channel images, or
46+ Set channels to a list with each of these elements, e.g. `` channels = [0,0] `` if
47+ you want to segment cells in grayscale or for single channel images, or
4948``channels = [2,3] `` if you green cells with blue nuclei.
5049
5150The `'cyto3' ` model is trained on 9 datasets, see the `Cellpose3 paper <https://www.biorxiv.org/content/10.1101/2024.02.10.579780v2 >`_
@@ -57,27 +56,28 @@ The size models are ``size_cytotorch_0.npy``, ``size_cyto2torch_0.npy``, and ``s
5756Nucleus model (`'nuclei' `)
5857^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5958
60- The nuclear model in cellpose is trained on two-channel images, where
61- the first channel is the channel to segment, and the second channel is
62- always set to an array of zeros. Therefore set the first channel as
63- 0=grayscale, 1=red, 2=green, 3=blue; and set the second channel to zero, e.g.
64- `` channels = [0,0] `` if you want to segment nuclei in grayscale or for single channel images, or
65- `` channels = [3,0] `` if you want to segment blue nuclei.
59+ The nuclear model in cellpose is trained on two-channel images, where the first
60+ channel is the channel to segment, and the second channel is always set to an
61+ array of zeros. Therefore set the first channel as 0=grayscale, 1=red, 2=green,
62+ 3=blue; and set the second channel to zero, e.g. `` channels = [0,0] `` if you
63+ want to segment nuclei in grayscale or for single channel images, or `` channels
64+ = [3,0] `` if you want to segment blue nuclei.
6665
6766The `'nuclei' ` model is downloadable from the website with MODEL_NAME ``nucleitorch_0 ``,
6867and size model ``size_nucleitorch_0.npy ``.
6968
7069Other built-in models
71- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7271
73- The main built-in models are dataset-specific models trained on one of the 9 datasets
74- in the Cellpose3 paper. These models do not have a size model.
75- If the diameter is set to 0.0, then the model uses the default ``diam_mean `` for the
72+ The main built-in models are dataset-specific models trained on one of the 9
73+ datasets in the Cellpose3 paper. These models do not have a size model. If the
74+ diameter is set to 0.0, then the model uses the default ``diam_mean `` for the
7675diameter (``30.0 ``).
7776
78- These models can be loaded and used in the notebook with e.g.
79- ``models.CellposeModel(model_type='tissuenet_cp3') `` or ``models.CellposeModel(model_type='livecell_cp3') ``,
80- or in the command line with ``python -m cellpose --pretrained_model tissuenet_cp3 ``.
77+ These models can be loaded and used in the notebook with e.g.
78+ ``models.CellposeModel(model_type='tissuenet_cp3') `` or
79+ ``models.CellposeModel(model_type='livecell_cp3') ``, or in the command line with
80+ ``python -m cellpose --pretrained_model tissuenet_cp3 ``.
8181
8282The dataset-specific models were trained on the training images from the following datasets:
8383 - ``tissuenet_cp3 ``: `tissuenet dataset <https://datasets.deepcell.org/ >`_.
@@ -99,28 +99,73 @@ We see no improvement with transformer models in the Cellpose3 paper and the
9999but the models are available as ``transformer_cp3 `` and ``neurips_cellpose_transformer ``. These model take three channels as input.
100100The u-net based Neurips challenge model is available as ``neurips_cellpose_default `` and also takes three channels as input.
101101
102- User-trained models
103- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102+ User-trained models
103+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104104
105105By default, models are trained with the ROIs resized to a diameter of 30.0
106- (``diam_mean = 30 ``) -- this is necessary if you want to start from a pretrained
107- cellpose model. If you want to use a different diameter and use pretraining,
108- we recommend performing training yourself on the cellpose dataset with that diameter so the
109- model learns objects at that size. All user-trained models will save the
110- ``diam_mean `` so it will be loaded automatically along with the model weights.
111-
112- Each model also saves the ``diam_labels `` which is the mean diameter of the
113- ROIs in the training images. This value is auto-loaded into the GUI for use
114- with the model, or will be used if the diameter is 0
115- (``diameter=0 `` or ``--diameter 0 ``).
116-
117- These models can be loaded and used in the notebook with e.g.
106+ (``diam_mean = 30 ``) -- this is necessary if you want to start from a pretrained
107+ cellpose model. If you want to use a different diameter and use pretraining, we
108+ recommend performing training yourself on the cellpose dataset with that
109+ diameter so the model learns objects at that size. All user-trained models will
110+ save the ``diam_mean `` so it will be loaded automatically along with the model
111+ weights.
112+
113+ Each model also saves the ``diam_labels `` which is the mean diameter of the ROIs
114+ in the training images. This value is auto-loaded into the GUI for use with the
115+ model, or will be used if the diameter is 0 (``diameter=0 `` or ``--diameter
116+ 0 ``).
117+
118+ These models can be loaded and used in the notebook with e.g.
118119``models.CellposeModel(model_type='name_in_gui') `` or with the full path
119- ``models.CellposeModel(pretrained_model='/full/path/to/model') `` . If you trained in the
120- GUI, you can automatically use the ``model_type `` argument. If you trained in the
121- command line, you need to first add the model to the cellpose path either in the GUI
122- in the Models menu, or using the command line:
123- ``python -m cellpose --add_model /full/path/to/model ``.
124-
125- Or these models can be used in the command line with ``python -m cellpose --pretrained_model name_in_gui ``
126- or ``python -m cellpose --pretrained_model /full/path/to/model `` .
120+ ``models.CellposeModel(pretrained_model='/full/path/to/model') `` . If you
121+ trained in the GUI, you can automatically use the ``model_type `` argument. If
122+ you trained in the command line, you need to first add the model to the cellpose
123+ path either in the GUI in the Models menu, or using the command line: ``python
124+ -m cellpose --add_model /full/path/to/model ``.
125+
126+ Or these models can be used in the command line with ``python -m cellpose
127+ --pretrained_model name_in_gui `` or ``python -m cellpose --pretrained_model
128+ /full/path/to/model ``.
129+
130+ Finding models on BioImage.IO
131+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
133+ `BioImage.IO <https://bioimage.io/ >`_ is a repository for sharing AI models,
134+ datasets and tools for bioimage analysis. You may look for Cellpose models on
135+ BioImage.IO Model Zoo by searching for the tag ``cellpose ``. To download a
136+ model, click on the model card, click the download icon, and choose "Download by
137+ Weight Format" - "Pytorch State Dict".
138+
139+ Sharing models on BioImage.IO
140+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141+
142+ You can also share your trained Cellpose models on the BioImage.IO Model Zoo. To
143+ do this, you need to export your model in the BioImage.IO format using
144+ ``cellpose/export.py `` and then upload the packaged model to the Model Zoo.
145+
146+ Detailed steps:
147+
148+ 1. Train a Cellpose model and check if it works well on your data.
149+ 2. Create an environment ``python -m pip install 'cellpose[bioimageio]' `` or
150+ ``'cellpose[all]' `` if you haven't already. Note that most users installed
151+ ``'cellpose[gui]' `` without the bioimageio packages.
152+ 3. Export the model using ``export.py `` script. Use ``python export.py --help ``
153+ to see the usage, or check the example in `its docstring
154+ <https://github.com/MouseLand/cellpose/blob/8bc3f628be732a733e923e93c30c11172e564895/cellpose/export.py#L3-L38> `_.
155+ In short, you need to name your models, specify if the model runs on
156+ cytoplasm/nuclei/both, and provide:
157+
158+ 1. a model filepath,
159+ 2. a README.md filepath,
160+ 3. a cover image filepath(s),
161+ 4. a short description string,
162+ 5. a license name like ``MIT ``,
163+ 6. a link to your GitHub repo (or Cellpose repo),
164+ 7. information about the authors and what to cite,
165+ 8. tags including ``cellpose ``, ``2d `` and ``3d `` (Cellpose models handle
166+ both).
167+
168+ 4. If you are updating a uploaded model, you should also specify the model ID
169+ and icon. Don't forget to increment the version number.
170+ 5. Go to `BioImage.IO <https://bioimage.io/ >`_, click "Upload", and follow the
171+ instructions there.
0 commit comments