我使用 Fashionmnist 数据集,其中包含 60,000 张黑白 28x28 图像。 我使用的架构是vgg16。但它不接受照片的尺寸,我们必须调整它们的大小。 你能帮忙告诉我应该使用什么代码来调整大小吗?
最佳答案
您不能使用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), 1) # resize
img = np.array(img) # re-transform into an array
关于python - 无法将大小为 47040000 的数组 reshape 为预训练神经网络的形状 (60000,32,32,1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59429047/