cellpose icon indicating copy to clipboard operation
cellpose copied to clipboard

Save Files as *.npy output from Jupyter Notebook not generated

Open JT-24 opened this issue 1 year ago • 3 comments

I am trying to run Cellpose 2.0 through a Jupyter notebook (have used the same one previously without issue and have not changed any code). The block dedicated to generating the .npy files runs without error, but the .npy files are not being saved to the google drive folder with the source images (nor anywhere else for that matter). I require the .npy files as some manual annotation is still necessary.

The issue is observed after executing the following code block in a Jupyter notebook after running the Custom model:

from cellpose import io

io.masks_flows_to_seg(images, masks, flows, diameter*np.ones(len(masks)), files, [chan,chan2])

The subsequent code block works just fine and generates the png/tif files etc. as required without issue:

io.save_masks(images, masks, flows, files, channels=[chan, chan2], png=True, # save masks as PNGs and save example image tif=True, # save masks as TIFFs save_txt=True, # save txt outlines for ImageJ save_flows=False, # save flows as TIFFs save_outlines=False, # save outlines as TIFFs )

Has anyone else experienced this issue? Or is there a workaround? I am running the segmentation on local cpu in the interim, however this is much more time consuming. Any feedback or input is much appreciated, thanks!

JT-24 avatar Mar 18 '24 06:03 JT-24

I've noticed the exact same thing - io.masks_flows_to_seg() runs cleanly but doesn't actually save anything anywhere, while io.save_masks() works as expected (as does plt.savefig() from downstream plots in the example code).

Salient package versions:

cellpose version: 	3.0.6 
platform:       	         linux 
python version: 	3.8.5 
torch version:  	1.8.2+cu102

Thanks!

awight-watershed avatar Mar 18 '24 22:03 awight-watershed

Good to know it's not just a local issue in that case, thanks for your comment! Indeed, io.save_masks() works perfectly fine. For me, I don't run plt.savefig() but the subsequent code block after io.save_masks() runs plt.figure and plt.imshow which is currently returning an error: CRITICAL:cellpose.io:ERROR: could not read file, 'NoneType' object has no attribute 'ndim'.

However, I think this is to do with my images as they are stitched images taken with a confocal microscope. It isn't an issue for me though, as I am only concerned with obtaining the masks and .npy files. I've run similar images using the Jupyter notebook code to implement Cellpose 2.0 and have not had this issue with the .npy files happen before.

JT-24 avatar Mar 18 '24 23:03 JT-24

~~The io.save_masks() function will save the masks, while the io.masks_flows_to_seg() function only returns the mask data. Closing for now, reopen if needed.~~

Ill look into this

mrariden avatar Mar 19 '24 16:03 mrariden

Should be fixed with #932

mrariden avatar May 07 '24 18:05 mrariden