caffe-----silence layer 作用

最近看到prototxt里面有silence这个层,好奇是干什么用的,而且看源码也出奇的简单:

#include <vector>

#include "caffe/layers/silence_layer.hpp"
#include "caffe/util/math_functions.hpp"

namespace caffe {

template <typename Dtype>
void SilenceLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
      const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
  for (int i = 0; i < bottom.size(); ++i) {
    if (propagate_down[i]) {
      caffe_set(bottom[i]->count(), Dtype(0),
                bottom[i]->mutable_cpu_diff());
    }
  }
}

#ifdef CPU_ONLY
STUB_GPU(SilenceLayer);
#endif

INSTANTIATE_CLASS(SilenceLayer);
REGISTER_LAYER_CLASS(Silence);

}  // namespace caffe

 

仅仅是在反向的时候将diff置为0.

 

查到如下相关解释,

The use of this layer is simply to avoid that the output of unused blobs is reported in the log. 
Being an output manager layer, it is obviously zero its gradient. For instance, let us assume we are using AlexNet and we change the bottom of the 'fc7' layer to 'pool5' instead of 'fc6'.

If we do not delete the 'fc6' blob declaration, this layer is not used anymore but its ouput will be printed in stderr:
it is considered as an output of the whole architecture.
If we want to keep 'fc6' for some reasons, but without showing its values, we can use the 'SilenceLayer'.

SilenceLayer的作用就是避免在log中打印并没有使用的blobs的信息。作为一个output的管理层,梯度是0。

举例就是,我们在使用AlexNet,我们将fc7的bottom由fc6改为pool5,而且我们不想删除fc6声明的话,此时fc6 layer虽然不会用到但是会输出错误信息到stderr,

我们此时可以通过使用slicence layer 来保存fc6声明,而且不会报错。

 

参考:

https://stackoverflow.com/questions/42172871/explain-silence-layer-in-caffe

https://blog.csdn.net/Soleilhao/article/details/71775643

转载于:https://www.cnblogs.com/hellowooorld/p/11326229.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值