![](/img/trans.png)
[英]ValueError: cannot reshape array of size 60000 into shape (60000,784)
[英]Cannot reshape array of size 47040000 into shape (60000,32,32,1) for pre-trained neural network
我使用 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.