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

[BUG] can't use restore function with CLI #1105

Open
romainGuiet opened this issue Feb 11, 2025 · 2 comments
Open

[BUG] can't use restore function with CLI #1105

romainGuiet opened this issue Feb 11, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@romainGuiet
Copy link

Describe the bug
Can't run a restore from CLI

To Reproduce

  • fresh install cellpose 3.1.0
mamba create -n cellpose-310 python=3.8 -y
mamba activate cellpose-310
mamba install pytorch pytorch-cuda=11.8 -c pytorch -c nvidia -y
pip install cellpose==3.1.0 scikit-image
python -Xutf8 -m cellpose --dir C:\Users\guiet\AppData\Local\Temp\cellposeTemp  --model_type cyto3 --restore_type denoise_cyto3 --diameter 30 --verbose --save_tif --no_npy --use_gpu

or

python -Xutf8 -m cellpose --dir C:\Users\guiet\AppData\Local\Temp\cellposeTemp  --model_type cyto3 --restore_type denoise_cyto3 --diameter 25 --chan2_restore --chan 1 --chan2 1

get error : __main__.py: error: unrecognized arguments: --model_type cyto3

NOTE :
a minimal running line for cellpose segmentation without the restoration :

python -Xutf8 -m cellpose --dir C:\Users\guiet\AppData\Local\Temp\cellposeTemp  --pretrained_model cyto3 --diameter 30 --verbose --save_tif --no_npy --use_gpu

If I remove --model_type cyto3 , like :

python -Xutf8 -m cellpose --dir C:\Users\guiet\AppData\Local\Temp\cellposeTemp --pretrained_model cyto3 --chan 0 --chan2 0 --diameter 0 --verbose --save_tif --no_npy --use_gpu --restore_type denoise_cyto3

I get the error :

2025-02-11 09:26:49,094 [INFO] WRITING LOG OUTPUT TO C:\Users\guiet\.cellpose\run.log
2025-02-11 09:26:49,095 [INFO]
cellpose version:       3.1.0
platform:               win32
python version:         3.8.20
torch version:          2.4.1
2025-02-11 09:26:49,436 [INFO] ** TORCH CUDA version installed and working. **
2025-02-11 09:26:49,437 [INFO] >>>> using GPU (CUDA)
2025-02-11 09:26:49,446 [INFO] >>>> running cellpose on 1 images using chan_to_seg GRAY and chan (opt) NONE
2025-02-11 09:26:49,448 [INFO] >> denoise_cyto3 << model set to be used
D:\conda\conda-envs\cellpose-310\lib\site-packages\cellpose\resnet_torch.py:271: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  state_dict = torch.load(filename, map_location=device)
2025-02-11 09:26:49,717 [INFO] >>>> model diam_mean =  30.000 (ROIs rescaled to this size during training)
2025-02-11 09:26:49,718 [INFO] >> cyto3 << model set to be used
2025-02-11 09:26:49,783 [INFO] >>>> loading model C:\Users\guiet\.cellpose\models\cyto3
2025-02-11 09:26:49,859 [INFO] >>>> model diam_mean =  30.000 (ROIs rescaled to this size during training)
2025-02-11 09:26:49,859 [INFO] >>>> cannot auto-estimate diameter for image restoration
Traceback (most recent call last):
  File "D:\conda\conda-envs\cellpose-310\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\conda\conda-envs\cellpose-310\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\conda\conda-envs\cellpose-310\lib\site-packages\cellpose\__main__.py", line 358, in <module>
    main()
  File "D:\conda\conda-envs\cellpose-310\lib\site-packages\cellpose\__main__.py", line 195, in main
    diameter = model.diam_labels
AttributeError: 'CellposeDenoiseModel' object has no attribute 'diam_labels'

Thank you for your help,

Best,

Romain

@romainGuiet romainGuiet added the bug Something isn't working label Feb 11, 2025
@romainGuiet
Copy link
Author

romainGuiet commented Feb 11, 2025

one needs to specify the diameter value, it can't be 0!
the line :

python -Xutf8 -m cellpose --dir C:\Users\guiet\AppData\Local\Temp\cellposeTemp --pretrained_model cyto3 --chan 0 --chan2 0 --diameter 30 --verbose --save_tif --no_npy --use_gpu --restore_type denoise_cyto3

works

Cheers

R

@carsen-stringer
Copy link
Member

thanks, let me add a useful error message!

@carsen-stringer carsen-stringer self-assigned this Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants