I define a focal loss function which has 3 parts: computeOutput, backprop, and loss. When I train with this new focal loss, it happens loss increase with Progress(should decrease and convergence). Would you pls advise how to modify this focal loss function?
In loss.cc, I added focal loss:
I define a focal loss function which has 3 parts: computeOutput, backprop, and loss. When I train with this new focal loss, it happens loss increase with Progress(should decrease and convergence). Would you pls advise how to modify this focal loss function? In loss.cc, I added focal loss:
FocalLoss::FocalLoss(std::shared_ptr& wo) : Loss(wo) {}
void FocalLoss::computeOutput(Model::State& state) const { Vector& output = state.output; output.mul(*wo_, state.hidden); real max = output[0], z = 0; int32_t osz = output.size(); for (int32_t i = 0; i < osz; i++) { max = std::max(output[i], max); } for (int32_t i = 0; i < osz; i++) { output[i] = exp(output[i] - max); z += output[i]; } for (int32_t i = 0; i < osz; i++) { output[i] /= z; } }
real FocalLoss::forward( const std::vector& targets,
int32_t targetIndex,
Model::State& state,
real lr,
bool backprop) {
computeOutput(state);
}