[英]ValueError: could not broadcast input array from shape (50,50,3) into shape (50,50)
Trying to load data from dataset into an array data[ ], giving me a broadcasting error.试图将数据集中的数据加载到数组 data[] 中,给我一个广播错误。
code:代码:
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)
error:错误:
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)
Images are usually loaded in as X * Y * 3 (or 3 * X * Y) arrays, as images store values for the red, green and blue pixelvalues.图像通常加载为 X * Y * 3(或 3 * X * Y)arrays,因为图像存储红色、绿色和蓝色像素值的值。 So either reshape them into a 50,50,3 array (creating a 4D N * 50 * 50 *3) array, or think on how you want to merge the 3 color channels.
因此,要么将它们重塑为 50、50、3 数组(创建 4D N * 50 * 50 *3)数组,要么考虑如何合并 3 个颜色通道。
If you want to make a greyscale picture out of it (which can be stored in a 50x50 array), use for example luminosity method: val = (0.3 * R) + (0.59 * G) + (0.11 * B).如果您想从中制作灰度图片(可以存储在 50x50 阵列中),请使用例如亮度方法:val = (0.3 * R) + (0.59 * G) + (0.11 * B)。
But this depends on your application.但这取决于您的应用程序。 I assume that (given the way you construct your image array) that it's gonna be used in a Neural Network?
我假设(考虑到您构建图像阵列的方式)它将用于神经网络? Then I'd just use the 3 channels.
然后我只使用3个频道。 Tensorflow can deal with that, Conv2d even has a variable to set the number of channels.
Tensorflow 可以处理,Conv2d 甚至有一个变量来设置通道数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.