Skip to content

Commit

Permalink
Merge pull request #3937 from emaggiori/exp
Browse files Browse the repository at this point in the history
Issue with the exp layer when the base is e
  • Loading branch information
jeffdonahue committed Apr 8, 2016
2 parents 843575e + 3c3dc95 commit d21772c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/caffe/layers/exp_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void ExpLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const Dtype input_scale = this->layer_param_.exp_param().scale();
const Dtype input_shift = this->layer_param_.exp_param().shift();
inner_scale_ = log_base * input_scale;
outer_scale_ = (input_shift == Dtype(0)) ? Dtype(1) : pow(base, input_shift);
outer_scale_ = (input_shift == Dtype(0)) ? Dtype(1) :
( (base != Dtype(-1)) ? pow(base, input_shift) : exp(input_shift) );
}

template <typename Dtype>
Expand Down
20 changes: 20 additions & 0 deletions src/caffe/test/test_neuron_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,26 @@ TYPED_TEST(NeuronLayerTest, TestExpGradient) {
this->TestExpGradient(kBase, kScale, kShift);
}

TYPED_TEST(NeuronLayerTest, TestExpLayerWithShift) {
typedef typename TypeParam::Dtype Dtype;
// Test default base of "-1" -- should actually set base := e,
// with a non-zero shift
const Dtype kBase = -1;
const Dtype kScale = 1;
const Dtype kShift = 1;
this->TestExpForward(kBase, kScale, kShift);
}

TYPED_TEST(NeuronLayerTest, TestExpGradientWithShift) {
typedef typename TypeParam::Dtype Dtype;
// Test default base of "-1" -- should actually set base := e,
// with a non-zero shift
const Dtype kBase = -1;
const Dtype kScale = 1;
const Dtype kShift = 1;
this->TestExpGradient(kBase, kScale, kShift);
}

TYPED_TEST(NeuronLayerTest, TestExpLayerBase2) {
typedef typename TypeParam::Dtype Dtype;
const Dtype kBase = 2;
Expand Down

0 comments on commit d21772c

Please sign in to comment.