Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] tell user the command in the GUI to use in CLI (Model trained in the GUI but run in the command window produces vastly different, poor results) #758

Closed
daniel-nolan142 opened this issue Jul 28, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@daniel-nolan142
Copy link

daniel-nolan142 commented Jul 28, 2023

Describe the bug
I am trying to run a model that I trained in the GUI, in the command window of Anaconda Prompt and the results from the model are vastly different than when I run the model in the GUI. The model significantly underperforms and I am wondering if there is a way to have the model perform as it does in the GUI so I don't have to individually apply the model to each image. I am using the model to trace water droplets. Let me know if there is anything that I am not doing correctly as I am still fairly new to cellpose

This is the image I am testing

image

This is the mask I recieve when I run the model in the GUI
image

And this is the mask I get when I run the exact same model, but from the Anaconda Prompt command window with the below command
image

Run log
(base) C:\Users\dnolan>python -m cellpose --dir C:\Users\dnolan\Desktop\20230713_gramnegs_repeat --pretrained_model C:\Users\dnolan.cellpose\models\10droplets --save_png --verbose
2023-07-28 13:23:18,426 [INFO] WRITING LOG OUTPUT TO C:\Users\dnolan.cellpose\run.log
2023-07-28 13:23:18,427 [INFO]
cellpose version: 2.2.3.dev1+g59bd0cd
platform: win32
python version: 3.10.9
torch version: 2.0.1+cpu
2023-07-28 13:23:18,427 [INFO] >>>> using CPU
2023-07-28 13:23:18,445 [INFO] >>>> running cellpose on 86 images using chan_to_seg GRAY and chan (opt) NONE
2023-07-28 13:23:18,445 [INFO] >>>> loading model C:\Users\dnolan.cellpose\models\10droplets
2023-07-28 13:23:18,581 [INFO] >>>> model diam_mean = 30.000 (ROIs rescaled to this size during training)
2023-07-28 13:23:18,581 [INFO] >>>> model diam_labels = 52.5
2023-07-28 13:23:18,584 [INFO] >>>> using diameter 30.000 for all images
2023-07-28 13:23:18,586 [INFO] 0%| | 0/86 [00:00<?, ?it/s]
2023-07-28 13:23:32,744 [INFO] 1%|1 | 1/86 [00:14<20:03, 14.16s/it]
2023-07-28 13:23:47,396 [INFO] 2%|2 | 2/86 [00:28<20:13, 14.45s/it]
2023-07-28 13:24:02,825 [INFO] 3%|3 | 3/86 [00:44<20:36, 14.90s/it]
2023-07-28 13:24:18,128 [INFO] 5%|4 | 4/86 [00:59<20:34, 15.06s/it]
2023-07-28 13:24:33,456 [INFO] 6%|5 | 5/86 [01:14<20:27, 15.15s/it]
2023-07-28 13:24:48,694 [INFO] 7%|6 | 6/86 [01:30<20:14, 15.18s/it]
2023-07-28 13:25:04,638 [INFO] 8%|8 | 7/86 [01:46<20:19, 15.43s/it]
2023-07-28 13:25:22,854 [INFO] 9%|9 | 8/86 [02:04<21:12, 16.32s/it]
2023-07-28 13:25:46,367 [INFO] 10%|# | 9/86 [02:27<23:49, 18.57s/it]
2023-07-28 13:26:03,050 [WARNING] no masks found, will not save PNG or outlines
2023-07-28 13:26:03,051 [INFO] 12%|#1 | 10/86 [02:44<22:46, 17.99s/it]
2023-07-28 13:26:18,796 [INFO] 13%|#2 | 11/86 [03:00<21:37, 17.30s/it]
2023-07-28 13:26:34,454 [INFO] 14%|#3 | 12/86 [03:15<20:43, 16.80s/it]
2023-07-28 13:26:50,158 [INFO] 15%|#5 | 13/86 [03:31<20:02, 16.47s/it]
2023-07-28 13:27:05,659 [INFO] 16%|#6 | 14/86 [03:47<19:24, 16.18s/it]
2023-07-28 13:27:21,081 [INFO] 17%|#7 | 15/86 [04:02<18:52, 15.95s/it]
2023-07-28 13:27:36,800 [INFO] 19%|#8 | 16/86 [04:18<18:31, 15.88s/it]
2023-07-28 13:27:52,237 [INFO] 20%|#9 | 17/86 [04:33<18:06, 15.75s/it]
2023-07-28 13:28:07,618 [INFO] 21%|## | 18/86 [04:49<17:43, 15.64s/it]
2023-07-28 13:28:23,189 [INFO] 22%|##2 | 19/86 [05:04<17:26, 15.62s/it]
2023-07-28 13:28:38,846 [INFO] 23%|##3 | 20/86 [05:20<17:11, 15.63s/it]
2023-07-28 13:28:54,293 [INFO] 24%|##4 | 21/86 [05:35<16:52, 15.57s/it]
2023-07-28 13:29:09,927 [INFO] 26%|##5 | 22/86 [05:51<16:37, 15.59s/it]
2023-07-28 13:29:25,400 [INFO] 27%|##6 | 23/86 [06:06<16:20, 15.56s/it]
2023-07-28 13:29:40,924 [INFO] 28%|##7 | 24/86 [06:22<16:03, 15.55s/it]
2023-07-28 13:29:56,505 [INFO] 29%|##9 | 25/86 [06:37<15:48, 15.56s/it]
2023-07-28 13:30:12,303 [INFO] 30%|### | 26/86 [06:53<15:37, 15.63s/it]
2023-07-28 13:30:27,894 [INFO] 31%|###1 | 27/86 [07:09<15:21, 15.62s/it]
2023-07-28 13:30:45,449 [INFO] 33%|###2 | 28/86 [07:26<15:39, 16.20s/it]
2023-07-28 13:31:03,471 [INFO] 34%|###3 | 29/86 [07:44<15:54, 16.75s/it]
2023-07-28 13:31:19,580 [INFO] 35%|###4 | 30/86 [08:00<15:27, 16.56s/it]
2023-07-28 13:31:38,100 [INFO] 36%|###6 | 31/86 [08:19<15:42, 17.14s/it]
2023-07-28 13:31:54,837 [INFO] 37%|###7 | 32/86 [08:36<15:19, 17.02s/it]
2023-07-28 13:32:10,129 [INFO] 38%|###8 | 33/86 [08:51<14:34, 16.50s/it]
2023-07-28 13:32:26,623 [INFO] 40%|###9 | 34/86 [09:08<14:18, 16.50s/it]
2023-07-28 13:32:44,995 [INFO] 41%|#### | 35/86 [09:26<14:30, 17.06s/it]
2023-07-28 13:33:05,680 [INFO] 42%|####1 | 36/86 [09:47<15:07, 18.15s/it]
2023-07-28 13:33:25,863 [INFO] 43%|####3 | 37/86 [10:07<15:19, 18.76s/it]
2023-07-28 13:33:46,242 [INFO] 44%|####4 | 38/86 [10:27<15:23, 19.25s/it]
2023-07-28 13:34:08,971 [INFO] 45%|####5 | 39/86 [10:50<15:53, 20.29s/it]
2023-07-28 13:34:30,267 [INFO] 47%|####6 | 40/86 [11:11<15:47, 20.59s/it]
2023-07-28 13:34:56,051 [INFO] 48%|####7 | 41/86 [11:37<16:36, 22.15s/it]
2023-07-28 13:35:13,815 [INFO] 49%|####8 | 42/86 [11:55<15:16, 20.83s/it]
2023-07-28 13:35:29,914 [INFO] 50%|##### | 43/86 [12:11<13:54, 19.41s/it]
2023-07-28 13:35:46,555 [INFO] 51%|#####1 | 44/86 [12:27<13:00, 18.58s/it]
before running any Cellpose functions.

@daniel-nolan142 daniel-nolan142 added the bug Something isn't working label Jul 28, 2023
@mrariden
Copy link
Collaborator

mrariden commented Aug 7, 2023

Hi @daniel-nolan142 can you verify that all of the settings in the GUI are being used when you call the command line program? Channels, cell size, flow_threshold, cellprob_threshold all might change your results.

@derekthirstrup
Copy link

derekthirstrup commented Sep 11, 2023

@mrariden I have experienced this same issue. I get excellent results using the GUI with cellpose 2.2.2 when trained on a 1080 Ti for our lattice lightsheet data. However, I get a lower quality segmentation that picks up way more background noise when I process 3d stacks with the same model on our A100 headless nodes. Can you please output the segmentation parameters used for the GUI mode so that the results match when running a big batch of images in headless processing mode?

@mrariden mrariden self-assigned this Oct 5, 2023
@carsen-stringer carsen-stringer added enhancement New feature or request and removed bug Something isn't working labels Feb 13, 2024
@carsen-stringer carsen-stringer changed the title Model trained in the GUI but run in the command window produces vastly different, poor results tell user the command in the GUI to use in CLI (Model trained in the GUI but run in the command window produces vastly different, poor results) Feb 13, 2024
@carsen-stringer carsen-stringer changed the title tell user the command in the GUI to use in CLI (Model trained in the GUI but run in the command window produces vastly different, poor results) [FEATURE] tell user the command in the GUI to use in CLI (Model trained in the GUI but run in the command window produces vastly different, poor results) Feb 13, 2024
@masa6161
Copy link

masa6161 commented Feb 27, 2024

Hi. I'm newby for the cellpose and very appreciate for great work of developers and community.
I think a similar point in this thread; GUI works excellently, but CLI might be different, at least for my data.

I'm using version 3.0.5 and the codes in CLI are below;

from cellpose import core, denoise, io, utils
model = denoise.CellposeDenoiseModel(gpu=False,model_type="cyto3",restore_type="denoise_cyto3")
masks, flows, styles, diams = model.eval(imgs, diameter=None, channels=[0,0],niter = 2000)
io.masks_flows_to_seg(fnames_tif, masks, flows, fnames_save, diams=diams)

These are almost similar to the demo notebooks with small modifications I think.
In response to @mrariden 's comments, flow_threshold and cellprob_threshold should be default values (0.4 and 0) if I use this code.

On the other hand, in GUI, after using the "denoise" function, I set these parameters as the channel to segment is "0: gary" (because my image is gray-scale), cell size is 9.4, this was automatically calibrated, flow_threshold was 0.4 and cellprob_threshold was 0 for the same image.

I checked the intermediate variable diams (2D-array? I think this might be a single float value...) in CLI, and it might be correctly determined because the values in this variable were proper (max value is ~7).
Probably, the auto-detected value of cell diameter is not reflected for the estimation step in CLI.
I got an almost similar result by using 30 for the cell diameter in GUI and manually pre-determined diameter (e.g. 10) leads to an almost similar result with GUI.

I'd really like to know how to match the EXCELLENT result with GUI to that with CLI!

@carsen-stringer
Copy link
Member

Please set the diameter when running the CellposeDenoise model to what you get from the calibrate button in the GUI, or ideally you actually know the diameter/can estimate it yourself based on the image. You are not setting the diameter in your code at all here so it defaults to 30, which you are saying is wrong

@carsen-stringer
Copy link
Member

Also the output of the CellposeDenoise model is not diameter: https://cellpose.readthedocs.io/en/latest/restore.html#cellposedenoisemodel

@masa6161
Copy link

Thank you for your quick reply!

As your comment, that it is not set the cell diameter if diameter = None, does it mean that I need another step to automatically estimate cell diameters? If I will not perform denoising, is it automatically estimated?

@carsen-stringer
Copy link
Member

Correct yes the Cellpose model can estimate it for you but it's very much not recommended to do that in noisy and blurry images because the segmentation model is not trained on these images. Also generally you should approximately know your diameter and use that because Cellpose is not perfect at estimating it.

@masa6161
Copy link

Thank you for a clear explanation and I'm sure it.
I was reading the API docs and the diameter estimation could be perform firstly with Cellpose and then the actual cell detection will be. I'll give that a try if I need to.
Again, Thank you so much!

@Aymen480
Copy link

Hello, I am now trying to convert the CellposeDenoiseModel() to ONNX format.

import torch.onnx
from cellpose.denoise import DenoiseModel, CellposeDenoiseModel
from cellpose.models import model_path
import cellpose.denoise as Dn

model = CellposeDenoiseModel(
pretrained_model=False,
model_type="cyto2_cp3", restore_type="denoise_cyto3",
chan2_restore=False)
model_paths_dn = model_path("denoise_cyto3")
model_path_cn = model_path("cyto2_cp3")
model.dn.net.load_model(model_paths_dn)
model.cp.net.load_model(model_path_cn)
model.eval()

The problem here is that I couldn't get the network model. It is not like in DenoiseModel or CellposeModel, where the net is already based on CPnet.
Does anyone have any ideas?

@carsen-stringer
Copy link
Member

correct it is a combination of the two models, we will not support ONNX exporting.

regarding different predictions in GUI vs CLI, please comment in issue #972

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants