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

The predictions by Command line and GUI are different #972

Open
ycwei0321 opened this issue Jul 15, 2024 · 12 comments
Open

The predictions by Command line and GUI are different #972

ycwei0321 opened this issue Jul 15, 2024 · 12 comments

Comments

@ycwei0321
Copy link

Hello,

I'm recently using the CellPose to do the cell count. However, I found the predictions between GUI and command line are very different that the GUI gave me a better prediction, can you give me some suggestions?

Here is the command I used:
cellpose --dir “D:/user/CellPose/input” --image_path “D:/user/CellPose/Input” --add_model “C:/Users/winshah/.cellpose/models/cyto2_cp3.npy” --chan 0 --use_gpu --flow_threshold 0.4 --cellprob_threshold 0 --save_rois --save_png --save_outlines --savedir “D:/user/CellPose/Output”

Here is the screenshot of the GUI I use:
image

If I want to get the similar result by command line, whant kind of parameter should I use?

I found if I use the pretrained model named cyto3, it gave me the opposite results. The result from command line is much better than the GUI.

Thanks for your help.

@ReallyCoolBean
Copy link

I also have the issue of different output in the GUI and from the command line using Cellpose2.0 and we are not alone, as I found others reporting that, however no good explanation or solution to the problem: #843 and #758

I trained a model using command line and now when I evaluate it through the command line in PyTorch, I have good results. Here is the code snippet:
image
and here is one of my images, a z-stack of dimensions: (41,2,2045,2046), here visualised in napari 15th slice in a stack with predicted masks. I am using 2 channels: green (2) as the main channel labelling cells and red (1) with nuclei.
image

Now this is what happens when I run the model with the same parameters in GUI:
image
Model does a poorer job, it predicts sometimes many tiny masks eg. top right corner instead of a one normal mask.

To make things even more confusing, when I try to run the same model on the same image in Arivis with the same parameters, this is what happens (again showing 15th slice from the z-stack).
image

Prediction is different than from Cellpose GUI and different than from the command line. Everything is run in the same environment. Does anyone have any idea what's going on? I don't know which result to trust. I have the best results fromt he command line and this is also where I did evaluation of different parameters and now I want to give the model to another person so they can work with it in Arivis and we can't replicate the results.

@carsen-stringer
Copy link
Member

can you please check if this is the case in cellpose v3? this is the old GUI. also it would be helpful if you could please provide the image that has discrepancies in segmentation, then I can debug it, thanks

@ReallyCoolBean
Copy link

Hey, thank you for looking into this! I cloned our environment and upgraded to cellpose3 and the problem persists in the new GUI (screenshot attached). What is the best way to provide you with the image? It's 680MB, so I can't upload it here.
image

@carsen-stringer
Copy link
Member

if you can provide a google drive link that would be great thanks, and the CLI command you are using

@ycwei0321
Copy link
Author

if you can provide a google drive link that would be great thanks, and the CLI command you are using

Hi

Thanks for your response. I can also provide some example images I tried before. Please see them in this drive link: https://drive.google.com/drive/folders/1UKnCFPk5G3RQkn65VJcfyzjkuvu7y-I4?usp=sharing

Below is the command I used for the cell count, I tried to keep the parameter same with the GUI.

cellpose --dir “D:/Yichao/CellPose/input” --image_path “D:/Yichao/CellPose/Input” --add_model “C:/Users/winshah/.cellpose/models/cyto2_cp3.npy” --chan 0 --use_gpu --flow_threshold 0.4 --cellprob_threshold 0 --save_rois --save_png --save_outlines --savedir “D:/Yichao/CellPose/Output”

If you have any questions, please let me know. Thanks for your kind help.

@carsen-stringer
Copy link
Member

carsen-stringer commented Sep 13, 2024

you've added ".npy" to the end of the model name, I think the command you want is

python -m cellpose --verbose --dir /path/to/images/ --pretrained_model cyto2_cp3 --chan 0 --flow_threshold 0.4 --cellprob_threshold 0 --save_rois --save_png --save_outlines

with this command and using the "cyto2_cp3" model in the GUI I got the exact same result (using CPU, got 1012 cells for img1t.tif in both cases).

going to close this issue for now, but let me know if you have more questions

@ReallyCoolBean
Copy link

Here is a folder with my example image and the model I trained:
https://drive.google.com/drive/folders/1ptaGPKS77ihv1Ewwte1eVuVbX1r-_wPg?usp=sharing
Perhaps I didn't describe correctly what I'm doing, I am actually not using cellpose CLI, but cellpose API by running code in PyCharm. I was inspired by the colab notebook you posted here. Here is the line of code that I am using:

masks = model.eval(test_data,
channels=[2, 1],
diameter=123,
cellprob_threshold=0,
flow_threshold=0.4,
stitch_threshold=0.2)[0]

where model is the model that I provided in the google drive and test_data is the image. The same model and the same image were loaded in GUI and I believe the parameters in GUI were also the same as in my code (see screenshots).

@carsen-stringer
Copy link
Member

Since this is 3D, can you please check if the normalization parameters are the same in both cases? They are printed in the GUI as a dictionary, and you can input that dictionary into normalize in eval.

Regarding arivis outputs, their code is closed source and I don't have a license so we can't verify whether it would work the same way

@ReallyCoolBean
Copy link

Thank you for the advice! Sadly, I still get different results: GUI predicts 871 ROIs while the python script predicts 149. I ran again the model in Cellpose3 GUI and I got the same result as before (here showing plane 14):
image
I checked the output in the terminal and normalization parameters:
image
I then run the following python script:
image
and this is my result:
image

@carsen-stringer
Copy link
Member

Can you include what is printed when the script runs? I think you're missing the do_3D=True flag in model.eval

@carsen-stringer
Copy link
Member

Oh I see you are stitching, please do include what the script is printing

@ReallyCoolBean
Copy link

ReallyCoolBean commented Oct 2, 2024

Well, it doesn't print much, just that images from my test set were loaded and that model finished finished running for the one image that I selected. I'm not sure why it says 40/40 while the image had 41 planes.
image

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

No branches or pull requests

3 participants