From 876766bce609acaa4a668c6d4eab2bfba7d03a5f Mon Sep 17 00:00:00 2001 From: Sergio Guadarrama Date: Thu, 15 May 2014 18:42:50 -0700 Subject: [PATCH] Added the code for threshold_layer to the repo --- src/caffe/layers/threshold_layer.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/caffe/layers/threshold_layer.cpp diff --git a/src/caffe/layers/threshold_layer.cpp b/src/caffe/layers/threshold_layer.cpp new file mode 100644 index 0000000..bec89cd --- /dev/null +++ b/src/caffe/layers/threshold_layer.cpp @@ -0,0 +1,32 @@ +// Copyright 2014 BVLC and contributors. + +#include + +#include "caffe/layer.hpp" +#include "caffe/vision_layers.hpp" + + +namespace caffe { + +template +void ThresholdLayer::SetUp(const vector*>& bottom, + vector*>* top) { + NeuronLayer::SetUp(bottom, top); + threshold_ = this->layer_param_.threshold_param().threshold(); +} + +template +Dtype ThresholdLayer::Forward_cpu(const vector*>& bottom, + vector*>* 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 -- 2.7.4