最近看到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
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:caffe—–silence layer 作用 - Python技术站