From 422e8019d7b93a1b2cad1ce355f1e29a48d0a16b Mon Sep 17 00:00:00 2001 From: zkh2016 Date: Thu, 21 Apr 2022 09:09:07 +0000 Subject: [PATCH] fix docs --- .../fluid/tests/unittests/test_sparse_norm_op.py | 16 ++++++++++++++++ python/paddle/sparse/layer/norm.py | 7 +++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_sparse_norm_op.py b/python/paddle/fluid/tests/unittests/test_sparse_norm_op.py index 937f24c26f29d..3c3085ec8be69 100644 --- a/python/paddle/fluid/tests/unittests/test_sparse_norm_op.py +++ b/python/paddle/fluid/tests/unittests/test_sparse_norm_op.py @@ -69,3 +69,19 @@ def test_error_layout(self): sparse_batch_norm = paddle.sparse.BatchNorm( 3, data_format='NCDHW') sparse_batch_norm(sparse_x) + + def test2(self): + with _test_eager_guard(): + paddle.seed(123) + channels = 3 + x_data = paddle.randn((1, 6, 6, 6, channels)).astype('float32') + dense_x = paddle.to_tensor(x_data) + sparse_x = dense_x.to_sparse_coo(4) + batch_norm = paddle.sparse.BatchNorm(channels) + batch_norm_out = batch_norm(sparse_x) + print(batch_norm_out.shape) + # [1, 6, 6, 6, 3] + + +if __name__ == "__main__": + unittest.main() diff --git a/python/paddle/sparse/layer/norm.py b/python/paddle/sparse/layer/norm.py index 39b0028fe8ece..83b738a5dc354 100644 --- a/python/paddle/sparse/layer/norm.py +++ b/python/paddle/sparse/layer/norm.py @@ -66,8 +66,8 @@ class BatchNorm(paddle.nn.BatchNorm1D): Parameters: num_features(int): Indicate the number of channels of the input ``Tensor``. - epsilon(float, optional): The small value added to the variance to prevent division by zero. Default: 1e-5. momentum(float, optional): The value used for the moving_mean and moving_var computation. Default: 0.9. + epsilon(float, optional): The small value added to the variance to prevent division by zero. Default: 1e-5. weight_attr(ParamAttr|bool, optional): The parameter attribute for Parameter `scale` of batch_norm. If it is set to None or one attribute of ParamAttr, batch_norm will create ParamAttr as weight_attr. If it is set to Fasle, the weight is not learnable. @@ -92,13 +92,12 @@ class BatchNorm(paddle.nn.BatchNorm1D): .. code-block:: python import paddle - import numpy as np from paddle.fluid.framework import _test_eager_guard with _test_eager_guard(): - np.random.seed(123) + paddle.seed(123) channels = 3 - x_data = np.random.random(size=(1, 6, 6, 6, channels)).astype('float32') + x_data = paddle.randn((1, 6, 6, 6, channels)).astype('float32') dense_x = paddle.to_tensor(x_data) sparse_x = dense_x.to_sparse_coo(4) batch_norm = paddle.sparse.BatchNorm(channels)