简体   繁体   English

ValueError:无法将输入数组从形状(50,50,3)广播到形状(50,50)

[英]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.

相关问题 ValueError:无法为张量“输入/X:0”提供形状(1、50、50、3)的值,其形状为“(?、50、50、1)” - ValueError: Cannot feed value of shape (1, 50, 50, 3) for Tensor 'input/X:0', which has shape '(?, 50, 50, 1)' ValueError:形状(50,50)和(3,1)不对齐:50(dim 1)!= 3(dim 0) - ValueError: shapes (50,50) and (3,1) not aligned: 50 (dim 1) != 3 (dim 0) ValueError:检查输入时出错:预期 input_1 有 5 个维度,但得到形状为 (1221, 50, 50, 1) 的数组 - ValueError: Error when checking input: expected input_1 to have 5 dimensions, but got array with shape (1221, 50, 50, 1) 检查输入时出错:预期 conv2d_1_input 的形状为 (50, 50, 1) 但得到的数组的形状为 (50, 50, 3) - Error when checking input: expected conv2d_1_input to have shape (50, 50, 1) but got array with shape (50, 50, 3) ValueError:检查目标时出错:预期density_1具有2维,但数组的形状为(68,50,50,50,1) - ValueError: Error when checking target: expected dense_1 to have 2 dimensions, but got array with shape (68, 50, 50, 50, 1) ValueError:必须通过二维输入。 形状=(1, 50, 2) - ValueError: Must pass 2-d input. shape=(1, 50, 2) 无法将大小为 20000 的数组重塑为形状 (8,50,50,3) - cannot reshape array of size 20000 into shape (8,50,50,3) ValueError:检查输入时出错:预期lstm_1_input具有3个维,但数组的形状为(393613,50) - ValueError: Error when checking input: expected lstm_1_input to have 3 dimensions, but got array with shape (393613, 50) Python ValueError:具有形状()的不可广播输出操作数与广播形状不匹配(50,) - Python ValueError: non-broadcastable output operand with shape () doesn't match the broadcast shape (50,) ValueError:检查输入时出错:预期 input_1 具有形状 (50,),但使用 ELMo 嵌入和 LSTM 获得形状为 (1,) 的数组 - ValueError: Error when checking input: expected input_1 to have shape (50,) but got array with shape (1,) with ELMo embeddings and LSTM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM