У меня есть набор данных размером 28x28. Массив точек данных x
имеет форму (10000, 28, 28)
, массив меток y
имеет форму (10000,)
.
Следующий код:
x = x.reshape(-1, 28, 28, 1)
model = Sequential([
Conv2D(8, kernel_size=(3, 3), padding="same", activation=tf.nn.relu, input_shape=(28, 28, 1)),
Dense(64, activation=tf.nn.relu),
Dense(64, activation=tf.nn.relu),
Dense(10, activation=tf.nn.softmax)
])
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
model.fit(x, y, epochs=5) #error
дает:
ValueError: Error when checking target: expected dense_3 to have 4 dimensions, but got array with shape (10000, 1)
model.summary()
вывод:
Layer (type) Output Shape Param #
=================================================================
conv2d_1 (Conv2D) (None, 28, 28, 8) 80
_________________________________________________________________
dense_1 (Dense) (None, 28, 28, 64) 576
_________________________________________________________________
dense_2 (Dense) (None, 28, 28, 64) 4160
_________________________________________________________________
dense_3 (Dense) (None, 28, 28, 10) 650
=================================================================
Total params: 5,466
Trainable params: 5,466
Non-trainable params: 0
_________________________________________________________________