cellpose icon indicating copy to clipboard operation
cellpose copied to clipboard

update masks_flows_to_seg to not require diameter input

Open davidfoub opened this issue 3 years ago • 4 comments

I have trained a model using cellpose 2.0 GUI but I am running into errors getting it to run in notebook. import skimage.io import time, os, sys #import matplotlib.pyplot as plt #import matplotlib as mpl #%matplotlib inline #mpl.rcParams['figure.dpi'] = 300 from cellpose import utils, io from os import listdir from os.path import isfile, join

imgpath='C:\Users\labuser\Documents\David\2p_images\cleaned\middle\' onlyfilename = [f for f in listdir(imgpath) if isfile(join(imgpath, f))]

files = [] count=0 for f in onlyfilename: files.append(imgpath+f) data = skimage.io.imread(files[count]) print(data.shape) count+=1 print(files)

from cellpose import models

model_path = "C:\Users\labuser\Documents\David\2p_images\cleaned\middle\models\Xenopus_tectum" cell_model = models.CellposeModel(gpu=True, pretrained_model=model_path) #size_model = models.SizeModel(cp_model = "", pretrained_size = model_path) channels = [0,0] for file in files: img = io.imread(file) masks, flows, styles, diams = cell_model.eval(img, channels=[0,0], cellprob_threshold=0.0, flow_threshold=0.4, resample =False) io.masks_flows_to_seg(img, masks, flows, diams, file, channels) io.save_masks(img, masks, flows, file, tif=True)

ValueError Traceback (most recent call last) Input In [18], in <cell line: 8>() 8 for file in files: 9 img = io.imread(file) ---> 10 masks, flows, styles, diams = cell_model.eval(img, channels=[0,0], 11 cellprob_threshold=0.0, flow_threshold=0.4, resample =False) 12 io.masks_flows_to_seg(img, masks, flows, diams, file, channels) 13 io.save_masks(img, masks, flows, file, tif=True)

ValueError: not enough values to unpack (expected 4, got 3)

davidfoub avatar Apr 07 '22 02:04 davidfoub

please try masks, flows, styles = cell_model.eval(img, channels=[0,0], cellprob_threshold=0.0, flow_threshold=0.4, resample =False)

(the CellposeModel eval does not return a diameter, only the Cellpose class does since it has a size model)

carsen-stringer avatar Apr 07 '22 02:04 carsen-stringer

The masks_flows_to_seg requires the diams argument. But since cellposemodel doesn't output diams I'm stuck.


TypeError Traceback (most recent call last) Input In [10], in <cell line: 8>() 9 img = io.imread(file) 10 masks, flows, styles = cell_model.eval(img, channels=[0,0], 11 cellprob_threshold=0.0, flow_threshold=0.4, resample =False) ---> 12 io.masks_flows_to_seg(images=img, masks=masks, flows=flows, file_names =file, channels=channels) 13 io.save_masks(img, masks, flows, file, tif=True)

TypeError: masks_flows_to_seg() missing 1 required positional argument: 'diams'

davidfoub avatar Apr 07 '22 02:04 davidfoub

The masks_flows_to_seg requires the diams argument. But since cellposemodel doesn't output diams I'm stuck.

TypeError Traceback (most recent call last) Input In [10], in <cell line: 8>() 9 img = io.imread(file) 10 masks, flows, styles = cell_model.eval(img, channels=[0,0], 11 cellprob_threshold=0.0, flow_threshold=0.4, resample =False) ---> 12 io.masks_flows_to_seg(images=img, masks=masks, flows=flows, file_names =file, channels=channels) 13 io.save_masks(img, masks, flows, file, tif=True)

TypeError: masks_flows_to_seg() missing 1 required positional argument: 'diams'

I have input the diams argument manually based on the value from the user-trained model. I don't know if this is the best way to do this though.

davidfoub avatar Apr 07 '22 02:04 davidfoub

thanks I will make that an optional argument from now on

carsen-stringer avatar Apr 14 '22 16:04 carsen-stringer

added in new release

carsen-stringer avatar Feb 13 '24 00:02 carsen-stringer