From 79d2030f9da4fcc52686afd62f7ddd17bf5a60cf Mon Sep 17 00:00:00 2001 From: dinglinhe Date: Thu, 6 May 2021 09:10:24 +0800 Subject: [PATCH] Update docs of BatchNorm2d and SparsetToDense --- mindspore/nn/layer/normalization.py | 16 +++++++++------- mindspore/nn/sparse/sparse.py | 26 +++++++++++++++----------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/mindspore/nn/layer/normalization.py b/mindspore/nn/layer/normalization.py index 671c236161..60f69699af 100644 --- a/mindspore/nn/layer/normalization.py +++ b/mindspore/nn/layer/normalization.py @@ -381,13 +381,15 @@ class BatchNorm2d(_BatchNorm): moving_var_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the moving variance. The values of str refer to the function `initializer` including 'zeros', 'ones', etc. Default: 'ones'. use_batch_statistics (bool): - If true, use the mean value and variance value of current batch data and track running mean - and running varance. - If false, use the mean value and variance value of specified value, and not track statistical value. - If None, The use_batch_statistics is automatically assigned process according to the training and eval mode. - During training, batchnorm2d process will be same with use_batch_statistics=True. - Contrarily, in eval, batchnorm2d process will be same with use_batch_statistics=False. - Default: None. + + - If true, use the mean value and variance value of current batch data and track running mean + and running varance. + - If false, use the mean value and variance value of specified value, and not track statistical value. + - If None, The use_batch_statistics is automatically assigned process according to + the training and eval mode. During training, batchnorm2d process will be the same + with use_batch_statistics=True. Contrarily, in eval, batchnorm2d process will be the same + with use_batch_statistics=False. + data_format (str): The optional value for data format, is 'NHWC' or 'NCHW'. Default: 'NCHW'. diff --git a/mindspore/nn/sparse/sparse.py b/mindspore/nn/sparse/sparse.py index 8a1bd85678..73f93c2159 100644 --- a/mindspore/nn/sparse/sparse.py +++ b/mindspore/nn/sparse/sparse.py @@ -29,20 +29,24 @@ class SparseToDense(Cell): Returns: Tensor, the tensor converted. + Supported Platforms: + ``CPU`` + Examples: - >>> class SparseToDenseCell(nn.Cell): - ... def __init__(self, dense_shape): - ... super(SparseToDenseCell, self).__init__() - ... self.dense_shape = dense_shape - ... self.sparse_to_dense = nn.SparseToDense() - ... def construct(self, indices, values): - ... sparse = SparseTensor(indices, values, self.dense_shape) - ... return self.sparse_to_dense(sparse) - ... + >>> import mindspore as ms + >>> from mindspore import Tensor, SparseTensor + >>> import mindspore.nn as nn + >>> indices = Tensor([[0, 1], [1, 2]]) - >>> values = Tensor([1, 2], dtype=ms.float32) + >>> values = Tensor([1, 2], dtype=ms.int32) >>> dense_shape = (3, 4) - >>> SparseToDenseCell(dense_shape)(indices, values) + >>> sparse_tensor = SparseTensor(indices, values, dense_shape) + >>> sparse_to_dense = nn.SparseToDense() + >>> result = sparse_to_dense(sparse_tensor) + >>> print(result) + [[0 1 0 0] + [0 0 2 0] + [0 0 0 0]] """ def __init__(self): super(SparseToDense, self).__init__()