Skip to content

Commit e4fb149

Browse files
authored
Merge branch 'MouseLand:main' into distributed
2 parents 4c8e8a9 + 70c0d07 commit e4fb149

File tree

10 files changed

+109
-42
lines changed

10 files changed

+109
-42
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,34 @@ labels: bug
66
assignees: ''
77

88
---
9+
## Before you fill out this form:
10+
**Did you review the FAQ?**
11+
- [ ] Yes, I reviewed the FAQ on the [cellpose ReadTheDocs](https://cellpose.readthedocs.io/en/latest/faq.html)
912

10-
**Describe the bug**
13+
**Did you look through previous (open AND closed) issues posted on GH?**
14+
- [ ] Yes, I [searched for related previous GH issues](https://github.com/MouseLand/cellpose/issues?q=is%3Aissue).
15+
16+
## Now fill this form out completely:
17+
### **Describe the bug**
1118
A clear and concise description of what the bug is.
1219

13-
**To Reproduce**
20+
### **To Reproduce**
1421
Steps to reproduce the behavior:
1522
1. Go to '...'
1623
2. Click on '....'
1724
3. Scroll down to '....'
1825
4. See error
1926

20-
**Run log**
27+
### **Run log**
2128
Please post all command line/notebook output for us to understand the problem. For this please make sure you are running with verbose mode on. So command line, with `--verbose` tag, or in a notebook first run
2229
```from cellpose import io
2330
logger = io.logger_setup()
2431
```
2532
before running any Cellpose functions.
2633

27-
**Screenshots**
34+
<details><summary>Run logs</summary>
35+
your logs here.
36+
</details>
37+
38+
### **Screenshots**
2839
If applicable, add screenshots to help explain your problem.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: false

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ labels: enhancement
66
assignees: ''
77

88
---
9+
## Before you fill out this form:
10+
**Did you review the FAQ?**
11+
- [ ] Yes, I reviewed the FAQ on the [cellpose ReadTheDocs](https://cellpose.readthedocs.io/en/latest/faq.html)
912

10-
**Is your feature request related to a problem? Please describe.**
13+
**Did you look through previous (open AND closed) issues posted on GH?**
14+
- [ ] Yes, I [searched for related previous GH issues](https://github.com/MouseLand/cellpose/issues?q=is%3Aissue).
15+
16+
## Now fill this form out completely:
17+
### **Is your feature request related to a problem? Please describe.**
1118
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
1219

13-
**Describe the solution you'd like**
20+
### **Describe the solution you'd like**
1421
A clear and concise description of what you want to happen.
1522

16-
**Describe alternatives you've considered**
23+
### **Describe alternatives you've considered**
1724
A clear and concise description of any alternative solutions or features you've considered.
1825

19-
**Additional context**
26+
### **Additional context**
2027
Add any other context or screenshots about the feature request here.

.github/ISSUE_TEMPLATE/installation-issue.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@ labels: install
66
assignees: ''
77

88
---
9+
## Before you fill out this form:
10+
**Did you review the FAQ?**
11+
- [ ] Yes, I reviewed the FAQ on the [cellpose ReadTheDocs](https://cellpose.readthedocs.io/en/latest/faq.html)
912

10-
**Install problem**
13+
**Did you look through previous (open AND closed) issues posted on GH?**
14+
- [ ] Yes, I [searched for related previous GH issues](https://github.com/MouseLand/cellpose/issues?q=is%3Aissue).
15+
16+
## Now fill this form out completely:
17+
### **Install problem**
1118
Let us know what issues you are having with installation.
1219

13-
**Environment info**
20+
### **Environment info**
1421
Please run `conda list` in your cellpose environment in the terminal / anaconda prompt to let us know your software versions.
1522

16-
**Run log**
23+
<details><summary>Conda list output</summary>
24+
your conda list output
25+
</details>
26+
27+
### **Run log**
1728
Please post all command line/notebook output for us to understand the problem. For this please make sure you are running with verbose mode on. So command line, with `--verbose` tag, or in a notebook first run
1829

1930
```from cellpose import io

cellpose/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def assign_device(use_torch=True, gpu=False, device=0):
7777
if isinstance(device, str):
7878
if device != "mps" or not(gpu and torch.backends.mps.is_available()):
7979
device = int(device)
80-
if gpu and use_gpu(use_torch=True):
80+
if gpu and use_gpu(gpu_number=device, use_torch=use_torch):
8181
try:
8282
if torch.cuda.is_available():
8383
device = torch.device(f'cuda:{device}')

cellpose/io.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def save_masks(images, masks, flows, file_names, png=True, tif=False, channels=[
692692
save_outlines (bool, optional): Save outlines of masks. Defaults to False.
693693
dir_above (bool, optional): Save masks/flows in directory above. Defaults to False.
694694
in_folders (bool, optional): Save masks/flows in separate folders. Defaults to False.
695-
savedir (str, optional): Absolute path where images will be saved. If None, saves to image directory. Defaults to None.
695+
savedir (str, optional): Absolute or relative path where images will be saved. If None, saves to image directory. Defaults to None.
696696
save_txt (bool, optional): Save masks as list of outlines for ImageJ. Defaults to False.
697697
save_mpl (bool, optional): If True, saves a matplotlib figure of the original image/segmentation/flows. Does not work for 3D.
698698
This takes a long time for large images. Defaults to False.
@@ -724,11 +724,11 @@ def save_masks(images, masks, flows, file_names, png=True, tif=False, channels=[
724724

725725
if savedir is None:
726726
if dir_above:
727-
savedir = Path(file_names).parent.parent.absolute(
728-
) #go up a level to save in its own folder
727+
savedir = Path(file_names).parent.parent#go up a level to save in its own folder
729728
else:
730-
savedir = Path(file_names).parent.absolute()
729+
savedir = Path(file_names).parent
731730

731+
savedir = Path(savedir).resolve()
732732
check_dir(savedir)
733733

734734
basename = os.path.splitext(os.path.basename(file_names))[0]

cellpose/train.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def train_seg(net, train_data=None, train_labels=None, train_files=None,
310310
train_labels_files=None, train_probs=None, test_data=None,
311311
test_labels=None, test_files=None, test_labels_files=None,
312312
test_probs=None, channel_axis=None,
313-
load_files=True, batch_size=1, learning_rate=5e-5, SGD=False,
313+
load_files=True, batch_size=1, learning_rate=1e-5, SGD=False,
314314
n_epochs=100, weight_decay=0.1, normalize=True, compute_flows=False,
315315
save_path=None, save_every=100, save_each=False, nimg_per_epoch=None,
316316
nimg_test_per_epoch=None, rescale=False, scale_range=None, bsize=256,
@@ -331,11 +331,10 @@ def train_seg(net, train_data=None, train_labels=None, train_files=None,
331331
test_labels_files (list or None): List of test label file paths. Defaults to None.
332332
test_probs (List[float], optional): List of floats - probabilities for each image to be selected during testing. Defaults to None.
333333
load_files (bool, optional): Boolean - whether to load images and labels from files. Defaults to True.
334-
batch_size (int, optional): Integer - number of patches to run simultaneously on the GPU. Defaults to 8.
335-
learning_rate (float or List[float], optional): Float or list/np.ndarray - learning rate for training. Defaults to 0.005.
336-
n_epochs (int, optional): Integer - number of times to go through the whole training set during training. Defaults to 2000.
337-
weight_decay (float, optional): Float - weight decay for the optimizer. Defaults to 1e-5.
338-
momentum (float, optional): Float - momentum for the optimizer. Defaults to 0.9.
334+
batch_size (int, optional): Integer - number of patches to run simultaneously on the GPU. Defaults to 1.
335+
learning_rate (float or List[float], optional): Float or list/np.ndarray - learning rate for training. Defaults to 1e-5.
336+
n_epochs (int, optional): Integer - number of times to go through the whole training set during training. Defaults to 100.
337+
weight_decay (float, optional): Float - weight decay for the optimizer. Defaults to 0.1.
339338
SGD (bool, optional): Deprecated in v4.0.1+ - AdamW always used.
340339
normalize (bool or dict, optional): Boolean or dictionary - whether to normalize the data. Defaults to True.
341340
compute_flows (bool, optional): Boolean - whether to compute flows during training. Defaults to False.
@@ -344,7 +343,7 @@ def train_seg(net, train_data=None, train_labels=None, train_files=None,
344343
save_each (bool, optional): Boolean - save the network to a new filename at every [save_each] epoch. Defaults to False.
345344
nimg_per_epoch (int, optional): Integer - minimum number of images to train on per epoch. Defaults to None.
346345
nimg_test_per_epoch (int, optional): Integer - minimum number of images to test on per epoch. Defaults to None.
347-
rescale (bool, optional): Boolean - whether or not to rescale images during training. Defaults to True.
346+
rescale (bool, optional): Boolean - whether or not to rescale images during training. Defaults to False.
348347
min_train_masks (int, optional): Integer - minimum number of masks an image must have to use in the training set. Defaults to 5.
349348
model_name (str, optional): String - name of the network. Defaults to None.
350349

docs/faq.rst

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
FAQ
22
~~~~~~~~~~~~~~~~~~~~~~~~
33

4+
----------------------
5+
Cellpose settings and usage
6+
----------------------
7+
48
**Q: What should I set the** ``--flow_threshold``/``--cellprob_threshold``/``--diameter`` **parameter to?**
59

610
These parameters should be set experimentally by running Cellpose, viewing the results, and tuning the parameters
@@ -18,20 +22,6 @@ FAQ
1822
Some additional information on precision and accuracy can be found `here <https://forum.image.sc/t/how-to-interpret-cellposes-average-precision-model-evaluation-value/75231/3>`_.
1923

2024

21-
**Q: How do I download the pretrained models?**
22-
23-
The new Cellpose-SAM model (cpsam) will be downloaded from `https://huggingface.co/mouseland/cellpose-sam/blob/main/cpsam`_.
24-
25-
The old models will be downloaded automatically from the `website <https://www.cellpose.org/>`_ when you first run a
26-
pretrained model in cellpose. If you are having issues with the downloads, you can download them from this
27-
`google drive zip file <https://drive.google.com/file/d/1zHGFYCqRCTwTPwgEUMNZu0EhQy2zaovg/view?usp=sharing>`_,
28-
unzip the file and put the models in your home directory under the path ``.cellpose/models/``,
29-
e.g. on Windows this would be ``C:/Users/YOUR_USERNAME/.cellpose/models/`` or on Linux this would be
30-
``/home/YOUR_USERNAME/.cellpose/models/``, so ``/home/YOUR_USERNAME/.cellpose/models/cyto_0`` is the full
31-
path to one model for example. If you cannot access google drive, the models are also available on
32-
baidu: https://pan.baidu.com/s/1CARpRGCBHIYaz7KeyoX-fg thanks to @qixinbo!
33-
34-
3525
**Q: How can I use cellpose to recognize different types of cells in the same image?**
3626

3727
Cellpose does not natively support recognizing different types of cells (aka 'multiclass segmentation').
@@ -68,6 +58,24 @@ FAQ
6858
`here <https://pytorch.org/docs/stable/threading_environment_variables.html>`_.
6959

7060

61+
----------------------
62+
Models and training
63+
----------------------
64+
65+
**Q: How do I download the pretrained models?**
66+
67+
The new Cellpose-SAM model (cpsam) will be downloaded from `huggingface <https://huggingface.co/mouseland/cellpose-sam/blob/main/cpsam>`_.
68+
69+
The old models will be downloaded automatically from the `website <https://www.cellpose.org/>`_ when you first run a
70+
pretrained model in cellpose. If you are having issues with the downloads, you can download them from this
71+
`google drive zip file <https://drive.google.com/file/d/1zHGFYCqRCTwTPwgEUMNZu0EhQy2zaovg/view?usp=sharing>`_,
72+
unzip the file and put the models in your home directory under the path ``.cellpose/models/``,
73+
e.g. on Windows this would be ``C:/Users/YOUR_USERNAME/.cellpose/models/`` or on Linux this would be
74+
``/home/YOUR_USERNAME/.cellpose/models/``, so ``/home/YOUR_USERNAME/.cellpose/models/cyto_0`` is the full
75+
path to one model for example. If you cannot access google drive, the models are also available on
76+
baidu: https://pan.baidu.com/s/1CARpRGCBHIYaz7KeyoX-fg thanks to @qixinbo!
77+
78+
7179
**Q: How does HITL work?**
7280

7381
In cellpose HITL training always starts from a pretrained model but incorporates more training
@@ -111,4 +119,35 @@ colab/a cluster)**
111119

112120
5. Evaluate the trained model on the next image.
113121

114-
6. Repeat 3-5 until you have a working fine-tuned model.
122+
6. Repeat 3-5 until you have a working fine-tuned model.
123+
124+
125+
**Q: Why should I always start from the built-in cellpose model for fine-tuning rather than my fine-tuned model?**
126+
127+
Cellpose uses transfer learning,
128+
where a pre-trained network is used as a starting point that is 'good enough'. Cellpose was trained on a large
129+
and diverse training set of images so that it is a generalist segmentation model: it will segment many types
130+
of images. However, it is not perfect. This means that the
131+
network parameters are somewhat close to predicting good outputs for a new dataset.
132+
133+
After HITL training, you have a new trained network, with parameterst that are closer to your ideal network for that
134+
particular image dataset. To improve the model, you should then take this better performing network and train it again, no?
135+
136+
This is actually a bad idea. The result would be that the network would learn on your data, but it would start to
137+
memorize your data instead of generalizing. This is because each time you train a model, you are moving away from the
138+
generalist, pre-trained parameters, and toward a smaller target distribution of images. Done enough times, the network
139+
may lose the ability to generalize to new images.
140+
141+
Instead, the cellpose GUI forces you to always start with a pretrained model that is known to perform well to make
142+
the iteration cycle more robust. New data is added each cycle, but the model will always start with the generalist
143+
pre-trained model to produce a new fine-tuned model. As you continue the training cycle, the model will converge
144+
on the best model parameters to segment your images. You *should* use the new models to predict the segmentation,
145+
that is the point of the HITL design. Eventually, you will have a model that doesn't need additional training
146+
to accurately predict your segmentation.
147+
148+
149+
**Q: Why not train from scratch?**
150+
151+
You also have the option to train from scratch, but that will take much
152+
longer and requires much more data. The CP4 network leverages extensive pretraining (300k natural images,
153+
23k cellular images). You will need something similar to this to get generalist results.

docs/notebook.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ See :ref:`Settings` for more information on run settings.
2323

2424
masks, flows, styles = model.eval(imgs)
2525

26-
See example notebook at `run_cellpose.ipynb`_.
26+
See example notebook at `run_Cellpose-SAM.ipynb`_.
2727

28-
.. _run_cellpose.ipynb: https://nbviewer.jupyter.org/github/MouseLand/cellpose/blob/master/notebooks/run_cellpose.ipynb
28+
.. _run_cellpose.ipynb: https://github.com/MouseLand/cellpose/blob/main/notebooks/run_Cellpose-SAM.ipynb

tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ deps =
3636
# ignoring contrib tests for now
3737
commands =
3838
#linux: apt-get update && apt-get install libgl1
39-
pytest -v --color=yes --cov=cellpose --cov-report=xml --ignore=tests/contrib
40-
39+
pytest -vv -rA --color=yes --cov=cellpose --cov-report=xml --ignore=tests/contrib --durations=0

0 commit comments

Comments
 (0)