cellpose
cellpose copied to clipboard
io.masks_flows_to_seg errors silently without saving seg npy file [BUG]
Thanks for the nice software. I trained a model in the GUI and I was trying to now use a jupyter notebook to apply it to multiple images. I tried following the tutorial notebooks, and the model was running fine, but when I ran io.masks_flows_to_seg
, I did not see any seg npy files. I'm using python 3.8.19 on windows and cellpose version 3.0.7.
https://github.com/MouseLand/cellpose/blob/509ffca33737058b0b4e2e96d506514e10620eb3/cellpose/io.py#L499
I believe the above line is the issue. imgs_restore=None
but then [] * len(masks)
always equals an empty list []
of len 0 (even though something like [None] * len(masks)
would return a list of lists of len(masks)
). This causing the enumerate command on line 501 to fail silently and no .npy
https://github.com/MouseLand/cellpose/blob/509ffca33737058b0b4e2e96d506514e10620eb3/cellpose/io.py#L501 files are created.
I believe the same error is also in the test test_cyto2_to_seg
which at the moment might also return without error but does not save the seg npy files.
I think changing the offending line to imgs_restore = [[] for _ in masks]
might work.
The same error doesn't affect the GUI, which uses the _save_sets
function instead.
As a reference one can see the differences in the following lines:
n = 3
masks = [1] * n
r1 = [] * n
r2 = [None] * n
# nothing is printed since r1 is len 0
for i, v in enumerate(zip(masks, r1)):
print(i, r1)
# prints 1, 2, 3
for i, v in enumerate(zip(masks, r2)):
print(i, r2)
(sorry, just noticed this is a duplicate of https://github.com/MouseLand/cellpose/issues/894)
I may have encoutered the same type of behavior for io.save_rois
, empty zips. Either that or segmentation that was working on 2.2.3 stopped working on v3
Same problem here. I've updated, and now, when I run:
masks, flows, styles, diams = model.eval(imgs, diameter=None, channels=channels)
io.masks_flows_to_seg(imgs, masks, flows, new_files, channels=channels, diams=diams)
io.save_to_png(imgs, masks, flows, new_files)
I get the PNG files, but not *.seg.npy files without an error
Should be fixed with #932