将 3D 数组大小调整为 2D



我有一些代码看起来像这样

number_of_pairs = int(len(path_list) / 2)
pairs_of_images = [np.zeros(
(number_of_pairs, self.image_height, self.image_height, 1)) for i in range(2)]
labels = np.zeros((number_of_pairs, 1))
size = 105,105
for pair in range(number_of_pairs):
image = Image.open(path_list[pair * 2])
image = image.resize((105,105))
image = np.asarray(image).astype(np.float64)
print("before resize is{}".format(image))
pairs_of_images[0][pair, :, :, 0] = image

但是,我收到一个错误,其中

pairs_of_images[1][对, :, :, 0] = 图像
值错误: 无法 从形状 (105,105,4( 到形状 (105,105( 的广播输入数组

有没有办法摆脱数组的第三维?

替换

image = Image.open(path_list[pair * 2])

image = Image.open(path_list[pair * 2]).convert('L')

"L"模式将图像转换为单通道图像。

最新更新