diff options
author | Sean Bell <sbell@cs.cornell.edu> | 2014-11-19 17:25:08 -0500 |
---|---|---|
committer | Sean Bell <sbell@cs.cornell.edu> | 2014-11-19 17:25:08 -0500 |
commit | dbb6a2054651cbd0a5058d45a27575b9de41b5a5 (patch) | |
tree | 1ec1d3993def9932578390cfe59d4454a7802e7e /src/caffe/layers/tanh_layer.cpp | |
parent | eca019aca7efce5293bb3a821b4b20cb401e384e (diff) | |
download | caffeonacl-dbb6a2054651cbd0a5058d45a27575b9de41b5a5.tar.gz caffeonacl-dbb6a2054651cbd0a5058d45a27575b9de41b5a5.tar.bz2 caffeonacl-dbb6a2054651cbd0a5058d45a27575b9de41b5a5.zip |
fixed tanh to not return NaN for input values outside the range [-40, 40]
Diffstat (limited to 'src/caffe/layers/tanh_layer.cpp')
-rw-r--r-- | src/caffe/layers/tanh_layer.cpp | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/src/caffe/layers/tanh_layer.cpp b/src/caffe/layers/tanh_layer.cpp index 18413d9b..ee5ed773 100644 --- a/src/caffe/layers/tanh_layer.cpp +++ b/src/caffe/layers/tanh_layer.cpp @@ -14,11 +14,9 @@ void TanHLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { const Dtype* bottom_data = bottom[0]->cpu_data(); Dtype* top_data = top[0]->mutable_cpu_data(); - Dtype exp2x; const int count = bottom[0]->count(); for (int i = 0; i < count; ++i) { - exp2x = exp(2 * bottom_data[i]); - top_data[i] = (exp2x - Dtype(1)) / (exp2x + Dtype(1)); + top_data[i] = tanh(bottom_data[i]); } } |