首页 > 解决方案 > 无法在 cnn 中获取图像通道

问题描述

这种形式有一个数据集

images                                              label
C:/Users/Drive/training/real/abs322b.png              0
C:/Users/Drive/training/fake/gd3fsdf.png              1
C:/Users/Drive/training/real/xcs2zxd.png              0
C:/Users/Drive/training/fake/mnm3222.png              1

有 1500 行。

所以,我随机尝试了一些特定的图像来找到它的编号。频道数

 x=Image.open(dataset['image'][1100])
 x.shape
 AttributeError: 'PngImageFile' object has no attribute 'shape'

 x.ndim
 AttributeError: 'PngImageFile' object has no attribute 'ndim'

我想找到前 100 张图像的通道数,该怎么做?

标签: opencv

解决方案


x是 a PIL Image,所以你想要Image.size

print(x.size)

或者您可以将其设为 Numpy 数组并使用shape

na = np.array(x)
print(na.shape)

推荐阅读