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

io.masks_flows_to_seg errors silently without saving seg npy file [BUG] #904

Closed
davidhbrann opened this issue Mar 28, 2024 · 3 comments
Closed

Comments

@davidhbrann
Copy link

davidhbrann commented Mar 28, 2024

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.

imgs_restore = [] * len(masks)

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

file_name, img_restore] in enumerate(zip(images, masks, flows, diams, file_names, imgs_restore)):
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 #894)

@davidhbrann davidhbrann changed the title io.masks_flows_to_seg errors silently without saving seg npy file io.masks_flows_to_seg errors silently without saving seg npy file [BUG] Mar 28, 2024
@JulianoGianlupi
Copy link

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

@maorkn
Copy link

maorkn commented Apr 16, 2024

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

@mrariden
Copy link
Collaborator

mrariden commented May 7, 2024

Should be fixed with #932

@mrariden mrariden closed this as completed May 7, 2024
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

4 participants