From 9cc415728b11d757fdf75061e682020cd86123b0 Mon Sep 17 00:00:00 2001 From: bingyaweng Date: Fri, 21 Aug 2020 09:01:42 +0800 Subject: [PATCH] fic param check --- mindspore/nn/probability/bnn_layers/bnn_cell_wrapper.py | 4 ++-- mindspore/nn/probability/bnn_layers/conv_variational.py | 5 ++--- mindspore/nn/probability/bnn_layers/dense_variational.py | 3 +-- .../nn/probability/bnn_layers/layer_distribution.py | 9 +++++---- mindspore/nn/probability/transforms/transform_bnn.py | 4 ++-- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/mindspore/nn/probability/bnn_layers/bnn_cell_wrapper.py b/mindspore/nn/probability/bnn_layers/bnn_cell_wrapper.py index 3aef08133e..86d91c03d5 100644 --- a/mindspore/nn/probability/bnn_layers/bnn_cell_wrapper.py +++ b/mindspore/nn/probability/bnn_layers/bnn_cell_wrapper.py @@ -65,9 +65,9 @@ class WithBNNLossCell: """ def __init__(self, backbone, loss_fn, dnn_factor=1, bnn_factor=1): - if not isinstance(dnn_factor, (int, float)): + if isinstance(dnn_factor, bool) or not isinstance(dnn_factor, (int, float)): raise TypeError('The type of `dnn_factor` should be `int` or `float`') - if not isinstance(bnn_factor, (int, float)): + if isinstance(bnn_factor, bool) or not isinstance(bnn_factor, (int, float)): raise TypeError('The type of `bnn_factor` should be `int` or `float`') self.backbone = backbone diff --git a/mindspore/nn/probability/bnn_layers/conv_variational.py b/mindspore/nn/probability/bnn_layers/conv_variational.py index 6389ea9b2f..b3f77e9a7c 100644 --- a/mindspore/nn/probability/bnn_layers/conv_variational.py +++ b/mindspore/nn/probability/bnn_layers/conv_variational.py @@ -173,13 +173,12 @@ class ConvReparam(_ConvVariational): r""" Convolutional variational layers with Reparameterization. - See more details in paper `Auto-Encoding Variational Bayes - ` + See more details in paper `Auto-Encoding Variational Bayes `_. Args: in_channels (int): The number of input channel :math:`C_{in}`. out_channels (int): The number of output channel :math:`C_{out}`. - kernel_size (Union[int, tuple[int]]): The data type is int or + kernel_size (Union[int, tuple[int]]): The data type is int or tuple with 2 integers. Specifies the height and width of the 2D convolution window. Single int means the value if for both height and width of the kernel. A tuple of 2 ints means the diff --git a/mindspore/nn/probability/bnn_layers/dense_variational.py b/mindspore/nn/probability/bnn_layers/dense_variational.py index bb1d027e50..5adddffc16 100644 --- a/mindspore/nn/probability/bnn_layers/dense_variational.py +++ b/mindspore/nn/probability/bnn_layers/dense_variational.py @@ -132,8 +132,7 @@ class DenseReparam(_DenseVariational): r""" Dense variational layers with Reparameterization. - See more details in paper `Auto-Encoding Variational Bayes - ` + See more details in paper `Auto-Encoding Variational Bayes `_. Applies dense-connected layer for the input. This layer implements the operation as: diff --git a/mindspore/nn/probability/bnn_layers/layer_distribution.py b/mindspore/nn/probability/bnn_layers/layer_distribution.py index 262af94403..778d4914f7 100644 --- a/mindspore/nn/probability/bnn_layers/layer_distribution.py +++ b/mindspore/nn/probability/bnn_layers/layer_distribution.py @@ -78,16 +78,17 @@ class NormalPosterior(Cell): if not isinstance(shape, (tuple, list)): raise TypeError('The type of `shape` should be `tuple` or `list`') - if not isinstance(loc_mean, (int, float)): + if isinstance(loc_mean, bool) or not isinstance(loc_mean, (int, float)): raise TypeError('The type of `loc_mean` should be `int` or `float`') - if not isinstance(untransformed_scale_mean, (int, float)): + if isinstance(untransformed_scale_mean, bool) or not isinstance(untransformed_scale_mean, (int, float)): raise TypeError('The type of `untransformed_scale_mean` should be `int` or `float`') - if not (isinstance(loc_std, (int, float)) and loc_std >= 0): + if isinstance(loc_std, bool) or not (isinstance(loc_std, (int, float)) and loc_std >= 0): raise TypeError('The type of `loc_std` should be `int` or `float` and its value should > 0') - if not (isinstance(untransformed_scale_std, (int, float)) and untransformed_scale_std >= 0): + if isinstance(loc_std, bool) or not (isinstance(untransformed_scale_std, (int, float)) and + untransformed_scale_std >= 0): raise TypeError('The type of `untransformed_scale_std` should be `int` or `float` and ' 'its value should > 0') diff --git a/mindspore/nn/probability/transforms/transform_bnn.py b/mindspore/nn/probability/transforms/transform_bnn.py index 3853c48b23..dd3fe68e72 100644 --- a/mindspore/nn/probability/transforms/transform_bnn.py +++ b/mindspore/nn/probability/transforms/transform_bnn.py @@ -61,9 +61,9 @@ class TransformToBNN: """ def __init__(self, trainable_dnn, dnn_factor=1, bnn_factor=1): - if not isinstance(dnn_factor, (int, float)): + if isinstance(dnn_factor, bool) or not isinstance(dnn_factor, (int, float)): raise TypeError('The type of `dnn_factor` should be `int` or `float`') - if not isinstance(bnn_factor, (int, float)): + if isinstance(bnn_factor, bool) or not isinstance(bnn_factor, (int, float)): raise TypeError('The type of `bnn_factor` should be `int` or `float`') net_with_loss = trainable_dnn.network