From: Jonathan L Long Date: Fri, 25 Apr 2014 23:38:48 +0000 (-0700) Subject: make gradient checker's kink use feature absolute value X-Git-Tag: submit/tizen/20180823.020014~692^2~19^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a61a2acc4e05bf73db6885bef4f9e32a46d278c7;p=platform%2Fupstream%2Fcaffeonacl.git make gradient checker's kink use feature absolute value In theory, layer functions could be nonsmooth anywhere; in all cases in use so far, they are nonsmooth at either zero or +1 and -1. In the future, it might be necessary to generalize the kink mechanism beyond this stopgap measure. --- diff --git a/src/caffe/test/test_gradient_check_util.hpp b/src/caffe/test/test_gradient_check_util.hpp index da54a96..bcf0397 100644 --- a/src/caffe/test/test_gradient_check_util.hpp +++ b/src/caffe/test/test_gradient_check_util.hpp @@ -22,6 +22,9 @@ namespace caffe { template class GradientChecker { public: + // kink and kink_range specify an ignored nonsmooth region of the form + // kink - kink_range <= |feature value| <= kink + kink_range, + // which accounts for all nonsmoothness in use by caffe GradientChecker(const Dtype stepsize, const Dtype threshold, const unsigned int seed = 1701, const Dtype kink = 0., const Dtype kink_range = -1) @@ -151,7 +154,8 @@ void GradientChecker::CheckGradientSingle(Layer* layer, Dtype feature = current_blob->cpu_data()[feat_id]; // LOG(ERROR) << "debug: " << current_blob->cpu_data()[feat_id] << " " // << current_blob->cpu_diff()[feat_id]; - if (kink_ - kink_range_ > feature || feature > kink_ + kink_range_) { + if (kink_ - kink_range_ > fabs(feature) + || fabs(feature) > kink_ + kink_range_) { // We check relative accuracy, but for too small values, we threshold // the scale factor by 1. Dtype scale = max(