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)
- + top_diff[i] * negative_slope * (bottom_data[i] < 0);
+ bottom_diff[i] = top_diff[i] * ((bottom_data[i] >= 0)
+ + negative_slope * (bottom_data[i] < 0));
}
}
}
__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_diff[index] * (in_data[index] < 0) * negative_slope;
+ out_diff[index] = in_diff[index] * ((in_data[index] >= 0)
+ + (in_data[index] < 0) * negative_slope);
}
}
TYPED_TEST(NeuronLayerTest, TestReLUGradientWithNegativeSlope) {
typedef typename TypeParam::Dtype Dtype;
LayerParameter layer_param;
- ReLULayer<Dtype> layer(layer_param);
layer_param.ParseFromString("relu_param{negative_slope:0.01}");
+ ReLULayer<Dtype> layer(layer_param);
GradientChecker<Dtype> checker(1e-2, 1e-3, 1701, 0., 0.01);
checker.CheckGradientEltwise(&layer, &(this->blob_bottom_vec_),
&(this->blob_top_vec_));