我正在使用驾驶数据图像(即个人用户的轨迹)在 CNN 模型中预测他们的商店访问。我的图片大多是黑白的,360 x 360 像素。当我将图像转换为 numpy 数组时,尺寸为 360 x 360 x 4,RGB 为 3。一个
from PIL import Image
from numpy import asarray
# load the image
image = Image.open(os.path.join(fig_path, 'image.png'))
# convert image to numpy array
data = asarray(image)
print(type(data))
# summarize shape
print(data.shape)
# create Pillow image
image2 = Image.fromarray(data)
print(type(image2))
# summarize image details
print(image2.mode)
print(image2.size)
然后我使用 temp[] 向量堆叠 CNN 所需的所有图像,并一一附加到它,并使用 .但是当我将整个矩阵作为 input_shape 输入到 CNN 模型中时,它会崩溃。以下是错误信息:
知道我的尺寸发生了什么变化吗?
答案 0 :(得分:0)
那可能是 alpha 通道。尝试像这样丢弃它:
data = asarray(image)
data = data[:,:,:3]
print(type(data))
print(data.shape)
# <class 'numpy.ndarray'>
# (677, 586, 3)
支持this answer。