summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/caffe/test/test_gradient_check_util.hpp5
-rw-r--r--src/caffe/layers/contrastive_loss_layer.cpp3
-rw-r--r--src/caffe/test/test_contrastive_loss_layer.cpp2
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 25f35d15..b25a8487 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<Dtype>::CheckGradientSingle(Layer<Dtype>* 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<Dtype>(
+ 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 74002087..45facd4a 100644
--- a/src/caffe/layers/contrastive_loss_layer.cpp
+++ b/src/caffe/layers/contrastive_loss_layer.cpp
@@ -51,7 +51,8 @@ void ContrastiveLossLayer<Dtype>::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<Dtype>(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 592997e4..95901f14 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<Dtype>(margin - sqrt(dist_sq), 0.0);
loss += dist*dist;
}
}