咖啡中的欧几里得损失层 [英] Euclidean Loss Layer in Caffe

查看:94
本文介绍了咖啡中的欧几里得损失层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在caffe中实现自己的损失层,并且在尝试实现时,正在使用其他层作为参考。然而,令我困惑的一件事是在 Backward_cpu 中使用 top [0]-> cpu_diff() 。我将使用 EuclideanLossLayer 作为参考。这是我的问题

I am currently trying to implement my own loss layer in caffe, and while attempting to do so, am using other layers as a reference. One thing that puzzles me, however, is the use of top[0]->cpu_diff() in Backward_cpu. I will be using the EuclideanLossLayer as a reference. Here are my questions


  • 据我了解, 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();


  • 再次在 EuclideanLossLayer 中,则使用以下代码段来计算与激活有关的错误的导数:

  • 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
    

    如果我的第一个假设正确,则 top [0] -> cpu_diff()确实包含上一层的误差导数,为什么我们只使用第一个元素,即 top [0]-> cpu_diff()[ 0] 而不是与整个向量相乘,即 top [0]-> cpu_diff()

    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()?

    推荐答案

    对于损失层,没有下一层,因此顶部diff blob在技术上是未定义和未使用的-但是Caffe正在使用此预分配的空间来存储无关的数据:Caffe支持将损失层与用户定义的权重(原型中的loss_weight)相乘,此信息(单个标量浮点数)存储在diff的第一个元素中顶部Blob的数组。这就是为什么您会在每个损耗层看到它们乘以该数量以支持该功能的原因。 Caffe有关损耗层的教程对此进行了解释。

    For loss layers, there is no next layer, and so the top diff blob is technically undefined and unused - but Caffe is using this preallocated space to store unrelated data: Caffe supports multiplying loss layers with a user-defined weight (loss_weight in the prototxt), this information (a single scalar floating point number) is stored in the first element of the diff array of the top blob. That's why you'll see in every loss layer, that they multiply by that amount to support that functionality. This is explained in Caffe's tutorial about the loss layer.

    此权重通常用于增加网络的辅助损耗。您可以在Google的深入了解卷积深度监督的网

    This weight is usually used to add auxiliary losses to the network. You can read more about it in Google's Going Deeper with Convoltions or in Deeply-Supervised Nets.

    这篇关于咖啡中的欧几里得损失层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆