简体   繁体   English

fastai - plot 验证和训练准确度

[英]fastai - plot validation and training accuracy

I have used Keras before, and then I plotted the training and validation accuracy of datasets this way—我之前用过Keras,然后我用这种方式绘制了数据集的训练和验证准确率——

plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])

I'm currently learning fastai, and have already plotted training and validation losses.我目前正在学习 fastai,并且已经绘制了训练和验证损失。 But I don't know how to plot validation accuracy and training accuracy.但是我不知道 plot 验证准确率和训练准确率如何。

learn.recorder.plot_losses()

Would anyone please help?有人可以帮忙吗?

Check out: https://forums.fast.ai/t/plotting-metrics-after-learning/69937/3查看: https://forums.fast.ai/t/plotting-metrics-after-learning/69937/3

The function plot_metrics() by Ignacio Oguiza is detailed there.那里详细介绍了 Ignacio Oguiza 的 function plot_metrics()。 Without it, you'll get an error 'Learner' object has no attribute 'plot_metrics'没有它,你会得到一个错误'Learner' object has no attribute 'plot_metrics'

Once implemented, you can call plot_metrics() as Sirynka has mentioned:实施后,您可以调用 plot_metrics() 正如 Sirynka 提到的:

learn.recorder.plot_metrics() learn.recorder.plot_metrics()

And you may get some nice charts:你可能会得到一些漂亮的图表: 在此处输入图像描述

Post here just for people who are using the latest FastAI version 2.此处仅适用于使用最新 FastAI 版本 2 的人。

The aforementioned methods are out of date and was for Fast AI version 1.上述方法已过时,适用于 Fast AI 版本 1。

For the latest version, you should use a Callback with fit method:对于最新版本,您应该使用带有 fit 方法的回调:

learn.fit_one_cycle(10, slice(5e-3,5e-2),cbs=[ShowGraphCallback()])

Here is the document这是文件

The benefit of using this new callback for plot the train validation metrics is it happens directly after each epoch of training and validation, no need for a separated line of code.对 plot 训练验证指标使用这个新回调的好处是它直接在训练和验证的每个 epoch 之后发生,不需要单独的代码行。

learn.recorder.plot_metrics()

will plot all the metrics that you'v specified in将 plot 您指定的所有指标

learn = cnn_learner(data, models.resnet34,
    metrics=[accuracy, error_rate])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM