From 1878a1b0f1bb1f35ada5fe2c63121fca978b7939 Mon Sep 17 00:00:00 2001 From: liangchenghui Date: Fri, 13 Nov 2020 20:57:11 +0800 Subject: [PATCH] fix example error --- mindspore/nn/layer/pooling.py | 2 +- mindspore/ops/operations/__init__.py | 5 ++++- mindspore/ops/operations/array_ops.py | 11 ++++++----- mindspore/ops/operations/nn_ops.py | 6 +++--- mindspore/ops/operations/other_ops.py | 7 ++++++- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/mindspore/nn/layer/pooling.py b/mindspore/nn/layer/pooling.py index 9beb5fc80b..ce91ed9735 100644 --- a/mindspore/nn/layer/pooling.py +++ b/mindspore/nn/layer/pooling.py @@ -371,7 +371,7 @@ class AvgPool1d(_PoolNd): self.squeeze = P.Squeeze(2) def construct(self, x): - _shape_check(self.shape(x)) + x = F.depend(x, _shape_check(self.shape(x))) batch, channel, width = self.shape(x) if width == self.kernel_size[1]: x = self.reduce_mean(x, 2) diff --git a/mindspore/ops/operations/__init__.py b/mindspore/ops/operations/__init__.py index 29485fafb8..93d0b06a31 100644 --- a/mindspore/ops/operations/__init__.py +++ b/mindspore/ops/operations/__init__.py @@ -82,7 +82,8 @@ from .nn_ops import (LSTM, SGD, Adam, FusedSparseAdam, FusedSparseLazyAdam, Appl ApplyRMSProp, ApplyCenteredRMSProp, BasicLSTMCell, InTopK, UniformCandidateSampler) from . import _quant_ops from ._quant_ops import * -from .other_ops import (Assign, InplaceAssign, IOU, BoundingBoxDecode, BoundingBoxEncode, PopulationCount, +from .other_ops import (Assign, InplaceAssign, IOU, BoundingBoxDecode, BoundingBoxEncode, + ConfusionMatrix, PopulationCount, CheckValid, MakeRefKey, Partial, Depend, identity, CheckBprop, Push, Pull) from ._thor_ops import (CusBatchMatMul, CusCholeskyTrsm, CusFusedAbsMax1, CusImg2Col, CusMatMulCubeDenseLeft, CusMatMulCubeFraczRightMul, CusMatMulCube, CusMatrixCombine, CusTranspose02314, @@ -289,6 +290,7 @@ __all__ = [ 'DepthwiseConv2dNative', 'UnsortedSegmentSum', 'UnsortedSegmentMin', + 'UnsortedSegmentMax', 'UnsortedSegmentProd', "AllGather", "AllReduce", @@ -377,6 +379,7 @@ __all__ = [ "UniformCandidateSampler", "LRN", "Mod", + "ConfusionMatrix", "PopulationCount", "ParallelConcat", "Push", diff --git a/mindspore/ops/operations/array_ops.py b/mindspore/ops/operations/array_ops.py index 10753f4a0f..70e804af62 100644 --- a/mindspore/ops/operations/array_ops.py +++ b/mindspore/ops/operations/array_ops.py @@ -2104,18 +2104,19 @@ class Slice(PrimitiveWithInfer): Slices a tensor in the specified shape. Inputs: - x (Tensor): The target tensor. - begin (tuple): The beginning of the slice. Only constant value is allowed. - size (tuple): The size of the slice. Only constant value is allowed. + - **x** (Tensor): The target tensor. + - **begin** (tuple): The beginning of the slice. Only constant value is allowed. + - **size** (tuple): The size of the slice. Only constant value is allowed. - Returns: - Tensor. + Outputs: + Tensor, the shape is : input `size`, the data type is the same as input `x`. Examples: >>> data = Tensor(np.array([[[1, 1, 1], [2, 2, 2]], >>> [[3, 3, 3], [4, 4, 4]], >>> [[5, 5, 5], [6, 6, 6]]]).astype(np.int32)) >>> type = P.Slice()(data, (1, 0, 0), (1, 1, 3)) + >>> print(type) [[[3 3 3]]] """ diff --git a/mindspore/ops/operations/nn_ops.py b/mindspore/ops/operations/nn_ops.py index bad2ab4429..7392befa1f 100644 --- a/mindspore/ops/operations/nn_ops.py +++ b/mindspore/ops/operations/nn_ops.py @@ -5412,7 +5412,7 @@ class Dropout(PrimitiveWithInfer): Args: keep_prob (float): The keep rate, between 0 and 1, e.g. keep_prob = 0.9, - means dropping out 10% of input units. + means dropping out 10% of input units. Inputs: - **input** (Tensor) - The input tensor. @@ -5426,9 +5426,9 @@ class Dropout(PrimitiveWithInfer): >>> x = Tensor((20, 16, 50, 50), mindspore.float32) >>> output, mask = dropout(x) >>> print(output) - [ 0. 32. 0. 0.] + [0. 32. 0. 0.] >>> print(mask) - [0. 1. 0. 0.] + [0. 1. 0. 0.] """ @prim_attr_register diff --git a/mindspore/ops/operations/other_ops.py b/mindspore/ops/operations/other_ops.py index 25c39f1572..c51aa6a313 100644 --- a/mindspore/ops/operations/other_ops.py +++ b/mindspore/ops/operations/other_ops.py @@ -492,7 +492,12 @@ class ConfusionMatrix(PrimitiveWithInfer): >>> confusion_matrix = P.ConfusionMatrix(4) >>> labels = Tensor([0, 1, 1, 3], mindspore.int32) >>> predictions = Tensor([1, 2, 1, 3], mindspore.int32) - >>> confusion_matrix(labels, predictions) + >>> output = confusion_matrix(labels, predictions) + >>> print(output) + [[0 1 0 0 + [0 1 1 0] + [0 0 0 0] + [0 0 0 1]] """ @prim_attr_register