caffe_mul(count, top_data, bottom[i]->cpu_data(), top_data);
}
break;
+ case EltwiseParameter_EltwiseOp_SUM:
+ caffe_add(count, bottom[0]->cpu_data(), bottom[1]->cpu_data(), top_data);
+ for (int i = 2; i < bottom.size(); ++i) {
+ caffe_add(count, top_data, bottom[i]->cpu_data(), top_data);
+ }
+ break;
default:
LOG(FATAL) << "Unknown elementwise operation.";
}
caffe_div(count, top_data, bottom_data, bottom_diff);
caffe_mul(count, bottom_diff, top_diff, bottom_diff);
break;
+ case EltwiseParameter_EltwiseOp_SUM:
+ caffe_copy(count, top_diff, bottom_diff);
+ break;
default:
LOG(FATAL) << "Unknown elementwise operation.";
}
caffe_gpu_mul(count, top_data, bottom[i]->gpu_data(), top_data);
}
break;
+ case EltwiseParameter_EltwiseOp_SUM:
+ caffe_gpu_add(count, bottom[0]->gpu_data(), bottom[1]->gpu_data(), top_data);
+ for (int i = 2; i < bottom.size(); ++i) {
+ caffe_gpu_add(count, top_data, bottom[i]->gpu_data(), top_data);
+ }
+ break;
default:
LOG(FATAL) << "Unknown elementwise operation.";
}
caffe_gpu_div(count, top_data, bottom_data, bottom_diff);
caffe_gpu_mul(count, bottom_diff, top_diff, bottom_diff);
break;
+ case EltwiseParameter_EltwiseOp_SUM:
+ caffe_gpu_copy(count, top_diff, bottom_diff);
+ break;
default:
LOG(FATAL) << "Unknown elementwise operation.";
}
EXPECT_EQ(this->blob_top_->width(), 5);
}
-TYPED_TEST(EltwiseLayerTest, TestCPU) {
+TYPED_TEST(EltwiseLayerTest, TestProdCPU) {
Caffe::set_mode(Caffe::CPU);
LayerParameter layer_param;
EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();
}
}
-TYPED_TEST(EltwiseLayerTest, TestGPU) {
+TYPED_TEST(EltwiseLayerTest, TestSumCPU) {
+ Caffe::set_mode(Caffe::CPU);
+ LayerParameter layer_param;
+ EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();
+ eltwise_param->set_operation(EltwiseParameter_EltwiseOp_SUM);
+ shared_ptr<EltwiseLayer<TypeParam> > layer(
+ new EltwiseLayer<TypeParam>(layer_param));
+ layer->SetUp(this->blob_bottom_vec_, &(this->blob_top_vec_));
+ layer->Forward(this->blob_bottom_vec_, &(this->blob_top_vec_));
+ const TypeParam* data = this->blob_top_->cpu_data();
+ const int count = this->blob_top_->count();
+ const TypeParam* in_data_a = this->blob_bottom_a_->cpu_data();
+ const TypeParam* in_data_b = this->blob_bottom_b_->cpu_data();
+ const TypeParam* in_data_c = this->blob_bottom_c_->cpu_data();
+ for (int i = 0; i < count; ++i) {
+ EXPECT_EQ(data[i], in_data_a[i] + in_data_b[i] + in_data_c[i]);
+ }
+}
+
+TYPED_TEST(EltwiseLayerTest, TestProdGPU) {
Caffe::set_mode(Caffe::GPU);
LayerParameter layer_param;
EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();
}
}
-TYPED_TEST(EltwiseLayerTest, TestCPUGradient) {
+TYPED_TEST(EltwiseLayerTest, TestSumGPU) {
+ Caffe::set_mode(Caffe::GPU);
+ LayerParameter layer_param;
+ EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();
+ eltwise_param->set_operation(EltwiseParameter_EltwiseOp_SUM);
+ shared_ptr<EltwiseLayer<TypeParam> > layer(
+ new EltwiseLayer<TypeParam>(layer_param));
+ layer->SetUp(this->blob_bottom_vec_, &(this->blob_top_vec_));
+ layer->Forward(this->blob_bottom_vec_, &(this->blob_top_vec_));
+ const TypeParam* data = this->blob_top_->cpu_data();
+ const int count = this->blob_top_->count();
+ const TypeParam* in_data_a = this->blob_bottom_a_->cpu_data();
+ const TypeParam* in_data_b = this->blob_bottom_b_->cpu_data();
+ const TypeParam* in_data_c = this->blob_bottom_c_->cpu_data();
+ for (int i = 0; i < count; ++i) {
+ EXPECT_EQ(data[i], in_data_a[i] + in_data_b[i] + in_data_c[i]);
+ }
+}
+
+TYPED_TEST(EltwiseLayerTest, TestProdCPUGradient) {
Caffe::set_mode(Caffe::CPU);
LayerParameter layer_param;
EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();
&(this->blob_top_vec_));
}
-TYPED_TEST(EltwiseLayerTest, TestGPUGradient) {
+TYPED_TEST(EltwiseLayerTest, TestSumCPUGradient) {
+ Caffe::set_mode(Caffe::CPU);
+ LayerParameter layer_param;
+ EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();
+ eltwise_param->set_operation(EltwiseParameter_EltwiseOp_SUM);
+ EltwiseLayer<TypeParam> layer(layer_param);
+ GradientChecker<TypeParam> checker(1e-2, 1e-3);
+ checker.CheckGradientEltwise(&layer, &(this->blob_bottom_vec_),
+ &(this->blob_top_vec_));
+}
+
+TYPED_TEST(EltwiseLayerTest, TestSumGPUGradient) {
Caffe::set_mode(Caffe::GPU);
LayerParameter layer_param;
EltwiseParameter* eltwise_param = layer_param.mutable_eltwise_param();
- eltwise_param->set_operation(EltwiseParameter_EltwiseOp_PROD);
+ eltwise_param->set_operation(EltwiseParameter_EltwiseOp_SUM);
EltwiseLayer<TypeParam> layer(layer_param);
GradientChecker<TypeParam> checker(1e-2, 1e-2);
checker.CheckGradientEltwise(&layer, &(this->blob_bottom_vec_),