training-accuracy nan
When I was training using my own dataset, the training accuracy was shown to be nan when in epoch 8N-1(e.g. epoch 7, 15,23,31....). This makes me feel puzzled....
Also, in the example https://github.com/dmlc/mxnet-notebooks/blob/master/python/how_to/finetune.ipynb, the training accuracy falls to be nan in epoch 6. I was wondering how did this happen?
because when called get() for a metric, the count is 0, which is often due to reset() is called. it doesn't not affect model, but sometime annoying.
@mli many thanks,it's really annoying...
same problem. really annoying
same problem. Does anyone know how to fix it?
#5528
The "Epoch[x] Train-accuracy=xxx" line printed at the end of every epoch gives the impression that the accuracy metric is for the entire epoch. In reality, it is NOT.
For example if an epoch consists of 101 batches and we were printing metrics every 10 batch because callback was created that way, what will be printed as 'Train-accuracy=xxx' at the end of an epoch is actually just the accuracy from a single batch (101'st batch). Printing this as 'Epoch[x] Train-accuracy=xxx' is very misleading.
Ideally we should remove this misleading print statement. But then, I'm sure there is a lot of existing scripts out there that look for this statement. We can't remove this without breaking those scripts. Since this will be a breaking change, let's do it in a major version change.
For now, to avoid the nan error, we can avoid resetting the metrics when processing callback for the last batch. It will be reset at the beginning of the next epoch anyway.
This should fix it:
diff --git a/python/mxnet/module/base_module.py b/python/mxnet/module/base_module.py
index c03f8e7..10b3e75 100644
--- a/python/mxnet/module/base_module.py
+++ b/python/mxnet/module/base_module.py
@@ -22,6 +22,7 @@
import time
import logging
import warnings
+from copy import deepcopy
from .. import metric
from .. import ndarray
@@ -523,8 +524,9 @@ class BaseModule(object):
monitor.toc_print()
if batch_end_callback is not None:
+ arg_eval_metric = eval_metric if not end_of_batch else deepcopy(eval_metric)
batch_end_params = BatchEndParam(epoch=epoch, nbatch=nbatch,
- eval_metric=eval_metric,
+ eval_metric=arg_eval_metric,
locals=locals())
for callback in _as_list(batch_end_callback):
callback(batch_end_params)
Indu - why is this issue still open if PR 10437 fixed the issue?
Fixed by https://github.com/apache/incubator-mxnet/pull/10437