Added the code for threshold_layer to the repo
authorSergio Guadarrama <sguada@gmail.com>
Fri, 16 May 2014 01:42:50 +0000 (18:42 -0700)
committerSergio <sguada@gmail.com>
Tue, 27 May 2014 17:32:23 +0000 (10:32 -0700)
src/caffe/layers/threshold_layer.cpp [new file with mode: 0644]

diff --git a/src/caffe/layers/threshold_layer.cpp b/src/caffe/layers/threshold_layer.cpp
new file mode 100644 (file)
index 0000000..bec89cd
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2014 BVLC and contributors.
+
+#include <vector>
+
+#include "caffe/layer.hpp"
+#include "caffe/vision_layers.hpp"
+
+
+namespace caffe {
+
+template <typename Dtype>
+void ThresholdLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
+      vector<Blob<Dtype>*>* top) {
+  NeuronLayer<Dtype>::SetUp(bottom, top);
+  threshold_ = this->layer_param_.threshold_param().threshold();
+}
+
+template <typename Dtype>
+Dtype ThresholdLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
+    vector<Blob<Dtype>*>* top) {
+  const Dtype* bottom_data = bottom[0]->cpu_data();
+  Dtype* top_data = (*top)[0]->mutable_cpu_data();
+  const int count = bottom[0]->count();
+  for (int i = 0; i < count; ++i) {
+    top_data[i] = ( bottom_data[i] > threshold_) ? Dtype(1) : Dtype(0);
+  }
+  return Dtype(0);
+}
+
+INSTANTIATE_CLASS(ThresholdLayer);
+
+}  // namespace caffe