Caffe中的欧几里得损失层

8

我目前正在尝试在caffe中实现自己的损失层,在此过程中,我使用其他层作为参考。然而,有一件事让我感到困惑,就是在Backward_cpu中使用了top [0] -> cpu_diff()。我将使用EuclideanLossLayer作为参考。这是我的问题:

  • It is my understanding that top[0]->cpu_diff() holds the error derivative from the next layer, but what if there is no other layer, how is it initialised? since it is used in EuclideanLossLayer without performing any checks:

    const Dtype alpha = sign * top[0]->cpu_diff()[0] / bottom[i]->num();
    
  • Again, in the EuclideanLossLayer, the derivative for the error with respect to the activations is calculated using the following code snippet:

    const Dtype alpha = sign * top[0]->cpu_diff()[0] / bottom[i]->num();
    caffe_cpu_axpby(
      bottom[i]->count(),              // count
      alpha,                              // alpha
      diff_.cpu_data(),                   // a
      Dtype(0),                           // beta
      bottom[i]->mutable_cpu_diff());  // b
    

    If my first assumption is correct, and top[0]->cpu_diff() does indeed hold the error derivative for the layer above, why do we only use the first element i.e. top[0]->cpu_diff()[0] as opposed to multiplying by the whole vector i.e. top[0]->cpu_diff()?

1个回答

13
对于损失层,没有下一层,因此顶部的diff blob在技术上未定义且未使用 - 但是Caffe正在使用这个预先分配的空间来存储不相关的数据:Caffe支持将损失层与用户定义的权重(在prototxt中为loss_weight)相乘,这个信息(单个标量浮点数)被存储在顶部blob的diff数组的第一个元素中。这就是为什么您会在每个损失层中看到它们乘以该数量以支持该功能的原因。这在Caffe关于损失层的教程中有解释。
这个权重通常用于向网络添加辅助损失。您可以在Google的《卷积神经网络进阶》《深度监督网络》中了解更多信息。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接