预期输入有 4 个维度,但得到了具有形状的数组

expected input to have 4 dimensions, but got array with shape

我有这个错误

Error when checking input: expected input_13 to have 4 dimensions, but got array with shape (7, 100, 100)

对于下面的代码,我应该如何重塑数组以适应 4 维,我搜索了它但不明白以前的解决方案。请询问是否不清楚它在卷积神经网络中非常常见的问题。

inputs=Input(shape=(100,100,1))

x=Conv2D(16,(3,3), padding='same')(inputs)
x=Activation('relu')(x)
x=Conv2D(8,(3,3))(x)
x=Activation('relu')(x)
x=MaxPooling2D(pool_size=(2,2))(x)
x=Dropout(0.2)(x)
x=Dense(num_classes)(x)
x=Activation('softmax')(x)
output=Activation('softmax')(x)
model=Model([inputs], output)

如果 x 是您的数据数组,您应该简单地应用以下转换:

x = x.reshape((-1, 100, 100, 1))