【问题标题】:KeyError: 'mae' when plotting Keras model training progressKeyError: 'mae' 绘制 Keras 模型训练进度时
【发布时间】:2020-04-05 06:16:28
【问题描述】:

我遵循与Kearas regression models 教程中显示的完全相同的代码,但无法访问tfdocs.plots.HistoryPlotter() 方法。 (Google Colab 和 TensorFlow 的新手)。其余单元格在训练进度图旁边工作。

触发错误的代码sn-p:

plotter.plot({'Basic': history}, metric = 'mae') plt.ylim([0, 10])
plt.ylabel('MAE [MPG]')

还有错误:

KeyError                                  Traceback (most recent call last)
<ipython-input-25-deee24f0bc59> in <module>()
----> 1 plotter.plot({'Basic': history}, metric = 'mae')
      2 plt.ylim([0, 10])
      3 plt.ylabel('MAE [MPG]')

/usr/local/lib/python3.6/dist-packages/tensorflow_docs/plots/__init__.py in plot(self, histories, metric, smoothing_std)
     86         self.color_table[name] = color
     87 
---> 88       train_value = history.history[metric]
     89       val_value = history.history['val_' + metric]
     90       if smoothing_std is not None:

KeyError: 'mae'

并且还从 tensorflow_docs 导入必要的函数(如教程页面所示),没有任何错误:

!pip install -q git+https://github.com/tensorflow/docs

非常感谢任何帮助!

【问题讨论】:

  • 我相信 'mae' 不包含在历史记录中,您是否按照文档的建议正确初始化了变量?
  • 谢谢。 @tharina11 建议解决了这个问题。

标签: python tensorflow keras google-colaboratory


【解决方案1】:

将代码中的“mae”替换为“mean_absolute_error”。

【讨论】:

  • 谢谢,@tharina11!那行得通!您能否详细说明为什么mae 不起作用?是keras版本问题吗?
  • 不是keras错误。我运行了视频描述中提供的 colab 笔记本 (tensorflow.org/tutorials/keras/regression) 中提供的确切代码。绘制此图之前的两个单元格,有一个输出表,它是绘图代码的数据源。在那里我看到了“mean_absolute_error”而不是“mae”(这是您在图中绘制的参数)。 :)
猜你喜欢
  • 2018-01-10
  • 2019-11-12
  • 2018-08-21
  • 2019-09-24
  • 2021-05-14
  • 1970-01-01
  • 1970-01-01
  • 2020-08-03
  • 1970-01-01
相关资源
最近更新 更多