I am trying to train a model but got an error says (ValueError: Shapes (16, 16) and (16, 2) are incompatible)

I am trying to train a model but got an error says (ValueError: Shapes (16, 16) and (16, 2) are incompatible)

我正在从事语音情感识别项目,在尝试拟合模型时出现以下错误:收到错误提示:

(ValueError: Shapes (16, 16) and (16, 2) are incompatible)

首先我会在开始拟合模型之前展示之前的代码:******

from keras.callbacks import ReduceLROnPlateau
    lr_reduce = ReduceLROnPlateau(monitor='val_loss', factor=0.9, patience=20, min_lr=0.000001)
    
mcp_save = ModelCheckpoint('model/aug_noiseNshift_2class2_np.h5', save_best_only=True, monitor='val_loss', mode='min')
mymodel = model.fit(x_traincnn, y_train, batch_size=16, epochs=700, validation_data = (x_testcnn, y_test), callbacks=[mcp_save, lr_reduce])

我收到以下错误:

ValueError: in user code:

    /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:830 train_function  *
        return step_function(self, iterator)
    /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:813 run_step  *
        outputs = model.train_step(data)
    /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:771 train_step  *
        loss = self.compiled_loss(
    /usr/local/lib/python3.7/dist-packages/keras/engine/compile_utils.py:201 __call__  *
        loss_value = loss_obj(y_t, y_p, sample_weight=sw)
    /usr/local/lib/python3.7/dist-packages/keras/losses.py:142 __call__  *
        losses = call_fn(y_true, y_pred)
    /usr/local/lib/python3.7/dist-packages/keras/losses.py:246 call  *
        return ag_fn(y_true, y_pred, **self._fn_kwargs)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:206 wrapper  **
        return target(*args, **kwargs)
    /usr/local/lib/python3.7/dist-packages/keras/losses.py:1631 categorical_crossentropy
        y_true, y_pred, from_logits=from_logits)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:206 wrapper
        return target(*args, **kwargs)
    /usr/local/lib/python3.7/dist-packages/keras/backend.py:4827 categorical_crossentropy
        target.shape.assert_is_compatible_with(output.shape)
    /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/tensor_shape.py:1161 assert_is_compatible_with
        raise ValueError("Shapes %s and %s are incompatible" % (self, other))

    ValueError: Shapes (16, 16) and (16, 2) are incompatible

你能帮忙吗?

问题是,我做了一个模型 (16,2) 的形状,而它必须是 (16,16)。我的输出有16个不同的类,不是2个,我把模型的最后一层或者输出层改成16个输出。 我犯了一个简单的错误,因为我是初学者。