omnipose icon indicating copy to clipboard operation
omnipose copied to clipboard

Omnipose not working on stacks

Open smury opened this issue 2 years ago • 2 comments

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 avatar Oct 26 '23 15:10 smury

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.

smury avatar Oct 27 '23 14:10 smury

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

kevinjohncutler avatar Dec 21 '23 01:12 kevinjohncutler