簡體   English   中英

ValueError:檢查輸入時出錯:預期 conv2d_36_input 的形狀為 (3, 32, 32) 但得到的數組的形狀為 (1, 10, 10)

[英]ValueError: Error when checking input: expected conv2d_36_input to have shape (3, 32, 32) but got array with shape (1, 10, 10)

當我嘗試運行我的訓練 model 時出現錯誤,我應該怎么做才能通過錯誤報告?

我的 model 或我的重塑部件有什么問題嗎?

這是我的重塑部分

# Reshape and normalize training data
trainX = train.reshape(train.shape[0], 1, 10, 10).astype( 'float32' )
x_train = trainX / 255.0
y_train = train[:,99]
# print(y_train)
# # # Reshape and normalize test data
testX = test.reshape(test.shape[0], 1, 10, 10).astype(     'float32' )
x_test = testX / 255.0
y_test = test[:,99]
# print(y_test)

這是我的 model:

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(3, 32, 32), 
activation='relu', padding='same'))
model.add(Dropout(0.2))
model.add(BatchNormalization())
model.add(Conv2D(64, (3, 3), padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(BatchNormalization())

然后如果我將我的數據重塑為 3*32*32 然后出現值錯誤報告:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-31-36bf3e556ae8> in <module>()
----> 1 trainX = train.reshape(train.shape[0], 3, 32, 32).astype( 'float32' )
  2 x_train = trainX / 255.0
  3 y_train = train[:,10]
  4 # print(y_train)
  5 # # # Reshape and normalize test data

訓練和測試數據集的輸入形狀與 model 不同。 使用input_shape()時,您需要記住所需輸入的大小。 在您的情況下,您的形狀看起來像 (1,10,10),這是一個 10x10 圖像,具有一級通道/深度(即黑白圖像)。 但是,您使用的 model 需要 (3,32,32) 形狀,該形狀被轉換為 32x32 尺寸的彩色圖像(即 3 通道代表 RGB 顏色)。

因此,如果您將 model 更改為以下代碼,它可能會起作用,但您還需要優化其他參數,例如 Conv2D 所需的功能 map:

model.add(Conv2D(32, (3, 3), **input_shape=(1, 10, 10)**,activation='relu', padding='same'))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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