From a7acfc5b357b8d7de29bd3cf240309c2deb72a2e Mon Sep 17 00:00:00 2001 From: HydrogenSulfate <490868991@qq.com> Date: Tue, 1 Mar 2022 13:16:45 +0800 Subject: [PATCH] update error_string when target is out of bound (#40001) --- python/paddle/nn/functional/loss.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/nn/functional/loss.py b/python/paddle/nn/functional/loss.py index e59ef5ebfb..e6efde8362 100755 --- a/python/paddle/nn/functional/loss.py +++ b/python/paddle/nn/functional/loss.py @@ -1667,11 +1667,11 @@ def cross_entropy(input, label_min = paddle.min(valid_label) label_max = paddle.max(valid_label) if label_min < 0: - raise ValueError("label should not out of bound, but got{}". - format(label_min)) + raise ValueError("Target {} is out of lower bound.".format( + label_min.item())) if label_max >= input.shape[axis]: - raise ValueError("label should not out of bound, but got{}". - format(label_max)) + raise ValueError("Target {} is out of upper bound.".format( + label_max.item())) if core.is_compiled_with_npu() or core.is_compiled_with_mlu(): _, _, out = _C_ops.softmax_with_cross_entropy( input, label, 'soft_label', soft_label, 'ignore_index', -- GitLab