即使在使用展平后,密集层尺寸误差仍然存在

2024-09-27 21:31:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Keras的新手,使用下面的模型来试验MNIST问题。你知道吗

model = Sequential()

model.add(Conv2D(filters=32, kernel_size=(5, 5), input_shape=(28, 28, 1),
             padding='same', activation='relu',
             bias_initializer='RandomNormal'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same'))

model.add(Conv2D(filters=32, kernel_size=(3, 3), padding='same',    
          activation='relu', bias_initializer='RandomNormal'))
model.add(MaxPooling2D(pool_size=(2, 2), padding='same'))

model.add(Flatten())

model.add(Dense(256, activation='relu'))
model.add(Dropout(0.4))

model.add(Dense(10, activation='softmax'))

我得到这个错误,即使我添加了一个平坦层:

ValueError: Error when checking target: expected dense_2 to have 2     
dimensions, but got array with shape (4200, 28, 28, 10)

如果对第一个密集层有效,为什么第二个(softmax)层有问题?你知道吗

谢谢你的帮助。你知道吗


Tags: addsizemodelactivationkernelfiltersrelusame

热门问题