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

Intermediate saving of seg_npy, tif and png for batch processing #151

Closed
Michael-shannon opened this issue Nov 23, 2020 · 5 comments
Closed

Comments

@Michael-shannon
Copy link

Hiya

It would be useful to (as default) have cellpose save the segmentation results of each timepoint directly after processing them in batch mode, rather than right at the end.

At the moment, cellpose only saves seg_npy, tif and png of the masks after completing processing from the entire dataset when run in batch either from jupyter or in command line.

Let's say you have a 100 timepoint 3D dataset, each timepoint consisting of a separate z stack made of 50 planes - if the computer fails, does an update, or another lab member presses the wrong key at timepoint 99, all segmentation data will be lost.

To fix this, in Jupyter a simple for loop would work (provided by Carsen):

for filename in filenames:
img = io.imread(filename)
masks, flows, styles, diams = model.eval(img, diameter=diameter, channels=channels)
io.masks_flows_to_seg(img, masks, flows, diams, filename, channels)
io.save_masks(img, masks, flows, filename, tif=True)

It would be good to also have this working from command line.

Thanks,

Michael

@carsen-stringer
Copy link
Member

I've changed the CLI script so it runs in a loop as well, thanks for noticing this, this is better behavior

@Michael-shannon
Copy link
Author

I wanted to try running this via CLI, but received the following error. When I go back to the previous version of cellpose, it runs fine, but without the loop behaviour.

`

(cellpose2) E:\CELLPOSE_GIT\cellpose>python -m cellpose --dir E:/DATA/MichaelShannon/Benchmarking_Data/3D_nuclei/MJSdataTimelapse/test/ --pretrained_model nuclei --diameter 24 --save_png --use_gpu --do_3D --save_tif --batch_size 4
matplotlib not installed
** CUDA version installed and working. **

using GPU
using diameter 24.00 for all images
running cellpose on 1 images using chan_to_seg GRAY and chan (opt) NONE
0%| | 0/1 [00:00<?, ?it/s]cellpose_residual_on_style_on_concatenation_off
processing 1 image(s)
multi-stack tiff read in as having 22 planes 1 channels

running YX: 22 planes of size (1024, 1024)

25 16

0%| | 0/22 [00:00<?, ?it/s][12:13:00] c:\jenkins\workspace\mxnet-tag\mxnet\src\operator\nn\cudnn./cudnn_algoreg-inl.h:97: Running performance tests to find the best convolution algorithm, this can take a while... (set the environment variable MXNET_CUDNN_AUTOTUNE_DEFAULT to 0 to disable)

5%|████████▊ | 1/22 [00:07<02:44, 7.81s/it]
9%|█████████████████▌ | 2/22 [00:08<01:53, 5.65s/it]
14%|██████████████████████████▎ | 3/22 [00:09<01:18, 4.14s/it]
18%|███████████████████████████████████ | 4/22 [00:09<00:55, 3.08s/it]
23%|███████████████████████████████████████████▊ | 5/22 [00:10<00:39, 2.34s/it]
27%|████████████████████████████████████████████████████▋ | 6/22 [00:10<00:29, 1.82s/it]
32%|█████████████████████████████████████████████████████████████▍ | 7/22 [00:11<00:21, 1.46s/it]
36%|██████████████████████████████████████████████████████████████████████▏ | 8/22 [00:12<00:16, 1.20s/it]
41%|██████████████████████████████████████████████████████████████████████████████▉ | 9/22 [00:12<00:13, 1.02s/it]
45%|███████████████████████████████████████████████████████████████████████████████████████▎ | 10/22 [00:13<00:10, 1.11it/s]
50%|████████████████████████████████████████████████████████████████████████████████████████████████ | 11/22 [00:13<00:08, 1.23it/s]
55%|████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 12/22 [00:14<00:07, 1.33it/s]
59%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 13/22 [00:15<00:06, 1.41it/s]
64%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ | 14/22 [00:15<00:05, 1.48it/s]
68%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 15/22 [00:16<00:04, 1.52it/s]
73%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 16/22 [00:16<00:03, 1.56it/s]
77%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 17/22 [00:17<00:03, 1.58it/s]
82%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ | 18/22 [00:18<00:02, 1.60it/s]
86%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊ | 19/22 [00:18<00:01, 1.61it/s]
91%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌ | 20/22 [00:19<00:01, 1.62it/s]
95%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 21/22 [00:19<00:00, 1.62it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [00:20<00:00, 1.07it/s]
25 16

0%| | 0/22 [00:00<?, ?it/s]
5%|████████▊ | 1/22 [00:00<00:12, 1.65it/s]
9%|█████████████████▌ | 2/22 [00:01<00:12, 1.65it/s]
14%|██████████████████████████▎ | 3/22 [00:01<00:11, 1.65it/s]
18%|███████████████████████████████████ | 4/22 [00:02<00:10, 1.65it/s]
23%|███████████████████████████████████████████▊ | 5/22 [00:03<00:10, 1.65it/s]
27%|████████████████████████████████████████████████████▋ | 6/22 [00:03<00:09, 1.65it/s]
32%|█████████████████████████████████████████████████████████████▍ | 7/22 [00:04<00:09, 1.65it/s]
36%|██████████████████████████████████████████████████████████████████████▏ | 8/22 [00:04<00:08, 1.65it/s]
41%|██████████████████████████████████████████████████████████████████████████████▉ | 9/22 [00:05<00:07, 1.65it/s]
45%|███████████████████████████████████████████████████████████████████████████████████████▎ | 10/22 [00:06<00:07, 1.65it/s]
50%|████████████████████████████████████████████████████████████████████████████████████████████████ | 11/22 [00:06<00:06, 1.64it/s]
55%|████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 12/22 [00:07<00:06, 1.65it/s]
59%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 13/22 [00:07<00:05, 1.65it/s]
64%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ | 14/22 [00:08<00:04, 1.64it/s]
68%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 15/22 [00:09<00:04, 1.64it/s]
73%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 16/22 [00:09<00:03, 1.64it/s]
77%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 17/22 [00:10<00:03, 1.64it/s]
82%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ | 18/22 [00:10<00:02, 1.64it/s]
86%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊ | 19/22 [00:11<00:01, 1.64it/s]
91%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌ | 20/22 [00:12<00:01, 1.65it/s]
95%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 21/22 [00:12<00:00, 1.65it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [00:13<00:00, 1.64it/s]
25 16

0%| | 0/22 [00:00<?, ?it/s]
5%|████████▊ | 1/22 [00:00<00:12, 1.65it/s]
9%|█████████████████▌ | 2/22 [00:01<00:12, 1.65it/s]
14%|██████████████████████████▎ | 3/22 [00:01<00:11, 1.65it/s]
18%|███████████████████████████████████ | 4/22 [00:02<00:10, 1.65it/s]
23%|███████████████████████████████████████████▊ | 5/22 [00:03<00:10, 1.65it/s]
27%|████████████████████████████████████████████████████▋ | 6/22 [00:03<00:09, 1.65it/s]
32%|█████████████████████████████████████████████████████████████▍ | 7/22 [00:04<00:09, 1.65it/s]
36%|██████████████████████████████████████████████████████████████████████▏ | 8/22 [00:04<00:08, 1.65it/s]
41%|██████████████████████████████████████████████████████████████████████████████▉ | 9/22 [00:05<00:07, 1.63it/s]
45%|███████████████████████████████████████████████████████████████████████████████████████▎ | 10/22 [00:06<00:07, 1.64it/s]
50%|████████████████████████████████████████████████████████████████████████████████████████████████ | 11/22 [00:06<00:06, 1.64it/s]
55%|████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 12/22 [00:07<00:06, 1.64it/s]
59%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 13/22 [00:07<00:05, 1.64it/s]
64%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ | 14/22 [00:08<00:04, 1.64it/s]
68%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 15/22 [00:09<00:04, 1.64it/s]
73%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 16/22 [00:09<00:03, 1.64it/s]
77%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 17/22 [00:10<00:03, 1.64it/s]
82%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ | 18/22 [00:10<00:02, 1.64it/s]
86%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊ | 19/22 [00:11<00:01, 1.64it/s]
91%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌ | 20/22 [00:12<00:01, 1.64it/s]
95%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 21/22 [00:12<00:00, 1.64it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [00:13<00:00, 1.64it/s]
25 16

0%| | 0/22 [00:00<?, ?it/s]
5%|████████▊ | 1/22 [00:00<00:12, 1.65it/s]
9%|█████████████████▌ | 2/22 [00:01<00:12, 1.65it/s]
14%|██████████████████████████▎ | 3/22 [00:01<00:11, 1.65it/s]
18%|███████████████████████████████████ | 4/22 [00:02<00:10, 1.65it/s]
23%|███████████████████████████████████████████▊ | 5/22 [00:03<00:10, 1.64it/s]
27%|████████████████████████████████████████████████████▋ | 6/22 [00:03<00:09, 1.64it/s]
32%|█████████████████████████████████████████████████████████████▍ | 7/22 [00:04<00:09, 1.64it/s]
36%|██████████████████████████████████████████████████████████████████████▏ | 8/22 [00:04<00:08, 1.64it/s]
41%|██████████████████████████████████████████████████████████████████████████████▉ | 9/22 [00:05<00:07, 1.64it/s]
45%|███████████████████████████████████████████████████████████████████████████████████████▎ | 10/22 [00:06<00:07, 1.64it/s]
50%|████████████████████████████████████████████████████████████████████████████████████████████████ | 11/22 [00:06<00:06, 1.64it/s]
55%|████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 12/22 [00:07<00:06, 1.64it/s]
59%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 13/22 [00:07<00:05, 1.64it/s]
64%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ | 14/22 [00:08<00:04, 1.64it/s]
68%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 15/22 [00:09<00:04, 1.63it/s]
73%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 16/22 [00:09<00:03, 1.64it/s]
77%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 17/22 [00:10<00:03, 1.64it/s]
82%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ | 18/22 [00:10<00:02, 1.64it/s]
86%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊ | 19/22 [00:11<00:01, 1.64it/s]
91%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌ | 20/22 [00:12<00:01, 1.64it/s]
95%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎ | 21/22 [00:12<00:00, 1.64it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 22/22 [00:13<00:00, 1.64it/s]

running ZY: 1024 planes of size (22, 1024)

5 16

0%| | 0/342 [00:00<?, ?it/s][12:14:05] c:\jenkins\workspace\mxnet-tag\mxnet\src\operator\nn\cudnn./cudnn_algoreg-inl.h:97: Running performance tests to find the best convolution algorithm, this can take a while... (set the environment variable MXNET_CUDNN_AUTOTUNE_DEFAULT to 0 to disable)
0%| | 0/342 [00:03<?, ?it/s]
0%| | 0/1 [01:12<?, ?it/s]
Traceback (most recent call last):
File "C:\Users\3i.conda\envs\cellpose2\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "C:\Users\3i.conda\envs\cellpose2\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "E:\CELLPOSE_GIT\cellpose\cellpose_main
.py", line 261, in
main()
File "E:\CELLPOSE_GIT\cellpose\cellpose_main
.py", line 157, in main
batch_size=args.batch_size)
File "E:\CELLPOSE_GIT\cellpose\cellpose\models.py", line 263, in eval
stitch_threshold=stitch_threshold)
File "E:\CELLPOSE_GIT\cellpose\cellpose\models.py", line 1239, in eval
tile_overlap=tile_overlap, progress=progress)
File "E:\CELLPOSE_GIT\cellpose\cellpose\models.py", line 772, in _run_3D
bsize=bsize, tile_overlap=tile_overlap)
File "E:\CELLPOSE_GIT\cellpose\cellpose\models.py", line 516, in _run_nets
tile_overlap=tile_overlap, bsize=bsize)
File "E:\CELLPOSE_GIT\cellpose\cellpose\models.py", line 583, in _run_net
y,style = self._run_tiled(imgs, augment=augment, bsize=bsize, tile_overlap=tile_overlap)
File "E:\CELLPOSE_GIT\cellpose\cellpose\models.py", line 671, in _run_tiled
yfi = transforms.average_tiles(y, ysub, xsub, Ly, Lx)
File "E:\CELLPOSE_GIT\cellpose\cellpose\transforms.py", line 83, in average_tiles
yf[:, ysub[j][0]:ysub[j][1], xsub[j][0]:xsub[j][1]] += y[j] * mask
ValueError: operands could not be broadcast together with shapes (3,32,224) (224,224)`

@carsen-stringer
Copy link
Member

sorry about that, can you try the master branch now? I'm trying to make the 3D batches run faster, particularly in YZ and XZ

@Michael-shannon
Copy link
Author

Yes I will do, thanks for the fast fix. I will be able to try again next week.

@Michael-shannon
Copy link
Author

Would like to confirm that this is fully fixed now.

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