From 41d0c77e5849f97744a3ca5933fd20887bb97f43 Mon Sep 17 00:00:00 2001 From: Tea Date: Thu, 12 Nov 2015 15:15:22 +0800 Subject: [PATCH] Convert std::max args to Dtype --- include/caffe/test/test_gradient_check_util.hpp | 5 +++-- src/caffe/layers/contrastive_loss_layer.cpp | 3 ++- src/caffe/test/test_contrastive_loss_layer.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/caffe/test/test_gradient_check_util.hpp b/include/caffe/test/test_gradient_check_util.hpp index 25f35d1589e..b25a84875ef 100644 --- a/include/caffe/test/test_gradient_check_util.hpp +++ b/include/caffe/test/test_gradient_check_util.hpp @@ -169,8 +169,9 @@ void GradientChecker::CheckGradientSingle(Layer* layer, || fabs(feature) > kink_ + kink_range_) { // We check relative accuracy, but for too small values, we threshold // the scale factor by 1. - Dtype scale = std::max( - std::max(fabs(computed_gradient), fabs(estimated_gradient)), 1.); + Dtype scale = std::max( + std::max(fabs(computed_gradient), fabs(estimated_gradient)), + Dtype(1.)); EXPECT_NEAR(computed_gradient, estimated_gradient, threshold_ * scale) << "debug: (top_id, top_data_id, blob_id, feat_id)=" << top_id << "," << top_data_id << "," << blob_id << "," << feat_id diff --git a/src/caffe/layers/contrastive_loss_layer.cpp b/src/caffe/layers/contrastive_loss_layer.cpp index 74002087ec9..45facd4a4f5 100644 --- a/src/caffe/layers/contrastive_loss_layer.cpp +++ b/src/caffe/layers/contrastive_loss_layer.cpp @@ -51,7 +51,8 @@ void ContrastiveLossLayer::Forward_cpu( if (legacy_version) { loss += std::max(margin - dist_sq_.cpu_data()[i], Dtype(0.0)); } else { - Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]), 0.0); + Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]), + Dtype(0.0)); loss += dist*dist; } } diff --git a/src/caffe/test/test_contrastive_loss_layer.cpp b/src/caffe/test/test_contrastive_loss_layer.cpp index 592997e4578..95901f14297 100644 --- a/src/caffe/test/test_contrastive_loss_layer.cpp +++ b/src/caffe/test/test_contrastive_loss_layer.cpp @@ -77,7 +77,7 @@ TYPED_TEST(ContrastiveLossLayerTest, TestForward) { if (this->blob_bottom_y_->cpu_data()[i]) { // similar pairs loss += dist_sq; } else { - Dtype dist = std::max(margin - sqrt(dist_sq), 0.0); + Dtype dist = std::max(margin - sqrt(dist_sq), 0.0); loss += dist*dist; } }