![](/img/trans.png)
[英]ValueError: Cannot feed value of shape (1, 50, 50, 3) for Tensor 'input/X:0', which has shape '(?, 50, 50, 1)'
[英]ValueError: could not broadcast input array from shape (50,50,3) into shape (50,50)
试图将数据集中的数据加载到数组 data[] 中,给我一个广播错误。
代码:
path = os.path.join(cur_path , r'Pothole_Image_Data')
print(path)
images = os.listdir(path)
for i in images :
try :
image = Image.open(path + '\\' + i )
image = image.resize((50,50))
image = np.array(image)
data.append(image)
except :
print("Image not found")
data = np.array(data)
print(data.shape)
错误:
ValueError Traceback (most recent call last)
11 print("Image not found")
---> 13 data = np.array(data)
14 print(data.shape)
ValueError: could not broadcast input array from shape (50,50,3) into shape (50,50)
图像通常加载为 X * Y * 3(或 3 * X * Y)arrays,因为图像存储红色、绿色和蓝色像素值的值。 因此,要么将它们重塑为 50、50、3 数组(创建 4D N * 50 * 50 *3)数组,要么考虑如何合并 3 个颜色通道。
如果您想从中制作灰度图片(可以存储在 50x50 阵列中),请使用例如亮度方法:val = (0.3 * R) + (0.59 * G) + (0.11 * B)。
但这取决于您的应用程序。 我假设(考虑到您构建图像阵列的方式)它将用于神经网络? 然后我只使用3个频道。 Tensorflow 可以处理,Conv2d 甚至有一个变量来设置通道数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.