【发布时间】:2021-05-08 04:41:43
【问题描述】:
我的训练数据中有标签 0、2、4、6、8。所以,从技术上讲,我有 5 个类,但是当我编写以下代码时,
model = keras.Sequential([
layers.Dense(units=512, activation="relu",input_shape=[784]),
layers.Dense(units=512, activation="relu"),
layers.Dense(units=5,activation="softmax")
])
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'],
)
history = model.fit(
training_X, training_Y.reshape(2465,1),
validation_data=(val_X, val_Y.reshape(986,1)),
epochs=50,
verbose = 1
)
我收到此错误,
InvalidArgumentError: Received a label value of 8 which is outside the valid range of [0, 5). Label values: 6 8 4 6 2 4 8 0 2 2 4 6 0 2 6 4 4 2 2 8 0 0 6 0 2 8 0 2 2 6 4 4
那么,我如何只使用 5 个输出单元并针对这些标签进行训练?
【问题讨论】:
标签: python tensorflow deep-learning