Skip to content

Commit 6726fb3

Browse files
committed
add softplus layer
1 parent 5ce332b commit 6726fb3

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

FEATURES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ scaled_tanh_layer
6363
shape_layer
6464
shuffle_channel_layer
6565
sin_layer
66+
softplus_layer
6667
softsign_layer
6768
space_to_batch_nd_layer
6869
space_to_depth_layer
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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_
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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

0 commit comments

Comments
 (0)