【问题标题】:How to fix ' KeyError: 'accuracy' ' when running flowers_tf_lite.ipynb?运行flowers_tf_lite.ipynb时如何修复'KeyError:'accuracy''?
【发布时间】:2023-03-18 07:30:02
【问题描述】:

当我运行flowers_tf_lite.ipynb 脚本时。

Link to flowers_tf_lite.ipynb script

getting KeyError: 'accuracy' 错误停止了程序。

如何解决此类错误?

acc = history.history['accuracy']

val_acc = history.history['val_accuracy']

loss = history.history['loss']

val_loss = history.history['val_loss']

plt.figure(figsize=(8, 8))

plt.subplot(2, 1, 1)

plt.plot(acc, label='Training Accuracy')

plt.plot(val_acc, label='Validation Accuracy')

plt.legend(loc='lower right')

plt.ylabel('Accuracy')

plt.ylim([min(plt.ylim()),1])

plt.title('Training and Validation Accuracy')


plt.subplot(2, 1, 2)

plt.plot(loss, label='Training Loss')

plt.plot(val_loss, label='Validation Loss')

plt.legend(loc='upper right')

plt.ylabel('Cross Entropy')

plt.ylim([0,1.0])

plt.title('Training and Validation Loss')

plt.xlabel('epoch')

plt.show()

Img of KeyError: 'accuracy' error

【问题讨论】:

    标签: python tensorflow keyerror


    【解决方案1】:

    模型编译后,准确度指标分别命名为'acc'和'val_acc',可以使用

    model.metrics_names
    

    这会给你

    ['loss', 'acc', 'val_acc']

    所以你只需要改变上面代码的前两行

    acc = history.history['acc']
    val_acc = history.history['val_acc']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-31
      相关资源
      最近更新 更多