void forward_cost_layer(cost_layer l, network_state state) { if (!state.truth) return; if(l.cost_type == MASKED){ int i; for(i = 0; i < l.batch*l.inputs; ++i){ if(state.truth[i] == SECRET_NUM) state.input[i] = SECRET_NUM; } } if(l.cost_type == SMOOTH){ smooth_l1_cpu(l.batch*l.inputs, state.input, state.truth, l.delta); } else { copy_cpu(l.batch*l.inputs, state.truth, 1, l.delta, 1); axpy_cpu(l.batch*l.inputs, -1, state.input, 1, l.delta, 1); } *(l.output) = dot_cpu(l.batch*l.inputs, l.delta, 1, l.delta, 1); //printf("cost: %f\n", *l.output); }
void forward_cost_layer(cost_layer l, network * net) { if (!net->truth) return; if(l.cost_type == MASKED){ int i; for(i = 0; i < l.batch*l.inputs; ++i){ if(net->truth[i] == SECRET_NUM) net->input[i] = SECRET_NUM; } } if(l.cost_type == SMOOTH){ smooth_l1_cpu(l.batch*l.inputs, net->input, net->truth, l.delta, l.output); }else if(l.cost_type == L1){ l1_cpu(l.batch*l.inputs, net->input, net->truth, l.delta, l.output); } else { l2_cpu(l.batch*l.inputs, net->input, net->truth, l.delta, l.output); } l.cost[0] = sum_array(l.output, l.batch*l.inputs); }