脾气暴躁:增大第4维的尺寸

时间:2018-10-12 03:33:12

标签: python numpy keras autoencoder

我有一个4D numpy数组:(#images,高度,宽度,通道)RGB图像。确切尺寸是(46,224,224,3)。

我也有相同图像的灰度版本。确切的尺寸是(46,224,224,1)。

我正在与Keras一起玩,试图使自动编码器从灰度级中学习图像值,但是模型抱怨尺寸,所以我想将2个额外的通道添加到灰度级数组中,但是我似乎不知道怎么办。

temp_gray_images = np.zeros(original_images.shape, dtype=np.float32)
temp_gray_images[:,:,:,0] = gray_images
ValueError: could not broadcast input array from shape (46,224,224,1) into shape (46,224,224)

因此,我随后了解了numpy.hstack,并打开了一个新终端,并尝试使用一些虚拟数据和我可以处理的许多尺寸,并能够获得预期的结果。但是,这似乎不适用于4维。

temp_gray_images = np.hstack([gray_images, np.zeros([original_images.shape[0], original_images.shape[1], original_images.shape[2], 2])])
ValueError: all the input array dimensions except for the concatenation axis must match exactly

这没有意义,因为我将前三个尺寸保持相同大小。

但是最终验证数据与火车数据不匹配,因为RGB和灰度中有2个额外的通道。

x_train shape: (46, 224, 224, 3)
xtest_shape shape: (46, 224, 224, 1)
autoencoder.fit(x_train, x_train, epochs=50, batch_size=256, shuffle=True, validation_data=(x_test, x_test))

谢谢。

1 个答案:

答案 0 :(得分:0)

这就是您要寻找的吗?

NetworkId

重复将将灰度图像复制到所需数量的通道中