diff --git a/mindspore/nn/probability/README.md b/mindspore/nn/probability/README.md index 3ebeed59862..ccc9acaa91c 100644 --- a/mindspore/nn/probability/README.md +++ b/mindspore/nn/probability/README.md @@ -452,14 +452,14 @@ for eval_data in ds_eval.create_dict_iterator(): ### Examples Examples in [mindspore/tests/st/probability](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability) are as follows: -- [Bayesian LeNet](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/test_bnn_layer.py). How to construct and train a LeNet by bnn layers. -- [Transform whole DNN model to BNN](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/test_transform_bnn_model.py): How to transform whole DNN model to BNN. -- [Transform DNN layer to BNN](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/test_transform_bnn_layer.py): How to transform one certainty type of layer in DNN model to corresponding Bayesian layer. -- [Variational Auto-Encoder](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/test_gpu_svi_vae.py): Variational Auto-Encoder (VAE) model trained with MNIST to generate sample images. -- [Conditional Variational Auto-Encoder](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/test_gpu_svi_cvae.py): Conditional Variational Auto-Encoder (CVAE) model trained with MNIST to generate sample images. -- [VAE-GAN](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/test_gpu_vae_gan.py): VAE-GAN model trained with MNIST to generate sample images. -- [Uncertainty Estimation](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/test_uncertainty.py): Evaluate uncertainty of model and data.. +- [Bayesian LeNet](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/bnn_layers/test_bnn_layer.py). How to construct and train a LeNet by bnn layers. +- [Transform whole DNN model to BNN](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/transforms/test_transform_bnn_model.py): How to transform whole DNN model to BNN. +- [Transform DNN layer to BNN](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/transforms/test_transform_bnn_layer.py): How to transform one certainty type of layer in DNN model to corresponding Bayesian layer. +- [Variational Auto-Encoder](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/dpn/test_gpu_svi_vae.py): Variational Auto-Encoder (VAE) model trained with MNIST to generate sample images. +- [Conditional Variational Auto-Encoder](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/dpn/test_gpu_svi_cvae.py): Conditional Variational Auto-Encoder (CVAE) model trained with MNIST to generate sample images. +- [VAE-GAN](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/dpn/test_gpu_vae_gan.py): VAE-GAN model trained with MNIST to generate sample images. +- [Uncertainty Estimation](https://gitee.com/mindspore/mindspore/tree/master/tests/st/probability/toobox/test_uncertainty.py): Evaluate uncertainty of model and data.. ### Community As part of MindSpore, we are committed to creating an open and friendly environment. -- [Gitee](https://gitee.com/mindspore/mindspore/issues): Report bugs or make feature requests. \ No newline at end of file +- [Gitee](https://gitee.com/mindspore/mindspore/issues): Report bugs or make feature requests. diff --git a/tests/st/probability/dataset.py b/tests/st/probability/bnn_layers/dataset.py similarity index 100% rename from tests/st/probability/dataset.py rename to tests/st/probability/bnn_layers/dataset.py diff --git a/tests/st/probability/test_bnn_layer.py b/tests/st/probability/bnn_layers/test_bnn_layer.py similarity index 100% rename from tests/st/probability/test_bnn_layer.py rename to tests/st/probability/bnn_layers/test_bnn_layer.py diff --git a/tests/st/probability/test_gpu_svi_cvae.py b/tests/st/probability/dpn/test_gpu_svi_cvae.py similarity index 100% rename from tests/st/probability/test_gpu_svi_cvae.py rename to tests/st/probability/dpn/test_gpu_svi_cvae.py diff --git a/tests/st/probability/test_gpu_svi_vae.py b/tests/st/probability/dpn/test_gpu_svi_vae.py similarity index 100% rename from tests/st/probability/test_gpu_svi_vae.py rename to tests/st/probability/dpn/test_gpu_svi_vae.py diff --git a/tests/st/probability/test_gpu_vae_gan.py b/tests/st/probability/dpn/test_gpu_vae_gan.py similarity index 100% rename from tests/st/probability/test_gpu_vae_gan.py rename to tests/st/probability/dpn/test_gpu_vae_gan.py diff --git a/tests/st/probability/test_uncertainty.py b/tests/st/probability/toolbox/test_uncertainty.py similarity index 100% rename from tests/st/probability/test_uncertainty.py rename to tests/st/probability/toolbox/test_uncertainty.py diff --git a/tests/st/probability/transforms/dataset.py b/tests/st/probability/transforms/dataset.py new file mode 100644 index 00000000000..df9eecda1fe --- /dev/null +++ b/tests/st/probability/transforms/dataset.py @@ -0,0 +1,60 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +""" +Produce the dataset +""" + +import mindspore.dataset as ds +import mindspore.dataset.vision.c_transforms as CV +import mindspore.dataset.transforms.c_transforms as C +from mindspore.dataset.vision import Inter +from mindspore.common import dtype as mstype + + +def create_dataset(data_path, batch_size=32, repeat_size=1, + num_parallel_workers=1): + """ + create dataset for train or test + """ + # define dataset + mnist_ds = ds.MnistDataset(data_path) + + resize_height, resize_width = 32, 32 + rescale = 1.0 / 255.0 + shift = 0.0 + rescale_nml = 1 / 0.3081 + shift_nml = -1 * 0.1307 / 0.3081 + + # define map operations + resize_op = CV.Resize((resize_height, resize_width), interpolation=Inter.LINEAR) # Bilinear mode + rescale_nml_op = CV.Rescale(rescale_nml, shift_nml) + rescale_op = CV.Rescale(rescale, shift) + hwc2chw_op = CV.HWC2CHW() + type_cast_op = C.TypeCast(mstype.int32) + + # apply map operations on images + mnist_ds = mnist_ds.map(operations=type_cast_op, input_columns="label", num_parallel_workers=num_parallel_workers) + mnist_ds = mnist_ds.map(operations=resize_op, input_columns="image", num_parallel_workers=num_parallel_workers) + mnist_ds = mnist_ds.map(operations=rescale_op, input_columns="image", num_parallel_workers=num_parallel_workers) + mnist_ds = mnist_ds.map(operations=rescale_nml_op, input_columns="image", num_parallel_workers=num_parallel_workers) + mnist_ds = mnist_ds.map(operations=hwc2chw_op, input_columns="image", num_parallel_workers=num_parallel_workers) + + # apply DatasetOps + buffer_size = 10000 + mnist_ds = mnist_ds.shuffle(buffer_size=buffer_size) # 10000 as in LeNet train script + mnist_ds = mnist_ds.batch(batch_size, drop_remainder=True) + mnist_ds = mnist_ds.repeat(repeat_size) + + return mnist_ds diff --git a/tests/st/probability/test_transform_bnn_layer.py b/tests/st/probability/transforms/test_transform_bnn_layer.py similarity index 100% rename from tests/st/probability/test_transform_bnn_layer.py rename to tests/st/probability/transforms/test_transform_bnn_layer.py diff --git a/tests/st/probability/test_transform_bnn_model.py b/tests/st/probability/transforms/test_transform_bnn_model.py similarity index 100% rename from tests/st/probability/test_transform_bnn_model.py rename to tests/st/probability/transforms/test_transform_bnn_model.py diff --git a/tests/ut/python/nn/probability/test_vae.py b/tests/ut/python/nn/probability/dpn/test_vae.py similarity index 100% rename from tests/ut/python/nn/probability/test_vae.py rename to tests/ut/python/nn/probability/dpn/test_vae.py