Browse Source

!15993 Update docs of BatchNorm2d and SparsetToDense

From: @dinglinhe123
Reviewed-by: @wuxuejian,@liangchenghui,@liangchenghui
Signed-off-by: @wuxuejian,@liangchenghui,@liangchenghui
pull/15993/MERGE
mindspore-ci-bot Gitee 4 years ago
parent
commit
2a8e47ea53
2 changed files with 24 additions and 18 deletions
  1. +9
    -7
      mindspore/nn/layer/normalization.py
  2. +15
    -11
      mindspore/nn/sparse/sparse.py

+ 9
- 7
mindspore/nn/layer/normalization.py View File

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



+ 15
- 11
mindspore/nn/sparse/sparse.py View File

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


Loading…
Cancel
Save