caffe ----- silence layer effect

Recently seen prototxt silence inside this layer, curious about what to use, but also look at the source code is surprisingly simple:

#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

 

Only in reverse when the diff is set to 0.

 

We found the following related interpretation,

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 role is to avoid printing information blobs in the log and not in use. As an output management, gradient 0.

For example it is that we use AlexNet, we will fc7 the bottom of fc6 changed pool5, and we do not want to delete, then fc6 statement, although this time fc6 layer will not be used but will output an error message to stderr,

At this point we can be saved by using fc6 statement slicence layer, and without error.

 

reference:

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

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

Guess you like

Origin www.cnblogs.com/hellowooorld/p/11326229.html