无法将大小为47040000的数组重塑为形状(60000,32,32,1)

问题描述 投票:0回答:1

我使用fashionmnist数据集,其中包含60,000张黑白28x28黑白图像。我使用的架构是vgg16。但是它不接受照片的尺寸,我们必须调整它们的尺寸。

您能帮我告诉我应该使用什么代码来调整大小。

enter image description here

python keras anaconda google-colaboratory vgg-net
1个回答
0
投票

您不能将reshape数组用于不同数量的像素。您正在寻找的是一种调整大小的方法。您可以使用PIL

import numpy as np
from PIL import Image

img = np.random.randint(0, 255, (32, 32, 3)).astype('uint8') # random image
Out[36]: 
array([[[164, 205,  41],
        [ 29, 187, 195],
        [ 33,  44, 175],
        ...,
        [154,  76, 179],
        [243, 127, 170],
        [ 51, 133, 130]], # etc...
img = Image.fromarray(img).resize((28, 28), 3)) # resize
img = np.array(img) # re-transform into an array
© www.soinside.com 2019 - 2024. All rights reserved.