From dbb6a2054651cbd0a5058d45a27575b9de41b5a5 Mon Sep 17 00:00:00 2001 From: Sean Bell Date: Wed, 19 Nov 2014 17:25:08 -0500 Subject: fixed tanh to not return NaN for input values outside the range [-40, 40] --- src/caffe/layers/tanh_layer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/caffe/layers/tanh_layer.cpp') 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::Forward_cpu(const vector*>& bottom, const vector*>& 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]); } } -- cgit v1.2.3