From 529a732737432074335ed9d16fb8affd36b08257 Mon Sep 17 00:00:00 2001 From: tqchen Date: Mon, 6 Apr 2015 08:45:54 -0700 Subject: [PATCH] add label error --- src/learner/objective-inl.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/learner/objective-inl.hpp b/src/learner/objective-inl.hpp index 61ed9c9c5..11d6610c7 100644 --- a/src/learner/objective-inl.hpp +++ b/src/learner/objective-inl.hpp @@ -197,6 +197,7 @@ class SoftmaxMultiClassObj : public IObjFunction { gpair.resize(preds.size()); const unsigned nstep = static_cast(info.labels.size() * nclass); const bst_omp_uint ndata = static_cast(preds.size() / nclass); + int label_error = 0; #pragma omp parallel { std::vector rec(nclass); @@ -208,8 +209,9 @@ class SoftmaxMultiClassObj : public IObjFunction { Softmax(&rec); const unsigned j = i % nstep; int label = static_cast(info.labels[j]); - utils::Check(label >= 0 && label < nclass, - "SoftmaxMultiClassObj: label must be in [0, num_class)"); + if (label < 0 || label >= nclass) { + label_error = label; label = 0; + } const float wt = info.GetWeight(j); for (int k = 0; k < nclass; ++k) { float p = rec[k]; @@ -222,6 +224,8 @@ class SoftmaxMultiClassObj : public IObjFunction { } } } + utils::Check(label_error >= 0 && label_error < nclass, + "SoftmaxMultiClassObj: label must be in [0, num_class), found %d in label", label_error); } virtual void PredTransform(std::vector *io_preds) { this->Transform(io_preds, output_prob);