MouseLand / cellpose

a generalist algorithm for cellular segmentation with human-in-the-loop capabilities
https://www.cellpose.org/
BSD 3-Clause "New" or "Revised" License
1.24k stars 359 forks source link

[BUG] GUI diameter is reset to 30 when training own model #963

Closed manerotoni closed 1 week ago

manerotoni commented 1 week ago

Describe the bug Using cellpose 3.0.7 Training a model with image and masks from directory resets the diameter to default 30. As in my case the diameter is 80, this leads to a poor training.

To Reproduce Steps to reproduce the behavior:

  1. Go to a directory that contains images and segmention masks. Load one image
  2. Change diameter to something different than 30
  3. [Models > Train model with image and masks in folder]
  4. Look at the prompt it will show ">>>> model diam_mean = 30.000 (ROIs rescaled to this size during training)"
  5. The diameter returned to 30 and the classifier has also quite a bad performance
carsen-stringer commented 1 week ago

This is fixed in the latest release, I'll reopen if it's not working for you

manerotoni commented 1 week ago

Thanks for the quick reply. I upgraded cellpose3 and the diameter is now not reverted to 30.

However, I am not sure if there is still not a problem. I checked cellpose 2 and 3 side by side with the same data and I consistently get worse results for cellpose3. Although the starting models are different, given enough training data one should get a similar result.

The loss function in cellpose2 reaches values <0.2 (0.16), in cellpose 3 i barely get close to 0.4 (typically >0.4). Also visually the segmentation results in cellpose3 look worse. I tried several different models and the results are consistent. I will rescale the data for cellpose3 and see if I get a different result.

train model in cellpose2

Cellpose2 gives me an hint that the the mean of training label mask is not 30

>>>> mean of training label mask diameters (saved to model) 68.676

train model in cellpos3

I do not get an hint whether the labels have been rescaled or not.

2024-06-18 16:09:49,163 [INFO] >>>> model diam_mean =  30.000 (ROIs rescaled to this size during training)
GUI_INFO: name of new model: cyto_20240618_155600
2024-06-18 16:09:49,690 [INFO] computing flows for labels
100%|███████████████████████████████████████████████████████████████████████████████████████████████| 16/16 [00:02<00:00,  6.20it/s]
2024-06-18 16:09:52,616 [INFO] >>>> median diameter set to = 30
2024-06-18 16:09:52,617 [INFO] >>>> mean of training label mask diameters (saved to model) 68.676
2024-06-18 16:11:10,542 [INFO] >>>> model diam_mean =  30.000 (ROIs rescaled to this size during training)
GUI_INFO: name of new model: cyto3_cp3_20240618_155847
2024-06-18 16:11:10,542 [INFO] computing flows for labels
100%|██████████████████████████████████████████████████████████████████████████████████| 16/16 [00:02<00:00,  7.35it/s]
2024-06-18 16:11:12,727 [INFO] >>> computing diameters
100%|█████████████████████████████████████████████████████████████████████████████████| 16/16 [00:00<00:00, 422.34it/s]
2024-06-18 16:11:12,765 [INFO] >>> using channels [0, 0]
carsen-stringer commented 1 week ago

oh there was another bug with the nimg_per_epoch that I just fixed, but I'm not sure if that's enough to make such a large difference. please try pip install git+https://github.com/mouseland/cellpose.git

On Tue, Jun 18, 2024 at 10:48 AM Antonio Politi @.***> wrote:

Thanks for the quick reply. I upgrade cellpose3 and the diameter is now not reverted to 30.

However, I am not sure if there is still not a problem. I checked cellpose 2 and 3 side by side and I consistently get worse results for cellpose3. Although the starting models are different, given enough training data one should get a similar result.

The loss function in cellpose2 reaches values <0.2 (0.16), in cellpose 3 i barely get close to 0.4 (typically >0.4). The segmentation results in cellpose3 are significantly worse. I tried several different models and the results are consistent. I will rescale the data for cellpose3 and see if I get a different result. train model in cellpose2

Cellpose2 gives me an hint that the the mean of training label mask is not 30

mean of training label mask diameters (saved to model) 68.676

train model in cellpos3

I do not get an hint whether the labels have been rescaled or not.

2024-06-18 16:09:49,163 [INFO] >>>> model diam_mean = 30.000 (ROIs rescaled to this size during training) GUI_INFO: name of new model: cyto_20240618_155600 2024-06-18 16:09:49,690 [INFO] computing flows for labels 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 16/16 [00:02<00:00, 6.20it/s] 2024-06-18 16:09:52,616 [INFO] >>>> median diameter set to = 30 2024-06-18 16:09:52,617 [INFO] >>>> mean of training label mask diameters (saved to model) 68.676 2024-06-18 16:11:10,542 [INFO] >>>> model diam_mean = 30.000 (ROIs rescaled to this size during training) GUI_INFO: name of new model: cyto3_cp3_20240618_155847 2024-06-18 16:11:10,542 [INFO] computing flows for labels 100%|██████████████████████████████████████████████████████████████████████████████████| 16/16 [00:02<00:00, 7.35it/s] 2024-06-18 16:11:12,727 [INFO] >>> computing diameters 100%|█████████████████████████████████████████████████████████████████████████████████| 16/16 [00:00<00:00, 422.34it/s] 2024-06-18 16:11:12,765 [INFO] >>> using channels [0, 0]

— Reply to this email directly, view it on GitHub https://github.com/MouseLand/cellpose/issues/963#issuecomment-2176293838, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADS6TFITGEVVC5FXEBT4FLDZIBCDTAVCNFSM6AAAAABJP6PZYSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZWGI4TGOBTHA . You are receiving this because you modified the open/close state.Message ID: @.***>