File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ scaled_tanh_layer
6363shape_layer
6464shuffle_channel_layer
6565sin_layer
66+ softplus_layer
6667softsign_layer
6768space_to_batch_nd_layer
6869space_to_depth_layer
Original file line number Diff line number Diff line change 1+ #ifndef CAFFE_SOFTPLUS_LAYER_HPP_
2+ #define CAFFE_SOFTPLUS_LAYER_HPP_
3+
4+ #include < vector>
5+
6+ #include " caffe/blob.hpp"
7+ #include " caffe/layer.hpp"
8+ #include " caffe/proto/caffe.pb.h"
9+
10+ #include " caffe/layers/neuron_layer.hpp"
11+
12+ namespace caffe {
13+
14+
15+ template <typename Dtype>
16+ class SoftplusLayer : public NeuronLayer <Dtype> {
17+ public:
18+ explicit SoftplusLayer (const LayerParameter& param)
19+ : NeuronLayer<Dtype>(param) {}
20+
21+ virtual inline const char * type () const { return " Softplus" ; }
22+
23+ protected:
24+ virtual void Forward_cpu (const vector<Blob<Dtype>*>& bottom,
25+ const vector<Blob<Dtype>*>& top);
26+ virtual void Backward_cpu (const vector<Blob<Dtype>*>& top,
27+ const vector<bool >& propagate_down, const vector<Blob<Dtype>*>& bottom) {
28+ for (int i = 0 ; i < propagate_down.size (); ++i) {
29+ if (propagate_down[i]) { NOT_IMPLEMENTED; }
30+ }
31+ }
32+ };
33+
34+ } // namespace caffe
35+
36+ #endif // CAFFE_SOFTPLUS_LAYER_HPP_
Original file line number Diff line number Diff line change 1+ #include < math.h>
2+ #include < vector>
3+
4+ #include " caffe/layers/softplus_layer.hpp"
5+
6+ namespace caffe {
7+
8+
9+ template <typename Dtype>
10+ void SoftplusLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
11+ const vector<Blob<Dtype>*>& top) {
12+ const Dtype* bottom_data = bottom[0 ]->cpu_data ();
13+ Dtype* top_data = top[0 ]->mutable_cpu_data ();
14+ const int count = bottom[0 ]->count ();
15+ for (int i = 0 ; i < count; ++i) {
16+ top_data[i] = logf (expf (bottom_data[i]) + 1 );
17+ }
18+ }
19+
20+ INSTANTIATE_CLASS (SoftplusLayer);
21+ REGISTER_LAYER_CLASS (Softplus);
22+
23+ } // namespace caffe
You can’t perform that action at this time.
0 commit comments