From 29f78aa973ca995219b1851ffd90b98d078572d5 Mon Sep 17 00:00:00 2001 From: Jonathan L Long Date: Mon, 21 Apr 2014 23:41:50 -0700 Subject: [PATCH] make CheckGradientExhaustive fail for topless layers Without this commit, it is possible to mistakenly call CheckGradientExhaustive on a layer with no top blobs (i.e., a loss layer), causing the gradient check to silently succeed while doing nothing. With this commit, doing so will cause the test to fail. --- src/caffe/test/test_gradient_check_util.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/caffe/test/test_gradient_check_util.hpp b/src/caffe/test/test_gradient_check_util.hpp index 6ef76e2..1975886 100644 --- a/src/caffe/test/test_gradient_check_util.hpp +++ b/src/caffe/test/test_gradient_check_util.hpp @@ -135,6 +135,7 @@ template void GradientChecker::CheckGradientExhaustive(Layer* layer, vector*>* bottom, vector*>* top, int check_bottom) { layer->SetUp(*bottom, top); + CHECK_GT(top->size(), 0) << "Exhaustive mode requires at least one top blob."; // LOG(ERROR) << "Exhaustive Mode."; for (int i = 0; i < top->size(); ++i) { // LOG(ERROR) << "Exhaustive: blob " << i << " size " << top[i]->count(); -- 2.7.4