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

Omnipose not working on stacks #61

Open
smury opened this issue Oct 26, 2023 · 2 comments
Open

Omnipose not working on stacks #61

smury opened this issue Oct 26, 2023 · 2 comments

Comments

@smury
Copy link

smury commented Oct 26, 2023

Hello,

As the title says, I am having trouble with stacks. As a test I put 5 copies of the e1t1_crop.tif test image into a stack and ran omnipose with
python -m omnipose --dir D:\[location of folder] --save_tif --dir_above --no_npy --in_folders --omni --pretrained_model bact_phase_omni --cluster --mask_threshold 1 --flow_threshold 0 --diameter 30

but I got the following error:

C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\superqt\collapsible_collapsible.py:4: PythonQtWarning: Selected binding 'pyqt5' could not be found; falling back to 'pyqt6'
from qtpy.QtCore import (
!NEW LOGGING SETUP! To see cellpose progress, set --verbose
No --verbose => no progress or info printed
2023-10-26 16:51:56,582 [INFO] >>>> using CPU
2023-10-26 16:51:56,582 [INFO] This model uses boundary field, setting nclasses=3.
2023-10-26 16:51:56,582 [INFO] running omnipose on 1 image(s) using 2 channel(s).
2023-10-26 16:51:56,582 [INFO] channel(s) to seg: MONO and NONE
2023-10-26 16:51:56,582 [INFO] omni is ON, cluster is True
2023-10-26 16:51:56,708 [INFO] using diameter 30.00 for all images
2023-10-26 16:51:56,708 [INFO] 0%| | 0/1 [00:00<?, ?it/s]
2023-10-26 16:51:56,708 [INFO]
2023-10-26 16:51:56,708 [INFO] 0%| | 0/5 [00:00<?, ?it/s]
2023-10-26 16:52:00,186 [INFO]
2023-10-26 16:52:00,186 [INFO] 20%|## | 1/5 [00:03<00:13, 3.48s/it]
2023-10-26 16:52:03,400 [INFO]
2023-10-26 16:52:03,400 [INFO] 40%|#### | 2/5 [00:06<00:09, 3.32s/it]
2023-10-26 16:52:06,687 [INFO]
2023-10-26 16:52:06,687 [INFO] 60%|###### | 3/5 [00:09<00:06, 3.31s/it]
2023-10-26 16:52:09,863 [INFO]
2023-10-26 16:52:09,863 [INFO] 80%|######## | 4/5 [00:13<00:03, 3.25s/it]
2023-10-26 16:52:13,257 [INFO]
2023-10-26 16:52:13,257 [INFO] 100%|##########| 5/5 [00:16<00:00, 3.31s/it]
2023-10-26 16:52:13,263 [INFO] 100%|##########| 5/5 [00:16<00:00, 3.31s/it]
2023-10-26 16:52:13,267 [INFO] 0%| | 0/1 [00:16<?, ?it/s]
Traceback (most recent call last):
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\runpy.py", line 196, in run_module_as_main
return run_code(code, main_globals, None,
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\omnipose_main
.py", line 12, in
main()
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\omnipose_main
.py", line 9, in main
cellpose_omni_main(args)
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\cellpose_omni_main
.py", line 315, in main
io.save_masks(image, masks, flows, image_name, png=args.save_png, tif=args.save_tif,
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\cellpose_omni\io.py", line 498, in save_masks
save_masks(image, mask, flow, file_name, png=png, tif=tif, suffix=suffix, dir_above=dir_above,
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\cellpose_omni\io.py", line 563, in save_masks
imsave(os.path.join(maskdir,basename + '_cp_masks' + suffix + ext), masks)
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\cellpose_omni\io.py", line 138, in imsave
tifffile.imsave(filename, arr)
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\tifffile\tifffile.py", line 1326, in imsave
imwrite(*args, **kwargs)
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\tifffile\tifffile.py", line 1270, in imwrite
with TiffWriter(
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\tifffile\tifffile.py", line 1594, in init
self._fh = FileHandle(file, mode=mode, size=0)
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\tifffile\tifffile.py", line 14214, in init
self.open()
File "C:\Users\murrays.TER\AppData\Local\anaconda3\envs\omnipose\lib\site-packages\tifffile\tifffile.py", line 14233, in open
self._fh = open(
OSError: [Errno 22] Invalid argument: 'C:\Users\murrays.TER\masks\:_cp_masks.tif'

It looks like something is going wrong with the path. The location in the last line of the error is not where the masks are supposed to go. That colon is obviously not right.

Everything works fine when acting on a single image and adding --z_axis 2 doesn't change anything.

If I use the gui, the stack dimensions are not determined correctly and it analyses 384 planes of size (392,1).

@smury
Copy link
Author

smury commented Oct 27, 2023

So I fixed it by

changing the these lines in io.py
-- 138 tifffile.imsave(filename, arr)
++138 tifffile.imsave(filename, arr,append=True)

--497 for image, mask, flow, file_name in zip(images, masks, flows, file_names):
--498 save_masks(image, mask, flow, file_name, png=png, tif=tif, suffix=suffix, dir_above=dir_above,
++497 for image, mask, flow in zip(images, masks, flows):
++498 save_masks(image, mask, flow, file_names, png=png, tif=tif, suffix=suffix, dir_above=dir_above,

I haven't made a pull request because I am still figuring out how python and omnipose work (new to both!)
Maybe someone can review it first.

@kevinjohncutler
Copy link
Owner

@smury Sorry for the extreme delay, was inundated with wrapping up my PhD program. Those changes make sense to me.

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

2 participants