I am trying to implement a custom loss function in Mxnet, using its C++ API. The question of loss function has already been risen in python (how to use customized loss function with mxnet?) even though it doesn't address the specific question of the output.
Let say I want to create my own softmax function, I could do the following:
Symbol expFc2 = exp(fc2);
Symbol sumExp = sum("sumExp", expFc2, dmlc::optional<Shape>(Shape(1)));
Symbol expandedSumExp = expand_dims("expandedSumExp", sumExp, 1);
Symbol customSoftmax = broadcast_div(expFc2, expandedSumExp);
Symbol cross_entropy = (-1) * (one_hot("OneHotDataLabel", data_label, 10) * log(customSoftmax) + (1 - one_hot("OneHotDataLabel", data_label, 10)) * log(1 - customSoftmax));
Symbol lenet = MakeLoss(cross_entropy);
However, whenever I get the output, auto curOutput = exe->outputs;
, I seem to get the value after the computation of the loss function, which would be the cross_entropy
.
How to get the result of the customSoftmax
computation?