kevinjohncutler / omnipose

Omnipose: a high-precision solution for morphology-independent cell segmentation
https://omnipose.readthedocs.io
Other
101 stars 30 forks source link

GUI Preprocessing Discrepency #94

Closed YashM8 closed 4 months ago

YashM8 commented 5 months ago

When I pass an image into the GUI and run segmentation, it works.

But when I run the following script -

`se_GPU = core.use_gpu() print('>>> GPU activated? {}'.format(use_GPU))

model = models.CellposeModel(gpu=use_GPU, model_type="cyto2") print("Model Initialized")

files = ["stitch/image_1.png", "stitch/image_1.png"]

for filename in files: img = io.imread(filename) img = img.astype(np.float32)

masks, flows, styles = model.eval([img])

np_masks = np.array(masks)
masks_int = np_masks.astype(int)

print()
print(np.array(masks).shape)
print(len(flows))
print()

fig = plt.figure(figsize=(12, 5))
plot.show_segmentation(fig, img, masks_int, flows[0])
plt.tight_layout()
plt.show()

`

I get the error -

Traceback (most recent call last): File "/Users/ypm/Desktop/DnnTrack/dnn.py", line 54, in <module> masks, flows, styles = model.eval([img]) File "/opt/miniconda3/envs/omnipose/lib/python3.9/site-packages/cellpose_omni/models.py", line 1006, in eval maski, stylei, flowi = self.eval(x[i], File "/opt/miniconda3/envs/omnipose/lib/python3.9/site-packages/cellpose_omni/models.py", line 1085, in eval masks, styles, dP, cellprob, p, bd, tr, affinity, bounds = self._run_cp(x, File "/opt/miniconda3/envs/omnipose/lib/python3.9/site-packages/cellpose_omni/models.py", line 1313, in _run_cp outputs = dynamics.compute_masks(dP[:,i], cellprob[i], niter=niter, File "/opt/miniconda3/envs/omnipose/lib/python3.9/site-packages/cellpose_omni/dynamics.py", line 779, in compute_masks p , inds, tr = follow_flows(dP * cp_mask / 5., mask=cp_mask, inds=inds, niter=niter, interp=interp, File "/opt/miniconda3/envs/omnipose/lib/python3.9/site-packages/cellpose_omni/dynamics.py", line 613, in follow_flows p_interp, tr = steps2D_interp(p[:,inds[:,0], inds[:,1]], dP, niter, use_gpu=use_gpu, File "/opt/miniconda3/envs/omnipose/lib/python3.9/site-packages/cellpose_omni/dynamics.py", line 395, in steps2D_interp pt = torch.from_numpy(p[[1,0]].T).double().to(device).unsqueeze(0).unsqueeze(0) # p is n_points by 2, so pt is [1 1 2 n_points] TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

I wonder what the GUI is doing to nullify this error.

kevinjohncutler commented 4 months ago

@YashM8 I think I came across this too and I fixed this in the last couple git versions, please pull the repo and try it out! I have been using it in the GUI and notebook on M1 over the last few days. Will close for now, but please reopen if the problem persists.