【发布时间】:2021-05-18 20:01:41
【问题描述】:
我正在关注我最近得到的一本新书,但我遇到了这个错误,我不知道我做错了什么
ValueError:形状 (None, 10, 2, 2) 和 (None, 10) 不兼容
这里是代码
from keras import models
from keras import layers
network = models.Sequential()
network.add(layers.Dense(512, activation='relu', input_shape=(28 * 28,)))
network.add(layers.Dense(10, activation='softmax'))
network.compile(optimizer = 'rmsprop',
loss = 'categorical_crossentropy',
metrics=['accuracy'])
train_images = train_images.reshape((60000, 28 * 28))
train_images = train_images.astype('float32') / 255
test_images = test_images.reshape((10000, 28 * 28))
test_images = test_images.astype('float32') / 255
from tensorflow.keras.utils import to_categorical
train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)
network.fit(train_images, train_labels, epochs=1, batch_size = 128)
【问题讨论】:
-
哪一行报错了?
-
它说最后一行
-
总是将完整的错误消息(从单词“Traceback”开始)作为文本(不是截图,不是链接到外部门户)有问题(不是评论)。还有其他有用的信息。
-
您预处理数据的方式可能出错,如果问题仍然存在,请发布完整的代码。
标签: python tensorflow machine-learning keras deep-learning