This is useful for suppressing undesired outputs.
};
/**
+ * @brief Ignores bottom blobs while producing no top blobs. (This is useful
+ * to suppress outputs during testing.)
+ */
+template <typename Dtype>
+class SilenceLayer : public Layer<Dtype> {
+ public:
+ explicit SilenceLayer(const LayerParameter& param)
+ : Layer<Dtype>(param) {}
+ virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top) {}
+
+ virtual inline LayerParameter_LayerType type() const {
+ return LayerParameter_LayerType_SILENCE;
+ }
+ virtual inline int MinBottomBlobs() const { return 1; }
+ virtual inline int ExactNumTopBlobs() const { return 0; }
+
+ protected:
+ virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top) {}
+ // We can't define Forward_gpu here, since STUB_GPU will provide
+ // its own definition for CPU_ONLY mode.
+ virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top);
+ virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
+ const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom);
+ virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
+ const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom);
+};
+
+/**
* @brief Computes the softmax function.
*
* TODO(dox): thorough documentation for Forward, Backward, and proto params.
return new PowerLayer<Dtype>(param);
case LayerParameter_LayerType_RELU:
return new ReLULayer<Dtype>(param);
+ case LayerParameter_LayerType_SILENCE:
+ return new SilenceLayer<Dtype>(param);
case LayerParameter_LayerType_SIGMOID:
return new SigmoidLayer<Dtype>(param);
case LayerParameter_LayerType_SIGMOID_CROSS_ENTROPY_LOSS:
--- /dev/null
+#include <vector>
+
+#include "caffe/common_layers.hpp"
+#include "caffe/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, 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_data());
+ }
+ }
+}
+
+#ifdef CPU_ONLY
+STUB_GPU(SilenceLayer);
+#endif
+
+INSTANTIATE_CLASS(SilenceLayer);
+
+} // namespace caffe
--- /dev/null
+#include <vector>
+
+#include "caffe/common_layers.hpp"
+#include "caffe/layer.hpp"
+#include "caffe/util/math_functions.hpp"
+
+namespace caffe {
+
+template <typename Dtype>
+void SilenceLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top) {
+ // Do nothing.
+}
+
+template <typename Dtype>
+void SilenceLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
+ const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom) {
+ for (int i = 0; i < bottom->size(); ++i) {
+ if (propagate_down[i]) {
+ caffe_gpu_set((*bottom)[i]->count(), Dtype(0),
+ (*bottom)[i]->mutable_gpu_data());
+ }
+ }
+}
+
+INSTANTIATE_CLASS(SilenceLayer);
+
+} // namespace caffe
// line above the enum. Update the next available ID when you add a new
// LayerType.
//
- // LayerType next available ID: 36 (last added: ABSVAL)
+ // LayerType next available ID: 37 (last added: SILENCE)
enum LayerType {
// "NONE" layer type is 0th enum element so that we don't cause confusion
// by defaulting to an existent LayerType (instead, should usually error if
RELU = 18;
SIGMOID = 19;
SIGMOID_CROSS_ENTROPY_LOSS = 27;
+ SILENCE = 36;
SOFTMAX = 20;
SOFTMAX_LOSS = 21;
SPLIT = 22;