From f7c855c7c32131162d4cf0dbaa46b4c406171355 Mon Sep 17 00:00:00 2001 From: liuxiao93 Date: Tue, 23 Feb 2021 17:19:51 +0800 Subject: [PATCH] fix some error message and api bug. --- mindspore/nn/loss/loss.py | 12 ++++++------ mindspore/ops/_grad/grad_nn_ops.py | 2 +- mindspore/ops/operations/nn_ops.py | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mindspore/nn/loss/loss.py b/mindspore/nn/loss/loss.py index f711cad43fb..b07ada0f1bf 100644 --- a/mindspore/nn/loss/loss.py +++ b/mindspore/nn/loss/loss.py @@ -834,14 +834,14 @@ class BCEWithLogitsLoss(_Loss): .. math:: \ell(x, y) = \begin{cases} - L, & \text{if reduction} = \text{`none';}\\ - \operatorname{mean}(L), & \text{if reduction} = \text{`mean';}\\ - \operatorname{sum}(L), & \text{if reduction} = \text{`sum'.} + L, & \text{if reduction} = \text{'none';}\\ + \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\ + \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.} \end{cases} Args: - reduction (str): Type of reduction to be applied to loss. The optional values are "mean", "sum", and "none". - If "none", do not perform reduction. Default:`mean`. + reduction (str): Type of reduction to be applied to loss. The optional values are 'mean', 'sum', and 'none'. + If 'none', do not perform reduction. Default:'mean'. weight (Tensor, optional): A rescaling weight applied to the loss of each batch element. If not None, it must can be broadcast to a tensor with shape of `predict`, data type must be float16 or float32. Default: None. @@ -854,7 +854,7 @@ class BCEWithLogitsLoss(_Loss): - **target** (Tensor) - Ground truth label. Has the same data type and shape with `predict`. Outputs: - Scalar. If reduction is "none", it's a tensor with the same shape and type as input `predict`. + Scalar. If reduction is 'none', it's a tensor with the same shape and type as input `predict`. Raises: TypeError: If data type of `predict` or `target` is neither float16 nor float32. diff --git a/mindspore/ops/_grad/grad_nn_ops.py b/mindspore/ops/_grad/grad_nn_ops.py index f3006a8fb3a..d8104271b5e 100755 --- a/mindspore/ops/_grad/grad_nn_ops.py +++ b/mindspore/ops/_grad/grad_nn_ops.py @@ -1217,7 +1217,7 @@ def get_bprop_ce_with_logits_loss(self): reduction = self.reduction mul = P.Mul() sigmoid = P.Sigmoid() - add = P.TensorAdd() + add = P.Add() sub = P.Sub() size = P.Size() diff --git a/mindspore/ops/operations/nn_ops.py b/mindspore/ops/operations/nn_ops.py index 22f66c8d07d..2f863823038 100644 --- a/mindspore/ops/operations/nn_ops.py +++ b/mindspore/ops/operations/nn_ops.py @@ -3725,14 +3725,14 @@ class BCEWithLogitsLoss(PrimitiveWithInfer): .. math:: \ell(x, y) = \begin{cases} - L, & \text{if reduction} = \text{`none';}\\ - \operatorname{mean}(L), & \text{if reduction} = \text{`mean';}\\ - \operatorname{sum}(L), & \text{if reduction} = \text{`sum'.} + L, & \text{if reduction} = \text{'none';}\\ + \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\ + \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.} \end{cases} Args: - reduction (str): Type of reduction to be applied to loss. The optional values are "mean", "sum", and "none". - If "none", do not perform reduction. Default:`mean`. + reduction (str): Type of reduction to be applied to loss. The optional values are 'mean', 'sum', and 'none'. + If 'none', do not perform reduction. Default:'mean'. Inputs: - **predict** (Tensor) - Input logits. Data type must be float16 or float32. @@ -3745,7 +3745,7 @@ class BCEWithLogitsLoss(PrimitiveWithInfer): Data type must be float16 or float32. Outputs: - Scalar. If reduction is "none", it's a tensor with the same shape and type as input `predict`. + Scalar. If reduction is 'none', it's a tensor with the same shape and type as input `predict`. Raises: TypeError: If data type of any input is neither float16 nor float32. @@ -3785,7 +3785,7 @@ class BCEWithLogitsLoss(PrimitiveWithInfer): for i, v in enumerate(reversed_pos_shape): if v not in (reversed_target[i], 1): raise ValueError(f"For {self.name}, shapes can not broadcast. " - f"predict: {tuple(predict)}, weight shape {tuple(weight)}.") + f"predict: {tuple(predict)}, weight shape {tuple(pos_weight)}.") if self.reduction in ('mean', 'sum'): shape = []