Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/caffe/test/test_gradient_check_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/caffe/layers/contrastive_loss_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/caffe/test/test_contrastive_loss_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down