python - 无法将大小为 47040000 的数组 reshape 为预训练神经网络的形状 (60000,32,32,1)

标签 python keras anaconda google-colaboratory vgg-net

我使用 Fashionmnist 数据集,其中包含 60,000 张黑白 28x28 图像。 我使用的架构是vgg16。但它不接受照片的尺寸,我们必须调整它们的大小。 你能帮忙告诉我应该使用什么代码来调整大小吗?

enter image description here

最佳答案

您不能使用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/

相关文章:

python - 计算从 4 个 mysql 表中检索到的所有可能文本对的余弦相似度

python - 如何在 python shell 中重新加载一个类?

deep-learning - 简单的加权嵌入网络

python - 如何让 Sphinx 自动摘要显示实例属性的文档?

python - Django:通过manage.py使用服务器和gunicorn等其他服务器之间的区别。哪个更好?

python - 使用 tf.data 和 mode.fit 时 1DConv 输入的维度出错

tensorflow - 无法在深度学习中序列化大于 4 GiB 的字节对象

python - 在 gitlab CI 期间激活 conda 环境

python - 如何从控制台运行 twisted?

python - 在 Python 脚本中激活 Conda 环境