ValueError: Error when checking input: expected conv2d_36_input to have shape (3, 32, 32) but got array with shape (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)

当我尝试 运行 我的训练模型时出现错误我应该怎么做才能通过错误报告?

我的模型或者reshape部分有问题吗?

这是我改造的部分

# 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 = 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

您的训练和测试数据集的输入形状与您的模型不同。使用 input_shape() 时,您需要记住所需输入的大小。在你的情况下,你的形状看起来像 (1,10,10),这是一张 10x10 图像,一级 channel/depth(即黑白图像)。但是,您使用的模型需要一个 (3,32,32) 形状,它被转换成具有 32x32 尺寸的彩色图像(即 3 通道代表 RGB 颜色)。

因此,如果您按照以下代码更改模型,它可能会起作用,但您还需要优化其他参数,例如 Conv2D 所需的特征图:

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