最近两天刚开始用mxnet,训练时发现log只有accuracy,没有loss,训练半天到跑验证的时候才发现loss为NAN了。
这样不能随时看到loss的变化而及时做出调整,比较浪费时间精力。

在python mxnet安装路径下有相关接口和文件。
我用的Anaconda2,路径为Anaconda2\Lib\site-packages\mxnet\metric.py
这是一个在线评价模块Online evaluation metric module。里面给出了一些精度、loss等的评价示例类,并且给出了详细直观的示例。这些评价类的基类都是class EvalMetric(object)。
如精度评价:
class Accuracy(EvalMetric):
"""Computes accuracy classification score.
The accuracy score is defined as
.. math::
\\text{accuracy}(y, \\hat{y}) = \\frac{1}{n} \\sum_{i=0}^{n-1}
\\text{1}(\\hat{y_i} == y_i)
Parameters
----------
axis : int, default=1
The axis that represents classes
name : str
Name of this metric instance for display.
output_names : list of str, or None
Name of predictions that should be used when updating wit

在使用MXNet进行训练时,发现只能看到accuracy而没有loss输出,这可能导致训练过程中无法及时调整参数。解决方案在于自定义评估指标。参考MXNet的`mxnet/metric.py`文件,可以找到如Accuracy和Loss等示例类。通过继承`EvalMetric`基类,可以创建自己的评价接口。例如,添加cross entropy loss的监控。在训练模型时,通过`mod.fit`的`eval_metrics`参数使用自定义的评价指标,从而在训练过程中显示loss。
最低0.47元/天 解锁文章
1551





