簡體   English   中英

無法將大小為 47040000 的數組重塑為預訓練神經網絡的形狀 (60000,32,32,1)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM