how to print loss value for each batch
For bugs or installation issues, please provide the following information. The more information you provide, the more likely people will be able to help you.
Environment info
Operating System:
Compiler:
Package used (Python/R/Scala/Julia):
MXNet version:
Or if installed from source:
MXNet commit hash (git rev-parse HEAD):
If you are using python package, please provide
Python version and distribution:
If you are using R package, please provide
R sessionInfo():
Error Message:
Please paste the full error message, including stack trace.
Minimum reproducible example
if you are using your own code, please provide a short script that reproduces the error.
Steps to reproduce
or if you are running standard examples, please provide the commands you have run that lead to the error.
1.how to print loss value for each batch? 2. 3.
What have you tried to solve it?
1.I have read the issue #809 and read the callback.py but I don't think its what I want .Does anyone have any ideas? 2. 3.
use mx.metric.EvalMetric,when you create the module,take it as arguments,and it will be updated every batch,then use callback to print it.
Thanks for your reply @lilhope.Sorry I doesn't say it clear.I used a mx.symbol.softmaxoutput as my last layer to achieve a image classification problem but got a bad performance. So I want to see the loss value used in training .Since I'm a new comer of mxnet and in my unstandered that EvalMetric is used only for reporting?
@Arielnabai ,You mean you don't want to print the last layer output?If you want to print the output of internal layers,one method is use mx.symbol.Group([softmaxout,mx.symobl.BlockGrad(loss)]),while the loss is the layer you want to output,then you can use the EvalMetricto print it If you don't familiar with EvalMetric,I can share you some naive code,hope it helps.
@lilhope ,Thanks for your reply .It seems I mislead you.For the last sofemaxoutput layer ,we konw it's a loss layer and softmax layer,so where I can see the loss function and how to print the loss value?
If I don't say it clear,Or you can see the issue #1915 ,I want print the softmaxoutput loss(the cross entropy loss?)Appreciative If you can give some helps.
@Arielnabai Correct me if I'm wrong. Do you want to print the loss for every mini-batch as Metric prints the accumulated loss(average over all, and reset when an epoch starts). The easiest way I think is to print the loss when Metric calculates it. You can rewrite your own Metric by following some metrics here. Take CrossEntropy for an example. you can print the loss when it calculates the loss in this line(which is a sum not an average).
@lilhope hello , I met the same problem . I want to print the loss ,but I don't konw how to use mx.symbol.Group([softmaxout,mx.symobl.BlockGrad(loss)]) and eval_metric .Can you share your naive code to [email protected] ? Thank you!
@luoyetx,@lilhope Will,Thanks for both of you. I will try to rewrire my own Metric.
@Arielnabai can you tell me how to print loss value for each batch ?
@salemmohammed I guess you already figured how to do it, but this discussion is top1 result for "how to print loss mxnet module", so I will paste the solution here:
accuracy = mx.metric.Accuracy()
ce_loss = mx.metric.CrossEntropy()
comp_metric = mx.metric.CompositeEvalMetric([accuracy, ce_loss])
and then pass comp_metric to module.fit(...eval_metric=comp_metric)