如何修复:TypeError:通过 python 使用 cellpose 时,“list”对象没有属性“shape”

在 cellpose 中,我的图形显示为空白,没有做任何掩码或分割,它返回此类型错误:“列表”对象没有属性“形状”。我想知道是否有人可以帮我弄清楚如何制作它以便程序识别该功能并显示图像?

它标记的包含类型错误消息的代码是:

TypeError Traceback (most recent call last)
    in ()
    ----> 1 plot.show_segmentation (fig,imgs[idx],maski,flowi,channels=channels[idx])
1 frames
    /usr/local/lib/python3.7/dist-packages/cellpose/plot.py in image_to_rgb(img0,channels)
    169 if img.shape[0]<5:
    170 img = np.transpose(img,(1,2,0))
    --> 171 if channels[0]==0:
    172 img = img.mean(axis=-1)[:,:,np.newaxis]
    173 for i in range(img.shape[-1]):

这是它在没有错误消息的情况下标记的实际代码:

fig = plt.figure(figsize=(12,5))
plot.show_segmentation(fig,imgs,channels=channels)
plt.tight_layout()
plt.show()

这也是一张带有空白图像的屏幕截图 This is the blank image This is the snapshot of my error code This is what I want my image to look like when the code is complete

我试过用print()和type()函数检查,我试过转换为整数,我试过导入np.array,但不知道在我的代码中分配它的位置,等等。没有其中正在发挥作用。如果有人可以帮我弄清楚如何让它通过python识别纤维素中的功能,将不胜感激!非常感谢您的任何帮助,我非常感谢!

温暖的祝福和非常感谢!

作为完整参考,这里是我正在使用的完整代码,这也是 cellpose 网站供参考:https://colab.research.google.com/github/MouseLand/cellpose/blob/master/notebooks/run_cellpose_GPU.ipynb#scrollTo=8P5voZOVM-H9

代码开始'''

!nvcc --version
!nvidia-smi
!pip install cellpose
import numpy as np
import time,os,sys
from urllib.parse import urlparse
import skimage.io
import matplotlib.pyplot as plt
import matplotlib as mpl
%matplotlib inline
mpl.rcParams['figure.dpi'] = 300

from urllib.parse import urlparse
from cellpose import models

use_GPU = models.use_gpu()
print('>>> GPU activated? %d'%use_GPU)

from IPython.display import Image
Image('WellA01_ChannelBrightfield_Seq0000.png')
files = ['WellA01_ChannelBrightfield_Seq0000.png']
import skimage.io 
imgs = [skimage.io.imread('WellA01_ChannelBrightfield_Seq0000.png')]
nimg = len(imgs)

plt.figure(figsize=(8,4))
for k,img in enumerate(imgs[:-1]):
  plt.subplot(1,3,k+1)
  plt.imshow(img)
from cellpose import models
import skimage.io



imgs_2D = imgs

from cellpose import models
model = models.Cellpose(gpu=True,model_type='cyto')

# define CHANNELS to run segementation on
#grayscale=0,R=1,G=2,B=3
channels = ['cytoplasm','nucleus']
# IF ALL YOUR IMAGES ARE THE SAME TYPE,you can give a list with 2 elements
channels = [0,0] 

# if diameter is set to None,the size of the cells is estimated on a per image basis
# you can set the average cell `diameter` in pixels yourself (recommended) 
# diameter can be a list or a single number for all images

masks,flows,styles,diams = model.eval(imgs,diameter=None,channels=[0,0],flow_threshold=None,do_3D=False)
import numpy as np
# DISPLAY RESULTS
from cellpose import plot

nimg = len(imgs_2D)
for idx in range(nimg):
    maski = masks
    flowi = flows[0]

    fig = plt.figure(figsize=(12,5))
    plot.show_segmentation(fig,channels=channels)
    plt.tight_layout()
    plt.show() 

代码结束'''

dasiy123zs 回答:如何修复:TypeError:通过 python 使用 cellpose 时,“list”对象没有属性“shape”

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/4492.html

大家都在问