#include <cstring>
#include <vector>
+#include "google/protobuf/text_format.h"
#include "gtest/gtest.h"
#include "caffe/blob.hpp"
TYPED_TEST(NeuronLayerTest, TestReLUWithNegativeSlope) {
typedef typename TypeParam::Dtype Dtype;
LayerParameter layer_param;
- layer_param.ParseFromString("relu_param{negative_slope:0.01}");
+ CHECK(google::protobuf::TextFormat::ParseFromString(
+ "relu_param { negative_slope: 0.01 }", &layer_param));
ReLULayer<Dtype> layer(layer_param);
layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);
layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
const Dtype* bottom_data = this->blob_bottom_->cpu_data();
const Dtype* top_data = this->blob_top_->cpu_data();
for (int i = 0; i < this->blob_bottom_->count(); ++i) {
- EXPECT_GE(top_data[i], 0.);
- EXPECT_TRUE(top_data[i] == 0 || top_data[i] == bottom_data[i]);
+ if (top_data[i] >= 0) {
+ EXPECT_FLOAT_EQ(top_data[i], bottom_data[i]);
+ } else {
+ EXPECT_FLOAT_EQ(top_data[i], bottom_data[i] * 0.01);
+ }
}
}
TYPED_TEST(NeuronLayerTest, TestReLUGradientWithNegativeSlope) {
typedef typename TypeParam::Dtype Dtype;
LayerParameter layer_param;
- layer_param.ParseFromString("relu_param{negative_slope:0.01}");
+ CHECK(google::protobuf::TextFormat::ParseFromString(
+ "relu_param { negative_slope: 0.01 }", &layer_param));
ReLULayer<Dtype> layer(layer_param);
GradientChecker<Dtype> checker(1e-2, 1e-3, 1701, 0., 0.01);
checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,
TYPED_TEST(CuDNNNeuronLayerTest, TestReLUWithNegativeSlopeCuDNN) {
Caffe::set_mode(Caffe::GPU);
LayerParameter layer_param;
- layer_param.ParseFromString("relu_param{negative_slope:0.01}");
+ CHECK(google::protobuf::TextFormat::ParseFromString(
+ "relu_param { negative_slope: 0.01 }", &layer_param));
CuDNNReLULayer<TypeParam> layer(layer_param);
layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);
layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
TYPED_TEST(CuDNNNeuronLayerTest, TestReLUGradientWithNegativeSlopeCuDNN) {
Caffe::set_mode(Caffe::GPU);
LayerParameter layer_param;
- layer_param.ParseFromString("relu_param{negative_slope:0.01}");
+ CHECK(google::protobuf::TextFormat::ParseFromString(
+ "relu_param { negative_slope: 0.01 }", &layer_param));
CuDNNReLULayer<TypeParam> layer(layer_param);
GradientChecker<TypeParam> checker(1e-2, 1e-3, 1701, 0., 0.01);
checker.CheckGradientEltwise(&layer, this->blob_bottom_vec_,