Browse Source

!12548 fix some error message and api bug of BCEWithLogitsLoss.

From: @liu_xiao_93
Reviewed-by: @liangchenghui,@wuxuejian
Signed-off-by: @liangchenghui,@wuxuejian
tags/v1.2.0-rc1
mindspore-ci-bot Gitee 5 years ago
parent
commit
095d7fb877
3 changed files with 14 additions and 14 deletions
  1. +6
    -6
      mindspore/nn/loss/loss.py
  2. +1
    -1
      mindspore/ops/_grad/grad_nn_ops.py
  3. +7
    -7
      mindspore/ops/operations/nn_ops.py

+ 6
- 6
mindspore/nn/loss/loss.py View File

@@ -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.


+ 1
- 1
mindspore/ops/_grad/grad_nn_ops.py View File

@@ -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()



+ 7
- 7
mindspore/ops/operations/nn_ops.py View File

@@ -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 = []


Loading…
Cancel
Save