From bd6527b0f306d923f5bea03502483408dab46edf Mon Sep 17 00:00:00 2001 From: qipeng Date: Wed, 23 Jul 2014 11:48:19 -0700 Subject: [PATCH] numerical stability improvement --- src/caffe/layers/relu_layer.cpp | 4 ++-- src/caffe/layers/relu_layer.cu | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/caffe/layers/relu_layer.cpp b/src/caffe/layers/relu_layer.cpp index 3a3e8a2..b94086d 100644 --- a/src/caffe/layers/relu_layer.cpp +++ b/src/caffe/layers/relu_layer.cpp @@ -33,8 +33,8 @@ void ReLULayer::Backward_cpu(const vector*>& top, const int count = (*bottom)[0]->count(); Dtype negative_slope = this->layer_param_.relu_param().negative_slope(); for (int i = 0; i < count; ++i) { - bottom_diff[i] = top_diff[i] * ((bottom_data[i] >= 0) - + negative_slope * (bottom_data[i] < 0)); + bottom_diff[i] = top_diff[i] * ((bottom_data[i] > 0) + + negative_slope * (bottom_data[i] <= 0)); } } } diff --git a/src/caffe/layers/relu_layer.cu b/src/caffe/layers/relu_layer.cu index 503147c..e0d6aa1 100644 --- a/src/caffe/layers/relu_layer.cu +++ b/src/caffe/layers/relu_layer.cu @@ -39,8 +39,8 @@ template __global__ void ReLUBackward(const int n, const Dtype* in_diff, const Dtype* in_data, Dtype* out_diff, Dtype negative_slope) { CUDA_KERNEL_LOOP(index, n) { - out_diff[index] = in_diff[index] * ((in_data[index] >= 0) - + (in_data[index] < 0) * negative_slope); + out_diff[index] = in_diff[index] * ((in_data[index] > 0) + + (in_data[index] <= 0) * negative_slope); } } -- 2.7.4