【发布时间】:2021-12-30 21:48:18
【问题描述】:
我正在尝试对 inceptionv3 算法使用迁移学习进行一些图像分类。我有 48x48 灰度图像,但 inception v3 模型需要的最小输入尺寸为 75x5(见下文)
pre_trained_model = InceptionV3(input_shape = (48,48,3),
include_top = False,
weights = 'imagenet')
ValueError: Input size must be at least 75x75; Received: input_shape=(48, 48, 3)
如果我尝试将数组重塑为大于 75x75 的尺寸,我会收到以下错误,这是有道理的
train_images = train_image_array.reshape((train_image_array.shape[0], 76, 76, 1))
ValueError: cannot reshape array of size 66145536 into shape (28709,76,76,1)
如何将我的数组填充为大于 75x75 的东西?我觉得这应该很容易,但我似乎找不到解决方案。我填充数组的代码如下:
image_array = np.zeros(shape=(len(data), 48, 48))
image_label = np.array(list(map(int, data['emotion'])))
for i, row in enumerate(data.index):
image = np.fromstring(data.loc[row, 'pixels'], dtype=int, sep=' ')
image = np.reshape(image, (48, 48))
image_array[i] = image
return image_array, image_label
【问题讨论】:
-
Reshape 和 resize 不一样,你想调整图片的大小,而不是 reshape。
-
@Dr.史努比如果我用
image = np.resize(image, (150,150))调整我的图像大小,然后尝试重塑train_images = train_image_array.reshape((train_image_array.shape[0], 150, 150, 1))我仍然得到与数组大小相同的错误 ValueError: cannot reshape array of size 66145536 into shape (28709,150,150,1) -
您似乎只调整了一张图像的大小,而不是您的整个图像数据集?
标签: python tensorflow keras