0

下面是我在训练网络中的最后一层:

layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "final"
  bottom: "label"
  top: "loss"
  loss_param {
    ignore_label: 255
    normalization: VALID
  }
}

注意我采用了 softmax_loss 层。由于它的计算形式是这样的:-log(概率),所以很奇怪损失可以是负数,如下所示(迭代 80)。

I0404 23:32:49.400624  6903 solver.cpp:228] Iteration 79, loss = 0.167006
I0404 23:32:49.400806  6903 solver.cpp:244]     Train net output #0: loss = 0.167008 (* 1 = 0.167008 loss)
I0404 23:32:49.400825  6903 sgd_solver.cpp:106] Iteration 79, lr = 0.0001
I0404 23:33:25.660655  6903 solver.cpp:228] Iteration 80, loss = -1.54972e-06
I0404 23:33:25.660845  6903 solver.cpp:244]     Train net output #0: loss = 0 (* 1 = 0 loss)
I0404 23:33:25.660862  6903 sgd_solver.cpp:106] Iteration 80, lr = 0.0001
I0404 23:34:00.451464  6903 solver.cpp:228] Iteration 81, loss = 1.89034
I0404 23:34:00.451661  6903 solver.cpp:244]     Train net output #0: loss = 1.89034 (* 1 = 1.89034 loss) 

谁能为我解释一下?这怎么会发生?非常感谢!

PS:我这里做的任务是语义分割。总共有 20 个对象类加上背景(所以 21 个类)。标签范围为 0-21。额外的标签 225 被忽略,可以在本文开头的 SoftmaxWithLoss 定义中找到。

4

1 回答 1

0

caffe 是在 GPU 还是 CPU 上运行?打印出你在 softmax 操作后得到的 prob_data:

// find the next line in your cpu or gpu Forward function
softmax_layer_->Forward(softmax_bottom_vec_, softmax_top_vec_);
// make sure you have data in cpu
const Dtype* prob_data = prob_.cpu_data();

for (int i = 0; i < prob_.count(); i++) {
    printf("%f ", prob_data[i]);
}
于 2017-04-06T22:38:37.313 回答