【问题标题】:Trouble training data with Keras使用 Keras 训练数据时遇到问题
【发布时间】:2021-08-18 17:28:09
【问题描述】:

美好的一天,我正在与 Google colab 一起训练模型,当我尝试运行这段代码时

history_1 = model_1.fit(x_train, y_train, epochs=1000, batch_size=16, validation_data=(x_validate, y_validate))

我得到错误:

ValueError                                Traceback (most recent call last)
<ipython-input-3-bd00c937585f> in <module>()
----> 1 history_1 = model_1.fit(x_train, y_train, epochs=1000, batch_size=16, validation_data=(x_validate, y_validate))

3 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training_utils.py in check_loss_and_target_compatibility(targets, loss_fns, output_shapes)
    683           raise ValueError('A target array with shape ' + str(y.shape) +
    684                            ' was passed for an output of shape ' + str(shape) +
--> 685                            ' while using as loss `' + loss_name + '`. '
    686                            'This loss expects targets to have the same shape '
    687                            'as the output.')

ValueError: A target array with shape (600, 1) was passed for an output of shape (None, 16) while using as loss `mean_squared_error`. This loss expects targets to have the same shape as the output.

我不确定我的输入有什么问题,我遵循 TinyML 书中的示例,有人可以帮助澄清如何解决这个问题吗?

【问题讨论】:

  • 你需要分享模型

标签: tensorflow keras tf.keras


【解决方案1】:

尝试使用 SparseCategoricalCrossentropy 而不是 CategoricalCrossentropy。看起来您的基本事实标签很稀疏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-08
    • 1970-01-01
    • 2019-10-16
    • 2019-09-28
    • 2020-02-25
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多