mindspore 2.0.0a0__cp38-cp38-win_amd64.whl → 2.0.0rc1__cp38-cp38-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/__init__.py +4 -2
- mindspore/_c_dataengine.cp38-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp38-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp38-win_amd64.pyd +0 -0
- mindspore/_check_jit_forbidden_api.py +102 -0
- mindspore/_checkparam.py +1066 -1001
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +4 -3
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +50 -48
- mindspore/_extends/parallel_compile/akg_compiler/util.py +9 -4
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +4 -4
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +9 -4
- mindspore/_extends/parse/__init__.py +5 -3
- mindspore/_extends/parse/namespace.py +16 -1
- mindspore/_extends/parse/parser.py +107 -22
- mindspore/_extends/parse/resources.py +0 -7
- mindspore/_extends/parse/standard_method.py +885 -413
- mindspore/amp.py +52 -57
- mindspore/boost/boost.py +2 -2
- mindspore/boost/boost_cell_wrapper.py +38 -20
- mindspore/boost/dim_reduce.py +3 -3
- mindspore/boost/group_loss_scale_manager.py +1 -1
- mindspore/common/__init__.py +4 -6
- mindspore/common/_decorator.py +2 -0
- mindspore/common/_register_for_adapter.py +55 -0
- mindspore/common/_stub_tensor.py +201 -0
- mindspore/common/_utils.py +41 -7
- mindspore/common/api.py +215 -141
- mindspore/common/dtype.py +8 -1
- mindspore/common/dump.py +2 -2
- mindspore/common/initializer.py +4 -2
- mindspore/common/jit_config.py +17 -13
- mindspore/common/mutable.py +33 -13
- mindspore/common/parameter.py +23 -21
- mindspore/common/seed.py +8 -24
- mindspore/common/sparse_tensor.py +62 -41
- mindspore/common/tensor.py +852 -1154
- mindspore/communication/__init__.py +2 -2
- mindspore/communication/_comm_helper.py +11 -4
- mindspore/communication/management.py +22 -21
- mindspore/config/op_info.config +501 -1008
- mindspore/context.py +201 -23
- mindspore/dataset/__init__.py +6 -6
- mindspore/dataset/audio/__init__.py +7 -7
- mindspore/dataset/audio/transforms.py +670 -30
- mindspore/dataset/audio/utils.py +47 -4
- mindspore/dataset/audio/validators.py +223 -1
- mindspore/dataset/callback/ds_callback.py +2 -2
- mindspore/dataset/core/config.py +210 -14
- mindspore/dataset/core/validator_helpers.py +2 -2
- mindspore/{parallel/nn/layers.py → dataset/debug/__init__.py} +7 -8
- mindspore/dataset/debug/debug_hook.py +65 -0
- mindspore/dataset/debug/pre_defined_hook.py +67 -0
- mindspore/dataset/engine/__init__.py +7 -3
- mindspore/dataset/engine/cache_client.py +1 -1
- mindspore/dataset/engine/datasets.py +322 -66
- mindspore/dataset/engine/datasets_audio.py +80 -76
- mindspore/dataset/engine/datasets_standard_format.py +51 -38
- mindspore/dataset/engine/datasets_text.py +232 -118
- mindspore/dataset/engine/datasets_user_defined.py +41 -17
- mindspore/dataset/engine/datasets_vision.py +746 -225
- mindspore/dataset/engine/graphdata.py +75 -10
- mindspore/dataset/engine/iterators.py +45 -5
- mindspore/dataset/engine/offload.py +48 -28
- mindspore/dataset/engine/validators.py +117 -8
- mindspore/dataset/text/__init__.py +6 -5
- mindspore/dataset/text/transforms.py +86 -3
- mindspore/dataset/text/utils.py +6 -4
- mindspore/dataset/text/validators.py +25 -0
- mindspore/dataset/transforms/__init__.py +3 -2
- mindspore/dataset/transforms/c_transforms.py +1 -1
- mindspore/dataset/transforms/transforms.py +2 -2
- mindspore/dataset/utils/__init__.py +2 -1
- mindspore/dataset/utils/line_reader.py +121 -0
- mindspore/dataset/vision/__init__.py +2 -3
- mindspore/dataset/vision/c_transforms.py +9 -9
- mindspore/dataset/vision/py_transforms.py +5 -5
- mindspore/dataset/vision/py_transforms_util.py +2 -0
- mindspore/dataset/vision/transforms.py +160 -161
- mindspore/dataset/vision/utils.py +3 -3
- mindspore/experimental/map_parameter.py +38 -26
- mindspore/include/OWNERS +0 -1
- mindspore/include/api/callback/callback.h +9 -13
- mindspore/include/api/callback/ckpt_saver.h +2 -2
- mindspore/include/api/callback/loss_monitor.h +2 -2
- mindspore/include/api/callback/lr_scheduler.h +5 -5
- mindspore/include/api/callback/time_monitor.h +2 -2
- mindspore/include/api/callback/train_accuracy.h +4 -6
- mindspore/include/api/cfg.h +19 -6
- mindspore/include/api/context.h +44 -9
- mindspore/include/api/delegate.h +1 -1
- mindspore/include/api/metrics/accuracy.h +2 -2
- mindspore/include/api/metrics/metrics.h +4 -3
- mindspore/include/api/model.h +9 -4
- mindspore/include/api/model_parallel_runner.h +2 -2
- mindspore/include/api/net.h +12 -11
- mindspore/include/api/serialization.h +19 -3
- mindspore/include/api/types.h +3 -3
- mindspore/include/dataset/constants.h +7 -0
- mindspore/include/dataset/text.h +59 -0
- mindspore/jpeg62.dll +0 -0
- mindspore/log.py +1 -1
- mindspore/mindrecord/filereader.py +18 -0
- mindspore/mindrecord/filewriter.py +197 -34
- mindspore/mindrecord/shardreader.py +9 -0
- mindspore/mindrecord/shardwriter.py +1 -1
- mindspore/mindrecord/tools/cifar100_to_mr.py +3 -3
- mindspore/mindrecord/tools/cifar10_to_mr.py +3 -3
- mindspore/mindrecord/tools/csv_to_mr.py +3 -3
- mindspore/mindrecord/tools/imagenet_to_mr.py +16 -11
- mindspore/mindrecord/tools/mnist_to_mr.py +2 -2
- mindspore/mindrecord/tools/tfrecord_to_mr.py +6 -6
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_shared_lib.dll +0 -0
- mindspore/nn/__init__.py +0 -4
- mindspore/nn/cell.py +204 -132
- mindspore/nn/dynamic_lr.py +1 -1
- mindspore/nn/grad/cell_grad.py +7 -6
- mindspore/nn/layer/__init__.py +5 -4
- mindspore/nn/layer/activation.py +40 -89
- mindspore/nn/layer/basic.py +255 -624
- mindspore/nn/layer/channel_shuffle.py +7 -6
- mindspore/nn/layer/combined.py +1 -1
- mindspore/nn/layer/container.py +41 -4
- mindspore/nn/layer/conv.py +64 -28
- mindspore/nn/layer/dense.py +9 -8
- mindspore/nn/layer/embedding.py +27 -25
- mindspore/nn/layer/image.py +53 -46
- mindspore/nn/layer/math.py +97 -105
- mindspore/nn/layer/normalization.py +117 -86
- mindspore/nn/layer/padding.py +185 -95
- mindspore/nn/layer/pooling.py +817 -414
- mindspore/nn/layer/rnn_cells.py +10 -15
- mindspore/nn/layer/rnns.py +37 -38
- mindspore/nn/layer/thor_layer.py +11 -12
- mindspore/nn/layer/timedistributed.py +5 -5
- mindspore/nn/layer/transformer.py +701 -0
- mindspore/nn/learning_rate_schedule.py +8 -8
- mindspore/nn/loss/__init__.py +5 -4
- mindspore/nn/loss/loss.py +334 -199
- mindspore/nn/optim/ada_grad.py +6 -6
- mindspore/nn/optim/adadelta.py +2 -3
- mindspore/nn/optim/adafactor.py +4 -5
- mindspore/nn/optim/adam.py +126 -62
- mindspore/nn/optim/adamax.py +3 -4
- mindspore/nn/optim/adasum.py +6 -6
- mindspore/nn/optim/asgd.py +2 -2
- mindspore/nn/optim/ftrl.py +67 -38
- mindspore/nn/optim/lamb.py +4 -5
- mindspore/nn/optim/lars.py +2 -2
- mindspore/nn/optim/lazyadam.py +43 -4
- mindspore/nn/optim/momentum.py +6 -5
- mindspore/nn/optim/optimizer.py +3 -1
- mindspore/nn/optim/proximal_ada_grad.py +2 -2
- mindspore/nn/optim/rmsprop.py +1 -1
- mindspore/nn/optim/rprop.py +8 -9
- mindspore/nn/optim/sgd.py +19 -13
- mindspore/nn/optim/thor.py +10 -15
- mindspore/nn/probability/__init__.py +0 -2
- mindspore/nn/probability/bijector/bijector.py +4 -4
- mindspore/nn/probability/bijector/invert.py +1 -1
- mindspore/nn/probability/bijector/softplus.py +2 -2
- mindspore/nn/probability/bnn_layers/dense_variational.py +1 -1
- mindspore/nn/probability/bnn_layers/layer_distribution.py +2 -2
- mindspore/nn/probability/distribution/_utils/utils.py +9 -15
- mindspore/nn/probability/distribution/bernoulli.py +3 -3
- mindspore/nn/probability/distribution/beta.py +1 -1
- mindspore/nn/probability/distribution/categorical.py +5 -7
- mindspore/nn/probability/distribution/cauchy.py +3 -3
- mindspore/nn/probability/distribution/distribution.py +2 -2
- mindspore/nn/probability/distribution/exponential.py +2 -2
- mindspore/nn/probability/distribution/gamma.py +3 -3
- mindspore/nn/probability/distribution/geometric.py +1 -1
- mindspore/nn/probability/distribution/gumbel.py +3 -3
- mindspore/nn/probability/distribution/half_normal.py +15 -11
- mindspore/nn/probability/distribution/laplace.py +16 -13
- mindspore/nn/probability/distribution/logistic.py +2 -2
- mindspore/nn/probability/distribution/normal.py +1 -1
- mindspore/nn/probability/distribution/poisson.py +1 -1
- mindspore/nn/probability/distribution/student_t.py +20 -15
- mindspore/nn/probability/distribution/transformed_distribution.py +4 -4
- mindspore/nn/probability/distribution/uniform.py +2 -2
- mindspore/nn/reinforcement/_tensors_queue.py +3 -3
- mindspore/nn/reinforcement/tensor_array.py +2 -2
- mindspore/nn/sparse/sparse.py +2 -2
- mindspore/nn/wrap/cell_wrapper.py +27 -10
- mindspore/nn/wrap/grad_reducer.py +2 -2
- mindspore/nn/wrap/loss_scale.py +40 -24
- mindspore/numpy/array_creations.py +33 -22
- mindspore/numpy/array_ops.py +35 -30
- mindspore/numpy/logic_ops.py +6 -27
- mindspore/numpy/math_ops.py +22 -19
- mindspore/numpy/utils.py +1 -1
- mindspore/numpy/utils_const.py +108 -58
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/_constants.py +0 -6
- mindspore/ops/_grad/__init__.py +2 -1
- mindspore/ops/_grad/grad_array_ops.py +86 -117
- mindspore/ops/_grad/grad_base.py +23 -1
- mindspore/ops/_grad/grad_clip_ops.py +2 -3
- mindspore/ops/_grad/grad_comm_ops.py +34 -24
- mindspore/ops/_grad/grad_implementations.py +9 -45
- mindspore/ops/_grad/grad_inner_ops.py +47 -4
- mindspore/ops/_grad/grad_math_ops.py +142 -117
- mindspore/ops/_grad/grad_nn_ops.py +71 -165
- mindspore/ops/_grad/grad_sequence_ops.py +296 -0
- mindspore/ops/_grad/grad_sparse.py +7 -6
- mindspore/ops/_grad_experimental/__init__.py +1 -0
- mindspore/ops/_grad_experimental/grad_array_ops.py +150 -15
- mindspore/ops/_grad_experimental/grad_image_ops.py +16 -7
- mindspore/ops/_grad_experimental/grad_inner_ops.py +1 -22
- mindspore/ops/_grad_experimental/grad_linalg_ops.py +4 -11
- mindspore/ops/_grad_experimental/grad_math_ops.py +210 -89
- mindspore/ops/_grad_experimental/grad_nn_ops.py +26 -22
- mindspore/ops/_grad_experimental/grad_scalar_ops.py +112 -0
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +49 -8
- mindspore/ops/_op_impl/_custom_op/batch_matmul_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold.py +2 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2.py +2 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad_reduce.py +4 -4
- mindspore/ops/_op_impl/_custom_op/batchnorm_fold_grad.py +3 -3
- mindspore/ops/_op_impl/_custom_op/cholesky_trsm_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/correction_mul.py +2 -2
- mindspore/ops/_op_impl/_custom_op/correction_mul_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +1 -5
- mindspore/ops/_op_impl/_custom_op/dsd_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad_reduce.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad_reduce.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer_grad.py +2 -2
- mindspore/ops/_op_impl/_custom_op/fused_abs_max1_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/img2col_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_left_impl.py +2 -2
- mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_right_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_left_cast_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_right_mul_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/matmul_cube_impl.py +2 -2
- mindspore/ops/_op_impl/_custom_op/matmul_dds_impl.py +0 -4
- mindspore/ops/_op_impl/_custom_op/matrix_combine_impl.py +1 -1
- mindspore/ops/_op_impl/_custom_op/minmax_update_perchannel.py +2 -2
- mindspore/ops/_op_impl/_custom_op/minmax_update_perlayer.py +2 -2
- mindspore/ops/_op_impl/_custom_op/transpose02314_impl.py +1 -1
- mindspore/ops/_op_impl/aicpu/__init__.py +236 -4
- mindspore/ops/_op_impl/aicpu/abs.py +36 -0
- mindspore/ops/_op_impl/aicpu/{adaptive_avg_pool_2d_v1.py → adaptive_avg_pool_2d.py} +6 -5
- mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d_grad.py +34 -0
- mindspore/ops/_op_impl/aicpu/add.py +43 -0
- mindspore/ops/_op_impl/aicpu/addcdiv.py +0 -32
- mindspore/ops/_op_impl/aicpu/addcmul.py +0 -84
- mindspore/ops/_op_impl/aicpu/affine_grid_grad.py +35 -0
- mindspore/ops/_op_impl/aicpu/batch_matmul.py +43 -43
- mindspore/ops/_op_impl/aicpu/bernoulli.py +48 -0
- mindspore/{compression/common/__init__.py → ops/_op_impl/aicpu/bessel_i0.py} +15 -8
- mindspore/ops/_op_impl/aicpu/channel_shuffle.py +40 -0
- mindspore/ops/_op_impl/aicpu/conj.py +11 -0
- mindspore/ops/_op_impl/aicpu/cumulative_logsumexp.py +0 -3
- mindspore/ops/_op_impl/aicpu/deformable_offsets.py +38 -0
- mindspore/ops/_op_impl/aicpu/deformable_offsets_grad.py +43 -0
- mindspore/ops/_op_impl/aicpu/{adaptive_avg_pool_2d_grad_v1.py → digamma.py} +7 -9
- mindspore/ops/_op_impl/aicpu/flatten.py +1 -0
- mindspore/ops/_op_impl/aicpu/fmax.py +36 -0
- mindspore/ops/_op_impl/aicpu/fmin.py +37 -0
- mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_with_fixed_ksize.py +1 -1
- mindspore/ops/_op_impl/aicpu/fse_decode.py +43 -0
- mindspore/ops/_op_impl/aicpu/greater.py +41 -0
- mindspore/ops/_op_impl/aicpu/greater_equal.py +41 -0
- mindspore/ops/_op_impl/aicpu/index_put.py +50 -0
- mindspore/ops/_op_impl/aicpu/less.py +41 -0
- mindspore/{nn/probability/infer/variational/__init__.py → ops/_op_impl/aicpu/lgamma.py} +16 -10
- mindspore/ops/_op_impl/aicpu/mirror_pad.py +0 -4
- mindspore/ops/_op_impl/aicpu/mirror_pad_grad.py +0 -4
- mindspore/ops/_op_impl/aicpu/mul.py +3 -1
- mindspore/ops/_op_impl/aicpu/multinomial.py +14 -6
- mindspore/ops/_op_impl/aicpu/nllloss.py +38 -0
- mindspore/ops/_op_impl/aicpu/nllloss_grad.py +39 -0
- mindspore/ops/_op_impl/aicpu/ones_like.py +0 -2
- mindspore/ops/_op_impl/aicpu/polar.py +32 -0
- mindspore/ops/_op_impl/aicpu/polygamma.py +34 -0
- mindspore/ops/_op_impl/aicpu/quant_dtype_cast.py +40 -0
- mindspore/ops/_op_impl/aicpu/quantile.py +35 -0
- mindspore/ops/_op_impl/aicpu/ragged_tensor_to_sparse.py +73 -0
- mindspore/ops/_op_impl/aicpu/randperm_v2.py +41 -0
- mindspore/ops/_op_impl/aicpu/resize_bicubic.py +2 -8
- mindspore/ops/_op_impl/aicpu/resize_bicubic_grad.py +1 -1
- mindspore/ops/_op_impl/aicpu/resize_v2.py +68 -0
- mindspore/ops/_op_impl/aicpu/resize_v2_grad.py +68 -0
- mindspore/ops/_op_impl/aicpu/scatter_elements.py +4 -0
- mindspore/ops/_op_impl/aicpu/scatter_nd_update.py +2 -0
- mindspore/ops/_op_impl/aicpu/sequence_add.py +34 -0
- mindspore/ops/_op_impl/aicpu/sequence_add_offset.py +34 -0
- mindspore/ops/_op_impl/aicpu/sequence_addn.py +38 -0
- mindspore/ops/_op_impl/aicpu/smooth_l1_loss.py +35 -0
- mindspore/ops/_op_impl/aicpu/smooth_l1_loss_grad.py +37 -0
- mindspore/ops/_op_impl/aicpu/sparse_apply_adagrad_da.py +0 -24
- mindspore/ops/_op_impl/aicpu/sparse_cross.py +42 -0
- mindspore/ops/_op_impl/aicpu/sparse_slice.py +4 -0
- mindspore/ops/_op_impl/aicpu/sparse_slice_grad.py +6 -0
- mindspore/ops/_op_impl/aicpu/tensor_scatter_update.py +59 -0
- mindspore/ops/_op_impl/aicpu/trans_data.py +1 -0
- mindspore/ops/_op_impl/aicpu/tril_indices.py +34 -0
- mindspore/ops/_op_impl/aicpu/uniform.py +34 -0
- mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +1 -0
- mindspore/ops/_op_impl/aicpu/unique_consecutive.py +10 -2
- mindspore/ops/_op_impl/cpu/dynamic_shape.py +5 -1
- mindspore/ops/_op_impl/cpu/sparse_slice.py +4 -0
- mindspore/ops/_op_impl/cpu/sparse_slice_grad.py +6 -0
- mindspore/ops/_op_impl/cpu/tensor_shape.py +5 -1
- mindspore/ops/_op_impl/tbe/__init__.py +27 -611
- mindspore/ops/_op_impl/tbe/assign_add_ds.py +1 -0
- mindspore/ops/_op_impl/tbe/atomic_addr_clean.py +1 -1
- mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +1 -1
- mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +1 -0
- mindspore/ops/_op_impl/tbe/batch_to_space.py +1 -1
- mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +1 -1
- mindspore/ops/_op_impl/tbe/bn_infer_grad.py +4 -2
- mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -1
- mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -1
- mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +6 -4
- mindspore/ops/_op_impl/tbe/cast.py +0 -2
- mindspore/ops/_op_impl/tbe/cast_ds.py +3 -3
- mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +1 -0
- mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +2 -2
- mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +1 -1
- mindspore/ops/_op_impl/tbe/gather_nd.py +1 -0
- mindspore/ops/_op_impl/tbe/{index_add.py → inplace_index_add.py} +3 -6
- mindspore/ops/_op_impl/tbe/matmul_ds.py +2 -0
- mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +35 -0
- mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +35 -0
- mindspore/ops/_op_impl/tbe/scatter_mul.py +2 -0
- mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -2
- mindspore/ops/_op_impl/tbe/space_to_batch.py +1 -1
- mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +1 -1
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +15 -5
- mindspore/ops/_register_for_op.py +1 -0
- mindspore/ops/_utils/__init__.py +1 -2
- mindspore/ops/_utils/utils.py +19 -40
- mindspore/ops/_vmap/vmap_array_ops.py +116 -38
- mindspore/ops/_vmap/vmap_base.py +16 -9
- mindspore/ops/_vmap/vmap_convolution_ops.py +7 -10
- mindspore/ops/_vmap/vmap_grad_math_ops.py +4 -4
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +7 -5
- mindspore/ops/_vmap/vmap_image_ops.py +12 -5
- mindspore/ops/_vmap/vmap_math_ops.py +46 -5
- mindspore/ops/_vmap/vmap_nn_ops.py +15 -21
- mindspore/ops/_vmap/vmap_random_ops.py +1 -1
- mindspore/ops/bprop_mindir/AdaptiveAvgPool2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/AdaptiveMaxPool2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/AvgPool3D_bprop.mindir +150 -0
- mindspore/ops/bprop_mindir/AvgPool_bprop.mindir +66 -0
- mindspore/ops/bprop_mindir/BCEWithLogitsLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BatchNormGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BiasAddGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/BinaryCrossEntropy_bprop.mindir +33 -0
- mindspore/ops/bprop_mindir/BroadcastTo_bprop.mindir +220 -106
- mindspore/ops/bprop_mindir/CTCLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Conv2DBackpropFilter_bprop.mindir +240 -0
- mindspore/ops/bprop_mindir/Conv2DBackpropInput_bprop.mindir +247 -0
- mindspore/ops/bprop_mindir/Conv2DTranspose_bprop.mindir +247 -0
- mindspore/ops/bprop_mindir/Conv3DTranspose_bprop.mindir +315 -0
- mindspore/ops/bprop_mindir/Conv3D_bprop.mindir +278 -0
- mindspore/ops/bprop_mindir/DeformableOffsets_bprop.mindir +58 -0
- mindspore/ops/bprop_mindir/DepthwiseConv2dNative_bprop.mindir +138 -0
- mindspore/ops/bprop_mindir/Dropout2D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Dropout3D_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DropoutDoMask_bprop.mindir +22 -23
- mindspore/ops/bprop_mindir/DropoutGenMask_bprop.mindir +16 -17
- mindspore/ops/bprop_mindir/DropoutGrad_bprop.mindir +27 -0
- mindspore/ops/bprop_mindir/Dropout_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DynamicGRUV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DynamicRNN_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Elu_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/EmbeddingLookup_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ExpandDims_bprop.mindir +39 -41
- mindspore/ops/bprop_mindir/FastGeLU_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/Flatten_bprop.mindir +41 -43
- mindspore/ops/bprop_mindir/GatherNd_bprop.mindir +51 -57
- mindspore/ops/bprop_mindir/Gather_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/HSigmoid_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/HSwish_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/InstanceNorm_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/KLDivLoss_bprop.mindir +126 -0
- mindspore/ops/bprop_mindir/L2Loss_bprop.mindir +15 -0
- mindspore/ops/bprop_mindir/L2Normalize_bprop.mindir +30 -0
- mindspore/ops/bprop_mindir/LRN_bprop.mindir +43 -0
- mindspore/ops/bprop_mindir/LayerNormGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/LogSoftmax_bprop.mindir +23 -0
- mindspore/ops/bprop_mindir/MaxPool3DGradGrad_bprop.mindir +74 -0
- mindspore/ops/bprop_mindir/MaxPool3DGrad_bprop.mindir +74 -0
- mindspore/ops/bprop_mindir/MaxPool3D_bprop.mindir +75 -0
- mindspore/ops/bprop_mindir/MaxPoolGradGrad_bprop.mindir +65 -0
- mindspore/ops/bprop_mindir/MaxPoolWithArgmax_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/MirrorPad_bprop.mindir +27 -0
- mindspore/ops/bprop_mindir/Mish_bprop.mindir +35 -0
- mindspore/ops/bprop_mindir/MulNoNan_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/NLLLoss_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/OneHot_bprop.mindir +24 -25
- mindspore/ops/bprop_mindir/PReLU_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Pad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Padding_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/RNNTLoss_bprop.mindir +29 -0
- mindspore/ops/bprop_mindir/ROIAlign_bprop.mindir +82 -0
- mindspore/ops/bprop_mindir/ReLU6_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/ReLUV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ReluGrad_bprop.mindir +18 -19
- mindspore/ops/bprop_mindir/Reshape_bprop.mindir +53 -53
- mindspore/ops/bprop_mindir/ResizeBilinear_bprop.mindir +29 -0
- mindspore/ops/bprop_mindir/ResizeNearestNeighbor_bprop.mindir +77 -85
- mindspore/ops/bprop_mindir/SeLU_bprop.mindir +21 -0
- mindspore/ops/bprop_mindir/SigmoidCrossEntropyWithLogits_bprop.mindir +21 -0
- mindspore/ops/bprop_mindir/SigmoidGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Sigmoid_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/SmoothL1Loss_bprop.mindir +36 -0
- mindspore/ops/bprop_mindir/SoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Softplus_bprop.mindir +16 -0
- mindspore/ops/bprop_mindir/Softsign_bprop.mindir +33 -0
- mindspore/ops/bprop_mindir/SparseSoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Squeeze_bprop.mindir +37 -39
- mindspore/ops/bprop_mindir/StridedSlice_bprop.mindir +70 -72
- mindspore/ops/bprop_mindir/TanhGrad_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Tanh_bprop.mindir +66 -0
- mindspore/ops/bprop_mindir/Tile_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TopK_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TupleGetItem_bprop.mindir +17 -17
- mindspore/ops/bprop_mindir/UpsampleNearest3D_bprop.mindir +32 -0
- mindspore/ops/bprop_mindir/UpsampleTrilinear3D_bprop.mindir +38 -0
- mindspore/ops/bprop_mindir/generate_mindir.py +2 -0
- mindspore/ops/composite/__init__.py +7 -8
- mindspore/ops/composite/base.py +101 -47
- mindspore/ops/composite/math_ops.py +188 -158
- mindspore/ops/composite/multitype_ops/_compile_utils.py +415 -170
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +142 -87
- mindspore/ops/composite/multitype_ops/add_impl.py +6 -1
- mindspore/ops/composite/multitype_ops/div_impl.py +2 -3
- mindspore/ops/composite/multitype_ops/getitem_impl.py +31 -3
- mindspore/ops/composite/multitype_ops/greater_equal_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/greater_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/in_impl.py +9 -0
- mindspore/ops/composite/multitype_ops/less_equal_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/less_impl.py +31 -0
- mindspore/ops/composite/multitype_ops/mul_impl.py +21 -5
- mindspore/ops/composite/multitype_ops/not_in_impl.py +9 -0
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -4
- mindspore/ops/composite/multitype_ops/setitem_impl.py +21 -3
- mindspore/ops/composite/multitype_ops/sub_impl.py +1 -1
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +35 -4
- mindspore/ops/function/__init__.py +152 -8
- mindspore/ops/function/array_func.py +2555 -674
- mindspore/ops/function/clip_func.py +209 -13
- mindspore/ops/function/debug_func.py +2 -2
- mindspore/ops/function/grad/__init__.py +2 -1
- mindspore/ops/function/grad/grad_func.py +147 -62
- mindspore/ops/function/image_func.py +54 -38
- mindspore/ops/function/linalg_func.py +167 -16
- mindspore/ops/function/math_func.py +4849 -1492
- mindspore/ops/function/nn_func.py +2573 -988
- mindspore/ops/function/other_func.py +115 -0
- mindspore/ops/function/parameter_func.py +3 -3
- mindspore/ops/function/random_func.py +790 -73
- mindspore/ops/function/sparse_func.py +98 -78
- mindspore/ops/function/sparse_unary_func.py +54 -53
- mindspore/ops/function/spectral_func.py +27 -24
- mindspore/ops/function/vmap_func.py +22 -2
- mindspore/ops/functional.py +97 -37
- mindspore/ops/op_info_register.py +70 -28
- mindspore/ops/operations/__init__.py +47 -14
- mindspore/ops/operations/_csr_ops.py +7 -7
- mindspore/ops/operations/_embedding_cache_ops.py +5 -5
- mindspore/ops/operations/_grad_ops.py +276 -187
- mindspore/ops/operations/_inner_ops.py +319 -113
- mindspore/ops/operations/_ms_kernel.py +10 -8
- mindspore/ops/operations/_ocr_ops.py +9 -9
- mindspore/ops/operations/_opaque_predicate_registry.py +4 -0
- mindspore/ops/operations/_quant_ops.py +137 -102
- mindspore/ops/operations/_rl_inner_ops.py +121 -60
- mindspore/ops/operations/_scalar_ops.py +466 -0
- mindspore/ops/operations/_sequence_ops.py +1004 -2
- mindspore/ops/operations/_tensor_array.py +10 -11
- mindspore/ops/operations/_thor_ops.py +1 -1
- mindspore/ops/operations/array_ops.py +801 -466
- mindspore/ops/operations/comm_ops.py +51 -49
- mindspore/ops/operations/control_ops.py +2 -2
- mindspore/ops/operations/custom_ops.py +123 -44
- mindspore/ops/operations/debug_ops.py +24 -24
- mindspore/ops/operations/image_ops.py +240 -153
- mindspore/ops/operations/inner_ops.py +34 -50
- mindspore/ops/operations/linalg_ops.py +31 -9
- mindspore/ops/operations/math_ops.py +988 -757
- mindspore/ops/operations/nn_ops.py +965 -819
- mindspore/ops/operations/other_ops.py +51 -40
- mindspore/ops/operations/random_ops.py +204 -122
- mindspore/ops/operations/rl_ops.py +8 -9
- mindspore/ops/operations/sparse_ops.py +254 -93
- mindspore/ops/operations/spectral_ops.py +35 -3
- mindspore/ops/primitive.py +111 -9
- mindspore/parallel/_auto_parallel_context.py +189 -83
- mindspore/parallel/_offload_context.py +185 -0
- mindspore/parallel/_parallel_serialization.py +99 -7
- mindspore/parallel/_ps_context.py +9 -5
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +7 -1
- mindspore/{nn/transformer → parallel/_transformer}/__init__.py +6 -6
- mindspore/{nn/transformer → parallel/_transformer}/layers.py +6 -37
- mindspore/{nn/transformer → parallel/_transformer}/loss.py +4 -7
- mindspore/{nn/transformer → parallel/_transformer}/moe.py +20 -16
- mindspore/{nn/transformer → parallel/_transformer}/op_parallel_config.py +3 -3
- mindspore/{nn/transformer → parallel/_transformer}/transformer.py +48 -111
- mindspore/parallel/_utils.py +1 -2
- mindspore/parallel/algo_parameter_config.py +1 -1
- mindspore/parallel/checkpoint_transform.py +37 -34
- mindspore/parallel/shard.py +17 -18
- mindspore/profiler/common/validator/validate_path.py +2 -2
- mindspore/profiler/envprofiling.py +69 -47
- mindspore/profiler/parser/ascend_timeline_generator.py +49 -42
- mindspore/profiler/parser/base_timeline_generator.py +49 -56
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +98 -78
- mindspore/profiler/parser/hwts_log_parser.py +1 -1
- mindspore/profiler/parser/integrator.py +15 -14
- mindspore/profiler/parser/minddata_analyzer.py +2 -2
- mindspore/profiler/parser/msadvisor_analyzer.py +12 -25
- mindspore/profiler/parser/msadvisor_parser.py +2 -4
- mindspore/profiler/parser/optime_parser.py +17 -18
- mindspore/profiler/parser/profiler_info.py +2 -1
- mindspore/profiler/profiling.py +218 -186
- mindspore/rewrite/__init__.py +3 -1
- mindspore/rewrite/api/node.py +1 -114
- mindspore/rewrite/api/node_type.py +3 -0
- mindspore/rewrite/api/pattern_engine.py +31 -1
- mindspore/rewrite/api/scoped_value.py +4 -4
- mindspore/rewrite/api/symbol_tree.py +3 -78
- mindspore/rewrite/api/tree_node_helper.py +1 -1
- mindspore/rewrite/ast_creator_register.py +1 -0
- mindspore/rewrite/ast_helpers/__init__.py +2 -2
- mindspore/rewrite/ast_helpers/ast_creator.py +1 -2
- mindspore/rewrite/ast_helpers/ast_finder.py +65 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +11 -3
- mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +18 -2
- mindspore/rewrite/namespace.py +0 -2
- mindspore/rewrite/node.py +157 -11
- mindspore/rewrite/parsers/assign_parser.py +231 -53
- mindspore/rewrite/parsers/class_def_parser.py +187 -109
- mindspore/rewrite/parsers/for_parser.py +24 -14
- mindspore/rewrite/parsers/function_def_parser.py +21 -4
- mindspore/rewrite/parsers/if_parser.py +6 -2
- mindspore/rewrite/sparsify/__init__.py +0 -0
- mindspore/rewrite/sparsify/sparse_transformer.py +448 -0
- mindspore/rewrite/sparsify/sparsify.py +109 -0
- mindspore/rewrite/sparsify/utils.py +173 -0
- mindspore/rewrite/symbol_tree.py +256 -133
- mindspore/rewrite/symbol_tree_builder.py +38 -1
- mindspore/run_check/_check_version.py +69 -63
- mindspore/run_check/run_check.py +2 -1
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/__init__.py +1 -1
- mindspore/train/_utils.py +28 -5
- mindspore/train/amp.py +273 -102
- mindspore/train/callback/_backup_and_restore.py +5 -5
- mindspore/train/callback/_callback.py +2 -2
- mindspore/train/callback/_checkpoint.py +3 -3
- mindspore/train/callback/_early_stop.py +3 -3
- mindspore/train/callback/_lambda_callback.py +2 -2
- mindspore/train/callback/_landscape.py +29 -31
- mindspore/train/callback/_loss_monitor.py +3 -3
- mindspore/train/callback/_on_request_exit.py +3 -3
- mindspore/train/callback/_reduce_lr_on_plateau.py +4 -4
- mindspore/train/callback/_summary_collector.py +23 -16
- mindspore/train/callback/_time_monitor.py +3 -3
- mindspore/train/checkpoint_pb2.py +68 -8
- mindspore/train/data_sink.py +15 -3
- mindspore/train/dataset_helper.py +10 -15
- mindspore/train/loss_scale_manager.py +8 -11
- mindspore/train/metrics/__init__.py +1 -1
- mindspore/train/metrics/bleu_score.py +1 -1
- mindspore/train/metrics/confusion_matrix.py +1 -1
- mindspore/train/metrics/cosine_similarity.py +1 -1
- mindspore/train/metrics/dice.py +2 -2
- mindspore/train/metrics/fbeta.py +1 -1
- mindspore/train/metrics/hausdorff_distance.py +4 -3
- mindspore/train/metrics/mean_surface_distance.py +2 -2
- mindspore/train/metrics/occlusion_sensitivity.py +1 -1
- mindspore/train/metrics/perplexity.py +1 -1
- mindspore/train/metrics/precision.py +1 -1
- mindspore/train/metrics/recall.py +1 -1
- mindspore/train/metrics/roc.py +2 -2
- mindspore/train/metrics/root_mean_square_surface_distance.py +2 -2
- mindspore/train/mind_ir_pb2.py +116 -37
- mindspore/train/model.py +45 -28
- mindspore/train/serialization.py +295 -188
- mindspore/train/summary/_summary_adapter.py +1 -1
- mindspore/train/summary/summary_record.py +43 -13
- mindspore/train/train_thor/convert_utils.py +2 -2
- mindspore/train/train_thor/dataset_helper.py +3 -3
- mindspore/turbojpeg.dll +0 -0
- mindspore/version.py +1 -1
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/METADATA +3 -2
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/RECORD +610 -541
- mindspore/compression/__init__.py +0 -19
- mindspore/compression/common/constant.py +0 -124
- mindspore/compression/export/__init__.py +0 -19
- mindspore/compression/export/quant_export.py +0 -515
- mindspore/compression/quant/__init__.py +0 -28
- mindspore/compression/quant/qat.py +0 -634
- mindspore/compression/quant/quant_utils.py +0 -462
- mindspore/compression/quant/quantizer.py +0 -68
- mindspore/nn/layer/quant.py +0 -1868
- mindspore/nn/layer/rnn_utils.py +0 -90
- mindspore/nn/probability/dpn/__init__.py +0 -22
- mindspore/nn/probability/dpn/vae/__init__.py +0 -25
- mindspore/nn/probability/dpn/vae/cvae.py +0 -140
- mindspore/nn/probability/dpn/vae/vae.py +0 -124
- mindspore/nn/probability/infer/__init__.py +0 -22
- mindspore/nn/probability/infer/variational/elbo.py +0 -70
- mindspore/nn/probability/infer/variational/svi.py +0 -84
- mindspore/nn/probability/toolbox/__init__.py +0 -22
- mindspore/nn/probability/toolbox/anomaly_detection.py +0 -99
- mindspore/nn/probability/toolbox/uncertainty_evaluation.py +0 -364
- mindspore/nn/probability/transforms/__init__.py +0 -22
- mindspore/nn/probability/transforms/transform_bnn.py +0 -262
- mindspore/nn/probability/zhusuan/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/framework/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/framework/bn.py +0 -95
- mindspore/nn/probability/zhusuan/variational/__init__.py +0 -18
- mindspore/nn/probability/zhusuan/variational/elbo.py +0 -46
- mindspore/ops/_op_impl/aicpu/parallel_concat.py +0 -42
- mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
- mindspore/ops/bprop_mindir/AssignAdd_bprop.mindir +0 -19
- mindspore/ops/bprop_mindir/Cast_bprop.mindir +0 -19
- mindspore/ops/bprop_mindir/LogicalOr_bprop.mindir +0 -19
- mindspore/ops/bprop_mindir/MatMul_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ReLU_bprop.mindir +0 -17
- mindspore/ops/bprop_mindir/Transpose_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/UpdateState_bprop.mindir +0 -15
- mindspore/ops/composite/array_ops.py +0 -241
- mindspore/ops/composite/clip_ops.py +0 -134
- mindspore/ops/composite/random_ops.py +0 -426
- mindspore/ops/composite/vmap_ops.py +0 -38
- mindspore/parallel/nn/__init__.py +0 -42
- mindspore/parallel/nn/loss.py +0 -22
- mindspore/parallel/nn/moe.py +0 -21
- mindspore/parallel/nn/op_parallel_config.py +0 -22
- mindspore/parallel/nn/transformer.py +0 -31
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/WHEEL +0 -0
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/entry_points.txt +0 -0
- {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -23,8 +23,7 @@ from mindspore import log as logger
|
|
|
23
23
|
from mindspore._checkparam import _check_3d_int_or_tuple
|
|
24
24
|
from mindspore import context
|
|
25
25
|
from mindspore.ops import signature as sig
|
|
26
|
-
from mindspore
|
|
27
|
-
from mindspore._checkparam import Rel
|
|
26
|
+
from mindspore import _checkparam as validator
|
|
28
27
|
from mindspore.common import dtype as mstype
|
|
29
28
|
from mindspore.common._decorator import deprecated
|
|
30
29
|
from mindspore.ops.primitive import Primitive
|
|
@@ -117,7 +116,7 @@ class CeLU(Primitive):
|
|
|
117
116
|
def __init__(self, alpha=1.0):
|
|
118
117
|
"""Initialize CeLU"""
|
|
119
118
|
validator.check_value_type("alpha", alpha, [float], self.name)
|
|
120
|
-
validator.check_float(alpha, 0.0,
|
|
119
|
+
validator.check_float(alpha, 0.0, validator.NE, "alpha", self.name)
|
|
121
120
|
self.alpha = alpha
|
|
122
121
|
self.add_prim_attr('alpha', self.alpha)
|
|
123
122
|
|
|
@@ -148,10 +147,13 @@ class AdaptiveAvgPool3D(Primitive):
|
|
|
148
147
|
r"""
|
|
149
148
|
AdaptiveAvgPool3D operation.
|
|
150
149
|
|
|
150
|
+
.. warning::
|
|
151
|
+
This is an experimental API that is subject to change or deletion.
|
|
152
|
+
|
|
151
153
|
Refer to :func:`mindspore.ops.adaptive_avg_pool3d` for more details.
|
|
152
154
|
|
|
153
155
|
Supported Platforms:
|
|
154
|
-
``GPU`` ``CPU``
|
|
156
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
155
157
|
|
|
156
158
|
Examples:
|
|
157
159
|
>>> import mindspore
|
|
@@ -183,7 +185,7 @@ class AdaptiveAvgPool3D(Primitive):
|
|
|
183
185
|
for i, size in enumerate(self.output_size):
|
|
184
186
|
validator.check_value_type(f"output_size[{i}]", size, [int, type(None)], self.name)
|
|
185
187
|
if size is not None:
|
|
186
|
-
validator.check_number(f"output_size[{i}]", size, 0,
|
|
188
|
+
validator.check_number(f"output_size[{i}]", size, 0, validator.GE, self.name)
|
|
187
189
|
|
|
188
190
|
self.output_size = tuple(-1 if val is None else val for val in self.output_size)
|
|
189
191
|
|
|
@@ -191,67 +193,21 @@ class AdaptiveAvgPool3D(Primitive):
|
|
|
191
193
|
self.init_prim_io_names(inputs=['x'], outputs=['y'])
|
|
192
194
|
|
|
193
195
|
|
|
194
|
-
class
|
|
196
|
+
class AdaptiveAvgPool2D(Primitive):
|
|
195
197
|
r"""
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
This operator applies a 2D adaptive average pooling to an input signal composed of multiple input planes.
|
|
199
|
-
That is, for any input size, the size of the specified output is H x W.
|
|
200
|
-
The number of output features is equal to the number of input planes.
|
|
198
|
+
AdaptiveAvgPool2D operation.
|
|
201
199
|
|
|
202
|
-
|
|
203
|
-
H is the feature height, and W is the feature width.
|
|
204
|
-
|
|
205
|
-
For AdaptiveAvgPool2DV1:
|
|
206
|
-
|
|
207
|
-
.. math::
|
|
208
|
-
\begin{align}
|
|
209
|
-
h_{start} &= floor(i * H_{in} / H_{out})\\
|
|
210
|
-
h_{end} &= ceil((i + 1) * H_{in} / H_{out})\\
|
|
211
|
-
w_{start} &= floor(j * W_{in} / W_{out})\\
|
|
212
|
-
w_{end} &= ceil((j + 1) * W_{in} / W_{out})\\
|
|
213
|
-
Output(i,j) &= \frac{\sum Input[h_{start}:h_{end}, w_{start}:w_{end}]}{(h_{end}- h_{start})
|
|
214
|
-
* (w_{end}- w_{start})}
|
|
215
|
-
\end{align}
|
|
216
|
-
|
|
217
|
-
Args:
|
|
218
|
-
- output_size (Union[int, tuple]): The target output size is H x W.
|
|
219
|
-
ouput_size can be a tuple, or a single H for H x H, and H and W can be int or None
|
|
220
|
-
which means the output size is the same as the input.
|
|
221
|
-
|
|
222
|
-
Inputs:
|
|
223
|
-
- **input_x** (Tensor) - The input of AdaptiveAvgPool2DV1, which is a 3D or 4D tensor,
|
|
224
|
-
with float16 or float32 data type.
|
|
225
|
-
|
|
226
|
-
Outputs:
|
|
227
|
-
Tensor, with the same type as the `input_x`.
|
|
228
|
-
|
|
229
|
-
Shape of the output is `input_x_shape[:len(input_x_shape) - len(out_shape)] + out_shape`.
|
|
230
|
-
|
|
231
|
-
.. math::
|
|
232
|
-
out\_shape = \begin{cases}
|
|
233
|
-
input\_x\_shape[-2] + output\_size[1], & \text{if output_size is (None, w);}\\
|
|
234
|
-
output\_size[0] + input\_x\_shape[-1], & \text{if output_size is (h, None);}\\
|
|
235
|
-
input\_x\_shape[-2:], & \text{if output_size is (None, None);}\\
|
|
236
|
-
(h, h), & \text{if output_size is h;}\\
|
|
237
|
-
(h, w), & \text{if output_size is (h, w)}
|
|
238
|
-
\end{cases}
|
|
239
|
-
|
|
240
|
-
Raises:
|
|
241
|
-
TypeError: If `input_x` is not a tensor.
|
|
242
|
-
TypeError: If dtype of `input_x` is not float16 nor float32.
|
|
243
|
-
ValueError: If `output_size` is a tuple and the length of `output_size` is not 2.
|
|
244
|
-
ValueError: If the dimension of `input_x` is less than or equal to the dimension of `output_size`.
|
|
200
|
+
Refer to :func:`mindspore.ops.adaptive_avg_pool2d` for more details.
|
|
245
201
|
|
|
246
202
|
Supported Platforms:
|
|
247
|
-
``
|
|
203
|
+
``GPU``
|
|
248
204
|
|
|
249
205
|
Examples:
|
|
250
206
|
>>> # case 1: output_size=(None, 2)
|
|
251
207
|
>>> input_x = Tensor(np.array([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
|
|
252
208
|
... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
|
|
253
209
|
... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]), mindspore.float32)
|
|
254
|
-
>>> adaptive_avg_pool_2d = ops.
|
|
210
|
+
>>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((None, 2))
|
|
255
211
|
>>> output = adaptive_avg_pool_2d(input_x)
|
|
256
212
|
>>> print(output)
|
|
257
213
|
[[[1.5 2.5]
|
|
@@ -264,7 +220,7 @@ class AdaptiveAvgPool2DV1(Primitive):
|
|
|
264
220
|
[4.5 5.5]
|
|
265
221
|
[7.5 8.5]]]
|
|
266
222
|
>>> # case 2: output_size=2
|
|
267
|
-
>>> adaptive_avg_pool_2d = ops.
|
|
223
|
+
>>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D(2)
|
|
268
224
|
>>> output = adaptive_avg_pool_2d(input_x)
|
|
269
225
|
>>> print(output)
|
|
270
226
|
[[[3. 4.]
|
|
@@ -274,7 +230,7 @@ class AdaptiveAvgPool2DV1(Primitive):
|
|
|
274
230
|
[[3. 4.]
|
|
275
231
|
[6. 7.]]]
|
|
276
232
|
>>> # case 3: output_size=(1, 2)
|
|
277
|
-
>>> adaptive_avg_pool_2d = ops.
|
|
233
|
+
>>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((1, 2))
|
|
278
234
|
>>> output = adaptive_avg_pool_2d(input_x)
|
|
279
235
|
>>> print(output)
|
|
280
236
|
[[[4.5 5.5]]
|
|
@@ -284,77 +240,38 @@ class AdaptiveAvgPool2DV1(Primitive):
|
|
|
284
240
|
|
|
285
241
|
@prim_attr_register
|
|
286
242
|
def __init__(self, output_size):
|
|
287
|
-
"""Initialize
|
|
243
|
+
"""Initialize AdaptiveAvgPool2D."""
|
|
288
244
|
self.init_prim_io_names(inputs=['x'], outputs=['y'])
|
|
289
245
|
validator.check_value_type("output_size", output_size, [int, tuple], self.name)
|
|
290
246
|
if isinstance(output_size, tuple):
|
|
291
|
-
validator.check_int(len(output_size), 2,
|
|
247
|
+
validator.check_int(len(output_size), 2, validator.EQ, 'length of output_size', self.name)
|
|
292
248
|
self.output_size = (output_size, output_size) if isinstance(self.output_size, int) else output_size
|
|
293
249
|
for i, size in enumerate(self.output_size):
|
|
294
250
|
validator.check_value_type(f"output_size[{i}]", size, [int, type(None)], self.name)
|
|
295
251
|
if size is not None:
|
|
296
|
-
validator.check_number(f"output_size[{i}]", size, 0,
|
|
252
|
+
validator.check_number(f"output_size[{i}]", size, 0, validator.GE, self.name)
|
|
297
253
|
|
|
298
254
|
self.output_size = tuple(-1 if val is None else val for val in self.output_size)
|
|
299
255
|
self.add_prim_attr('output_size', self.output_size)
|
|
300
256
|
|
|
301
257
|
|
|
302
|
-
class
|
|
258
|
+
class AdaptiveMaxPool2D(Primitive):
|
|
303
259
|
r"""
|
|
304
|
-
2D adaptive
|
|
260
|
+
Performs 2D adaptive max pooling on a multi-plane input signal.
|
|
305
261
|
|
|
306
|
-
Refer to :func:`mindspore.ops.
|
|
307
|
-
|
|
308
|
-
Supported Platforms:
|
|
309
|
-
``GPU``
|
|
310
|
-
|
|
311
|
-
Examples:
|
|
312
|
-
>>> # case 1: output_size=(None, 2)
|
|
313
|
-
>>> input_x = Tensor(np.array([[[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
|
|
314
|
-
... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
|
|
315
|
-
... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]), mindspore.float32)
|
|
316
|
-
>>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((None, 2))
|
|
317
|
-
>>> output = adaptive_avg_pool_2d(input_x)
|
|
318
|
-
>>> print(output)
|
|
319
|
-
[[[[1.5 2.5]
|
|
320
|
-
[4.5 5.5]
|
|
321
|
-
[7.5 8.5]]
|
|
322
|
-
[[1.5 2.5]
|
|
323
|
-
[4.5 5.5]
|
|
324
|
-
[7.5 8.5]]
|
|
325
|
-
[[1.5 2.5]
|
|
326
|
-
[4.5 5.5]
|
|
327
|
-
[7.5 8.5]]]]
|
|
328
|
-
>>> # case 2: output_size=2
|
|
329
|
-
>>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D(2)
|
|
330
|
-
>>> output = adaptive_avg_pool_2d(input_x)
|
|
331
|
-
>>> print(output)
|
|
332
|
-
[[[[3. 4.]
|
|
333
|
-
[6. 7.]]
|
|
334
|
-
[[3. 4.]
|
|
335
|
-
[6. 7.]]
|
|
336
|
-
[[3. 4.]
|
|
337
|
-
[6. 7.]]]]
|
|
338
|
-
>>> # case 3: output_size=(1, 2)
|
|
339
|
-
>>> adaptive_avg_pool_2d = ops.AdaptiveAvgPool2D((1, 2))
|
|
340
|
-
>>> output = adaptive_avg_pool_2d(input_x)
|
|
341
|
-
>>> print(output)
|
|
342
|
-
[[[[4.5 5.5]]
|
|
343
|
-
[[4.5 5.5]]
|
|
344
|
-
[[4.5 5.5]]]]
|
|
345
|
-
"""
|
|
346
|
-
|
|
347
|
-
@prim_attr_register
|
|
348
|
-
def __init__(self, output_size):
|
|
349
|
-
"""Initialize AdaptiveAvgPool2D."""
|
|
350
|
-
super(AdaptiveAvgPool2D, self).__init__(output_size)
|
|
262
|
+
Refer to :func:`mindspore.ops.adaptive_max_pool2d` for more details.
|
|
351
263
|
|
|
264
|
+
Args:
|
|
265
|
+
output_size (Union[int, tuple]): The target output size. `ouput_size` can be a tuple :math:`(H, W)`,
|
|
266
|
+
or an int H for :math:`(H, H)`. :math:`H` and :math:`W` can be int or None.
|
|
267
|
+
If it is None, it means the output size is the same as the input size.
|
|
352
268
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
269
|
+
Inputs:
|
|
270
|
+
- **input_x** (Tensor) - The input of AdaptiveMaxPool2D, which is a 3D or 4D tensor,
|
|
271
|
+
with float16, float32 or float64 data type.
|
|
356
272
|
|
|
357
|
-
|
|
273
|
+
Outputs:
|
|
274
|
+
Tensor, with the same type as the `input_x`.
|
|
358
275
|
|
|
359
276
|
Supported Platforms:
|
|
360
277
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -366,7 +283,7 @@ class AdaptiveMaxPool2D(Primitive):
|
|
|
366
283
|
... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]), mindspore.float32)
|
|
367
284
|
>>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D((None, 2))
|
|
368
285
|
>>> output = adaptive_max_pool_2d(input_x)
|
|
369
|
-
>>> print(output)
|
|
286
|
+
>>> print(output[0])
|
|
370
287
|
[[[[2. 3.]
|
|
371
288
|
[5. 6.]
|
|
372
289
|
[8. 9.]]
|
|
@@ -379,7 +296,7 @@ class AdaptiveMaxPool2D(Primitive):
|
|
|
379
296
|
>>> # case 2: output_size=2
|
|
380
297
|
>>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D(2)
|
|
381
298
|
>>> output = adaptive_max_pool_2d(input_x)
|
|
382
|
-
>>> print(output)
|
|
299
|
+
>>> print(output[0])
|
|
383
300
|
[[[[5. 6.]
|
|
384
301
|
[8. 9.]]
|
|
385
302
|
[[5. 6.]
|
|
@@ -389,35 +306,45 @@ class AdaptiveMaxPool2D(Primitive):
|
|
|
389
306
|
>>> # case 3: output_size=(1, 2)
|
|
390
307
|
>>> adaptive_max_pool_2d = ops.AdaptiveMaxPool2D((1, 2))
|
|
391
308
|
>>> output = adaptive_max_pool_2d(input_x)
|
|
392
|
-
>>> print(output)
|
|
309
|
+
>>> print(output[0])
|
|
393
310
|
[[[[8. 9.]]
|
|
394
311
|
[[8. 9.]]
|
|
395
312
|
[[8. 9.]]]]
|
|
396
313
|
"""
|
|
397
314
|
|
|
398
315
|
@prim_attr_register
|
|
399
|
-
def __init__(self, output_size
|
|
316
|
+
def __init__(self, output_size):
|
|
400
317
|
"""Initialize AdaptiveMaxPool2D."""
|
|
401
318
|
validator.check_value_type("output_size", output_size, [int, tuple], self.name)
|
|
402
|
-
validator.check_value_type("return_indices", return_indices, [bool], self.name)
|
|
403
319
|
if isinstance(output_size, tuple):
|
|
404
|
-
validator.check_int(len(output_size), 2,
|
|
320
|
+
validator.check_int(len(output_size), 2, validator.EQ,
|
|
405
321
|
'length of output_size', self.name)
|
|
406
322
|
self.output_size = (output_size, output_size) if isinstance(self.output_size, int) else output_size
|
|
407
323
|
self.output_size = (-1 if self.output_size[0] is None else self.output_size[0],
|
|
408
324
|
-1 if self.output_size[1] is None else self.output_size[1])
|
|
409
325
|
for size in self.output_size:
|
|
410
|
-
validator.check_number("output_size", size, -1,
|
|
326
|
+
validator.check_number("output_size", size, -1, validator.GE, None)
|
|
411
327
|
self.add_prim_attr('output_size', self.output_size)
|
|
412
|
-
self.add_prim_attr('return_indices', return_indices)
|
|
413
328
|
|
|
414
329
|
|
|
415
330
|
class AdaptiveMaxPool3D(Primitive):
|
|
416
331
|
r"""
|
|
417
|
-
|
|
332
|
+
Performs 3D adaptive max pooling on a multi-plane input signal.
|
|
418
333
|
|
|
419
334
|
Refer to :func:`mindspore.ops.adaptive_max_pool3d` for more details.
|
|
420
335
|
|
|
336
|
+
Inputs:
|
|
337
|
+
- **x** (Tensor) - Tensor, with shape :math:`(C, D, H, W)` or :math:`(N, C, D, H, W)`.
|
|
338
|
+
- **output_size** (Union[int, tuple]) - The specified output size, which is an integer that represents depth,
|
|
339
|
+
height and width, or a tuple of three int numbers that represent depth, height and width respectively.
|
|
340
|
+
The value must be a positive integer. If it is None, the output size and input size of the corresponding
|
|
341
|
+
dimension are the same.
|
|
342
|
+
|
|
343
|
+
Outputs:
|
|
344
|
+
- **y** (Tensor) - Tensor, with the same number of dims and data type as the `input`.
|
|
345
|
+
- **argmax** (Tensor) - Tensor, the indices of max value, which has the same shape as the
|
|
346
|
+
`y` and it's data type is int32.
|
|
347
|
+
|
|
421
348
|
Supported Platforms:
|
|
422
349
|
``GPU`` ``CPU``
|
|
423
350
|
|
|
@@ -504,7 +431,7 @@ class Softplus(Primitive):
|
|
|
504
431
|
|
|
505
432
|
.. math::
|
|
506
433
|
|
|
507
|
-
\text{output} = \log(1 + \exp(\text{x}))
|
|
434
|
+
\text{output} = \log(1 + \exp(\text{x}))
|
|
508
435
|
|
|
509
436
|
Inputs:
|
|
510
437
|
- **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
@@ -595,7 +522,7 @@ class ReLUV3(Primitive):
|
|
|
595
522
|
Inputs:
|
|
596
523
|
- **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
597
524
|
additional dimensions, data type is
|
|
598
|
-
`number <https://www.mindspore.cn/docs/en/r2.0
|
|
525
|
+
`number <https://www.mindspore.cn/docs/en/r2.0/api_python/mindspore.html#mindspore.dtype>`_.
|
|
599
526
|
|
|
600
527
|
Outputs:
|
|
601
528
|
Tensor of shape :math:`(N, *)`, with the same type and shape as the `input_x`.
|
|
@@ -651,15 +578,13 @@ class Mish(PrimitiveWithInfer):
|
|
|
651
578
|
>>> x = Tensor(np.array([[-1.0, 4.0, -8.0], [2.0, -5.0, 9.0]]), mindspore.float32)
|
|
652
579
|
>>> mish = ops.Mish()
|
|
653
580
|
>>> output = mish(x)
|
|
654
|
-
>>> print(output)
|
|
655
|
-
|
|
656
|
-
[ 1.9439590 -0.0033576 9.0000000]]
|
|
581
|
+
>>> print(output.shape)
|
|
582
|
+
(2, 3)
|
|
657
583
|
"""
|
|
658
584
|
|
|
659
585
|
@prim_attr_register
|
|
660
586
|
def __init__(self):
|
|
661
587
|
"""Initialize Mish"""
|
|
662
|
-
super().__init__("Mish")
|
|
663
588
|
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
664
589
|
|
|
665
590
|
|
|
@@ -707,7 +632,6 @@ class SeLU(Primitive):
|
|
|
707
632
|
@prim_attr_register
|
|
708
633
|
def __init__(self):
|
|
709
634
|
"""Initialize SeLU"""
|
|
710
|
-
super().__init__("SeLU")
|
|
711
635
|
self.init_prim_io_names(inputs=['input_x'], outputs=['output'])
|
|
712
636
|
|
|
713
637
|
|
|
@@ -834,7 +758,7 @@ class Elu(Primitive):
|
|
|
834
758
|
def __init__(self, alpha=1.0):
|
|
835
759
|
"""Initialize Elu"""
|
|
836
760
|
validator.check_value_type("alpha", alpha, [float], self.name)
|
|
837
|
-
validator.check_number("alpha", alpha, 1.0,
|
|
761
|
+
validator.check_number("alpha", alpha, 1.0, validator.EQ, self.name)
|
|
838
762
|
self.init_prim_io_names(inputs=['x'], outputs=['output', 'mask'])
|
|
839
763
|
|
|
840
764
|
|
|
@@ -887,25 +811,7 @@ class HSigmoid(Primitive):
|
|
|
887
811
|
r"""
|
|
888
812
|
Hard sigmoid activation function.
|
|
889
813
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
Hard sigmoid is defined as:
|
|
893
|
-
|
|
894
|
-
.. math::
|
|
895
|
-
|
|
896
|
-
\text{hsigmoid}(x_{i}) = max(0, min(1, \frac{x_{i} + 3}{6})),
|
|
897
|
-
|
|
898
|
-
where :math:`x_i` is an element of the input Tensor.
|
|
899
|
-
|
|
900
|
-
Inputs:
|
|
901
|
-
- **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
902
|
-
additional dimensions.
|
|
903
|
-
|
|
904
|
-
Outputs:
|
|
905
|
-
Tensor, with the same type and shape as the `input_x`.
|
|
906
|
-
|
|
907
|
-
Raises:
|
|
908
|
-
TypeError: If `input_x` is not a Tensor.
|
|
814
|
+
Refer to :func:`mindspore.ops.hardsigmoid` for more details.
|
|
909
815
|
|
|
910
816
|
Supported Platforms:
|
|
911
817
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -1048,8 +954,8 @@ class InstanceNorm(PrimitiveWithInfer):
|
|
|
1048
954
|
"""Initialize InstanceNorm."""
|
|
1049
955
|
self.init_prim_io_names(inputs=['x', 'gamma', 'beta', 'mean', 'variance'],
|
|
1050
956
|
outputs=['y', 'save_mean', 'save_variance'])
|
|
1051
|
-
self.epsilon = validator.check_float_range(epsilon, 0, 1,
|
|
1052
|
-
self.momentum = validator.check_float_range(momentum, 0, 1,
|
|
957
|
+
self.epsilon = validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', self.name)
|
|
958
|
+
self.momentum = validator.check_float_range(momentum, 0, 1, validator.INC_BOTH, 'momentum', self.name)
|
|
1053
959
|
self._update_parameter = True
|
|
1054
960
|
self.add_prim_attr('side_effect_mem', True)
|
|
1055
961
|
|
|
@@ -1153,8 +1059,8 @@ class InstanceNormV2(Primitive):
|
|
|
1153
1059
|
outputs=['y', 'batch_mean', 'batch_variance'])
|
|
1154
1060
|
validator.check_is_float(epsilon, 'epsilon', self.name)
|
|
1155
1061
|
validator.check_is_float(momentum, 'momentum', self.name)
|
|
1156
|
-
validator.check_float_range(epsilon, 0, 1,
|
|
1157
|
-
validator.check_float_range(momentum, 0, 1,
|
|
1062
|
+
validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', self.name)
|
|
1063
|
+
validator.check_float_range(momentum, 0, 1, validator.INC_BOTH, 'momentum', self.name)
|
|
1158
1064
|
validator.check_bool(is_training, "is_training", self.name)
|
|
1159
1065
|
|
|
1160
1066
|
|
|
@@ -1196,8 +1102,8 @@ class BNTrainingUpdate(Primitive):
|
|
|
1196
1102
|
validator.check_value_type("isRef", isRef, [bool], self.name)
|
|
1197
1103
|
validator.check_value_type("epsilon", epsilon, [float], self.name)
|
|
1198
1104
|
validator.check_value_type("factor", factor, [float], self.name)
|
|
1199
|
-
self.epsilon = validator.check_float_range(epsilon, 0, 1,
|
|
1200
|
-
self.factor = validator.check_float_range(factor, 0, 1,
|
|
1105
|
+
self.epsilon = validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', 'BNTrainingUpdate')
|
|
1106
|
+
self.factor = validator.check_float_range(factor, 0, 1, validator.INC_BOTH, 'factor', 'BNTrainingUpdate')
|
|
1201
1107
|
self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
|
|
1202
1108
|
if context.get_context("device_target") != "GPU" and self.format == "NHWC":
|
|
1203
1109
|
raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
|
|
@@ -1221,8 +1127,9 @@ class BatchNorm(PrimitiveWithInfer):
|
|
|
1221
1127
|
|
|
1222
1128
|
y = \frac{x - mean}{\sqrt{variance + \epsilon}} * \gamma + \beta
|
|
1223
1129
|
|
|
1224
|
-
where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon,
|
|
1225
|
-
:math:`
|
|
1130
|
+
where :math:`\gamma` is scale, :math:`\beta` is bias, :math:`\epsilon` is epsilon,
|
|
1131
|
+
:math:`mean` is the mean of :math:`x`,
|
|
1132
|
+
:math:`variance` is the variance of :math:`x`.
|
|
1226
1133
|
|
|
1227
1134
|
.. warning::
|
|
1228
1135
|
- If the operation is used for inference, and outputs "reserve_space_1" and "reserve_space_2" are available,
|
|
@@ -1236,8 +1143,8 @@ class BatchNorm(PrimitiveWithInfer):
|
|
|
1236
1143
|
momentum (float): The hyper parameter to compute moving average for running_mean and running_var
|
|
1237
1144
|
(e.g. :math:`new\_running\_mean = (1 - momentum) * running\_mean + momentum * current\_mean`).
|
|
1238
1145
|
Momentum value must be [0, 1]. Default: 0.1.
|
|
1239
|
-
data_format (str): The optional value for data format, is 'NHWC' or 'NCHW'
|
|
1240
|
-
Default: "NCHW".
|
|
1146
|
+
data_format (str): The optional value for data format, is 'NHWC' or 'NCHW', and the 'NHWC' format
|
|
1147
|
+
is only supported in GPU target. Default: "NCHW".
|
|
1241
1148
|
|
|
1242
1149
|
Inputs:
|
|
1243
1150
|
If `is_training` is False, inputs are Tensors.
|
|
@@ -1273,7 +1180,7 @@ class BatchNorm(PrimitiveWithInfer):
|
|
|
1273
1180
|
TypeError: If dtype of `input_x`, `scale` is neither float16 nor float32.
|
|
1274
1181
|
|
|
1275
1182
|
Supported Platforms:
|
|
1276
|
-
``Ascend`` ``
|
|
1183
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
1277
1184
|
|
|
1278
1185
|
Examples:
|
|
1279
1186
|
>>> input_x = Tensor(np.ones([2, 2]), mindspore.float32)
|
|
@@ -1304,8 +1211,8 @@ class BatchNorm(PrimitiveWithInfer):
|
|
|
1304
1211
|
else:
|
|
1305
1212
|
self.add_prim_attr('side_effect_mem', True)
|
|
1306
1213
|
validator.check_value_type('is_training', is_training, (bool,), self.name)
|
|
1307
|
-
validator.check_float_range(epsilon, 0, 1,
|
|
1308
|
-
validator.check_float_range(momentum, 0, 1,
|
|
1214
|
+
validator.check_float_range(epsilon, 0, 1, validator.INC_RIGHT, 'epsilon', self.name)
|
|
1215
|
+
validator.check_float_range(momentum, 0, 1, validator.INC_BOTH, 'momentum', self.name)
|
|
1309
1216
|
self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
|
|
1310
1217
|
if context.get_context("device_target") != "GPU" and self.format == "NHWC":
|
|
1311
1218
|
raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
|
|
@@ -1318,12 +1225,12 @@ class BatchNorm(PrimitiveWithInfer):
|
|
|
1318
1225
|
def infer_shape(self, input_x, scale, bias, mean, variance):
|
|
1319
1226
|
input_x_channel = input_x[-1] if self.format == "NHWC" else input_x[1]
|
|
1320
1227
|
validator.check_equal_int(len(scale), 1, "scale rank", self.name)
|
|
1321
|
-
validator.check("scale shape", scale, "bias shape", bias,
|
|
1322
|
-
validator.check("scale shape[0]", scale[0], "input_x channel", input_x_channel,
|
|
1228
|
+
validator.check("scale shape", scale, "bias shape", bias, validator.EQ, self.name)
|
|
1229
|
+
validator.check("scale shape[0]", scale[0], "input_x channel", input_x_channel, validator.EQ, self.name)
|
|
1323
1230
|
if not self.is_training:
|
|
1324
1231
|
validator.check_equal_int(len(mean), 1, "mean rank", self.name)
|
|
1325
|
-
validator.check("mean shape", mean, "variance shape", variance,
|
|
1326
|
-
validator.check("mean shape", mean, "scale shape", scale,
|
|
1232
|
+
validator.check("mean shape", mean, "variance shape", variance, validator.EQ, self.name)
|
|
1233
|
+
validator.check("mean shape", mean, "scale shape", scale, validator.EQ, self.name)
|
|
1327
1234
|
return input_x, scale, scale, scale, scale
|
|
1328
1235
|
|
|
1329
1236
|
def infer_dtype(self, input_x, scale, bias, mean, variance):
|
|
@@ -1337,7 +1244,90 @@ class Conv2D(Primitive):
|
|
|
1337
1244
|
r"""
|
|
1338
1245
|
2D convolution layer.
|
|
1339
1246
|
|
|
1340
|
-
|
|
1247
|
+
Applies a 2D convolution over an input tensor which is typically of shape :math:`(N, C_{in}, H_{in}, W_{in})`,
|
|
1248
|
+
where :math:`N` is batch size, :math:`C` is channel number, :math:`H` is height, :math:`W` is width, :math:`X_i` is
|
|
1249
|
+
the :math:`i^{th}` input value and :math:`b_i` indicates the deviation value of the :math:`i^{th}` input value.
|
|
1250
|
+
For each batch of shape :math:`(C_{in}, H_{in}, W_{in})`, the formula is defined as:
|
|
1251
|
+
|
|
1252
|
+
.. math::
|
|
1253
|
+
|
|
1254
|
+
out_j = \sum_{i=0}^{C_{in} - 1} ccor(W_{ij}, X_i) + b_j,
|
|
1255
|
+
|
|
1256
|
+
where :math:`ccor` is the cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges
|
|
1257
|
+
from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to the :math:`i`-th channel of the :math:`j`-th
|
|
1258
|
+
filter and :math:`out_{j}` corresponds to the :math:`j`-th channel of the output. :math:`W_{ij}` is a slice
|
|
1259
|
+
of kernel and it has shape :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
1260
|
+
where :math:`\text{kernel_size[0]}` and :math:`\text{kernel_size[1]}` are the height and width of the
|
|
1261
|
+
convolution kernel. The full kernel has shape
|
|
1262
|
+
:math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
1263
|
+
where group is the group number to split the input in the channel dimension.
|
|
1264
|
+
|
|
1265
|
+
If the 'pad_mode' is set to be "pad", the output height and width will be
|
|
1266
|
+
:math:`\left \lfloor{1 + \frac{H_{in} + \text{padding[0]} + \text{padding[1]} - \text{kernel_size[0]} -
|
|
1267
|
+
(\text{kernel_size[0]} - 1) \times (\text{dilation[0]} - 1) }{\text{stride[0]}}} \right \rfloor` and
|
|
1268
|
+
:math:`\left \lfloor{1 + \frac{W_{in} + \text{padding[2]} + \text{padding[3]} - \text{kernel_size[1]} -
|
|
1269
|
+
(\text{kernel_size[1]} - 1) \times (\text{dilation[1]} - 1) }{\text{stride[1]}}} \right \rfloor` respectively.
|
|
1270
|
+
Where :math:`dilation` is Spacing between kernel elements, :math:`stride` is The step length of each step,
|
|
1271
|
+
:math:`padding` is zero-padding added to both sides of the input.
|
|
1272
|
+
|
|
1273
|
+
The first introduction can be found in paper `Gradient Based Learning Applied to Document Recognition
|
|
1274
|
+
<http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_.
|
|
1275
|
+
|
|
1276
|
+
Note:
|
|
1277
|
+
On Ascend platform, :math:`group = 1` must be satisfied.
|
|
1278
|
+
|
|
1279
|
+
Args:
|
|
1280
|
+
out_channel (int): The number of output channel :math:`C_{out}`.
|
|
1281
|
+
kernel_size (Union[int, tuple[int]]): The data type is int or a tuple of 2 integers. Specifies the height
|
|
1282
|
+
and width of the 2D convolution window. Single int means the value is for both the height and the width of
|
|
1283
|
+
the kernel. A tuple of 2 ints means the first value is for the height and the other is for the
|
|
1284
|
+
width of the kernel.
|
|
1285
|
+
mode (int): Modes for different convolutions. The value is currently not used. Default: 1.
|
|
1286
|
+
pad_mode (str): Specifies padding mode. The optional values are
|
|
1287
|
+
"same", "valid" and "pad". Default: "valid".
|
|
1288
|
+
|
|
1289
|
+
- same: Adopts the way of completion. The height and width of the output will be equal to
|
|
1290
|
+
the input `x` divided by stride. The padding will be evenly calculated in top and bottom,
|
|
1291
|
+
left and right possiblily.
|
|
1292
|
+
Otherwise, the last extra padding will be calculated from the bottom and the right side.
|
|
1293
|
+
If this mode is set, `pad` must be 0.
|
|
1294
|
+
|
|
1295
|
+
- valid: Adopts the way of discarding. The possible largest height and width of output will be returned
|
|
1296
|
+
without padding. Extra pixels will be discarded. If this mode is set, `pad` must be 0.
|
|
1297
|
+
|
|
1298
|
+
- pad: Implicit paddings on both sides of the input `x`. The number of `pad` will be padded to the input
|
|
1299
|
+
Tensor borders. `pad` must be greater than or equal to 0.
|
|
1300
|
+
pad (Union(int, tuple[int])): Implicit paddings on both sides of the input `x`. If `pad` is one integer,
|
|
1301
|
+
the paddings of top, bottom, left and right are the same, equal to pad. If `pad` is a tuple
|
|
1302
|
+
with four integers, the paddings of top, bottom, left and right will be equal to pad[0],
|
|
1303
|
+
pad[1], pad[2], and pad[3] accordingly. Default: 0.
|
|
1304
|
+
stride (Union(int, tuple[int])): The distance of kernel moving, an int number that represents
|
|
1305
|
+
the height and width of movement are both strides, or a tuple of two int numbers that
|
|
1306
|
+
represent height and width of movement respectively. Default: 1.
|
|
1307
|
+
dilation (Union(int, tuple[int])): The data type is int or a tuple of 2 integers. Specifies the dilation rate
|
|
1308
|
+
to use for dilated convolution. If set to be :math:`k > 1`, there will
|
|
1309
|
+
be :math:`k - 1` pixels skipped for each sampling location. Its value must
|
|
1310
|
+
be greater than or equal to 1 and bounded by the height and width of the
|
|
1311
|
+
input `x`. Default: 1.
|
|
1312
|
+
group (int): Splits input into groups. Default: 1.
|
|
1313
|
+
data_format (str): The optional value for data format, is 'NHWC' or 'NCHW'. Default: "NCHW".
|
|
1314
|
+
|
|
1315
|
+
Inputs:
|
|
1316
|
+
- **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
1317
|
+
- **weight** (Tensor) - Set size of kernel is :math:`(\text{kernel_size[0]}, \text{kernel_size[1]})`,
|
|
1318
|
+
then the shape is :math:`(C_{out}, C_{in}, \text{kernel_size[0]}, \text{kernel_size[1]})`.
|
|
1319
|
+
|
|
1320
|
+
Outputs:
|
|
1321
|
+
Tensor, the value that applied 2D convolution. The shape is :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
1322
|
+
|
|
1323
|
+
Raises:
|
|
1324
|
+
TypeError: If `kernel_size`, `stride`, `pad` or `dilation` is neither an int nor a tuple.
|
|
1325
|
+
TypeError: If `out_channel` or `group` is not an int.
|
|
1326
|
+
ValueError: If `kernel_size`, `stride` or `dilation` is less than 1.
|
|
1327
|
+
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
1328
|
+
ValueError: If `pad` is a tuple whose length is not equal to 4.
|
|
1329
|
+
ValueError: If `pad_mode` it not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0).
|
|
1330
|
+
ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
|
|
1341
1331
|
|
|
1342
1332
|
Supported Platforms:
|
|
1343
1333
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -1400,16 +1390,15 @@ class Conv2D(Primitive):
|
|
|
1400
1390
|
|
|
1401
1391
|
class DataFormatVecPermute(Primitive):
|
|
1402
1392
|
r"""
|
|
1403
|
-
|
|
1393
|
+
Converts the input tensor from the `src_format` to the `dst_format` by permuting its dimensions.
|
|
1404
1394
|
|
|
1405
1395
|
Args:
|
|
1406
|
-
src_format (str, optional):
|
|
1407
|
-
|
|
1408
|
-
dst_format (str, optional): An optional value for destination data format. The format can be 'NHWC' and 'NCHW'.
|
|
1409
|
-
Default: 'NCHW'.
|
|
1396
|
+
src_format (str, optional): the source data format, which can be 'NHWC' and 'NCHW'. Default: 'NHWC'.
|
|
1397
|
+
dst_format (str, optional): the target data format, which can be 'NHWC' and 'NCHW'. Default: 'NCHW'.
|
|
1410
1398
|
|
|
1411
1399
|
Inputs:
|
|
1412
|
-
- **input_x** (Tensor) - A Tensor of shape (4, ) or (4, 2) in source data format.
|
|
1400
|
+
- **input_x** (Tensor) - A Tensor of shape :math:`(4, )` or :math:`(4, 2)` in source data format.
|
|
1401
|
+
Supports int32 and int64 datatype.
|
|
1413
1402
|
|
|
1414
1403
|
Outputs:
|
|
1415
1404
|
Tensor, has the same data type and shape as the `input_x`.
|
|
@@ -1418,10 +1407,10 @@ class DataFormatVecPermute(Primitive):
|
|
|
1418
1407
|
TypeError: If `input_x` is not a Tensor.
|
|
1419
1408
|
TypeError: If dtype of `input_x` is neither int32 nor int64.
|
|
1420
1409
|
ValueError: If `src_format` or `dst_format` is not a str in ['NHWC', 'NCHW'].
|
|
1421
|
-
ValueError: If input_x shape is not (4, ) or (4, 2)
|
|
1410
|
+
ValueError: If `input_x` shape is not :math:`(4, )` or :math:`(4, 2)`.
|
|
1422
1411
|
|
|
1423
1412
|
Supported Platforms:
|
|
1424
|
-
``GPU`` ``CPU``
|
|
1413
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
1425
1414
|
|
|
1426
1415
|
Examples:
|
|
1427
1416
|
>>> class Net(nn.Cell):
|
|
@@ -1505,8 +1494,8 @@ class DepthwiseConv2dNative(PrimitiveWithInfer):
|
|
|
1505
1494
|
def infer_shape(self, x_shape, w_shape, b_shape=None):
|
|
1506
1495
|
validator.check_equal_int(len(w_shape), 4, "weight rank", self.name)
|
|
1507
1496
|
validator.check_equal_int(len(x_shape), 4, "x rank", self.name)
|
|
1508
|
-
validator.check("x_shape[1]", x_shape[1], "w_shape[1]", w_shape[1],
|
|
1509
|
-
validator.check('kernel_size', self.kernel_size, 'w_shape[2:4]', tuple(w_shape[2:4]),
|
|
1497
|
+
validator.check("x_shape[1]", x_shape[1], "w_shape[1]", w_shape[1], validator.EQ, self.name)
|
|
1498
|
+
validator.check('kernel_size', self.kernel_size, 'w_shape[2:4]', tuple(w_shape[2:4]), validator.EQ, self.name)
|
|
1510
1499
|
|
|
1511
1500
|
kernel_size_n, _, kernel_size_h, kernel_size_w = w_shape
|
|
1512
1501
|
_, _, stride_h, stride_w = self.stride
|
|
@@ -1804,55 +1793,11 @@ class MaxPoolV1(Primitive):
|
|
|
1804
1793
|
|
|
1805
1794
|
class MaxPoolWithArgmax(Primitive):
|
|
1806
1795
|
r"""
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
Typically the input is of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})`, MaxPool outputs
|
|
1810
|
-
regional maximum in the :math:`(H_{in}, W_{in})`-dimension. Given kernel size
|
|
1811
|
-
:math:`ks = (h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1)`, the operation is as follows:
|
|
1812
|
-
|
|
1813
|
-
.. math::
|
|
1814
|
-
\text{output}(N_i, C_j, h, w) = \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
|
|
1815
|
-
\text{input}(N_i, C_j, s_0 \times h + m, s_1 \times w + n)
|
|
1816
|
-
|
|
1817
|
-
Args:
|
|
1818
|
-
kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value and argmax
|
|
1819
|
-
value, is an int number that represents height and width of the kernel, or a tuple of
|
|
1820
|
-
two int numbers that represent height and width respectively. Default: 1.
|
|
1821
|
-
strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
|
|
1822
|
-
not only the height of movement but also the width of movement, or a tuple of two int numbers that
|
|
1823
|
-
represent height and width of movement respectively. Default: 1.
|
|
1824
|
-
pad_mode (str): The optional value for pad mode, is "same" or "valid".
|
|
1825
|
-
Default: "valid".
|
|
1826
|
-
|
|
1827
|
-
- same: Adopts the way of completion. The height and width of the output will be the same as
|
|
1828
|
-
the input. The total number of padding will be calculated in horizontal and vertical
|
|
1829
|
-
directions and evenly distributed to top, bottom, left and right if possible.
|
|
1830
|
-
Otherwise, the last extra padding will be done from the bottom and the right side.
|
|
1831
|
-
|
|
1832
|
-
- valid: Adopts the way of discarding. The possible largest height and width of output
|
|
1833
|
-
will be returned without padding. Extra pixels will be discarded.
|
|
1834
|
-
|
|
1835
|
-
data_format (str) : The optional value for data format, is 'NHWC' or 'NCHW'.
|
|
1836
|
-
Default: 'NCHW'.
|
|
1837
|
-
|
|
1838
|
-
Inputs:
|
|
1839
|
-
- **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
1840
|
-
Data type must be float16 or float32.
|
|
1841
|
-
|
|
1842
|
-
Outputs:
|
|
1843
|
-
Tuple of 2 Tensors, representing the maxpool result and where the max values are generated.
|
|
1844
|
-
|
|
1845
|
-
- **output** (Tensor) - Maxpooling result, with shape :math:`(N, C_{out}, H_{out}, W_{out})`.
|
|
1846
|
-
It has the same data type as `x`.
|
|
1847
|
-
- **mask** (Tensor) - Max values' index represented by the mask. Data type is int32.
|
|
1848
|
-
|
|
1849
|
-
Raises:
|
|
1850
|
-
TypeError: If the data type of `x` is neither float16 nor float32.
|
|
1851
|
-
TypeError: If `kernel_size` or `strides` is neither an int nor a tuple.
|
|
1852
|
-
TypeError: If `x` is not a Tensor.
|
|
1796
|
+
`ops.MaxPoolWithArgmax` is deprecated from version 2.0 and will be removed in a future version,
|
|
1797
|
+
use `ops.MaxPoolWithArgmaxV2` instead.
|
|
1853
1798
|
|
|
1854
1799
|
Supported Platforms:
|
|
1855
|
-
|
|
1800
|
+
Deprecated
|
|
1856
1801
|
|
|
1857
1802
|
Examples:
|
|
1858
1803
|
>>> x = Tensor(np.arange(1 * 3 * 3 * 4).reshape((1, 3, 3, 4)), mindspore.float32)
|
|
@@ -1867,6 +1812,7 @@ class MaxPoolWithArgmax(Primitive):
|
|
|
1867
1812
|
[33. 34. 35.]]]]
|
|
1868
1813
|
"""
|
|
1869
1814
|
|
|
1815
|
+
@deprecated("2.0", "ops.MaxPoolWithArgmaxV2", False)
|
|
1870
1816
|
@prim_attr_register
|
|
1871
1817
|
def __init__(self, kernel_size=1, strides=1, pad_mode="valid", data_format="NCHW"):
|
|
1872
1818
|
"""Initialize MaxPoolWithArgmax."""
|
|
@@ -1891,7 +1837,7 @@ class MaxPoolWithArgmax(Primitive):
|
|
|
1891
1837
|
self.add_prim_attr("strides", self.strides)
|
|
1892
1838
|
|
|
1893
1839
|
|
|
1894
|
-
class MaxPool3D(
|
|
1840
|
+
class MaxPool3D(Primitive):
|
|
1895
1841
|
r"""
|
|
1896
1842
|
Applies a 3D max pooling over an input Tensor which can be regarded as a composition of 3D planes.
|
|
1897
1843
|
|
|
@@ -1936,7 +1882,7 @@ class MaxPool3D(PrimitiveWithInfer):
|
|
|
1936
1882
|
|
|
1937
1883
|
Inputs:
|
|
1938
1884
|
- **x** (Tensor) - Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
|
|
1939
|
-
Data type must be float16 or
|
|
1885
|
+
Data type must be float16, float32 or float64.
|
|
1940
1886
|
|
|
1941
1887
|
Outputs:
|
|
1942
1888
|
Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})`. Has the data type of `x`.
|
|
@@ -2003,55 +1949,15 @@ class MaxPool3D(PrimitiveWithInfer):
|
|
|
2003
1949
|
validator.check_non_negative_int(item, 'pad_list item', self.name)
|
|
2004
1950
|
self.add_prim_attr("pad_list", self.pad_list)
|
|
2005
1951
|
|
|
2006
|
-
def infer_shape(self, x_shape):
|
|
2007
|
-
validator.check_equal_int(len(x_shape), 5, "x rank", self.name)
|
|
2008
|
-
batch, channel, input_d, input_h, input_w = x_shape
|
|
2009
|
-
self.add_prim_attr("x_shape", x_shape)
|
|
2010
|
-
_, _, kernel_d, kernel_h, kernel_w = self.kernel_size
|
|
2011
|
-
_, _, stride_d, stride_h, stride_w = self.strides
|
|
2012
|
-
|
|
2013
|
-
if self.pad_mode == "VALID":
|
|
2014
|
-
out_d = math.ceil((input_d - (kernel_d - 1)) / stride_d)
|
|
2015
|
-
out_h = math.ceil((input_h - (kernel_h - 1)) / stride_h)
|
|
2016
|
-
out_w = math.ceil((input_w - (kernel_w - 1)) / stride_w)
|
|
2017
|
-
elif self.pad_mode == "SAME":
|
|
2018
|
-
out_d = math.ceil(input_d / stride_d)
|
|
2019
|
-
out_h = math.ceil(input_h / stride_h)
|
|
2020
|
-
out_w = math.ceil(input_w / stride_w)
|
|
2021
|
-
else:
|
|
2022
|
-
out_d = ((input_d + self.pad_list[0] + self.pad_list[1] -
|
|
2023
|
-
(kernel_d - 1) - 1) / stride_d) + 1
|
|
2024
|
-
out_h = ((input_h + self.pad_list[2] + self.pad_list[3] -
|
|
2025
|
-
(kernel_h - 1) - 1) / stride_h) + 1
|
|
2026
|
-
out_w = ((input_w + self.pad_list[4] + self.pad_list[5] -
|
|
2027
|
-
(kernel_w - 1) - 1) / stride_w) + 1
|
|
2028
|
-
if self.ceil_mode:
|
|
2029
|
-
out_d = math.ceil(out_d)
|
|
2030
|
-
out_h = math.ceil(out_h)
|
|
2031
|
-
out_w = math.ceil(out_w)
|
|
2032
|
-
else:
|
|
2033
|
-
out_d = math.floor(out_d)
|
|
2034
|
-
out_h = math.floor(out_h)
|
|
2035
|
-
out_w = math.floor(out_w)
|
|
2036
|
-
out_shape = [batch, channel, out_d, out_h, out_w]
|
|
2037
|
-
|
|
2038
|
-
_check_shape('output', out_shape, self.name)
|
|
2039
|
-
return out_shape
|
|
2040
|
-
|
|
2041
|
-
def infer_dtype(self, x_dtype):
|
|
2042
|
-
validator.check_tensor_dtype_valid("x", x_dtype, [mstype.float16, mstype.float32], self.name)
|
|
2043
|
-
return x_dtype
|
|
2044
|
-
|
|
2045
1952
|
|
|
2046
1953
|
class MaxUnpool2D(Primitive):
|
|
2047
1954
|
r"""
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
MaxPool2D is not fully invertible, since the non-maximal values are lost.
|
|
1955
|
+
Calculates the partial inverse of MaxPool2D operation.
|
|
2051
1956
|
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
1957
|
+
Since MaxPool2D loses non-maximal values, it is not fully invertible.
|
|
1958
|
+
Therefore, MaxUnpool2D takes the output of MaxPool2D, including the indices of
|
|
1959
|
+
the maximal values, and computes a partial inverse where all non-maximal values are set to zero.
|
|
1960
|
+
Typically the input is of shape :math:`(N, C, H_{in}, W_{in})` ,
|
|
2055
1961
|
the output is of shape :math:`(N, C, H_{out}, W_{out})` , the operation is as follows:
|
|
2056
1962
|
|
|
2057
1963
|
.. math::
|
|
@@ -2060,6 +1966,9 @@ class MaxUnpool2D(Primitive):
|
|
|
2060
1966
|
W_{out} = (W{in} - 1) \times strides[1] - 2 \times pads[1] + ksize[1] \\
|
|
2061
1967
|
\end{array}
|
|
2062
1968
|
|
|
1969
|
+
.. warning::
|
|
1970
|
+
This is an experimental API that is subject to change or deletion.
|
|
1971
|
+
|
|
2063
1972
|
Args:
|
|
2064
1973
|
ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
|
|
2065
1974
|
is an int number that represents height and width of the kernel, or a tuple
|
|
@@ -2090,7 +1999,7 @@ class MaxUnpool2D(Primitive):
|
|
|
2090
1999
|
- **x** (Tensor) - The input Tensor to invert.
|
|
2091
2000
|
Tensor of shape :math:`(N, C, H_{in}, W_{in})` or :math:`(N, H_{in}, W_{in}, C)`.
|
|
2092
2001
|
- **argmax** (Tensor) - Max values' index represented by the `argmax`.
|
|
2093
|
-
Tensor of shape must be same with input
|
|
2002
|
+
Tensor of shape must be same with input `x`.
|
|
2094
2003
|
Values of `argmax` must belong to :math:`[0, H_{in} \times W_{in} - 1]`.
|
|
2095
2004
|
Data type must be in int32 or int64.
|
|
2096
2005
|
|
|
@@ -2110,7 +2019,7 @@ class MaxUnpool2D(Primitive):
|
|
|
2110
2019
|
computed by attr `ksize`, `strides` and `pads`.
|
|
2111
2020
|
|
|
2112
2021
|
Supported Platforms:
|
|
2113
|
-
``GPU`` ``CPU``
|
|
2022
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
2114
2023
|
|
|
2115
2024
|
Examples:
|
|
2116
2025
|
>>> x = Tensor(np.array([[[[0, 1], [8, 9]]]]).astype(np.float32))
|
|
@@ -2148,12 +2057,9 @@ class MaxUnpool2D(Primitive):
|
|
|
2148
2057
|
|
|
2149
2058
|
class MaxUnpool3D(Primitive):
|
|
2150
2059
|
r"""
|
|
2151
|
-
Computes
|
|
2152
|
-
|
|
2153
|
-
MaxUnpool3D is not fully invertible, since the non-maximal values are lost.
|
|
2060
|
+
Computes the inverse of :class:`mindspore.ops.MaxPool3D`.
|
|
2154
2061
|
|
|
2155
|
-
MaxUnpool3D
|
|
2156
|
-
values and computes a partial inverse in which all non-maximal values are set to zero.
|
|
2062
|
+
MaxUnpool3D keeps the maximal value and set all position of non-maximal values to zero.
|
|
2157
2063
|
Typically the input is of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`, the output is of
|
|
2158
2064
|
shape :math:`(N, C, D_{out}, H_{out}, W_{out})`, the operation is as follows.
|
|
2159
2065
|
|
|
@@ -2164,55 +2070,63 @@ class MaxUnpool3D(Primitive):
|
|
|
2164
2070
|
W_{out} = (W{in} - 1) \times strides[2] - 2 \times pads[2] + ksize[2] \\
|
|
2165
2071
|
\end{array}
|
|
2166
2072
|
|
|
2073
|
+
.. warning::
|
|
2074
|
+
This is an experimental API that is subject to change or deletion.
|
|
2075
|
+
|
|
2167
2076
|
Args:
|
|
2168
2077
|
ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
|
|
2169
2078
|
is an int number that represents depth, height and width of the kernel, or a tuple
|
|
2170
2079
|
of three int numbers that represent depth, height and width respectively.
|
|
2171
|
-
strides (Union[int, tuple[int]]): The distance of kernel moving
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
If
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
If
|
|
2180
|
-
If
|
|
2181
|
-
|
|
2080
|
+
strides (Union[int, tuple[int]], optional): The distance of kernel moving. Default: 0.
|
|
2081
|
+
|
|
2082
|
+
- If it is an int number, the depth, height and width of movement are all equal to `strides`.
|
|
2083
|
+
- If it is a tuple of three int numbers, they represent depth, height and width of movement respectively.
|
|
2084
|
+
- If strides is 0 or (0, 0, 0), then `strides` equal to `ksize`.
|
|
2085
|
+
|
|
2086
|
+
pads (Union[int, tuple[int]], optional): The pad value to be filled. Default: 0.
|
|
2087
|
+
|
|
2088
|
+
- If `pads` is an integer, the paddings of depth, height and width are the same, equal to pads.
|
|
2089
|
+
- If `pads` is a tuple of three integers, the padding of depth, height and width equal to pads[0],
|
|
2090
|
+
pads[1] and pads[2] correspondingly.
|
|
2091
|
+
|
|
2092
|
+
output_shape (tuple[int], optional) : The target output size. Default: ().
|
|
2093
|
+
If :math:`output\_shape == ()`, then the shape of output computed by kszie, strides and pads shown above.
|
|
2094
|
+
If :math:`output\_shape != ()`, then output_shape format must be :math:`(N, C, D, H, W)` or
|
|
2095
|
+
:math:`(N, D, H, W, C)` and output_shape must be in range
|
|
2182
2096
|
:math:`[(N, C, D_{out} - strides[0], H_{out} - strides[1], W_{out} - strides[2]),
|
|
2183
2097
|
(N, C, D_{out} + strides[0], H_{out} + strides[1], W_{out} + strides[2])]`.
|
|
2184
|
-
data_format (str) : The optional value for data format. Currently
|
|
2098
|
+
data_format (str, optional) : The optional value for data format. Currently
|
|
2099
|
+
support 'NCDHW' and 'NDHWC'. Default: 'NCDHW'.
|
|
2185
2100
|
|
|
2186
2101
|
Inputs:
|
|
2187
2102
|
- **x** (Tensor) - The input Tensor to invert.
|
|
2188
2103
|
Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})` or :math:`(N, D_{in}, H_{in}, W_{in}, C)`.
|
|
2189
|
-
- **argmax** (Tensor) - Max values' index
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
Data type must be in int32 or int64.
|
|
2104
|
+
- **argmax** (Tensor) - Max values' index. Tensor that has the same shape as `x`.
|
|
2105
|
+
Values of `argmax` must be in range :math:`[0, D_{in} \times H_{in} \times W_{in} - 1]`.
|
|
2106
|
+
Data type must be int32 or int64.
|
|
2193
2107
|
|
|
2194
2108
|
Outputs:
|
|
2195
2109
|
Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})` or :math:`(N, D_{out}, H_{out}, W_{out}, C)`.
|
|
2196
2110
|
Has the same data type with `x`.
|
|
2197
2111
|
|
|
2198
2112
|
Raises:
|
|
2199
|
-
TypeError: If data type of `x` or `argmax` is
|
|
2113
|
+
TypeError: If data type of `x` or `argmax` is Number.
|
|
2200
2114
|
TypeError: If `ksize`, `strides` or `pads` is neither int nor tuple.
|
|
2201
|
-
ValueError: If numbers in `strides`
|
|
2115
|
+
ValueError: If numbers in `strides` or `ksize` is negative.
|
|
2202
2116
|
ValueError: If numbers in `pads` is negative.
|
|
2203
2117
|
ValueError: If `ksize`, `strides` or `pads` is a tuple whose length is not equal to 3.
|
|
2204
2118
|
ValueError: If `data_format` is not a str or is neither `NCDHW` nor `NDHWC`.
|
|
2205
2119
|
ValueError: If `output_shape` whose length is neither 0 or 5.
|
|
2206
|
-
ValueError: If `output_shape` is not close to output size
|
|
2120
|
+
ValueError: If `output_shape` is not close to output size range
|
|
2207
2121
|
computed by attr `ksize, strides, pads`.
|
|
2208
2122
|
|
|
2209
2123
|
Supported Platforms:
|
|
2210
|
-
``GPU`` ``CPU``
|
|
2124
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
2211
2125
|
|
|
2212
2126
|
Examples:
|
|
2213
2127
|
>>> x = Tensor(np.array([[[[[0, 1], [8, 9]]]]]).astype(np.float32))
|
|
2214
2128
|
>>> argmax = Tensor(np.array([[[[[0, 1], [2, 3]]]]]).astype(np.int64))
|
|
2215
|
-
>>> maxunpool3d =
|
|
2129
|
+
>>> maxunpool3d = ops.MaxUnpool3D(ksize=1, strides=1, pads=0)
|
|
2216
2130
|
>>> output = maxunpool3d(x, argmax)
|
|
2217
2131
|
>>> print(output.asnumpy())
|
|
2218
2132
|
[[[[[0. 1.]
|
|
@@ -2242,7 +2156,7 @@ class MaxUnpool3D(Primitive):
|
|
|
2242
2156
|
self.output_shape = output_shape
|
|
2243
2157
|
|
|
2244
2158
|
|
|
2245
|
-
class AvgPool(
|
|
2159
|
+
class AvgPool(Primitive):
|
|
2246
2160
|
r"""
|
|
2247
2161
|
Average pooling operation.
|
|
2248
2162
|
|
|
@@ -2307,7 +2221,23 @@ class AvgPool(_Pool):
|
|
|
2307
2221
|
@prim_attr_register
|
|
2308
2222
|
def __init__(self, kernel_size=1, strides=1, pad_mode="valid", data_format="NCHW"):
|
|
2309
2223
|
"""Initialize AvgPool."""
|
|
2310
|
-
|
|
2224
|
+
self.init_prim_io_names(inputs=['x'], outputs=['output'])
|
|
2225
|
+
validator.check_value_type('kernel_size', kernel_size, [int, tuple], self.name)
|
|
2226
|
+
validator.check_value_type('strides', strides, [int, tuple], self.name)
|
|
2227
|
+
validator.check_value_type('pad_mode', pad_mode, [str], self.name)
|
|
2228
|
+
self.pad_mode = validator.check_string(pad_mode.upper(), ['VALID', 'SAME'], 'pad_mode', self.name)
|
|
2229
|
+
self.add_prim_attr("pad_mode", self.pad_mode)
|
|
2230
|
+
self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.name)
|
|
2231
|
+
if context.get_context("device_target") != "GPU" and self.format == "NHWC":
|
|
2232
|
+
raise ValueError(f"For '{self.name}', the 'NHWC' format is only supported in GPU target, "
|
|
2233
|
+
f"but got the 'data_format' is {self.format} and "
|
|
2234
|
+
f"the platform is {context.get_context('device_target')}.")
|
|
2235
|
+
self.add_prim_attr('data_format', self.format)
|
|
2236
|
+
self.kernel_size = _check_positive_int_or_tuple(
|
|
2237
|
+
"kernel_size", kernel_size, self.name, allow_four=False, ret_four=True)
|
|
2238
|
+
self.add_prim_attr("kernel_size", self.kernel_size)
|
|
2239
|
+
self.strides = _check_positive_int_or_tuple("strides", strides, self.name, allow_four=False, ret_four=True)
|
|
2240
|
+
self.add_prim_attr("strides", self.strides)
|
|
2311
2241
|
|
|
2312
2242
|
|
|
2313
2243
|
class AvgPoolV1(Primitive):
|
|
@@ -2489,6 +2419,22 @@ class MaxPool3DWithArgmax(Primitive):
|
|
|
2489
2419
|
\max_{l=0, \ldots, d_{ker}-1} \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
|
|
2490
2420
|
\text{input}(N_i, C_j, s_0 \times d + l, s_1 \times h + m, s_2 \times w + n)
|
|
2491
2421
|
|
|
2422
|
+
The output is a Tensor with shape :math:`(N_{out}, C_{out}, D_{out}, H_{out}, W_{out})` and its depth, height and
|
|
2423
|
+
width are:
|
|
2424
|
+
|
|
2425
|
+
.. math::
|
|
2426
|
+
\begin{array}{ll} \\
|
|
2427
|
+
D_{out} = \frac{D_{in} + 2 \times \text{pads}[0] - \text{dilation}[0] \times (\text{ksize}[0] - 1) - 1}
|
|
2428
|
+
{\text{stride}[0]} + 1 \\
|
|
2429
|
+
H_{out} = \frac{H_{in} + 2 \times \text{pads}[1] - \text{dilation}[1] \times (\text{ksize}[1] - 1) - 1}
|
|
2430
|
+
{\text{stride}[1]} + 1 \\
|
|
2431
|
+
W_{out} = \frac{W_{in} + 2 \times \text{pads}[2] - \text{dilation}[2] \times (\text{ksize}[2] - 1) - 1}
|
|
2432
|
+
{\text{stride}[2]} + 1 \\
|
|
2433
|
+
\end{array}
|
|
2434
|
+
|
|
2435
|
+
.. warning::
|
|
2436
|
+
This is an experimental API that is subject to change or deletion.
|
|
2437
|
+
|
|
2492
2438
|
Args:
|
|
2493
2439
|
ksize (Union[int, tuple[int]]): The size of kernel used to take the maximum value and arg
|
|
2494
2440
|
value, is an int number that represents depth, height and width of the kernel, or a tuple of
|
|
@@ -2524,7 +2470,7 @@ class MaxPool3DWithArgmax(Primitive):
|
|
|
2524
2470
|
ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
|
|
2525
2471
|
|
|
2526
2472
|
Supported Platforms:
|
|
2527
|
-
``GPU``
|
|
2473
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
2528
2474
|
|
|
2529
2475
|
Examples:
|
|
2530
2476
|
>>> x = Tensor(np.arange(2 * 1 * 2 * 2 * 2).reshape((2, 1, 2, 2, 2)), mindspore.float32)
|
|
@@ -2586,8 +2532,8 @@ class Conv2DTranspose(Conv2DBackpropInput):
|
|
|
2586
2532
|
dilation (Union[int, tuple[int]]): Specifies the dilation rate to be used for the dilated convolution.
|
|
2587
2533
|
Default: 1.
|
|
2588
2534
|
group (int): Splits input into groups. Default: 1.
|
|
2589
|
-
data_format (str): The format of input and output data. It should be 'NHWC' or 'NCHW'
|
|
2590
|
-
|
|
2535
|
+
data_format (str): The format of input and output data. It should be 'NHWC' or 'NCHW'.
|
|
2536
|
+
Default is 'NCHW'.
|
|
2591
2537
|
|
|
2592
2538
|
Inputs:
|
|
2593
2539
|
- **dout** (Tensor) - the gradients with respect to the output of the convolution.
|
|
@@ -2704,7 +2650,8 @@ class NLLLoss(Primitive):
|
|
|
2704
2650
|
|
|
2705
2651
|
Inputs:
|
|
2706
2652
|
- **logits** (Tensor) - Input logits, with shape :math:`(N, C)`. Data type only supports float32 or float16.
|
|
2707
|
-
- **labels** (Tensor) - Ground truth labels, with shape :math:`(N,)
|
|
2653
|
+
- **labels** (Tensor) - Ground truth labels, with shape :math:`(N,)`, where each value belong to
|
|
2654
|
+
:math:`[0, C-1]`. Data type only supports int32 or int64.
|
|
2708
2655
|
- **weight** (Tensor) - The rescaling weight to each class, with shape :math:`(C,)` and data type only
|
|
2709
2656
|
supports float32 or float16.
|
|
2710
2657
|
|
|
@@ -2716,13 +2663,15 @@ class NLLLoss(Primitive):
|
|
|
2716
2663
|
- **total_weight** (Tensor) - The `total_weight` is a scalar. The data type is the same with `weight's`.
|
|
2717
2664
|
|
|
2718
2665
|
Raises:
|
|
2719
|
-
TypeError: If dtype of `logits` or `weight` is neither float16 nor float32
|
|
2666
|
+
TypeError: If dtype of `logits` or `weight` is neither float16 nor float32.
|
|
2667
|
+
TypeError: If dtype of `labels` is neither int32 nor int64.
|
|
2720
2668
|
ValueError: If `logits` is not a one or two dimension tensor, `labels` and `weight` are not
|
|
2721
2669
|
one dimension tensors.
|
|
2722
2670
|
When `logits` is a two dimension tensor, the first dimension of `logits` is not equal to `labels`,
|
|
2723
2671
|
and second dimension of `logits` is not equal to `weight`.
|
|
2724
2672
|
When `logits` is a one dimension tensor, the dimensions of `logits`, `labels`
|
|
2725
2673
|
and `weight` should be equal to each other.
|
|
2674
|
+
ValueError: If the value of `labels` exceed :math:`[0, C-1]`, where :math:`C` is the number of classes.
|
|
2726
2675
|
|
|
2727
2676
|
Supported Platforms:
|
|
2728
2677
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2826,7 +2775,7 @@ class SparseSoftmaxCrossEntropyWithLogits(Primitive):
|
|
|
2826
2775
|
TypeError: If `is_grad` is not a bool.
|
|
2827
2776
|
TypeError: If dtype of `logits` is neither float16 nor float32.
|
|
2828
2777
|
TypeError: If dtype of `labels` is neither int32 nor int64.
|
|
2829
|
-
ValueError: If logits.shape[0] != labels.shape[0]
|
|
2778
|
+
ValueError: If :math:`logits.shape[0] != labels.shape[0]`.
|
|
2830
2779
|
|
|
2831
2780
|
Supported Platforms:
|
|
2832
2781
|
``GPU`` ``CPU``
|
|
@@ -2922,14 +2871,19 @@ class ApplyMomentum(Primitive):
|
|
|
2922
2871
|
gradient_scale (float): The scale of the gradient. Default: 1.0.
|
|
2923
2872
|
|
|
2924
2873
|
Inputs:
|
|
2925
|
-
- **variable** (Parameter) - Weights to be updated. Data type must be float
|
|
2874
|
+
- **variable** (Parameter) - Weights to be updated. Data type must be float64, int64, float, float16,
|
|
2875
|
+
int16, int32, int8, uint16, uint32, uint64, uint8, complex64, complex128.
|
|
2926
2876
|
- **accumulation** (Parameter) - Accumulated gradient value by moment weight,
|
|
2927
2877
|
has the same data type with `variable`.
|
|
2928
|
-
- **learning_rate** (Union[Number, Tensor]) - The learning rate value, must be a
|
|
2929
|
-
|
|
2878
|
+
- **learning_rate** (Union[Number, Tensor]) - The learning rate value, must be a float64, int64, float,
|
|
2879
|
+
float16, int16, int32, int8, uint16, uint32, uint64, uint8, complex64, complex128 number or
|
|
2880
|
+
a scalar tensor with float64, int64, float, float16, int16, int32, int8, uint16, uint32, uint64, uint8,
|
|
2881
|
+
complex64, complex128 data type.
|
|
2930
2882
|
- **gradient** (Tensor) - Gradient, has the same data type as `variable`.
|
|
2931
|
-
- **momentum** (Union[Number, Tensor]) - Momentum, must be a float
|
|
2932
|
-
|
|
2883
|
+
- **momentum** (Union[Number, Tensor]) - Momentum, must be a float64, int64, float, float16, int16, int32,
|
|
2884
|
+
int8, uint16, uint32, uint64, uint8, complex64, complex128 number or
|
|
2885
|
+
a scalar tensor with float64, int64, float, float16, int16, int32, int8, uint16, uint32, uint64, uint8,
|
|
2886
|
+
complex64, complex128 data type.
|
|
2933
2887
|
|
|
2934
2888
|
Outputs:
|
|
2935
2889
|
Tensor, parameters to be updated.
|
|
@@ -3003,21 +2957,47 @@ class SmoothL1Loss(Primitive):
|
|
|
3003
2957
|
def __init__(self, beta=1.0, reduction='none'):
|
|
3004
2958
|
"""Initialize SmoothL1Loss."""
|
|
3005
2959
|
validator.check_value_type('beta', beta, [float], self.name)
|
|
3006
|
-
validator.check('beta', beta, '', 0,
|
|
2960
|
+
validator.check('beta', beta, '', 0, validator.GT, self.name)
|
|
3007
2961
|
validator.check_string(
|
|
3008
2962
|
reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
|
|
2963
|
+
self.add_prim_attr('sigma', self.beta)
|
|
3009
2964
|
self.init_prim_io_names(inputs=['prediction', 'target'], outputs=['output'])
|
|
3010
2965
|
|
|
3011
2966
|
|
|
3012
2967
|
class MultiMarginLoss(Primitive):
|
|
3013
2968
|
r"""
|
|
3014
|
-
Creates a
|
|
3015
|
-
|
|
2969
|
+
Creates a loss function that minimizes the hinge loss
|
|
2970
|
+
for multi-class classification tasks.
|
|
2971
|
+
The loss is calculated by comparing the input and output of the function.
|
|
2972
|
+
|
|
2973
|
+
.. warning::
|
|
2974
|
+
This is an experimental API that is subject to change or deletion.
|
|
3016
2975
|
|
|
3017
2976
|
Refer to :func:`mindspore.ops.multi_margin_loss` for more details.
|
|
3018
2977
|
|
|
2978
|
+
Args:
|
|
2979
|
+
p (int, optional): The norm degree for pairwise distance. Should be 1 or 2. Default: 1.
|
|
2980
|
+
margin (int, optional): A parameter to change pairwise distance. Default: 1.0.
|
|
2981
|
+
reduction (str, optional): Apply specific reduction method to the output: 'none', 'mean',
|
|
2982
|
+
'sum'. Default: 'mean'.
|
|
2983
|
+
|
|
2984
|
+
- 'none': no reduction will be applied.
|
|
2985
|
+
- 'mean': the sum of the output will be divided by the number of elements in the output.
|
|
2986
|
+
- 'sum': the output will be summed.
|
|
2987
|
+
|
|
2988
|
+
Inputs:
|
|
2989
|
+
- **inputs** (Tensor) - Input , with shape :math:`(N, C)`. Data type only support float32, float16 or float64.
|
|
2990
|
+
- **target** (Tensor) - Ground truth labels, with shape :math:`(N,)`. Data type only support int64. The
|
|
2991
|
+
value of target should be non-negative, less than C.
|
|
2992
|
+
- **weight** (Tensor) - The rescaling weight to each class with shape :math:`(C,)`. Data type only
|
|
2993
|
+
support float16, float32 or float64.
|
|
2994
|
+
|
|
2995
|
+
Outputs:
|
|
2996
|
+
Tensor, When `reduction` is 'none', the shape is :math:`(N,)`.
|
|
2997
|
+
Otherwise, it is a scalar. Has the same data type with `inputs`.
|
|
2998
|
+
|
|
3019
2999
|
Supported Platforms:
|
|
3020
|
-
``CPU``
|
|
3000
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
3021
3001
|
|
|
3022
3002
|
Examples:
|
|
3023
3003
|
>>> x = Tensor(np.ones(shape=[3, 3]), mindspore.float32)
|
|
@@ -3033,7 +3013,7 @@ class MultiMarginLoss(Primitive):
|
|
|
3033
3013
|
def __init__(self, p=1, margin=1.0, reduction="mean"):
|
|
3034
3014
|
"""Initialize MultiMarginLoss"""
|
|
3035
3015
|
self.p = validator.check_value_type('p', p, [int], self.name)
|
|
3036
|
-
validator.check_int(p, {1, 2},
|
|
3016
|
+
validator.check_int(p, {1, 2}, validator.IN, 'p', self.name)
|
|
3037
3017
|
self.margin = validator.check_value_type('margin', margin, [float], self.name)
|
|
3038
3018
|
self.reduction = validator.check_string(reduction, ['none', 'sum', 'mean'], 'reduction', self.name)
|
|
3039
3019
|
self.init_prim_io_names(inputs=['x', 'target', 'weight'], outputs=['y'])
|
|
@@ -3217,10 +3197,13 @@ class RNNTLoss(PrimitiveWithInfer):
|
|
|
3217
3197
|
validator.check_equal_int(len(labels_shape), 2, 'labels_rank', self.name)
|
|
3218
3198
|
validator.check_equal_int(len(input_length_shape), 1, 'input_length_rank', self.name)
|
|
3219
3199
|
validator.check_equal_int(len(label_length_shape), 1, 'label_length_rank', self.name)
|
|
3220
|
-
validator.check('labels shape[0]', labels_shape[0], 'acts shape[0]', acts_shape[0],
|
|
3221
|
-
validator.check('labels shape[1]', labels_shape[1], 'acts shape[2]-1',
|
|
3222
|
-
|
|
3223
|
-
validator.check('
|
|
3200
|
+
validator.check('labels shape[0]', labels_shape[0], 'acts shape[0]', acts_shape[0], validator.EQ, self.name)
|
|
3201
|
+
validator.check('labels shape[1]', labels_shape[1], 'acts shape[2]-1',
|
|
3202
|
+
acts_shape[2] - 1, validator.EQ, self.name)
|
|
3203
|
+
validator.check('input_length size', input_length_shape[0], 'acts shape[0]',
|
|
3204
|
+
acts_shape[0], validator.EQ, self.name)
|
|
3205
|
+
validator.check('label_length size', label_length_shape[0], 'acts shape[0]',
|
|
3206
|
+
acts_shape[0], validator.EQ, self.name)
|
|
3224
3207
|
costs_shape = (acts_shape[0],)
|
|
3225
3208
|
return costs_shape, acts_shape
|
|
3226
3209
|
|
|
@@ -3301,13 +3284,10 @@ class SGD(PrimitiveWithCheck):
|
|
|
3301
3284
|
|
|
3302
3285
|
def check_shape(self, parameters_shape, gradient_shape, learning_rate_shape,
|
|
3303
3286
|
accum_shape, momentum_shape, stat_shape):
|
|
3304
|
-
validator.
|
|
3305
|
-
validator.check_int(len(
|
|
3306
|
-
validator.check_int(len(
|
|
3307
|
-
validator.
|
|
3308
|
-
validator.check_int(len(momentum_shape), 0, Rel.GE, f'momentum rank', self.name)
|
|
3309
|
-
validator.check_int(len(stat_shape), 0, Rel.GE, f'stat rank', self.name)
|
|
3310
|
-
validator.check("gradient shape", gradient_shape, "stat shape", stat_shape, Rel.EQ, self.name)
|
|
3287
|
+
validator.check_int(len(gradient_shape), 0, validator.GE, f'gradient rank', self.name)
|
|
3288
|
+
validator.check_int(len(learning_rate_shape), 0, validator.GE, f'learning rate rank', self.name)
|
|
3289
|
+
validator.check_int(len(momentum_shape), 0, validator.GE, f'momentum rank', self.name)
|
|
3290
|
+
validator.check_int(len(stat_shape), 0, validator.GE, f'stat rank', self.name)
|
|
3311
3291
|
|
|
3312
3292
|
def check_dtype(self, parameters_dtype, gradient_dtype, learning_rate_dtype,
|
|
3313
3293
|
accum_dtype, momentum_dtype, stat_dtype):
|
|
@@ -3348,7 +3328,7 @@ class ApplyRMSProp(PrimitiveWithInfer):
|
|
|
3348
3328
|
from being updated. Default: False.
|
|
3349
3329
|
|
|
3350
3330
|
Inputs:
|
|
3351
|
-
- **var** (
|
|
3331
|
+
- **var** (Parameter) - Weights to be updated.
|
|
3352
3332
|
- **mean_square** (Tensor) - Mean square gradients, must be the same type as `var`.
|
|
3353
3333
|
- **moment** (Tensor) - Delta of `var`, must be the same type as `var`.
|
|
3354
3334
|
- **learning_rate** (Union[Number, Tensor]) - Learning rate. Must be a float number or
|
|
@@ -3442,7 +3422,7 @@ class ApplyCenteredRMSProp(Primitive):
|
|
|
3442
3422
|
from being updated. Default: False.
|
|
3443
3423
|
|
|
3444
3424
|
Inputs:
|
|
3445
|
-
- **var** (
|
|
3425
|
+
- **var** (Parameter) - Weights to be updated.
|
|
3446
3426
|
- **mean_gradient** (Tensor) - Mean gradients, must be the same type as `var`.
|
|
3447
3427
|
- **mean_square** (Tensor) - Mean square gradients, must be the same type as `var`.
|
|
3448
3428
|
- **moment** (Tensor) - Delta of `var`, must be the same type as `var`.
|
|
@@ -3519,9 +3499,9 @@ class LayerNorm(Primitive):
|
|
|
3519
3499
|
- **input_x** (Tensor) - Tensor of shape :math:`(N, \ldots)`.
|
|
3520
3500
|
The input of LayerNorm.
|
|
3521
3501
|
- **gamma** (Tensor) - Tensor of shape :math:`(P_0, \ldots, P_\text{begin_params_axis})`.
|
|
3522
|
-
The learnable parameter
|
|
3502
|
+
The learnable parameter :math:`\gamma` as the scale on norm.
|
|
3523
3503
|
- **beta** (Tensor) - Tensor of shape :math:`(P_0, \ldots, P_\text{begin_params_axis})`.
|
|
3524
|
-
The learnable parameter
|
|
3504
|
+
The learnable parameter :math:`\beta` as the scale on norm.
|
|
3525
3505
|
|
|
3526
3506
|
Outputs:
|
|
3527
3507
|
tuple[Tensor], tuple of 3 tensors, the normalized input and the updated parameters.
|
|
@@ -3576,13 +3556,17 @@ class L2Normalize(Primitive):
|
|
|
3576
3556
|
where :math:`\epsilon` is epsilon and :math:`\sum_{i}^{}\left | x_i \right | ^2` calculate the sum of squares of
|
|
3577
3557
|
the input `x` along the dimension `axis`.
|
|
3578
3558
|
|
|
3559
|
+
Note:
|
|
3560
|
+
On Ascend, input data type of float64 is currently not supported.
|
|
3561
|
+
|
|
3579
3562
|
Args:
|
|
3580
3563
|
axis (Union[list(int), tuple(int), int]): Specify the axis for calculating the L2 norm. Default: 0.
|
|
3581
3564
|
epsilon (float): A small value added for numerical stability. Default: 1e-4.
|
|
3582
3565
|
|
|
3583
3566
|
Inputs:
|
|
3584
|
-
- **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N,
|
|
3585
|
-
|
|
3567
|
+
- **x** (Tensor) - Input to compute the normalization. Tensor of shape :math:`(N, *)`,
|
|
3568
|
+
where :math:`*` means any number of additional dimensions.
|
|
3569
|
+
Data type must be float16, float32 or float64.
|
|
3586
3570
|
|
|
3587
3571
|
Outputs:
|
|
3588
3572
|
Tensor, with the same type and shape as the `x`.
|
|
@@ -3591,7 +3575,7 @@ class L2Normalize(Primitive):
|
|
|
3591
3575
|
TypeError: If `axis` is not one of the following: list, tuple or int.
|
|
3592
3576
|
TypeError: If `epsilon` is not a float.
|
|
3593
3577
|
TypeError: If `x` is not a Tensor.
|
|
3594
|
-
TypeError: If dtype of `x` is
|
|
3578
|
+
TypeError: If dtype of `x` is not in [float16, float32, float64].
|
|
3595
3579
|
ValueError: If dimension of `x` is not greater than 0.
|
|
3596
3580
|
|
|
3597
3581
|
Supported Platforms:
|
|
@@ -3653,57 +3637,14 @@ class DropoutDoMask(Primitive):
|
|
|
3653
3637
|
|
|
3654
3638
|
class ResizeBilinear(PrimitiveWithInfer):
|
|
3655
3639
|
r"""
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
The resizing only affects the lower two dimensions which represent the height and width. The input images
|
|
3659
|
-
can be represented by different data types, but the data types of output images are always float32.
|
|
3660
|
-
|
|
3661
|
-
For general resize, refer to :func:`mindspore.ops.interpolate` for more details.
|
|
3662
|
-
|
|
3663
|
-
.. warning::
|
|
3664
|
-
This interface does not support dynamic shape and is subject to change or deletion,
|
|
3665
|
-
use :func:`mindspore.ops.interpolate` instead.
|
|
3666
|
-
|
|
3667
|
-
Args:
|
|
3668
|
-
size (Union[tuple[int], list[int]]): A tuple or list of 2 int elements :math:`(new\_height, new\_width)`,
|
|
3669
|
-
the new size of the images.
|
|
3670
|
-
align_corners (bool): If true, rescale input by :math:`(new\_height - 1) / (height - 1)`,
|
|
3671
|
-
which exactly aligns the 4 corners of images and resized images. If false,
|
|
3672
|
-
rescale by :math:`new\_height / height`. Default: False.
|
|
3673
|
-
half_pixel_centers (bool): Whether half pixel center. If set to True, `align_corners` should be False.
|
|
3674
|
-
Default: False.
|
|
3640
|
+
This API is deprecated, please use the :class:`mindspore.ops.ResizeBilinearV2` instead.
|
|
3641
|
+
For general resizing with other interpolation methods, refer to :func:`mindspore.ops.interpolate` for more details.
|
|
3675
3642
|
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
:math:`(batch, channels, height, width)`, with data type of float32 or float16.
|
|
3679
|
-
|
|
3680
|
-
Outputs:
|
|
3681
|
-
Tensor, resized image. 4-D with shape :math:`(batch, channels, new\_height, new\_width)`,
|
|
3682
|
-
with the same data type as input `x`.
|
|
3683
|
-
|
|
3684
|
-
Raises:
|
|
3685
|
-
TypeError: If `size` is neither a tuple nor list.
|
|
3686
|
-
TypeError: If `align_corners` is not a bool.
|
|
3687
|
-
TypeError: If `half_pixel_centers` is not a bool.
|
|
3688
|
-
TypeError: If `align_corners` and `half_pixel_centers` are all True.
|
|
3689
|
-
TypeError: If `half_pixel_centers` is True and device_target not Ascend.
|
|
3690
|
-
TypeError: If dtype of `x` is neither float16 nor float32.
|
|
3691
|
-
TypeError: If `x` is not a Tensor.
|
|
3692
|
-
ValueError: If length of shape of `x` is not equal to 4.
|
|
3643
|
+
Note:
|
|
3644
|
+
Dynamic shape feature is not supported for now.
|
|
3693
3645
|
|
|
3694
3646
|
Supported Platforms:
|
|
3695
|
-
``Ascend`` ``
|
|
3696
|
-
|
|
3697
|
-
Examples:
|
|
3698
|
-
>>> x = Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mindspore.float32)
|
|
3699
|
-
>>> resize_bilinear = ops.ResizeBilinear((5, 5))
|
|
3700
|
-
>>> output = resize_bilinear(x)
|
|
3701
|
-
>>> print(output)
|
|
3702
|
-
[[[[1. 2. 3. 4. 5.]
|
|
3703
|
-
[1. 2. 3. 4. 5.]
|
|
3704
|
-
[1. 2. 3. 4. 5.]
|
|
3705
|
-
[1. 2. 3. 4. 5.]
|
|
3706
|
-
[1. 2. 3. 4. 5.]]]]
|
|
3647
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
3707
3648
|
"""
|
|
3708
3649
|
|
|
3709
3650
|
@prim_attr_register
|
|
@@ -3723,7 +3664,7 @@ class ResizeBilinear(PrimitiveWithInfer):
|
|
|
3723
3664
|
validator.check_positive_int(value, f'{i}th value of size', self.name)
|
|
3724
3665
|
|
|
3725
3666
|
def infer_shape(self, input_shape):
|
|
3726
|
-
validator.check("dimension of input", len(input_shape), "", 4,
|
|
3667
|
+
validator.check("dimension of input", len(input_shape), "", 4, validator.EQ, self.name)
|
|
3727
3668
|
input_shape = list(input_shape)
|
|
3728
3669
|
batch, channel, _, _ = input_shape
|
|
3729
3670
|
out_shape = [batch, channel]
|
|
@@ -3780,22 +3721,24 @@ class UpsampleTrilinear3D(Primitive):
|
|
|
3780
3721
|
ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
|
|
3781
3722
|
|
|
3782
3723
|
Supported Platforms:
|
|
3783
|
-
|
|
3724
|
+
|
|
3784
3725
|
|
|
3785
3726
|
Examples:
|
|
3786
|
-
>>>
|
|
3787
|
-
>>>
|
|
3727
|
+
>>> net = ops.UpsampleTrilinear3D(output_size=[4, 64, 48])
|
|
3728
|
+
>>> in_x = Tensor(input_data=np.random.randn(2, 3, 4, 512, 256))
|
|
3729
|
+
>>> out = net(in_x)
|
|
3788
3730
|
>>> print(out.shape)
|
|
3789
3731
|
(2, 3, 4, 64, 48)
|
|
3790
|
-
|
|
3791
|
-
>>>
|
|
3732
|
+
>>>
|
|
3733
|
+
>>> net = ops.UpsampleTrilinear3D(output_size=[2, 4, 4])
|
|
3792
3734
|
>>> in_x = Tensor(np.arange(1, 5, dtype=np.float32).reshape((1, 1, 1, 2, 2)))
|
|
3793
|
-
>>> out =
|
|
3735
|
+
>>> out = net(in_x)
|
|
3794
3736
|
>>> print(out)
|
|
3795
3737
|
[[[[[1. 1.25 1.75 2. ]
|
|
3796
3738
|
[1.5 1.75 2.25 2.5 ]
|
|
3797
3739
|
[2.5 2.75 3.25 3.5 ]
|
|
3798
3740
|
[3. 3.25 3.75 4. ]]
|
|
3741
|
+
|
|
3799
3742
|
[[1. 1.25 1.75 2. ]
|
|
3800
3743
|
[1.5 1.75 2.25 2.5 ]
|
|
3801
3744
|
[2.5 2.75 3.25 3.5 ]
|
|
@@ -4036,7 +3979,7 @@ class GetNext(Primitive):
|
|
|
4036
3979
|
"""Initialize GetNext."""
|
|
4037
3980
|
validator.check_value_type("types", types, [list, tuple], self.name)
|
|
4038
3981
|
validator.check_value_type("shapes", shapes, [list, tuple], self.name)
|
|
4039
|
-
validator.check("types length", len(types), "shapes length", len(shapes),
|
|
3982
|
+
validator.check("types length", len(types), "shapes length", len(shapes), validator.EQ, self.name)
|
|
4040
3983
|
validator.check_value_type("output_num", output_num, [int], self.name)
|
|
4041
3984
|
|
|
4042
3985
|
|
|
@@ -4076,8 +4019,8 @@ class PReLU(PrimitiveWithInfer):
|
|
|
4076
4019
|
self.init_prim_io_names(inputs=['x', 'weight'], outputs=['output'])
|
|
4077
4020
|
|
|
4078
4021
|
|
|
4079
|
-
class LSTM(
|
|
4080
|
-
"""
|
|
4022
|
+
class LSTM(Primitive):
|
|
4023
|
+
r"""
|
|
4081
4024
|
Performs the Long Short-Term Memory (LSTM) on the input.
|
|
4082
4025
|
|
|
4083
4026
|
For detailsed information, please refer to :class:`mindspore.nn.LSTM`.
|
|
@@ -4092,20 +4035,20 @@ class LSTM(PrimitiveWithInfer):
|
|
|
4092
4035
|
LSTM layer except the last layer. The range of dropout is [0.0, 1.0].
|
|
4093
4036
|
|
|
4094
4037
|
Inputs:
|
|
4095
|
-
- **input** (Tensor) - Tensor of shape (
|
|
4096
|
-
(
|
|
4097
|
-
- **h** (
|
|
4098
|
-
- **c** (
|
|
4038
|
+
- **input** (Tensor) - Tensor of shape :math:`(seq\_len, batch\_size, input\_size)` or
|
|
4039
|
+
:math:`(batch\_size, seq\_len, input\_size)`.
|
|
4040
|
+
- **h** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)`.
|
|
4041
|
+
- **c** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)`.
|
|
4099
4042
|
- **w** (Tensor) - A weight Tensor.
|
|
4100
4043
|
|
|
4101
4044
|
Outputs:
|
|
4102
4045
|
Tuple, a tuple contains (`output`, `h_n`, `c_n`, `reserve`, `state`).
|
|
4103
4046
|
|
|
4104
|
-
- **output** (Tensor) - Tensor of shape (
|
|
4105
|
-
- **h_n** (Tensor) - Tensor of shape (
|
|
4106
|
-
- **c_n** (Tensor) - Tensor of shape (
|
|
4107
|
-
- **reserve** (Tensor) - Tensor of shape (r, 1)
|
|
4108
|
-
- **state** (Tensor) - Random number generator state and its shape is (s, 1)
|
|
4047
|
+
- **output** (Tensor) - Tensor of shape :math:`(seq\_len, batch\_size, num\_directions * hidden\_size)`.
|
|
4048
|
+
- **h_n** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)`.
|
|
4049
|
+
- **c_n** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)`.
|
|
4050
|
+
- **reserve** (Tensor) - Tensor of shape :math:`(r, 1)`.
|
|
4051
|
+
- **state** (Tensor) - Random number generator state and its shape is :math:`(s, 1)`.
|
|
4109
4052
|
|
|
4110
4053
|
Raises:
|
|
4111
4054
|
TypeError: If `input_size`, `hidden_size` or `num_layers` is not an int.
|
|
@@ -4151,37 +4094,13 @@ class LSTM(PrimitiveWithInfer):
|
|
|
4151
4094
|
self.has_bias = validator.check_value_type("has_bias", has_bias, (bool,), self.name)
|
|
4152
4095
|
self.bidirectional = validator.check_value_type("bidirectional", bidirectional, (bool,), self.name)
|
|
4153
4096
|
self.dropout = validator.check_value_type("dropout", dropout, [float], self.name)
|
|
4154
|
-
self.dropout = validator.check_float_range(dropout, 0, 1,
|
|
4097
|
+
self.dropout = validator.check_float_range(dropout, 0, 1, validator.INC_BOTH, 'dropout', self.name)
|
|
4155
4098
|
|
|
4156
4099
|
if bidirectional:
|
|
4157
4100
|
self.num_directions = 2
|
|
4158
4101
|
else:
|
|
4159
4102
|
self.num_directions = 1
|
|
4160
4103
|
|
|
4161
|
-
def infer_shape(self, x_shape, h_shape, c_shape, w_shape):
|
|
4162
|
-
validator.check_equal_int(len(x_shape), 3, "x rank", self.name)
|
|
4163
|
-
validator.check_equal_int(x_shape[2], self.input_size, "x[2]", self.name)
|
|
4164
|
-
|
|
4165
|
-
# h and c should be same shape
|
|
4166
|
-
validator.check_equal_int(len(h_shape), 3, "h rank", self.name)
|
|
4167
|
-
validator.check("h_shape", h_shape, "c_shape", c_shape, Rel.EQ, self.name)
|
|
4168
|
-
|
|
4169
|
-
validator.check_int(h_shape[0], self.num_layers * self.num_directions, Rel.EQ, "h[0]", self.name)
|
|
4170
|
-
validator.check_equal_int(h_shape[1], x_shape[1], "h[1]", self.name)
|
|
4171
|
-
validator.check_int(h_shape[2], self.hidden_size, Rel.EQ, "h[2]", self.name)
|
|
4172
|
-
|
|
4173
|
-
y_shape = (x_shape[0], x_shape[1], self.hidden_size * self.num_directions)
|
|
4174
|
-
|
|
4175
|
-
# set arbitrary shape for reserved space
|
|
4176
|
-
reserved_shape = (1, 1)
|
|
4177
|
-
state_shape = (1, 1)
|
|
4178
|
-
return y_shape, h_shape, c_shape, reserved_shape, state_shape
|
|
4179
|
-
|
|
4180
|
-
def infer_dtype(self, x_dtype, h_dtype, c_dtype, w_dtype):
|
|
4181
|
-
args = {'x': x_dtype, 'h': h_dtype, 'c': c_dtype, 'w': w_dtype}
|
|
4182
|
-
validator.check_tensors_dtypes_same_and_valid(args, (mstype.float32, mstype.float16), self.name)
|
|
4183
|
-
return x_dtype, x_dtype, x_dtype, x_dtype, x_dtype
|
|
4184
|
-
|
|
4185
4104
|
|
|
4186
4105
|
class SigmoidCrossEntropyWithLogits(Primitive):
|
|
4187
4106
|
r"""
|
|
@@ -4200,7 +4119,7 @@ class SigmoidCrossEntropyWithLogits(Primitive):
|
|
|
4200
4119
|
\end{array}
|
|
4201
4120
|
|
|
4202
4121
|
Inputs:
|
|
4203
|
-
- **logits** (Tensor) - Input logits. Tensor of shape :math:`(N, *)` where :math:`*` means
|
|
4122
|
+
- **logits** (Tensor) - Input logits. Tensor of shape :math:`(N, *)` where :math:`*` means any number
|
|
4204
4123
|
of additional dimensions.
|
|
4205
4124
|
- **label** (Tensor) - Ground truth label. With the same shape and type as `logits`.
|
|
4206
4125
|
|
|
@@ -4240,7 +4159,7 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
|
|
|
4240
4159
|
|
|
4241
4160
|
\begin{array}{ll} \\
|
|
4242
4161
|
p_{ij} = sigmoid(X_{ij}) = \frac{1}{1 + e^{-X_{ij}}} \\
|
|
4243
|
-
L_{ij} = -[Y_{ij}
|
|
4162
|
+
L_{ij} = -[Y_{ij}log(p_{ij}) + (1 - Y_{ij})log(1 - p_{ij})]
|
|
4244
4163
|
\end{array}
|
|
4245
4164
|
|
|
4246
4165
|
:math:`i` indicates the :math:`i^{th}` sample, :math:`j` indicates the category. Then,
|
|
@@ -4258,8 +4177,8 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
|
|
|
4258
4177
|
and the third method is to calculate the sum of all losses.
|
|
4259
4178
|
|
|
4260
4179
|
This operator will multiply the output by the corresponding weight.
|
|
4261
|
-
The tensor weight assigns different weights to each piece of data in the batch,
|
|
4262
|
-
and the tensor pos_weight adds corresponding weights to the positive examples of each category.
|
|
4180
|
+
The tensor `weight` assigns different weights to each piece of data in the batch,
|
|
4181
|
+
and the tensor `pos_weight` adds corresponding weights to the positive examples of each category.
|
|
4263
4182
|
|
|
4264
4183
|
In addition, it can trade off recall and precision by adding weights to positive examples.
|
|
4265
4184
|
In the case of multi-label classification the loss can be described as:
|
|
@@ -4271,8 +4190,8 @@ class BCEWithLogitsLoss(PrimitiveWithInfer):
|
|
|
4271
4190
|
\end{array}
|
|
4272
4191
|
|
|
4273
4192
|
where c is the class number (c>1 for multi-label binary classification, c=1 for single-label binary classification),
|
|
4274
|
-
n is the number of the sample in the batch and :math:`
|
|
4275
|
-
:math:`
|
|
4193
|
+
n is the number of the sample in the batch and :math:`P_c` is the weight of the positive answer for the class c.
|
|
4194
|
+
:math:`P_c>1` increases the recall, :math:`P_c<1` increases the precision.
|
|
4276
4195
|
|
|
4277
4196
|
Args:
|
|
4278
4197
|
reduction (str): Type of reduction to be applied to loss. The optional values are 'mean', 'sum', and 'none',
|
|
@@ -4335,8 +4254,8 @@ class Pad(Primitive):
|
|
|
4335
4254
|
be extended behind the input tensor in the `D` th dimension.
|
|
4336
4255
|
|
|
4337
4256
|
Inputs:
|
|
4338
|
-
- **input_x** (Tensor) - Tensor
|
|
4339
|
-
additional dimensions.
|
|
4257
|
+
- **input_x** (Tensor) - Tensor to be padded. It has shape :math:`(N, *)`, where :math:`*` means
|
|
4258
|
+
any number of additional dimensions.
|
|
4340
4259
|
|
|
4341
4260
|
Outputs:
|
|
4342
4261
|
Tensor, the tensor after padding.
|
|
@@ -4372,21 +4291,34 @@ class Pad(Primitive):
|
|
|
4372
4291
|
|
|
4373
4292
|
class PadV3(Primitive):
|
|
4374
4293
|
"""
|
|
4375
|
-
Pads the input
|
|
4294
|
+
Pads the input Tensor according to the `paddings`, `mode` and `paddings_contiguous`.
|
|
4376
4295
|
|
|
4377
4296
|
Args:
|
|
4378
4297
|
mode (str, optional): An optional string indicates padding mode,
|
|
4379
|
-
support "constant", "reflect", "edge". Default: "constant".
|
|
4298
|
+
support "constant", "reflect", "edge", "circular". Default: "constant".
|
|
4299
|
+
The effects of various padding modes are as follows:
|
|
4300
|
+
|
|
4301
|
+
- "constant": Pads the input Tensor with value specified by `constant_value`.
|
|
4302
|
+
- "reflect": Pads the input Tensor by reflecting the values of the pixels at the
|
|
4303
|
+
boundary of the Tensor.
|
|
4304
|
+
- "edge": Pads the input Tensor with the values of the pixels on the border of the Tensor.
|
|
4305
|
+
- "circular": Circular padding mode. In this mode, the pixels from one edge of the image
|
|
4306
|
+
are wrapped around to the opposite edge, such that the pixel on the right edge of the
|
|
4307
|
+
image is replaced with the pixel on the left edge, and the pixel on the bottom edge
|
|
4308
|
+
is replaced with the pixel on the top edge.
|
|
4309
|
+
|
|
4380
4310
|
paddings_contiguous (bool, optional): An optional bool value indicates if the padding is paddings_contiguous.
|
|
4381
4311
|
If true, paddings is arranged as [begin0, end0, begin1, end1, ...]
|
|
4382
4312
|
If false, paddings is arranged as [begin0, begin1, ..., end1, end2, ...]
|
|
4383
4313
|
Default:True.
|
|
4384
4314
|
|
|
4385
4315
|
Inputs:
|
|
4386
|
-
- **x** (Tensor) - Tensor
|
|
4387
|
-
additional dimensions.
|
|
4388
|
-
- **paddings** (Tensor) -
|
|
4389
|
-
|
|
4316
|
+
- **x** (Tensor) - Tensor to be padded. It has shape :math:`(N, *)`, where :math:`*` means
|
|
4317
|
+
any number of additional dimensions.
|
|
4318
|
+
- **paddings** (Tensor) - Specifies the number of zeros to be padded before and after each
|
|
4319
|
+
dimension of the input Tensor `x`. It's a 1D Tensor of type int32 or int64.
|
|
4320
|
+
- **constant_value** (Tensor, optional) - Padding value to use in 'constant' mode,
|
|
4321
|
+
if not specified, 0 is used instead. It has the same type as `x`.
|
|
4390
4322
|
|
|
4391
4323
|
Outputs:
|
|
4392
4324
|
Tensor, the tensor after padding.
|
|
@@ -4397,19 +4329,20 @@ class PadV3(Primitive):
|
|
|
4397
4329
|
ValueError: If `mode` is not a str or not in support modes.
|
|
4398
4330
|
ValueError: If `mode` is "constant", the element's number of `paddings` not be even.
|
|
4399
4331
|
ValueError: If `mode` is "constant", the element's number of `paddings` large than input dim * 2.
|
|
4400
|
-
ValueError: If `mode` is "edge" or "
|
|
4401
|
-
ValueError: If `mode` is "edge" or "
|
|
4402
|
-
the element's number of `paddings` is 2.
|
|
4403
|
-
ValueError: If `mode` is "edge" or "
|
|
4404
|
-
the element's number of `paddings` is 4.
|
|
4405
|
-
ValueError: If `mode` is "
|
|
4406
|
-
ValueError: If `mode` is "edge", x dims
|
|
4332
|
+
ValueError: If `mode` is "edge" "reflect" or "circular", the element's number of `paddings` is not 2, 4 or 6.
|
|
4333
|
+
ValueError: If `mode` is "edge" "reflect" or "circular", `x` dims equals 3,
|
|
4334
|
+
the element's number of `paddings` is not 2.
|
|
4335
|
+
ValueError: If `mode` is "edge" "reflect" or "circular", `x` dims equals 4,
|
|
4336
|
+
the element's number of `paddings` is not 4.
|
|
4337
|
+
ValueError: If `mode` is "circular", `x` dims equals 5, the element's number of `paddings` is not 6.
|
|
4338
|
+
ValueError: If `mode` is "edge", "reflect" or "circular", `x` dims smaller than 3.
|
|
4339
|
+
ValueError: If `mode` is "edge" or "circular", x dims bigger than 5.
|
|
4407
4340
|
ValueError: If `mode` is "reflect", x dims bigger than 4.
|
|
4408
4341
|
ValueError: If `mode` is "reflect", padding size bigger than the corresponding `x` dimension.
|
|
4409
4342
|
ValueError: After padding, output's shape number is not greater than 0.
|
|
4410
4343
|
|
|
4411
4344
|
Supported Platforms:
|
|
4412
|
-
``GPU`` ``CPU``
|
|
4345
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
4413
4346
|
|
|
4414
4347
|
Examples:
|
|
4415
4348
|
>>> # case1: mode="reflect", paddings_contiguous=True
|
|
@@ -4447,7 +4380,7 @@ class PadV3(Primitive):
|
|
|
4447
4380
|
def __init__(self, mode='constant', paddings_contiguous=True):
|
|
4448
4381
|
"""Initialize PadV3"""
|
|
4449
4382
|
self.init_prim_io_names(inputs=['x', 'paddings', 'constant_value'], outputs=['y'])
|
|
4450
|
-
validator.check_string(mode, ['constant', 'reflect', 'edge'], 'mode', self.name)
|
|
4383
|
+
validator.check_string(mode, ['constant', 'reflect', 'edge', 'circular'], 'mode', self.name)
|
|
4451
4384
|
validator.check_bool(paddings_contiguous, "paddings_contiguous", self.name)
|
|
4452
4385
|
self.mode = mode
|
|
4453
4386
|
self.paddings_contiguous = paddings_contiguous
|
|
@@ -4465,7 +4398,7 @@ class MirrorPad(Primitive):
|
|
|
4465
4398
|
- **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
|
|
4466
4399
|
additional dimensions.
|
|
4467
4400
|
- **paddings** (Tensor) - Paddings requires constant tensor. The value of `paddings` is a
|
|
4468
|
-
matrix(list), and its shape is (N, 2)
|
|
4401
|
+
matrix(list), and its shape is :math:`(N, 2)`. N is the rank of input data. All elements of paddings
|
|
4469
4402
|
are int type. For the input in the `D` th dimension, paddings[D, 0] indicates how many sizes
|
|
4470
4403
|
to be extended ahead of the input tensor in the `D` th dimension, and paddings[D, 1]
|
|
4471
4404
|
indicates how many sizes to be extended behind the input tensor in the `D` th dimension. Both
|
|
@@ -4492,7 +4425,7 @@ class MirrorPad(Primitive):
|
|
|
4492
4425
|
ValueError: If paddings.size is not equal to 2 * rank of input_x.
|
|
4493
4426
|
|
|
4494
4427
|
Supported Platforms:
|
|
4495
|
-
``GPU`` ``CPU``
|
|
4428
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
4496
4429
|
|
|
4497
4430
|
Examples:
|
|
4498
4431
|
>>> from mindspore import Tensor, nn, ops
|
|
@@ -4531,7 +4464,6 @@ class MirrorPad(Primitive):
|
|
|
4531
4464
|
self.init_prim_io_names(inputs=['x', 'paddings'], outputs=['y'])
|
|
4532
4465
|
validator.check_string(mode, ['REFLECT', 'SYMMETRIC'], 'mode', self.name)
|
|
4533
4466
|
self.mode = mode
|
|
4534
|
-
self.set_const_input_indexes([1])
|
|
4535
4467
|
|
|
4536
4468
|
|
|
4537
4469
|
class ComputeAccidentalHits(PrimitiveWithCheck):
|
|
@@ -4587,13 +4519,14 @@ class ComputeAccidentalHits(PrimitiveWithCheck):
|
|
|
4587
4519
|
self.init_prim_io_names(inputs=['true_classes', 'sampled_candidates'],
|
|
4588
4520
|
outputs=['indices', 'ids', 'weights'])
|
|
4589
4521
|
validator.check_value_type("num_true", num_true, [int], self.name)
|
|
4590
|
-
validator.check_number("num_true", num_true, 1,
|
|
4522
|
+
validator.check_number("num_true", num_true, 1, validator.GE, self.name)
|
|
4591
4523
|
self.num_true = num_true
|
|
4592
4524
|
|
|
4593
4525
|
def check_shape(self, true_classes_shape, sampled_candidates_shape):
|
|
4594
|
-
validator.check_int(len(true_classes_shape), 2,
|
|
4595
|
-
validator.check_int(len(sampled_candidates_shape), 1,
|
|
4596
|
-
validator.check("true_classes shape[1]", true_classes_shape[1], "num_true",
|
|
4526
|
+
validator.check_int(len(true_classes_shape), 2, validator.EQ, 'dim of true_classes', self.name)
|
|
4527
|
+
validator.check_int(len(sampled_candidates_shape), 1, validator.EQ, 'dim of sampled_candidates', self.name)
|
|
4528
|
+
validator.check("true_classes shape[1]", true_classes_shape[1], "num_true",
|
|
4529
|
+
self.num_true, validator.EQ, self.name)
|
|
4597
4530
|
|
|
4598
4531
|
indices_len = -1
|
|
4599
4532
|
return (indices_len,), (indices_len,), (indices_len,)
|
|
@@ -4665,7 +4598,7 @@ class ROIAlign(Primitive):
|
|
|
4665
4598
|
validator.check_value_type("spatial_scale", spatial_scale, [float], self.name)
|
|
4666
4599
|
validator.check_value_type("sample_num", sample_num, [int], self.name)
|
|
4667
4600
|
validator.check_value_type("roi_end_mode", roi_end_mode, [int], self.name)
|
|
4668
|
-
validator.check_int_range(roi_end_mode, 0, 1,
|
|
4601
|
+
validator.check_int_range(roi_end_mode, 0, 1, validator.INC_BOTH, "roi_end_mode", self.name)
|
|
4669
4602
|
self.pooled_height = pooled_height
|
|
4670
4603
|
self.pooled_width = pooled_width
|
|
4671
4604
|
self.spatial_scale = spatial_scale
|
|
@@ -4707,22 +4640,19 @@ class Adam(Primitive):
|
|
|
4707
4640
|
If false, update the gradients without using NAG. Default: False.
|
|
4708
4641
|
|
|
4709
4642
|
Inputs:
|
|
4710
|
-
- **var** (
|
|
4643
|
+
- **var** (Parameter) - Weights to be updated. The shape is :math:`(N, *)` where :math:`*` means,
|
|
4711
4644
|
any number of additional dimensions. The data type can be float16 or float32.
|
|
4712
|
-
- **m** (
|
|
4713
|
-
the shape
|
|
4714
|
-
- **v** (
|
|
4715
|
-
the shape
|
|
4716
|
-
- **beta1_power** (float) - :math:`beta_1^t(\beta_1^{t})` in the updating formula
|
|
4717
|
-
|
|
4718
|
-
- **
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
the data type value should be the same as `var`. The paper suggested value is :math:`0.9`.
|
|
4724
|
-
- **beta2** (float) - The exponential decay rate for the 2nd moment estimations,
|
|
4725
|
-
the data type value should be the same as `var`. The paper suggested value is :math:`0.999`.
|
|
4645
|
+
- **m** (Parameter) - The 1st moment vector in the updating formula,
|
|
4646
|
+
the shape should be the same as `var`.
|
|
4647
|
+
- **v** (Parameter) - the 2nd moment vector in the updating formula,
|
|
4648
|
+
the shape should be the same as `var`.
|
|
4649
|
+
- **beta1_power** (float) - :math:`beta_1^t(\beta_1^{t})` in the updating formula.
|
|
4650
|
+
- **beta2_power** (float) - :math:`beta_2^t(\beta_2^{t})` in the updating formula.
|
|
4651
|
+
- **lr** (float) - :math:`l` in the updating formula. The paper suggested value is :math:`10^{-8}`.
|
|
4652
|
+
- **beta1** (float) - The exponential decay rate for the 1st moment estimations.
|
|
4653
|
+
The paper suggested value is :math:`0.9`.
|
|
4654
|
+
- **beta2** (float) - The exponential decay rate for the 2nd moment estimations.
|
|
4655
|
+
The paper suggested value is :math:`0.999`.
|
|
4726
4656
|
- **epsilon** (float) - Term added to the denominator to improve numerical stability.
|
|
4727
4657
|
- **gradient** (Tensor) - Gradient, has the same shape and data type as `var`.
|
|
4728
4658
|
|
|
@@ -4735,7 +4665,7 @@ class Adam(Primitive):
|
|
|
4735
4665
|
|
|
4736
4666
|
Raises:
|
|
4737
4667
|
TypeError: If neither `use_locking` nor `use_nesterov` is a bool.
|
|
4738
|
-
TypeError: If `var`, `m` or `v` is not a
|
|
4668
|
+
TypeError: If `var`, `m` or `v` is not a Parameter.
|
|
4739
4669
|
TypeError: If `beta1_power`, `beta2_power1`, `lr`, `beta1`, `beta2`, `epsilon` or `gradient` is not a Tensor.
|
|
4740
4670
|
|
|
4741
4671
|
Supported Platforms:
|
|
@@ -4761,6 +4691,18 @@ class Adam(Primitive):
|
|
|
4761
4691
|
[[0.9996838 0.9996838]
|
|
4762
4692
|
[0.9996838 0.9996838]]
|
|
4763
4693
|
"""
|
|
4694
|
+
__mindspore_signature__ = (
|
|
4695
|
+
sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
4696
|
+
sig.make_sig('m', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T1),
|
|
4697
|
+
sig.make_sig('v', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T2),
|
|
4698
|
+
sig.make_sig('beta1_power', dtype=sig.sig_dtype.T3),
|
|
4699
|
+
sig.make_sig('beta2_power', dtype=sig.sig_dtype.T4),
|
|
4700
|
+
sig.make_sig('lr', dtype=sig.sig_dtype.T5),
|
|
4701
|
+
sig.make_sig('beta1', dtype=sig.sig_dtype.T6),
|
|
4702
|
+
sig.make_sig('beta2', dtype=sig.sig_dtype.T7),
|
|
4703
|
+
sig.make_sig('epsilon', dtype=sig.sig_dtype.T8),
|
|
4704
|
+
sig.make_sig('gradient', dtype=sig.sig_dtype.T)
|
|
4705
|
+
)
|
|
4764
4706
|
|
|
4765
4707
|
@prim_attr_register
|
|
4766
4708
|
def __init__(self, use_locking=False, use_nesterov=False):
|
|
@@ -5323,7 +5265,7 @@ class FusedSparseFtrl(Primitive):
|
|
|
5323
5265
|
self.lr = validator.check_positive_float(lr, "lr", self.name)
|
|
5324
5266
|
self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
|
|
5325
5267
|
self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
|
|
5326
|
-
self.lr_power = validator.check_number("lr_power", lr_power, 0,
|
|
5268
|
+
self.lr_power = validator.check_number("lr_power", lr_power, 0, validator.LE, self.name)
|
|
5327
5269
|
self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
5328
5270
|
|
|
5329
5271
|
|
|
@@ -5498,7 +5440,7 @@ class KLDivLoss(Primitive):
|
|
|
5498
5440
|
elif device_target == "GPU":
|
|
5499
5441
|
support_mode = ['none', 'mean', 'sum']
|
|
5500
5442
|
elif device_target == "Ascend":
|
|
5501
|
-
support_mode = ['none', 'batchmean', 'sum']
|
|
5443
|
+
support_mode = ['none', 'batchmean', 'sum', 'mean']
|
|
5502
5444
|
else:
|
|
5503
5445
|
raise ValueError(f"'{self.name}' unknown device target: '{device_target}'")
|
|
5504
5446
|
|
|
@@ -5518,7 +5460,7 @@ class BinaryCrossEntropy(Primitive):
|
|
|
5518
5460
|
|
|
5519
5461
|
In which, :math:`L` indicates the loss of all batch_sizes, :math:`l` indicates the loss of one batch_size,
|
|
5520
5462
|
and n indicates one batch_size in the 1-N range, :math:`w_n` indicates the
|
|
5521
|
-
weight of
|
|
5463
|
+
weight of :math:`n`-th batch of binary cross entropy. Then,
|
|
5522
5464
|
|
|
5523
5465
|
.. math::
|
|
5524
5466
|
\ell(x, y) = \begin{cases}
|
|
@@ -5528,8 +5470,7 @@ class BinaryCrossEntropy(Primitive):
|
|
|
5528
5470
|
\end{cases}
|
|
5529
5471
|
|
|
5530
5472
|
.. warning::
|
|
5531
|
-
- The value of
|
|
5532
|
-
- The value of "y" must be "0" or "1".
|
|
5473
|
+
- The value of :math:`x` must range from 0 to 1.
|
|
5533
5474
|
|
|
5534
5475
|
Args:
|
|
5535
5476
|
reduction (str): Specifies the reduction to be applied to the output.
|
|
@@ -5741,7 +5682,7 @@ class ApplyAdadelta(Primitive):
|
|
|
5741
5682
|
is not supported.
|
|
5742
5683
|
|
|
5743
5684
|
Supported Platforms:
|
|
5744
|
-
``Ascend`` ``
|
|
5685
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
5745
5686
|
|
|
5746
5687
|
Examples:
|
|
5747
5688
|
>>> import numpy as np
|
|
@@ -5818,10 +5759,10 @@ class ApplyAdagrad(Primitive):
|
|
|
5818
5759
|
update_slots (bool): If `True`, `accum` will be updated. Default: True.
|
|
5819
5760
|
|
|
5820
5761
|
Inputs:
|
|
5821
|
-
- **var** (Parameter) - Variable to be updated. With
|
|
5762
|
+
- **var** (Parameter) - Variable to be updated. With float or complex data type.
|
|
5822
5763
|
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
5823
5764
|
- **accum** (Parameter) - Accumulation to be updated. The shape and data type must be the same as `var`.
|
|
5824
|
-
- **lr** (Union[Number, Tensor]) - The learning rate value, must be a scalar. With
|
|
5765
|
+
- **lr** (Union[Number, Tensor]) - The learning rate value, must be a scalar. With float or complex data type.
|
|
5825
5766
|
- **grad** (Tensor) - A tensor for gradient. The shape and data type must be the same as `var`.
|
|
5826
5767
|
|
|
5827
5768
|
Outputs:
|
|
@@ -5831,12 +5772,12 @@ class ApplyAdagrad(Primitive):
|
|
|
5831
5772
|
- **accum** (Tensor) - The same shape and data type as `accum`.
|
|
5832
5773
|
|
|
5833
5774
|
Raises:
|
|
5834
|
-
TypeError: If dtype of `var`, `accum`, `lr` or `grad` is neither
|
|
5775
|
+
TypeError: If dtype of `var`, `accum`, `lr` or `grad` is neither float nor complex.
|
|
5835
5776
|
TypeError: If `lr` is neither a Number nor a Tensor.
|
|
5836
5777
|
RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
|
|
5837
5778
|
|
|
5838
5779
|
Supported Platforms:
|
|
5839
|
-
``Ascend`` ``
|
|
5780
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
5840
5781
|
|
|
5841
5782
|
Examples:
|
|
5842
5783
|
>>> class Net(nn.Cell):
|
|
@@ -5895,7 +5836,7 @@ class ApplyAdagradV2(Primitive):
|
|
|
5895
5836
|
the relatively highest priority data type.
|
|
5896
5837
|
|
|
5897
5838
|
Note:
|
|
5898
|
-
The difference is that `ApplyAdagradV2` has one more small constant value than `ApplyAdagrad`.
|
|
5839
|
+
The difference is that `ApplyAdagradV2` has one more small constant value :math:`\epsilon` than `ApplyAdagrad`.
|
|
5899
5840
|
|
|
5900
5841
|
Args:
|
|
5901
5842
|
epsilon (float): A small value added for numerical stability.
|
|
@@ -6016,7 +5957,7 @@ class SparseApplyAdagradV2(Primitive):
|
|
|
6016
5957
|
- **grad** (Tensor) - Gradients has the same data type as `var` and
|
|
6017
5958
|
:math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
|
|
6018
5959
|
- **indices** (Tensor) - A vector of indices into the first dimension of `var` and `accum`.
|
|
6019
|
-
The type must be int32 and indices.shape[0] = grad.shape[0]
|
|
5960
|
+
The type must be int32 and :math:`indices.shape[0] = grad.shape[0]`.
|
|
6020
5961
|
|
|
6021
5962
|
Outputs:
|
|
6022
5963
|
Tuple of 2 tensors, the updated parameters.
|
|
@@ -6032,7 +5973,7 @@ class SparseApplyAdagradV2(Primitive):
|
|
|
6032
5973
|
RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
|
|
6033
5974
|
|
|
6034
5975
|
Supported Platforms:
|
|
6035
|
-
``Ascend`` ``
|
|
5976
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
6036
5977
|
|
|
6037
5978
|
Examples:
|
|
6038
5979
|
>>> class Net(nn.Cell):
|
|
@@ -6201,10 +6142,10 @@ class SparseApplyProximalAdagrad(Primitive):
|
|
|
6201
6142
|
- **l2** (Union[Number, Tensor]) - l2 regularization strength, must be a float number or
|
|
6202
6143
|
a scalar tensor with float16 or float32 data type. It must be non-negative.
|
|
6203
6144
|
- **grad** (Tensor) - A tensor of the same type as `var` and
|
|
6204
|
-
grad.shape[1:] = var.shape[1:] if var.shape > 1.
|
|
6145
|
+
:math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
|
|
6205
6146
|
- **indices** (Tensor) - A tensor of indices in the first dimension of `var` and `accum`.
|
|
6206
6147
|
If there are duplicates in `indices`, the behavior is undefined. Must be one of the
|
|
6207
|
-
following types: int32, int64 and indices.shape[0] = grad.shape[0]
|
|
6148
|
+
following types: int32, int64 and :math:`indices.shape[0] = grad.shape[0]`.
|
|
6208
6149
|
|
|
6209
6150
|
Outputs:
|
|
6210
6151
|
Tuple of 2 tensors, the updated parameters.
|
|
@@ -6220,7 +6161,7 @@ class SparseApplyProximalAdagrad(Primitive):
|
|
|
6220
6161
|
RuntimeError: If the data type of `var`, `accum` and `grad` conversion of Parameter is not supported.
|
|
6221
6162
|
|
|
6222
6163
|
Supported Platforms:
|
|
6223
|
-
``Ascend`` ``GPU``
|
|
6164
|
+
``Ascend`` ``GPU``
|
|
6224
6165
|
|
|
6225
6166
|
Examples:
|
|
6226
6167
|
>>> class Net(nn.Cell):
|
|
@@ -6669,6 +6610,10 @@ class ApplyFtrl(Primitive):
|
|
|
6669
6610
|
|
|
6670
6611
|
For more details, please refer to :class:`mindspore.nn.FTRL`.
|
|
6671
6612
|
|
|
6613
|
+
Note:
|
|
6614
|
+
Currently, only positive numbers are supported on the Ascend platform,
|
|
6615
|
+
and the calculation results for other scenarios are not defined.
|
|
6616
|
+
|
|
6672
6617
|
Args:
|
|
6673
6618
|
use_locking (bool): Use locks for updating operation if true . Default: False.
|
|
6674
6619
|
|
|
@@ -6697,6 +6642,9 @@ class ApplyFtrl(Primitive):
|
|
|
6697
6642
|
TypeError: If dtype of `var`, `grad`, `lr`, `l1`, `l2` or `lr_power` is neither float16 nor float32.
|
|
6698
6643
|
TypeError: If `lr`, `l1`, `l2` or `lr_power` is neither a Number nor a Tensor.
|
|
6699
6644
|
TypeError: If `grad` is not a Tensor.
|
|
6645
|
+
RuntimeError: If the parameter types of `var`, `accum` and `linear` are inconsistent.
|
|
6646
|
+
RuntimeError: If the parameter types of `grad`, `lr`, `l1`, `l2`, `lr_power` are inconsistent with `var`
|
|
6647
|
+
and the precision is greater than `var`.
|
|
6700
6648
|
|
|
6701
6649
|
Supported Platforms:
|
|
6702
6650
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -6730,6 +6678,17 @@ class ApplyFtrl(Primitive):
|
|
|
6730
6678
|
[ 0.00066425 0.15075898]]
|
|
6731
6679
|
"""
|
|
6732
6680
|
|
|
6681
|
+
__mindspore_signature__ = (
|
|
6682
|
+
sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
6683
|
+
sig.make_sig('accum', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
6684
|
+
sig.make_sig('linear', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
6685
|
+
sig.make_sig('grad', dtype=sig.sig_dtype.T),
|
|
6686
|
+
sig.make_sig('lr', dtype=sig.sig_dtype.T),
|
|
6687
|
+
sig.make_sig('l1', dtype=sig.sig_dtype.T),
|
|
6688
|
+
sig.make_sig('l2', dtype=sig.sig_dtype.T),
|
|
6689
|
+
sig.make_sig('lr_power', dtype=sig.sig_dtype.T)
|
|
6690
|
+
)
|
|
6691
|
+
|
|
6733
6692
|
@prim_attr_register
|
|
6734
6693
|
def __init__(self, use_locking=False):
|
|
6735
6694
|
"""Initialize ApplyFtrl."""
|
|
@@ -6761,10 +6720,11 @@ class SparseApplyFtrl(Primitive):
|
|
|
6761
6720
|
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
6762
6721
|
- **accum** (Parameter) - The accumulation to be updated, must be same data type and shape as `var`.
|
|
6763
6722
|
- **linear** (Parameter) - The linear coefficient to be updated, must be the same data type and shape as `var`.
|
|
6764
|
-
- **grad** (Tensor) - A tensor of the same type as `var` and grad.shape[1:] = var.shape[1:]
|
|
6723
|
+
- **grad** (Tensor) - A tensor of the same type as `var` and :math:`grad.shape[1:] = var.shape[1:]`
|
|
6724
|
+
if var.shape > 1.
|
|
6765
6725
|
- **indices** (Tensor) - A tensor of indices in the first dimension of `var` and `accum`.
|
|
6766
6726
|
If there are duplicates in `indices`, the behavior is undefined.
|
|
6767
|
-
The type must be int32 or int64 and indices.shape[0] = grad.shape[0]
|
|
6727
|
+
The type must be int32 or int64 and :math:`indices.shape[0] = grad.shape[0]`.
|
|
6768
6728
|
|
|
6769
6729
|
Outputs:
|
|
6770
6730
|
- **var** (Tensor) - Tensor, has the same shape and data type as `var`.
|
|
@@ -6823,83 +6783,19 @@ class SparseApplyFtrl(Primitive):
|
|
|
6823
6783
|
self.lr = validator.check_positive_float(lr, "lr", self.name)
|
|
6824
6784
|
self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
|
|
6825
6785
|
self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
|
|
6826
|
-
self.lr_power = validator.check_number("lr_power", lr_power, 0,
|
|
6786
|
+
self.lr_power = validator.check_number("lr_power", lr_power, 0, validator.LE, self.name)
|
|
6827
6787
|
self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
6828
6788
|
self.init_prim_io_names(inputs=['var', 'accum', 'linear', 'grad', 'indices'],
|
|
6829
|
-
outputs=['var', 'accum', 'linear'])
|
|
6830
|
-
self.add_prim_attr('side_effect_mem', True)
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
class SparseApplyFtrlV2(PrimitiveWithInfer):
|
|
6834
|
-
"""
|
|
6835
|
-
Updates relevant entries according to the FTRL-proximal scheme. This class has one more attribute, named
|
|
6836
|
-
l2_shrinkage, than class SparseApplyFtrl.
|
|
6837
|
-
|
|
6838
|
-
All of inputs except `indices` comply with the implicit type conversion rules to make the data types consistent.
|
|
6839
|
-
If they have different data types, the lower priority data type will be converted to
|
|
6840
|
-
the relatively highest priority data type.
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
Args:
|
|
6844
|
-
lr (float): The learning rate value, must be positive.
|
|
6845
|
-
l1 (float): l1 regularization strength, must be greater than or equal to zero.
|
|
6846
|
-
l2 (float): l2 regularization strength, must be greater than or equal to zero.
|
|
6847
|
-
l2_shrinkage (float): L2 shrinkage regularization.
|
|
6848
|
-
lr_power (float): Learning rate power controls how the learning rate decreases during training,
|
|
6849
|
-
must be less than or equal to zero. Use fixed learning rate if `lr_power` is zero.
|
|
6850
|
-
use_locking (bool, optional): If `True`, the var and accumulation tensors will be protected from being updated.
|
|
6851
|
-
Default: False.
|
|
6852
|
-
|
|
6853
|
-
Inputs:
|
|
6854
|
-
- **var** (Parameter) - The variable to be updated. The data type must be float16 or float32.
|
|
6855
|
-
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
6856
|
-
- **accum** (Parameter) - The accumulation to be updated, must be same data type and shape as `var`.
|
|
6857
|
-
- **linear** (Parameter) - the linear coefficient to be updated, must be same data type and shape as `var`.
|
|
6858
|
-
- **grad** (Tensor) - A tensor of the same type as `var` and
|
|
6859
|
-
:math:`grad.shape[1:] = var.shape[1:]` if var.shape > 1.
|
|
6860
|
-
- **indices** (Tensor) - A vector of indices in the first dimension of `var` and `accum`.
|
|
6861
|
-
The type must be int32 and indices.shape[0] = grad.shape[0].
|
|
6862
|
-
|
|
6863
|
-
Outputs:
|
|
6864
|
-
Tuple of 3 Tensor, the updated parameters.
|
|
6789
|
+
outputs=['var', 'accum', 'linear'])
|
|
6790
|
+
self.add_prim_attr('side_effect_mem', True)
|
|
6865
6791
|
|
|
6866
|
-
- **var** (Tensor) - Tensor, has the same shape and data type as `var`.
|
|
6867
|
-
- **accum** (Tensor) - Tensor, has the same shape and data type as `accum`.
|
|
6868
|
-
- **linear** (Tensor) - Tensor, has the same shape and data type as `linear`.
|
|
6869
6792
|
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
TypeError: If dtype of `var`, `accum`, `linear` or `grad` is neither float16 nor float32.
|
|
6874
|
-
TypeError: If dtype of `indices` is not int32.
|
|
6875
|
-
RuntimeError: If the data type of all of inputs except `indices` conversion of Parameter is not supported.
|
|
6793
|
+
class SparseApplyFtrlV2(PrimitiveWithInfer):
|
|
6794
|
+
"""
|
|
6795
|
+
The SparseApplyFtrlV2 interface is deprecated, please use the :class:`mindspore.ops.SparseApplyFtrl` instead.
|
|
6876
6796
|
|
|
6877
6797
|
Supported Platforms:
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
Examples:
|
|
6881
|
-
>>> class SparseApplyFtrlV2Net(nn.Cell):
|
|
6882
|
-
... def __init__(self):
|
|
6883
|
-
... super(SparseApplyFtrlV2Net, self).__init__()
|
|
6884
|
-
... self.sparse_apply_ftrl_v2 = ops.SparseApplyFtrlV2(lr=0.01, l1=0.0, l2=0.0,
|
|
6885
|
-
... l2_shrinkage=0.0, lr_power=-0.5)
|
|
6886
|
-
... self.var = Parameter(Tensor(np.array([[0.2, 0.3]]).astype(np.float32)), name="var")
|
|
6887
|
-
... self.accum = Parameter(Tensor(np.array([[0.5, 0.9]]).astype(np.float32)), name="accum")
|
|
6888
|
-
... self.linear = Parameter(Tensor(np.array([[0.7, 0.5]]).astype(np.float32)), name="linear")
|
|
6889
|
-
...
|
|
6890
|
-
... def construct(self, grad, indices):
|
|
6891
|
-
... out = self.sparse_apply_ftrl_v2(self.var, self.accum, self.linear, grad, indices)
|
|
6892
|
-
... return out
|
|
6893
|
-
...
|
|
6894
|
-
>>> net = SparseApplyFtrlV2Net()
|
|
6895
|
-
>>> grad = Tensor(np.array([[0.8, 0.5]]).astype(np.float32))
|
|
6896
|
-
>>> indices = Tensor(np.ones([1]), mindspore.int32)
|
|
6897
|
-
>>> output = net(grad, indices)
|
|
6898
|
-
>>> print(output)
|
|
6899
|
-
(Tensor(shape=[1, 2], dtype=Float32, value=
|
|
6900
|
-
[[ 2.00000003e-01, 3.00000012e-01]]), Tensor(shape=[1, 2], dtype=Float32, value=
|
|
6901
|
-
[[ 5.00000000e-01, 8.99999976e-01]]), Tensor(shape=[1, 2], dtype=Float32, value=
|
|
6902
|
-
[[ 6.99999988e-01, 5.00000000e-01]]))
|
|
6798
|
+
Deprecated
|
|
6903
6799
|
"""
|
|
6904
6800
|
|
|
6905
6801
|
__mindspore_signature__ = (
|
|
@@ -6910,6 +6806,7 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
|
|
|
6910
6806
|
sig.make_sig('indices', dtype=sig.sig_dtype.T1)
|
|
6911
6807
|
)
|
|
6912
6808
|
|
|
6809
|
+
@deprecated("2.1", "ops.SparseApplyFtrl", False)
|
|
6913
6810
|
@prim_attr_register
|
|
6914
6811
|
def __init__(self, lr, l1, l2, l2_shrinkage, lr_power, use_locking=False):
|
|
6915
6812
|
"""Initialize SparseApplyFtrlV2."""
|
|
@@ -6920,18 +6817,18 @@ class SparseApplyFtrlV2(PrimitiveWithInfer):
|
|
|
6920
6817
|
self.lr = validator.check_positive_float(lr, "lr", self.name)
|
|
6921
6818
|
self.l1 = validator.check_non_negative_float(l1, "l1", self.name)
|
|
6922
6819
|
self.l2 = validator.check_non_negative_float(l2, "l2", self.name)
|
|
6923
|
-
self.lr_power = validator.check_number("lr_power", lr_power, 0,
|
|
6820
|
+
self.lr_power = validator.check_number("lr_power", lr_power, 0, validator.LE, self.name)
|
|
6924
6821
|
self.l2_shrinkage = validator.check_value_type("l2_shrinkage", l2_shrinkage, [float], self.name)
|
|
6925
6822
|
self.use_locking = validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
6926
6823
|
self.add_prim_attr('side_effect_mem', True)
|
|
6927
6824
|
|
|
6928
6825
|
def infer_shape(self, var_shape, accum_shape, linear_shape, grad_shape, indices_shape):
|
|
6929
|
-
validator.check('var shape', var_shape, 'accum shape', accum_shape,
|
|
6930
|
-
validator.check('var shape', var_shape, 'linear shape', linear_shape,
|
|
6826
|
+
validator.check('var shape', var_shape, 'accum shape', accum_shape, validator.EQ, self.name)
|
|
6827
|
+
validator.check('var shape', var_shape, 'linear shape', linear_shape, validator.EQ, self.name)
|
|
6931
6828
|
if len(var_shape) > 1:
|
|
6932
|
-
validator.check('var_shape[1:]', var_shape[1:], 'grad_shape[1:]', grad_shape[1:],
|
|
6933
|
-
validator.check_int(len(indices_shape), 1,
|
|
6934
|
-
validator.check('grad_shape[0]', grad_shape[0], 'indices_shape[0]', indices_shape[0],
|
|
6829
|
+
validator.check('var_shape[1:]', var_shape[1:], 'grad_shape[1:]', grad_shape[1:], validator.EQ, self.name)
|
|
6830
|
+
validator.check_int(len(indices_shape), 1, validator.EQ, "indices rank", self.name)
|
|
6831
|
+
validator.check('grad_shape[0]', grad_shape[0], 'indices_shape[0]', indices_shape[0], validator.EQ, self.name)
|
|
6935
6832
|
return var_shape, accum_shape, linear_shape
|
|
6936
6833
|
|
|
6937
6834
|
def infer_dtype(self, var_dtype, accum_dtype, linear_dtype, grad_dtype, indices_dtype):
|
|
@@ -6954,11 +6851,11 @@ class Dropout(PrimitiveWithCheck):
|
|
|
6954
6851
|
``Ascend`` ``GPU`` ``CPU``
|
|
6955
6852
|
|
|
6956
6853
|
Examples:
|
|
6957
|
-
>>> dropout = ops.
|
|
6854
|
+
>>> dropout = ops.Dropout(keep_prob=0.5)
|
|
6958
6855
|
>>> x = Tensor(np.ones([1, 2, 3, 4, 5]), mindspore.float32)
|
|
6959
6856
|
>>> output, mask = dropout(x)
|
|
6960
|
-
>>> print(output.shape)
|
|
6961
|
-
(1, 2, 3, 4, 5)
|
|
6857
|
+
>>> print(output.shape, mask.shape, mask.dtype)
|
|
6858
|
+
(1, 2, 3, 4, 5) (16,) UInt8
|
|
6962
6859
|
"""
|
|
6963
6860
|
|
|
6964
6861
|
@prim_attr_register
|
|
@@ -6966,10 +6863,10 @@ class Dropout(PrimitiveWithCheck):
|
|
|
6966
6863
|
"""Initialize Dropout."""
|
|
6967
6864
|
self.seed0 = validator.check_value_type("Seed0", Seed0, [int], self.name)
|
|
6968
6865
|
self.seed1 = validator.check_value_type("Seed1", Seed1, [int], self.name)
|
|
6969
|
-
self.keep_prob = validator.check_float_range(keep_prob, 0, 1,
|
|
6866
|
+
self.keep_prob = validator.check_float_range(keep_prob, 0, 1, validator.INC_RIGHT, "keep_prob", self.name)
|
|
6970
6867
|
|
|
6971
6868
|
def check_shape(self, x_shape):
|
|
6972
|
-
validator.check_int(len(x_shape), 1,
|
|
6869
|
+
validator.check_int(len(x_shape), 1, validator.GE, "x_shape", self.name)
|
|
6973
6870
|
|
|
6974
6871
|
def check_dtype(self, x_dtype):
|
|
6975
6872
|
valid_dtypes = (mstype.float16, mstype.float32, mstype.float64)
|
|
@@ -6987,7 +6884,25 @@ class Dropout2D(PrimitiveWithInfer):
|
|
|
6987
6884
|
Note:
|
|
6988
6885
|
The keep probability :math:`keep\_prob` is equal to :math:`1 - p` in :func:`mindspore.ops.dropout2d`.
|
|
6989
6886
|
|
|
6990
|
-
|
|
6887
|
+
Args:
|
|
6888
|
+
keep_prob (float, optional): The keep probability of a channel, between 0 and 1, e.g. `keep_prob` = 0.8,
|
|
6889
|
+
means dropping out 20% of channels. Default: 0.5.
|
|
6890
|
+
|
|
6891
|
+
Inputs:
|
|
6892
|
+
- **x** (Tensor) - A 4-D tensor with shape :math:`(N, C, H, W)`, where N is the batch size, C is the number
|
|
6893
|
+
of channels, H is the feature height, and W is the feature width. The data type should be int8, int16, int32,
|
|
6894
|
+
int64, float16 or float32.
|
|
6895
|
+
|
|
6896
|
+
Outputs:
|
|
6897
|
+
- **output** (Tensor) - With the same shape and data type as `x`.
|
|
6898
|
+
- **mask** (Tensor) - With the same shape as `x` and the data type is bool.
|
|
6899
|
+
|
|
6900
|
+
Raises:
|
|
6901
|
+
TypeError: If `x` is not a Tensor.
|
|
6902
|
+
TypeError: If dtype of `x` is not int8, int16, int32, int64, float16, float32 or float64.
|
|
6903
|
+
TypeError: If the data type of `keep_prob` is not float.
|
|
6904
|
+
ValueError: If `keep_prob` is out of the range `[0.0, 1.0]`.
|
|
6905
|
+
ValueError: If `x` shape is not `4D`.
|
|
6991
6906
|
|
|
6992
6907
|
Supported Platforms:
|
|
6993
6908
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -7005,7 +6920,7 @@ class Dropout2D(PrimitiveWithInfer):
|
|
|
7005
6920
|
"""Initialize Dropout2D."""
|
|
7006
6921
|
super().__init__("Dropout2D")
|
|
7007
6922
|
self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
|
|
7008
|
-
self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0,
|
|
6923
|
+
self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, validator.INC_BOTH, "keep_prob", self.name)
|
|
7009
6924
|
|
|
7010
6925
|
|
|
7011
6926
|
class Dropout3D(PrimitiveWithInfer):
|
|
@@ -7014,12 +6929,28 @@ class Dropout3D(PrimitiveWithInfer):
|
|
|
7014
6929
|
with probability 1-`keep_prob` from a Bernoulli distribution(For a 5-dimensional tensor with a shape of NCDHW,
|
|
7015
6930
|
the channel feature map refers to a 3-dimensional feature map with a shape of DHW).
|
|
7016
6931
|
|
|
7017
|
-
Dropout3D can improve the independence between channel feature maps.
|
|
7018
|
-
|
|
7019
6932
|
Note:
|
|
7020
6933
|
The keep probability :math:`keep\_prob` is equal to :math:`1 - p` in :func:`mindspore.ops.dropout3d`.
|
|
7021
6934
|
|
|
7022
|
-
|
|
6935
|
+
Dropout3D can improve the independence between channel feature maps.
|
|
6936
|
+
|
|
6937
|
+
Args:
|
|
6938
|
+
keep_prob (float): The keep probability of a channel, between 0 and 1, e.g. `keep_prob` = 0.8,
|
|
6939
|
+
means dropping out 20% of channels. Default: 0.5.
|
|
6940
|
+
|
|
6941
|
+
Inputs:
|
|
6942
|
+
- **x** (Tensor) - A 5-D tensor with shape :math:`(N, C, D, H, W)`, where N is the batch size, C is the number
|
|
6943
|
+
of channels, D is the feature depth, H is the feature height, and W is the feature width.
|
|
6944
|
+
The data type should be int8, int16, int32, int64, float16 or float32.
|
|
6945
|
+
|
|
6946
|
+
Outputs:
|
|
6947
|
+
- **output** (Tensor) - With the same shape and data type as `x`.
|
|
6948
|
+
- **mask** (Tensor) - With the same shape as `x` and the data type is bool.
|
|
6949
|
+
|
|
6950
|
+
Raises:
|
|
6951
|
+
TypeError: If the data type of `keep_prob` is not float.
|
|
6952
|
+
ValueError: If `keep_prob` is out of the range [0.0, 1.0];
|
|
6953
|
+
or if the dim of input is not 5-D.
|
|
7023
6954
|
|
|
7024
6955
|
Supported Platforms:
|
|
7025
6956
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -7037,7 +6968,7 @@ class Dropout3D(PrimitiveWithInfer):
|
|
|
7037
6968
|
"""Initialize Dropout3D."""
|
|
7038
6969
|
super().__init__("Dropout3D")
|
|
7039
6970
|
self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
|
|
7040
|
-
self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0,
|
|
6971
|
+
self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, validator.INC_BOTH, "keep_prob", self.name)
|
|
7041
6972
|
|
|
7042
6973
|
|
|
7043
6974
|
class CTCLoss(Primitive):
|
|
@@ -7133,7 +7064,7 @@ class CTCGreedyDecoder(Primitive):
|
|
|
7133
7064
|
Refer to :func:`mindspore.ops.ctc_greedy_decoder` for more details.
|
|
7134
7065
|
|
|
7135
7066
|
Supported Platforms:
|
|
7136
|
-
``Ascend`` ``CPU``
|
|
7067
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
7137
7068
|
|
|
7138
7069
|
Examples:
|
|
7139
7070
|
>>> inputs = Tensor(np.array([[[0.6, 0.4, 0.2], [0.8, 0.6, 0.3]],
|
|
@@ -7173,23 +7104,24 @@ class BasicLSTMCell(PrimitiveWithInfer):
|
|
|
7173
7104
|
def __init__(self, keep_prob=1.0, forget_bias=1.0, state_is_tuple=True, activation='tanh'):
|
|
7174
7105
|
"""Initialize BasicLSTMCell."""
|
|
7175
7106
|
self.keep_prob = validator.check_value_type("keep_prob", keep_prob, [float], self.name)
|
|
7176
|
-
self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0,
|
|
7107
|
+
self.keep_prob = validator.check_float_range(keep_prob, 0.0, 1.0, validator.INC_BOTH, "keep_prob", self.name)
|
|
7177
7108
|
self.forget_bias = validator.check_value_type("forget_bias", forget_bias, [float], self.name)
|
|
7178
7109
|
self.state_is_tuple = validator.check_value_type("state_is_tuple", state_is_tuple, [bool], self.name)
|
|
7179
7110
|
self.activation = validator.check_string(activation, ['tanh'], "activation", self.name)
|
|
7180
7111
|
|
|
7181
7112
|
def infer_shape(self, x_shape, h_shape, c_shape, w_shape, b_shape):
|
|
7182
|
-
validator.check_int(len(x_shape), 2,
|
|
7183
|
-
validator.check_int(len(h_shape), 2,
|
|
7184
|
-
validator.check_int(len(c_shape), 2,
|
|
7185
|
-
validator.check_int(len(w_shape), 2,
|
|
7186
|
-
validator.check_int(len(b_shape), 1,
|
|
7187
|
-
validator.check("x_shape[0]", x_shape[0], "h_shape[0]", h_shape[0],
|
|
7188
|
-
validator.check("c_shape[0]", c_shape[0], "h_shape[0]", h_shape[0],
|
|
7189
|
-
validator.check("c_shape[1]", c_shape[1], "h_shape[1]", h_shape[1],
|
|
7190
|
-
validator.check("w_shape[1]", w_shape[1], "4*h_shape[1]", 4 * h_shape[1],
|
|
7191
|
-
validator.check("w_shape[0]", w_shape[0], "x_shape[1]+h_shape[1]", x_shape[1] + h_shape[1],
|
|
7192
|
-
|
|
7113
|
+
validator.check_int(len(x_shape), 2, validator.EQ, "x rank", self.name)
|
|
7114
|
+
validator.check_int(len(h_shape), 2, validator.EQ, "h rank", self.name)
|
|
7115
|
+
validator.check_int(len(c_shape), 2, validator.EQ, "c rank", self.name)
|
|
7116
|
+
validator.check_int(len(w_shape), 2, validator.EQ, "w rank", self.name)
|
|
7117
|
+
validator.check_int(len(b_shape), 1, validator.EQ, "b rank", self.name)
|
|
7118
|
+
validator.check("x_shape[0]", x_shape[0], "h_shape[0]", h_shape[0], validator.EQ, self.name)
|
|
7119
|
+
validator.check("c_shape[0]", c_shape[0], "h_shape[0]", h_shape[0], validator.EQ, self.name)
|
|
7120
|
+
validator.check("c_shape[1]", c_shape[1], "h_shape[1]", h_shape[1], validator.EQ, self.name)
|
|
7121
|
+
validator.check("w_shape[1]", w_shape[1], "4*h_shape[1]", 4 * h_shape[1], validator.EQ, self.name)
|
|
7122
|
+
validator.check("w_shape[0]", w_shape[0], "x_shape[1]+h_shape[1]", x_shape[1] + h_shape[1],
|
|
7123
|
+
validator.EQ, self.name)
|
|
7124
|
+
validator.check("b_shape[0]", b_shape[0], "4*h_shape[1]", 4 * h_shape[1], validator.EQ, self.name)
|
|
7193
7125
|
ct_shape = c_shape
|
|
7194
7126
|
ht_shape = c_shape
|
|
7195
7127
|
it_shape = c_shape
|
|
@@ -7242,8 +7174,10 @@ class DynamicRNN(Primitive):
|
|
|
7242
7174
|
keep_prob (float): A float identifying the keep prob in the operator. Default: 1.0.
|
|
7243
7175
|
cell_clip (float): A float identifying the cell clip in the operator. Default: -1.0.
|
|
7244
7176
|
num_proj (int): An integer identifying the number projection in the operator. Default: 0.
|
|
7245
|
-
time_major (bool): A bool
|
|
7246
|
-
|
|
7177
|
+
time_major (bool): A bool specify the data format of `x`. If it is set to True, the format is
|
|
7178
|
+
:math:`(num\_step, batch\_size, input\_size)`, if it is set to False, the format is
|
|
7179
|
+
:math:`(batch\_size, num\_step, input\_size)`.
|
|
7180
|
+
Default: True. Only supports True at present.
|
|
7247
7181
|
activation (str): A string identifying the type of activation function in the operator. Default: 'tanh'.
|
|
7248
7182
|
Only 'tanh' is currently supported.
|
|
7249
7183
|
forget_bias (float): A float identifying the forget bias in the operator. Default: 0.0.
|
|
@@ -7500,7 +7434,7 @@ class InTopK(Primitive):
|
|
|
7500
7434
|
validator.check_value_type("k", k, [int], self.name)
|
|
7501
7435
|
|
|
7502
7436
|
|
|
7503
|
-
class LRN(
|
|
7437
|
+
class LRN(Primitive):
|
|
7504
7438
|
r"""
|
|
7505
7439
|
Local Response Normalization.
|
|
7506
7440
|
|
|
@@ -7509,7 +7443,7 @@ class LRN(PrimitiveWithInfer):
|
|
|
7509
7443
|
b_{c} = a_{c}\left(k + \frac{\alpha}{n}
|
|
7510
7444
|
\sum_{c'=\max(0, c-n/2)}^{\min(N-1,c+n/2)}a_{c'}^2\right)^{-\beta}
|
|
7511
7445
|
|
|
7512
|
-
where the :math:`a_{c}` indicates the specific value of the pixel corresponding to c in feature map;
|
|
7446
|
+
where the :math:`a_{c}` indicates the specific value of the pixel corresponding to :math:`c` in feature map;
|
|
7513
7447
|
where the :math:`n/2` indicates the `depth_radius`; where the :math:`k` indicates the `bias`;
|
|
7514
7448
|
where the :math:`\alpha` indicates the `alpha`; where the :math:`\beta` indicates the `beta`.
|
|
7515
7449
|
|
|
@@ -7599,10 +7533,10 @@ class AvgPool3D(Primitive):
|
|
|
7599
7533
|
|
|
7600
7534
|
- pad: Implicit paddings on both sides of the input in depth, height, width. The number of `pad` will
|
|
7601
7535
|
be padded to the input Tensor borders. `pad` must be greater than or equal to 0.
|
|
7602
|
-
pad (Union(int, tuple[int])): The pad value to be filled. Default: 0. If `pad` is an integer,
|
|
7603
|
-
|
|
7604
|
-
|
|
7605
|
-
|
|
7536
|
+
pad (Union(int, tuple[int], list[int])): The pad value to be filled. Default: 0. If `pad` is an integer,
|
|
7537
|
+
the paddings of head, tail, top, bottom, left and right are the same, equal to pad.
|
|
7538
|
+
If `pad` is a tuple of six integers, the padding of head, tail, top, bottom, left and right equal to
|
|
7539
|
+
pad[0], pad[1], pad[2], pad[3], pad[4] and pad[5] correspondingly.
|
|
7606
7540
|
ceil_mode (bool): If True, ceil instead of floor to compute the output shape. Default: False.
|
|
7607
7541
|
count_include_pad (bool): If True, averaging calculation will include the zero-padding. Default: True.
|
|
7608
7542
|
divisor_override (int): If specified, it will be used as divisor in the averaging calculation,
|
|
@@ -7650,7 +7584,7 @@ class AvgPool3D(Primitive):
|
|
|
7650
7584
|
self.add_prim_attr('kernel_size', self.kernel_size)
|
|
7651
7585
|
self.strides = _check_3d_int_or_tuple('strides', strides, self.name, ret_five=True)
|
|
7652
7586
|
self.add_prim_attr('strides', self.strides)
|
|
7653
|
-
validator.check_value_type('pad', pad, (int, tuple), self.name)
|
|
7587
|
+
validator.check_value_type('pad', pad, (int, tuple, list), self.name)
|
|
7654
7588
|
if isinstance(pad, int):
|
|
7655
7589
|
pad = (pad,) * 6
|
|
7656
7590
|
if len(pad) != 6:
|
|
@@ -7678,7 +7612,104 @@ class Conv3D(Primitive):
|
|
|
7678
7612
|
r"""
|
|
7679
7613
|
3D convolution layer.
|
|
7680
7614
|
|
|
7681
|
-
|
|
7615
|
+
Applies a 3D convolution over an input tensor which is typically of shape
|
|
7616
|
+
:math:`(N, C_{in}, D_{in}, H_{in}, W_{in})` and output shape
|
|
7617
|
+
:math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`, where :math:`N` is batch size, :math:`C` is channel number,
|
|
7618
|
+
:math:`D` is depth, :math:`H, W` is feature height and width respectively.
|
|
7619
|
+
the output value of a layer is calculated as:
|
|
7620
|
+
|
|
7621
|
+
.. math::
|
|
7622
|
+
|
|
7623
|
+
\operatorname{out}\left(N_{i}, C_{\text {out}_j}\right)=\operatorname{bias}\left(C_{\text {out}_j}\right)+
|
|
7624
|
+
\sum_{k=0}^{C_{in}-1} ccor(\text {weight}\left(C_{\text {out}_j}, k\right),
|
|
7625
|
+
\operatorname{input}\left(N_{i}, k\right))
|
|
7626
|
+
|
|
7627
|
+
where :math:`k` is kernel,
|
|
7628
|
+
:math:`ccor` is the `cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_ ,
|
|
7629
|
+
:math:`C_{in}` is the channel number of the input, :math:`out_{j}` corresponds to the jth channel of
|
|
7630
|
+
the output and :math:`j` is in the range of :math:`[0, C_{out}-1]`. :math:`\text{weight}(C_{\text{out}_j}, k)`
|
|
7631
|
+
is a convolution kernel slice with shape
|
|
7632
|
+
:math:`(\text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`,
|
|
7633
|
+
where :math:`\text{kernel_size[0]}`, :math:`\text{kernel_size[1]}` and :math:`\text{kernel_size[2]}` are
|
|
7634
|
+
the depth, height and width of the convolution kernel respectively. :math:`\text{bias}` is the bias parameter
|
|
7635
|
+
and :math:`\text{X}` is the input tensor.
|
|
7636
|
+
The shape of full convolution kernel is
|
|
7637
|
+
:math:`(C_{out}, C_{in} / \text{groups}, \text{kernel_size[0]}, \text{kernel_size[1]}, \text{kernel_size[2]})`,
|
|
7638
|
+
where `groups` is the number of groups to split `input` in the channel dimension.
|
|
7639
|
+
|
|
7640
|
+
For more details, please refer to the paper `Gradient Based Learning Applied to Document
|
|
7641
|
+
Recognition <http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_ .
|
|
7642
|
+
|
|
7643
|
+
If the 'pad_mode' is set to be "valid", the output depth, height and width will be
|
|
7644
|
+
:math:`\left \lfloor{1 + \frac{D_{in} + 2 \times \text{padding} - \text{ks_d} -
|
|
7645
|
+
(\text{ks_d} - 1) \times (\text{dilation} - 1) }{\text{stride}}} \right \rfloor` and
|
|
7646
|
+
:math:`\left \lfloor{1 + \frac{H_{in} + 2 \times \text{padding} - \text{ks_h} -
|
|
7647
|
+
(\text{ks_h} - 1) \times (\text{dilation} - 1) }{\text{stride}}} \right \rfloor` and
|
|
7648
|
+
:math:`\left \lfloor{1 + \frac{W_{in} + 2 \times \text{padding} - \text{ks_w} -
|
|
7649
|
+
(\text{ks_w} - 1) \times (\text{dilation} - 1) }{\text{stride}}} \right \rfloor` respectively. Where
|
|
7650
|
+
:math:`dilation` is Spacing between kernel elements, :math:`stride` is The step length of each step,
|
|
7651
|
+
:math:`padding` is zero-padding added to both sides of the input.
|
|
7652
|
+
|
|
7653
|
+
Args:
|
|
7654
|
+
out_channel (int): The number of output channel :math:`C_{out}`.
|
|
7655
|
+
kernel_size (Union[int, tuple[int]]): Specifies the depth, height
|
|
7656
|
+
and width of the 3D convolution window. It can be a single int or a tuple of 3 integers.
|
|
7657
|
+
Single int means the value is for the depth, height and width
|
|
7658
|
+
of the kernel. A tuple of 3 ints corresponds to the depth, height and width of the kernel respectively.
|
|
7659
|
+
mode (int): Modes for different convolutions. It is currently not used. Default: 1.
|
|
7660
|
+
stride (Union[int, tuple[int]], optional): The distance of kernel moving, it can be an int number
|
|
7661
|
+
that represents the depth, height and width of movement or a tuple of three int numbers that
|
|
7662
|
+
represent depth, height and width movement respectively. Default: 1.
|
|
7663
|
+
pad_mode (str, optional): Specifies padding mode. The optional values are
|
|
7664
|
+
"same", "valid" and "pad". Default: "valid".
|
|
7665
|
+
|
|
7666
|
+
- same: Adopts the way of completion. The depth, height and width of the output will be equal to
|
|
7667
|
+
the input `x` divided by stride. The padding will be evenly calculated in head and tail, top and bottom,
|
|
7668
|
+
left and right directions possiblily.
|
|
7669
|
+
Otherwise, the last extra padding will be calculated from the tail, bottom and the right side.
|
|
7670
|
+
If this mode is set, `pad` must be 0.
|
|
7671
|
+
|
|
7672
|
+
- valid: Adopts the way of discarding. The possible largest depth, height and width of output
|
|
7673
|
+
will be returned without padding. Extra pixels will be discarded. If this mode is set, `pad`
|
|
7674
|
+
must be 0.
|
|
7675
|
+
|
|
7676
|
+
- pad: Implicit paddings on both sides of the input in depth, height and width. The number of `pad` will
|
|
7677
|
+
be padded to the input Tensor borders. `pad` must be greater than or equal to 0.
|
|
7678
|
+
|
|
7679
|
+
pad (Union(int, tuple[int])): The pad value to be filled. Default: 0. If `pad` is an integer, the paddings of
|
|
7680
|
+
head, tail, top, bottom, left and right are the same, equal to pad. If `pad` is a tuple of six
|
|
7681
|
+
integers, the padding of head, tail, top, bottom, left and right equal to pad[0], pad[1], pad[2],
|
|
7682
|
+
pad[3], pad[4] and pad[5] correspondingly.
|
|
7683
|
+
dilation (Union[int, tuple[int]], optional): The data type is int or a tuple of 3 integers
|
|
7684
|
+
:math:`(dilation_d, dilation_h, dilation_w)`. Currently, dilation on depth only supports the case of 1
|
|
7685
|
+
on Ascend backend. Specifies the dilation rate to use for dilated convolution. If set :math:`k > 1`,
|
|
7686
|
+
there will be :math:`k - 1` pixels skipped for each sampling location.
|
|
7687
|
+
The value ranges for the depth, height, and width dimensions are [1, D], [1, H], and [1, W],
|
|
7688
|
+
respectively. Default: 1.
|
|
7689
|
+
group (int, optional):The number of groups into which the filter is divided. `in_channels`
|
|
7690
|
+
and `out_channels` must be divisible by `group`. Default: 1.
|
|
7691
|
+
data_format (str): The optional value for data format. Currently only support "NCDHW".
|
|
7692
|
+
|
|
7693
|
+
Inputs:
|
|
7694
|
+
- **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, D_{in}, H_{in}, W_{in})`.
|
|
7695
|
+
Currently input data type only support float16 and float32.
|
|
7696
|
+
- **weight** (Tensor) - Set size of kernel is :math:`(k_d, K_h, K_w)`, then the shape is
|
|
7697
|
+
:math:`(C_{out}, C_{in}/groups, k_d, K_h, K_w)`.
|
|
7698
|
+
Currently weight data type only support float16 and float32.
|
|
7699
|
+
- **bias** (Tensor) - Tensor of shape :math:`C_{in}`. Currently, only support none.
|
|
7700
|
+
|
|
7701
|
+
Outputs:
|
|
7702
|
+
Tensor, the value that applied 3D convolution. The shape is :math:`(N, C_{out}, D_{out}, H_{out}, W_{out})`.
|
|
7703
|
+
|
|
7704
|
+
Raises:
|
|
7705
|
+
TypeError: If `out_channel` or `group` is not an int.
|
|
7706
|
+
TypeError: If `kernel_size`, `stride`, `pad` or `dilation` is neither an int nor a tuple.
|
|
7707
|
+
ValueError: If `out_channel`, `kernel_size`, `stride` or `dilation` is less than 1.
|
|
7708
|
+
ValueError: If `pad` is less than 0.
|
|
7709
|
+
ValueError: If `pad_mode` is not one of 'same', 'valid' or 'pad'.
|
|
7710
|
+
ValueError: If `pad` is a tuple whose length is not equal to 6.
|
|
7711
|
+
ValueError: If `pad_mode` is not equal to 'pad' and `pad` is not equal to (0, 0, 0, 0, 0, 0).
|
|
7712
|
+
ValueError: If `data_format` is not 'NCDHW'.
|
|
7682
7713
|
|
|
7683
7714
|
Supported Platforms:
|
|
7684
7715
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -7741,7 +7772,11 @@ class Conv3D(Primitive):
|
|
|
7741
7772
|
self.add_prim_attr('data_format', self.format)
|
|
7742
7773
|
self.out_channel = validator.check_positive_int(out_channel, 'out_channel', self.name)
|
|
7743
7774
|
validator.check_value_type("group", group, (int,), self.name)
|
|
7744
|
-
validator.check_int_range(group, 1, out_channel,
|
|
7775
|
+
validator.check_int_range(group, 1, out_channel, validator.INC_BOTH, "group", self.name)
|
|
7776
|
+
device_target = context.get_context("device_target")
|
|
7777
|
+
if device_target == "Ascend" and group != 1:
|
|
7778
|
+
raise ValueError("On Ascend platform, group = 1 must be satisfied.")
|
|
7779
|
+
|
|
7745
7780
|
self.group = group
|
|
7746
7781
|
self.add_prim_attr('groups', self.group)
|
|
7747
7782
|
self.add_prim_attr('offset_x', 0)
|
|
@@ -7963,7 +7998,7 @@ class SparseApplyAdadelta(Primitive):
|
|
|
7963
7998
|
def __init__(self, epsilon, use_locking=False):
|
|
7964
7999
|
"""Initialize SparseApplyAdadelta"""
|
|
7965
8000
|
validator.check_value_type("epsilon", epsilon, [float], self.name)
|
|
7966
|
-
validator.check_number("epsilon", epsilon, 0.0,
|
|
8001
|
+
validator.check_number("epsilon", epsilon, 0.0, validator.GE, self.name)
|
|
7967
8002
|
validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
7968
8003
|
|
|
7969
8004
|
|
|
@@ -7974,11 +8009,15 @@ class CTCLossV2(Primitive):
|
|
|
7974
8009
|
The CTC algorithm is proposed in `Connectionist Temporal Classification: Labeling Unsegmented Sequence Data with
|
|
7975
8010
|
Recurrent Neural Networks <http://www.cs.toronto.edu/~graves/icml_2006.pdf>`_.
|
|
7976
8011
|
|
|
8012
|
+
.. warning::
|
|
8013
|
+
This is an experimental API that is subject to change or deletion.
|
|
8014
|
+
|
|
7977
8015
|
Args:
|
|
7978
8016
|
blank (int, optional): The blank label. Default: 0.
|
|
7979
8017
|
reduction (str, optional): Apply specific reduction method to the output. Currently only support 'none',
|
|
7980
8018
|
not case sensitive. Default: "none".
|
|
7981
|
-
zero_infinity (bool, optional):
|
|
8019
|
+
zero_infinity (bool, optional): If loss is infinite, this parameter determines whether to set that loss
|
|
8020
|
+
and its correlated gradient to zero. Default: False.
|
|
7982
8021
|
|
|
7983
8022
|
Inputs:
|
|
7984
8023
|
- **log_probs** (Tensor) - A tensor of shape :math:`(T, C, N)`, where :math:`T` is input length, :math:`N` is
|
|
@@ -8001,19 +8040,19 @@ class CTCLossV2(Primitive):
|
|
|
8001
8040
|
TypeError: If the dtype of `targets`, `input_lengths` or `target_lengths` is not int32 or int64.
|
|
8002
8041
|
ValueError: If the rank of `log_probs` is not 3.
|
|
8003
8042
|
ValueError: If the rank of `targets` is not 2.
|
|
8004
|
-
ValueError: If the shape of `input_lengths` does not match
|
|
8005
|
-
ValueError: If the shape of `target_lengths` does not match
|
|
8043
|
+
ValueError: If the shape of `input_lengths` does not match batch_size :math:`N`.
|
|
8044
|
+
ValueError: If the shape of `target_lengths` does not match batch_size :math:`N`.
|
|
8006
8045
|
TypeError: If the types of `targets`, `input_lengths` or `target_lengths` are different.
|
|
8007
8046
|
ValueError: If the value of `blank` is not in range [0, num_labels|C).
|
|
8008
8047
|
RuntimeError: If any value of `input_lengths` is larger than (num_labels|C).
|
|
8009
|
-
RuntimeError: If any `target_lengths[i]` is not in range [0, `input_length[i]`
|
|
8048
|
+
RuntimeError: If any `target_lengths[i]` is not in range [0, `input_length[i]`].
|
|
8010
8049
|
|
|
8011
8050
|
Supported Platforms:
|
|
8012
8051
|
``Ascend`` ``GPU`` ``CPU``
|
|
8013
8052
|
|
|
8014
8053
|
Examples:
|
|
8015
8054
|
>>> log_probs = Tensor(np.array([[[0.3, 0.6, 0.6]],
|
|
8016
|
-
|
|
8055
|
+
... [[0.9, 0.4, 0.2]]]).astype(np.float32))
|
|
8017
8056
|
>>> targets = Tensor(np.array([[0, 1]]), mstype.int32)
|
|
8018
8057
|
>>> input_lengths = Tensor(np.array([2]), mstype.int32)
|
|
8019
8058
|
>>> target_lengths = Tensor(np.array([1]), mstype.int32)
|
|
@@ -8258,17 +8297,19 @@ class Conv3DTranspose(Primitive):
|
|
|
8258
8297
|
f"when 'pad_mode' is not \"pad\", but got 'output_padding' is "
|
|
8259
8298
|
f"{output_padding} and 'pad_mode' is {pad_mode}.")
|
|
8260
8299
|
self.add_prim_attr('output_padding', self.output_padding)
|
|
8261
|
-
validator.check_int_range(self.kernel_size[0] * self.kernel_size[1] * self.kernel_size[2],
|
|
8262
|
-
|
|
8263
|
-
|
|
8300
|
+
validator.check_int_range(self.kernel_size[0] * self.kernel_size[1] * self.kernel_size[2],
|
|
8301
|
+
1, 343, validator.INC_BOTH,
|
|
8302
|
+
'The product of height, width and depth of kernel_size belonging [1, 343]',
|
|
8303
|
+
self.name)
|
|
8304
|
+
validator.check_int_range(self.stride[0] * self.stride[1] * self.stride[2], 1, 343, validator.INC_BOTH,
|
|
8264
8305
|
'The product of height, width and depth of stride belonging [1, 343]', self.name)
|
|
8265
|
-
validator.check_int_range(self.stride[1] * self.stride[2], 1, 256,
|
|
8306
|
+
validator.check_int_range(self.stride[1] * self.stride[2], 1, 256, validator.INC_BOTH,
|
|
8266
8307
|
'The product of height, width and depth of stride belonging [1, 256]', self.name)
|
|
8267
|
-
validator.check_int_range(self.output_padding[2], 0, max(self.dilation[2], self.stride[2]),
|
|
8308
|
+
validator.check_int_range(self.output_padding[2], 0, max(self.dilation[2], self.stride[2]), validator.INC_LEFT,
|
|
8268
8309
|
'output_padding_d belonging [0, max(stride_d, dilation_d))', self.name)
|
|
8269
|
-
validator.check_int_range(self.output_padding[3], 0, max(self.dilation[3], self.stride[3]),
|
|
8310
|
+
validator.check_int_range(self.output_padding[3], 0, max(self.dilation[3], self.stride[3]), validator.INC_LEFT,
|
|
8270
8311
|
'output_padding_h belonging [0, max(stride_h,dilation_h))', self.name)
|
|
8271
|
-
validator.check_int_range(self.output_padding[4], 0, max(self.dilation[4], self.stride[4]),
|
|
8312
|
+
validator.check_int_range(self.output_padding[4], 0, max(self.dilation[4], self.stride[4]), validator.INC_LEFT,
|
|
8272
8313
|
'output_padding_w belonging [0, max(stride_w,dilation_w))', self.name)
|
|
8273
8314
|
|
|
8274
8315
|
|
|
@@ -8286,7 +8327,9 @@ class Dilation2D(Primitive):
|
|
|
8286
8327
|
\text{input}(N_i, C_j, s_0 \times h + d_0 \times m, s_1 \times w + d_1 \times n) + \text{filter}(C_j, m, n)
|
|
8287
8328
|
|
|
8288
8329
|
.. warning::
|
|
8289
|
-
This
|
|
8330
|
+
This is an experimental API that is subjected to change or deletion.
|
|
8331
|
+
|
|
8332
|
+
Note:
|
|
8290
8333
|
If the input data type is float32, this operator is still executed in float16 mode.
|
|
8291
8334
|
|
|
8292
8335
|
Args:
|
|
@@ -8301,7 +8344,7 @@ class Dilation2D(Primitive):
|
|
|
8301
8344
|
each sampling location. Its value must be greater or equal to 1 and bounded by
|
|
8302
8345
|
the height and width of the input `x`.
|
|
8303
8346
|
|
|
8304
|
-
pad_mode (str): Specifies padding mode. The optional values are
|
|
8347
|
+
pad_mode (str, optional): Specifies padding mode. The optional values are
|
|
8305
8348
|
"same", "valid". Default: "same". Both upper and lower case are supported.
|
|
8306
8349
|
|
|
8307
8350
|
- same: Adopts the way of completion. The height and width of the output will be the same as
|
|
@@ -8309,10 +8352,10 @@ class Dilation2D(Primitive):
|
|
|
8309
8352
|
|
|
8310
8353
|
- valid: Adopts the way of discarding. The possible largest height and width of output will be returned
|
|
8311
8354
|
without padding. Extra pixels will be discarded.
|
|
8312
|
-
data_format (str): The value for data format, only 'NCHW' is supported at present. Default: "NCHW".
|
|
8355
|
+
data_format (str, optional): The value for data format, only 'NCHW' is supported at present. Default: "NCHW".
|
|
8313
8356
|
|
|
8314
8357
|
Inputs:
|
|
8315
|
-
- **x** (Tensor) - Input data. A
|
|
8358
|
+
- **x** (Tensor) - Input data. A 4-D Tensor, its shape must be
|
|
8316
8359
|
:math:`(N, C_{in}, H_{in}, W_{in})`.
|
|
8317
8360
|
- **filter** (Tensor) - A three dimension tensor with the same type as input. The shape must be
|
|
8318
8361
|
:math:`(C_{in}, H_{filter}, W_{filter})`.
|
|
@@ -8398,10 +8441,10 @@ class SoftShrink(Primitive):
|
|
|
8398
8441
|
r"""
|
|
8399
8442
|
Applies the SoftShrink function element-wise.
|
|
8400
8443
|
|
|
8401
|
-
Refer to :func:`mindspore.ops.
|
|
8444
|
+
Refer to :func:`mindspore.ops.softshrink` for more details.
|
|
8402
8445
|
|
|
8403
8446
|
Supported Platforms:
|
|
8404
|
-
``Ascend`` ``
|
|
8447
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
8405
8448
|
|
|
8406
8449
|
Examples:
|
|
8407
8450
|
>>> import mindspore
|
|
@@ -8419,7 +8462,7 @@ class SoftShrink(Primitive):
|
|
|
8419
8462
|
def __init__(self, lambd=0.5):
|
|
8420
8463
|
"""Initialize SoftShrink"""
|
|
8421
8464
|
validator.check_value_type("lambd", lambd, [float], self.name)
|
|
8422
|
-
validator.check_number("lambd", lambd, 0,
|
|
8465
|
+
validator.check_number("lambd", lambd, 0, validator.GE, self.name)
|
|
8423
8466
|
|
|
8424
8467
|
|
|
8425
8468
|
class HShrink(Primitive):
|
|
@@ -8429,7 +8472,7 @@ class HShrink(Primitive):
|
|
|
8429
8472
|
Refer to :func:`mindspore.ops.hardshrink` for more details.
|
|
8430
8473
|
|
|
8431
8474
|
Supported Platforms:
|
|
8432
|
-
``Ascend`` ``
|
|
8475
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
8433
8476
|
|
|
8434
8477
|
Examples:
|
|
8435
8478
|
>>> import mindspore as ms
|
|
@@ -8486,9 +8529,9 @@ class ApplyAdagradDA(Primitive):
|
|
|
8486
8529
|
Inputs:
|
|
8487
8530
|
- **var** (Parameter) - Variable to be updated. The data type must be float16 or float32.
|
|
8488
8531
|
The shape is :math:`(N, *)` where :math:`*` means, any number of additional dimensions.
|
|
8489
|
-
- **gradient_accumulator** (Parameter) - The dict of mutable tensor
|
|
8532
|
+
- **gradient_accumulator** (Parameter) - The dict of mutable tensor :math:`grad\_accum`. Must have the same
|
|
8490
8533
|
shape and dtype as `var`.
|
|
8491
|
-
- **gradient_squared_accumulator** (Parameter) - The dict of mutable tensor
|
|
8534
|
+
- **gradient_squared_accumulator** (Parameter) - The dict of mutable tensor :math:`grad\_squared\_accum`.
|
|
8492
8535
|
Must have the same shape and dtype as `var`.
|
|
8493
8536
|
- **grad** (Tensor) - A tensor for gradient. Must have the same shape and dtype as `var`.
|
|
8494
8537
|
- **lr** ([Number, Tensor]) - Scaling factor. Must be a scalar. With float32 or float16 data type.
|
|
@@ -8634,7 +8677,7 @@ class SparseApplyRMSProp(Primitive):
|
|
|
8634
8677
|
RuntimeError: If the data type of `var`, `ms`, `mom` and `grad` conversion of Parameter is not supported.
|
|
8635
8678
|
|
|
8636
8679
|
Supported Platforms:
|
|
8637
|
-
``Ascend`` ``
|
|
8680
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
8638
8681
|
|
|
8639
8682
|
Examples:
|
|
8640
8683
|
>>> class SparseApplyRMSPropNet(nn.Cell):
|
|
@@ -8682,9 +8725,9 @@ class SparseApplyRMSProp(Primitive):
|
|
|
8682
8725
|
validator.check_value_type("momentum", momentum, [float], self.name)
|
|
8683
8726
|
validator.check_value_type("epsilon", epsilon, [float], self.name)
|
|
8684
8727
|
validator.check_value_type("use_locking", use_locking, [bool], self.name)
|
|
8685
|
-
self.epsilon = validator.check_number("epsilon", epsilon, 0.0,
|
|
8686
|
-
self.momentum = validator.check_number("momentum", momentum, 0.0,
|
|
8687
|
-
self.rho = validator.check_float_range(rho, 0.0, 1.0,
|
|
8728
|
+
self.epsilon = validator.check_number("epsilon", epsilon, 0.0, validator.GT, self.name)
|
|
8729
|
+
self.momentum = validator.check_number("momentum", momentum, 0.0, validator.GE, self.name)
|
|
8730
|
+
self.rho = validator.check_float_range(rho, 0.0, 1.0, validator.INC_BOTH, "rho", self.name)
|
|
8688
8731
|
|
|
8689
8732
|
|
|
8690
8733
|
class SparseApplyCenteredRMSProp(Primitive):
|
|
@@ -8751,13 +8794,9 @@ class SparseApplyCenteredRMSProp(Primitive):
|
|
|
8751
8794
|
ValueError: If shape of `grad` is not same as shape of `var` except first dimension.
|
|
8752
8795
|
|
|
8753
8796
|
Supported Platforms:
|
|
8754
|
-
``GPU`` ``CPU``
|
|
8797
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
8755
8798
|
|
|
8756
8799
|
Examples:
|
|
8757
|
-
>>> import numpy as np
|
|
8758
|
-
>>> from mindspore import Tensor
|
|
8759
|
-
>>> import mindspore.common.dtype as mstype
|
|
8760
|
-
>>> import mindspore.ops.operations.nn_ops as nn_ops
|
|
8761
8800
|
>>> var = Tensor(np.array([[0.6, 0.4], [0.1, 0.5]]).astype(np.float32))
|
|
8762
8801
|
>>> mg = Tensor(np.array([[0.1, 0.3], [0.1, 0.5]]).astype(np.float32))
|
|
8763
8802
|
>>> ms = Tensor(np.array([[0.2, 0.1], [0.1, 0.2]]).astype(np.float32))
|
|
@@ -8776,10 +8815,10 @@ class SparseApplyCenteredRMSProp(Primitive):
|
|
|
8776
8815
|
"""
|
|
8777
8816
|
|
|
8778
8817
|
__mindspore_signature__ = (
|
|
8779
|
-
sig.make_sig('var', dtype=sig.sig_dtype.T),
|
|
8780
|
-
sig.make_sig('mg', dtype=sig.sig_dtype.T),
|
|
8781
|
-
sig.make_sig('ms', dtype=sig.sig_dtype.T),
|
|
8782
|
-
sig.make_sig('mom', dtype=sig.sig_dtype.T),
|
|
8818
|
+
sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
8819
|
+
sig.make_sig('mg', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
8820
|
+
sig.make_sig('ms', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
8821
|
+
sig.make_sig('mom', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
8783
8822
|
sig.make_sig('lr', dtype=sig.sig_dtype.T),
|
|
8784
8823
|
sig.make_sig('rho', dtype=sig.sig_dtype.T),
|
|
8785
8824
|
sig.make_sig('momentum', dtype=sig.sig_dtype.T),
|
|
@@ -8894,13 +8933,12 @@ class ApplyKerasMomentum(Primitive):
|
|
|
8894
8933
|
|
|
8895
8934
|
class MultilabelMarginLoss(Primitive):
|
|
8896
8935
|
r"""
|
|
8897
|
-
|
|
8936
|
+
Creates a loss criterion that minimizes the hinge loss for multi-class
|
|
8937
|
+
classification tasks.
|
|
8938
|
+
It takes a 2D mini-batch Tensor :math:`x` as input and a 2D
|
|
8939
|
+
Tensor :math:`y` containing target class indices as output.
|
|
8898
8940
|
|
|
8899
|
-
|
|
8900
|
-
hinge loss (margin-based loss) between input :math:`x` (a 2D mini-batch `Tensor`)
|
|
8901
|
-
and output :math:`y` (which is a 2D `Tensor` of target class indices).
|
|
8902
|
-
|
|
8903
|
-
Refer to :func:`mindspore.ops.multi_label_margin_loss` for more details.
|
|
8941
|
+
Refer to :func:`mindspore.ops.multilabel_margin_loss` for more details.
|
|
8904
8942
|
|
|
8905
8943
|
Supported Platforms:
|
|
8906
8944
|
``Ascend`` ``GPU``
|
|
@@ -8976,7 +9014,7 @@ class ApplyAdamWithAmsgrad(Primitive):
|
|
|
8976
9014
|
ValueError: If the shape of `beta1_power`, `beta2_power`, `lr` is not 0.
|
|
8977
9015
|
|
|
8978
9016
|
Supported Platforms:
|
|
8979
|
-
``Ascend`` ``
|
|
9017
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
8980
9018
|
|
|
8981
9019
|
Examples:
|
|
8982
9020
|
>>> class ApplyAdamWithAmsgradNet(nn.Cell):
|
|
@@ -9025,6 +9063,9 @@ class GridSampler3D(Primitive):
|
|
|
9025
9063
|
Given an input and a grid, the output is calculated using the input values
|
|
9026
9064
|
and pixel positions in the grid. Only volume (5-D) input is supported.
|
|
9027
9065
|
|
|
9066
|
+
.. warning::
|
|
9067
|
+
This is an experimental API that is subject to change or deletion.
|
|
9068
|
+
|
|
9028
9069
|
Refer to :func:`mindspore.ops.grid_sample` for more details.
|
|
9029
9070
|
|
|
9030
9071
|
Supported Platforms:
|
|
@@ -9062,35 +9103,40 @@ class FractionalMaxPool(Primitive):
|
|
|
9062
9103
|
r"""
|
|
9063
9104
|
Performs fractional max pooling on the input.
|
|
9064
9105
|
|
|
9065
|
-
Fractional max pooling is similar to regular max pooling,
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9106
|
+
Fractional max pooling is similar to regular max pooling, but with the added flexibility of
|
|
9107
|
+
allowing the overall reduction ratio `N` to be a non-integer value. In regular max pooling,
|
|
9108
|
+
an input set is reduced in size by taking the maximum value of `N x N` (usually 2x2)
|
|
9109
|
+
subsections of the set, with the goal of reducing the set by a factor of `N`, where `N` is an integer.
|
|
9110
|
+
|
|
9111
|
+
In contrast, fractional max pooling uses randomly generated pool sizes that are fairly uniform in size.
|
|
9070
9112
|
|
|
9071
9113
|
.. warning::
|
|
9072
9114
|
"pooling_ratio", currently only supports row and col dimension and should be >= 1.0, the first
|
|
9073
|
-
and last elements must be 1.0 because
|
|
9115
|
+
and last elements must be 1.0 because pooling on batch and channels dimensions is not allowed.
|
|
9074
9116
|
|
|
9075
9117
|
Args:
|
|
9076
|
-
pooling_ratio (list(float)): Decide the shape of output, is a list of
|
|
9077
|
-
Pooling ratio for each dimension of value should be
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
When set to False, the values are not reused.
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
fixed pool regions will not be used.
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9118
|
+
pooling_ratio (list(float)): Decide the shape of output, is a list of float numbers has length >= 4.
|
|
9119
|
+
Pooling ratio for each dimension of value should not be less than 0, currently only support
|
|
9120
|
+
for row and col dimension.
|
|
9121
|
+
pseudo_random(bool, optional): Generate the pooling sequence either randomly or pseudo-randomly.
|
|
9122
|
+
If the pseudo_random parameter is set to True, the sequence will be generated in a
|
|
9123
|
+
pseudo-random fashion, otherwise it will be generated randomly.
|
|
9124
|
+
Refer to `Fractional Max-Pooling <https://arxiv.org/pdf/1412.6071>`_
|
|
9125
|
+
by Benjamin Graham to understand the distinction between the two.
|
|
9126
|
+
Default: False.
|
|
9127
|
+
overlapping(bool, optional): When set to True, the values at the boundary of adjacent pooling cells
|
|
9128
|
+
will be shared by both cells during pooling process. When set to False, the values are not reused.
|
|
9129
|
+
Default: False.
|
|
9130
|
+
deterministic(bool, optional): If deterministic is set to True, a fixed pooling region will be used
|
|
9131
|
+
in the computation graph, ensuring that the FractionalMaxPool is deterministic.
|
|
9132
|
+
This is often used in unit tests. When set to False, fixed pool regions will not be used.
|
|
9133
|
+
Default: False.
|
|
9134
|
+
seed(int, optional): If either seed or seed2 are set to a non-zero value, the random number
|
|
9135
|
+
generator will be seeded using the specified seed. If neither seed nor seed2 are set,
|
|
9136
|
+
the generator will be seeded by a random seed.
|
|
9137
|
+
Default: 0.
|
|
9138
|
+
seed2(int, optional): The second seed to avoid seed collision.
|
|
9139
|
+
Default: 0.
|
|
9094
9140
|
|
|
9095
9141
|
Inputs:
|
|
9096
9142
|
- **x** (Tensor) -The data type must be one of the following types: float32, float64, int32, int64.
|
|
@@ -9112,7 +9158,7 @@ class FractionalMaxPool(Primitive):
|
|
|
9112
9158
|
ValueError: If the first and last element of `pooling_ratio` is not equal to 1.0.
|
|
9113
9159
|
|
|
9114
9160
|
Supported Platforms:
|
|
9115
|
-
``GPU`` ``CPU``
|
|
9161
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
9116
9162
|
|
|
9117
9163
|
Examples:
|
|
9118
9164
|
>>> x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]).reshape([1,4,4,1]).astype(np.int64)
|
|
@@ -9143,9 +9189,10 @@ class FractionalMaxPool(Primitive):
|
|
|
9143
9189
|
|
|
9144
9190
|
class FractionalMaxPool3DWithFixedKsize(Primitive):
|
|
9145
9191
|
r"""
|
|
9146
|
-
|
|
9147
|
-
The max-pooling operation is applied in kD
|
|
9148
|
-
|
|
9192
|
+
Applies a 3D fractional max pooling to an input signal composed of multiple input planes.
|
|
9193
|
+
The max-pooling operation is applied in :math:`(kD, kH, kW)` regions by a stochastic step size determined by
|
|
9194
|
+
the target output size `output_shape`.
|
|
9195
|
+
|
|
9149
9196
|
The number of output features is equal to the number of input planes.
|
|
9150
9197
|
|
|
9151
9198
|
Refer to the paper `Fractional MaxPooling by Ben Graham <https://arxiv.org/abs/1412.6071>`_ for more details.
|
|
@@ -9154,13 +9201,11 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
|
|
|
9154
9201
|
D the feature depth, H is the feature height, and W is the feature width.
|
|
9155
9202
|
|
|
9156
9203
|
Args:
|
|
9157
|
-
ksize (Union[float, tuple]):
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
specifying the size (D, H, W) of the output tensor.
|
|
9163
|
-
data_format (str) : The optional value for data format.
|
|
9204
|
+
ksize (Union[float, tuple]): Size of the pooling window. `ksize` can be a tuple of three values specify a
|
|
9205
|
+
shape :math:`(k_D, k_H, k_W)`, or a single int `K` for :math:`(K, K, K)`.
|
|
9206
|
+
output_shape (Union[int, tuple]): The target output shape. `output_shape` can be a tuple of three values
|
|
9207
|
+
specify a shape :math:`(D_{out}, H_{out}, W_{out})`, or a single float `S` for :math:`(S, S, S)`.
|
|
9208
|
+
data_format (str, optional): The optional value for data format.
|
|
9164
9209
|
Currently support 'NCDHW' and 'NHDWC'. Default: 'NCDHW'.
|
|
9165
9210
|
|
|
9166
9211
|
Inputs:
|
|
@@ -9193,13 +9238,13 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
|
|
|
9193
9238
|
ValueError: If the third dimension size of `random_samples` is not 3.
|
|
9194
9239
|
|
|
9195
9240
|
Supported Platforms:
|
|
9196
|
-
``GPU`` ``CPU``
|
|
9241
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
9197
9242
|
|
|
9198
9243
|
Examples:
|
|
9199
9244
|
>>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
|
|
9200
9245
|
... .reshape([1, 1, 2, 2, 4]), mstype.float32)
|
|
9201
9246
|
>>> random_samples = Tensor(np.array([0.7, 0.7, 0.7]).reshape([1, 1, 3]), mstype.float32)
|
|
9202
|
-
>>> ksize = (1
|
|
9247
|
+
>>> ksize = (1, 1, 1)
|
|
9203
9248
|
>>> output_shape = (1, 1, 2)
|
|
9204
9249
|
>>> net = ops.FractionalMaxPool3DWithFixedKsize(ksize = ksize, output_shape = output_shape)
|
|
9205
9250
|
>>> output, argmax = net(x, random_samples)
|
|
@@ -9213,15 +9258,15 @@ class FractionalMaxPool3DWithFixedKsize(Primitive):
|
|
|
9213
9258
|
def __init__(self, ksize, output_shape, data_format="NCDHW"):
|
|
9214
9259
|
"""Initialize FractionalMaxPool3DWithFixedKsize."""
|
|
9215
9260
|
self.init_prim_io_names(inputs=["x", "random_samples"], outputs=["y", "argmax"])
|
|
9216
|
-
validator.check_value_type("ksize", ksize, [
|
|
9261
|
+
validator.check_value_type("ksize", ksize, [int, tuple], self.name)
|
|
9217
9262
|
self.ksize = ksize
|
|
9218
|
-
if isinstance(self.ksize,
|
|
9263
|
+
if isinstance(self.ksize, int):
|
|
9219
9264
|
self.ksize = (ksize, ksize, ksize)
|
|
9220
9265
|
if len(self.ksize) != 3:
|
|
9221
|
-
raise ValueError(f"For '{self.name}', attr 'ksize' must be an positive
|
|
9222
|
-
f"three
|
|
9266
|
+
raise ValueError(f"For '{self.name}', attr 'ksize' must be an positive int number or a tuple of "
|
|
9267
|
+
f"three int numbers, but got {len(self.ksize)} numbers.")
|
|
9223
9268
|
for item in self.ksize:
|
|
9224
|
-
validator.
|
|
9269
|
+
validator.check_positive_int(item, 'ksize item', self.name)
|
|
9225
9270
|
self.output_shape = validator.check_value_type("output_shape", output_shape, [int, tuple], self.name)
|
|
9226
9271
|
self.data_format = validator.check_string(data_format, ['NCDHW', 'NDHWC'], 'data_format', self.name)
|
|
9227
9272
|
self.output_shape = _check_3d_int_or_tuple("output_shape", output_shape,
|
|
@@ -9234,11 +9279,10 @@ class FractionalAvgPool(Primitive):
|
|
|
9234
9279
|
r"""
|
|
9235
9280
|
Performs fractional avg pooling on the input.
|
|
9236
9281
|
|
|
9237
|
-
Fractional avg pooling is similar to regular avg pooling,
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
is performed.
|
|
9282
|
+
Fractional avg pooling is similar to regular avg pooling, but with the added flexibility of
|
|
9283
|
+
allowing the overall reduction ratio `N` to be a non-integer value. In regular avg pooling,
|
|
9284
|
+
an input set is reduced in size by taking the average value of `N x N` (usually 2x2)
|
|
9285
|
+
subsections of the set, with the goal of reducing the set by a factor of `N`, where `N` is an integer.
|
|
9242
9286
|
|
|
9243
9287
|
.. warning::
|
|
9244
9288
|
"pooling_ratio", currently only supports row and col dimension and should be >= 1.0, the first
|
|
@@ -9249,20 +9293,25 @@ class FractionalAvgPool(Primitive):
|
|
|
9249
9293
|
Pooling ratio for each dimension of value should be >=0, currently only support for row and col
|
|
9250
9294
|
dimension. The first and last elements must be 1.0 because we don't allow pooling on batch and
|
|
9251
9295
|
channels dimensions.
|
|
9252
|
-
pseudo_random(bool, optional):
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9296
|
+
pseudo_random(bool, optional): Generate the pooling sequence either randomly or pseudo-randomly.
|
|
9297
|
+
If the pseudo_random parameter is set to True, the sequence will be generated in a
|
|
9298
|
+
pseudo-random fashion, otherwise it will be generated randomly.
|
|
9299
|
+
Refer to `Fractional Max-Pooling <https://arxiv.org/pdf/1412.6071>`_
|
|
9300
|
+
by Benjamin Graham to understand the distinction between the two.
|
|
9301
|
+
Default: False.
|
|
9302
|
+
overlapping(bool, optional): When set to True, the values at the boundary of adjacent pooling cells
|
|
9303
|
+
will be shared by both cells during pooling process. When set to False, the values are not reused.
|
|
9304
|
+
Default: False.
|
|
9305
|
+
deterministic(bool, optional): If deterministic is set to True, a fixed pooling region will be used
|
|
9306
|
+
in the computation graph, ensuring that the FractionalAvgPool is deterministic.
|
|
9307
|
+
This is often used in unit tests. When set to False, fixed pool regions will not be used.
|
|
9308
|
+
Default: False.
|
|
9309
|
+
seed(int, optional): If either seed or seed2 are set to a non-zero value, the random number
|
|
9310
|
+
generator will be seeded using the specified seed. If neither seed nor seed2 are set,
|
|
9311
|
+
the generator will be seeded by a random seed.
|
|
9312
|
+
Default: 0.
|
|
9313
|
+
seed2(int, optional): The second seed to avoid seed collision.
|
|
9314
|
+
Default: 0.
|
|
9266
9315
|
|
|
9267
9316
|
Inputs:
|
|
9268
9317
|
- **x** (Tensor) -The data type must be one of the following types: float32, float64, int32, int64.
|
|
@@ -9284,7 +9333,7 @@ class FractionalAvgPool(Primitive):
|
|
|
9284
9333
|
ValueError: If the first and last element of `pooling_ratio` is not equal to 1.0.
|
|
9285
9334
|
|
|
9286
9335
|
Supported Platforms:
|
|
9287
|
-
``GPU`` ``CPU``
|
|
9336
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
9288
9337
|
|
|
9289
9338
|
Examples:
|
|
9290
9339
|
>>> x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]).reshape([1,4,4,1]).astype(np.int64)
|
|
@@ -9315,20 +9364,23 @@ class FractionalAvgPool(Primitive):
|
|
|
9315
9364
|
|
|
9316
9365
|
class NthElement(Primitive):
|
|
9317
9366
|
r"""
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9367
|
+
Computes the n-th smallest values for the last dimension of the input Tensor.
|
|
9368
|
+
|
|
9369
|
+
- When `input` is a 1-D Tensor (i.e. Vector), it finds the nth-smallest value in the vector
|
|
9370
|
+
and outputs its value as a scalar Tensor.
|
|
9371
|
+
- When `input` is matrices or has higher rank, it finds the nth-smallest value
|
|
9372
|
+
in each row (or vector along the last dimension) and outputs
|
|
9373
|
+
these values in a Tensor with shape of `values.shape = input.shape[:-1]`.
|
|
9323
9374
|
|
|
9324
9375
|
Args:
|
|
9325
|
-
reverse (bool, optional): An optional bool.
|
|
9326
|
-
in the vector
|
|
9376
|
+
reverse (bool, optional): An optional bool. If set to True, it find the :math:`n`-th largest value
|
|
9377
|
+
in the vector instead of the nth-smallest. Default: False.
|
|
9327
9378
|
|
|
9328
9379
|
Inputs:
|
|
9329
|
-
- **input** (Tensor) -
|
|
9330
|
-
- **n** (Union[int, Tensor]) - If the n is a
|
|
9331
|
-
Valid range of n is :math:`[0, input.shape[-1])
|
|
9380
|
+
- **input** (Tensor) - Input Tensor with 1-D or higher dimension.
|
|
9381
|
+
- **n** (Union[int, Tensor]) - If the `n` is a Tensor, it should be a 0-D Tensor, dtype is int32.
|
|
9382
|
+
Valid range of `n` is :math:`[0, input.shape[-1])` where :math:`input.shape[-1]` is
|
|
9383
|
+
last dimension size of `input`.
|
|
9332
9384
|
|
|
9333
9385
|
Outputs:
|
|
9334
9386
|
- **values** (Tensor) - Its shape satisfies: `values`.shape = `input`.shape[:-1].
|
|
@@ -9340,7 +9392,7 @@ class NthElement(Primitive):
|
|
|
9340
9392
|
ValueError**: If n is out of :math:`[0, input.shape[-1])`.
|
|
9341
9393
|
|
|
9342
9394
|
Supported Platforms:
|
|
9343
|
-
``GPU`` ``CPU``
|
|
9395
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
9344
9396
|
|
|
9345
9397
|
Examples:
|
|
9346
9398
|
>>> input = Tensor(np.array([[1,2,3],[4,5,6]]) , mstype.int8)
|
|
@@ -9368,7 +9420,7 @@ class PSROIPooling(Primitive):
|
|
|
9368
9420
|
spatial_scale (float): a scaling factor that maps the box coordinates to the input coordinates.
|
|
9369
9421
|
For example, if your boxes are defined on the scale of a 224x224 image and
|
|
9370
9422
|
your input is a 112x112 feature map (resulting from a 0.5x scaling of the original
|
|
9371
|
-
image), you
|
|
9423
|
+
image), you'll want to set this to 0.5.
|
|
9372
9424
|
group_size (int): the size of the output (in pixels) after the pooling is performed, as (height, width).
|
|
9373
9425
|
output_dim (int): the dim of the output after the pooling is performed.
|
|
9374
9426
|
|
|
@@ -9428,9 +9480,9 @@ class PSROIPooling(Primitive):
|
|
|
9428
9480
|
... group_size=7)
|
|
9429
9481
|
>>> out = psROIPooling(features, rois)
|
|
9430
9482
|
>>> print(out.shape)
|
|
9431
|
-
|
|
9483
|
+
(4, 3, 7, 7)
|
|
9432
9484
|
>>> print(out.dtype)
|
|
9433
|
-
|
|
9485
|
+
Float32
|
|
9434
9486
|
"""
|
|
9435
9487
|
|
|
9436
9488
|
@prim_attr_register
|
|
@@ -9477,11 +9529,9 @@ class TripletMarginLoss(Primitive):
|
|
|
9477
9529
|
Args:
|
|
9478
9530
|
p (int, optional): The norm degree for pairwise distance. Default: 2.
|
|
9479
9531
|
eps (float, optional): Default: 1e-06.
|
|
9480
|
-
swap (bool, optional): The distance swap
|
|
9481
|
-
`Learning local feature descriptors with triplets and shallow convolutional neural networks`
|
|
9482
|
-
by V. Balntas, E. Riba et al. Default: "False".
|
|
9532
|
+
swap (bool, optional): The distance swap. Default: False.
|
|
9483
9533
|
reduction (str, optional): Apply specific reduction method to the
|
|
9484
|
-
output:
|
|
9534
|
+
output: "none", "mean", "sum". Default: "mean".
|
|
9485
9535
|
|
|
9486
9536
|
Inputs:
|
|
9487
9537
|
- **x** (Tensor) - A sample randomly selected from the training set. Data type must be BasicType.
|
|
@@ -9512,7 +9562,7 @@ class TripletMarginLoss(Primitive):
|
|
|
9512
9562
|
ValueError: If `reduction` is not one of 'none', 'mean', 'sum'.
|
|
9513
9563
|
|
|
9514
9564
|
Supported Platforms:
|
|
9515
|
-
``GPU``
|
|
9565
|
+
``GPU``
|
|
9516
9566
|
|
|
9517
9567
|
Examples:
|
|
9518
9568
|
>>> loss = ops.TripletMarginLoss()
|
|
@@ -9542,7 +9592,7 @@ class DeformableOffsets(Primitive):
|
|
|
9542
9592
|
Refer to :func:`mindspore.ops.deformable_conv2d` for more details.
|
|
9543
9593
|
|
|
9544
9594
|
Supported Platforms:
|
|
9545
|
-
``Ascend`` ``
|
|
9595
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
9546
9596
|
"""
|
|
9547
9597
|
|
|
9548
9598
|
@prim_attr_register
|
|
@@ -9590,26 +9640,39 @@ class DeformableOffsets(Primitive):
|
|
|
9590
9640
|
|
|
9591
9641
|
class GridSampler2D(Primitive):
|
|
9592
9642
|
"""
|
|
9593
|
-
This operation samples 2d input_x by using interpolation based on flow field grid,
|
|
9594
|
-
:func:`mindspore.ops.affine_grid`.
|
|
9643
|
+
This operation samples 2d `input_x` by using interpolation based on flow field grid,
|
|
9644
|
+
which is usually gennerated by :func:`mindspore.ops.affine_grid`.
|
|
9645
|
+
|
|
9646
|
+
.. warning::
|
|
9647
|
+
This is an experimental API that is subject to change or deletion.
|
|
9595
9648
|
|
|
9596
9649
|
Args:
|
|
9597
|
-
interpolation_mode (str): An optional string specifying the interpolation method.
|
|
9650
|
+
interpolation_mode (str, optional): An optional string specifying the interpolation method.
|
|
9651
|
+
The optional values are
|
|
9598
9652
|
"bilinear" or "nearest". Default: "bilinear".
|
|
9599
|
-
padding_mode (str): An optional string specifying the pad method.
|
|
9600
|
-
"reflection". Default: "zeros".
|
|
9601
|
-
|
|
9653
|
+
padding_mode (str, optional): An optional string specifying the pad method.
|
|
9654
|
+
The optional values are "zeros", "border" or "reflection". Default: "zeros".
|
|
9655
|
+
When the sampling grid is outside input's bounds, effects of various padding modes are as follows:
|
|
9656
|
+
|
|
9657
|
+
- "zeros": Pads the input tensor with zeros.
|
|
9658
|
+
- "border": Pads the input tensor with the values of the pixels on the border of the tensor.
|
|
9659
|
+
- "reflection": Pads the input tensor by reflecting the values of the pixels at the
|
|
9660
|
+
boundary of the tensor.
|
|
9661
|
+
|
|
9662
|
+
align_corners (bool, optional): An optional bool. When set to True,
|
|
9663
|
+
the centers of the corner pixels of the input
|
|
9602
9664
|
and output tensors are aligned. When set to False, it is not aligned. Defaults to False.
|
|
9603
9665
|
|
|
9604
9666
|
Inputs:
|
|
9605
|
-
- **input_x** (Tensor) - A 4-D tensor with dtype of float16 or float32 and shape of
|
|
9606
|
-
H_{in}, W_{in})`.
|
|
9607
|
-
- **grid** (Tensor) - A 4-D tensor whose dtype is the same as `input_x` and whose shape is
|
|
9608
|
-
H_{out}, W_{out}, 2)`.
|
|
9667
|
+
- **input_x** (Tensor) - A 4-D tensor with dtype of float16 or float32 and shape of
|
|
9668
|
+
:math:`(N, C, H_{in}, W_{in})`.
|
|
9669
|
+
- **grid** (Tensor) - A 4-D tensor whose dtype is the same as `input_x` and whose shape is
|
|
9670
|
+
:math:`(N, H_{out}, W_{out}, 2)`.
|
|
9671
|
+
Used to specify the sampling pixel locations normalized by the input spatial
|
|
9609
9672
|
dimensions.
|
|
9610
9673
|
|
|
9611
9674
|
Outputs:
|
|
9612
|
-
|
|
9675
|
+
A 4-D Tensor whose dtype is the same as `input_x` and whose shape is :math:`(N, C, H_{out}, W_{out})`.
|
|
9613
9676
|
|
|
9614
9677
|
Raises:
|
|
9615
9678
|
TypeError: If `input_x` or `grid` is not a Tensor.
|
|
@@ -9661,37 +9724,16 @@ class Pdist(Primitive):
|
|
|
9661
9724
|
r"""
|
|
9662
9725
|
Computes the p-norm distance between each pair of row vectors in the input.
|
|
9663
9726
|
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p},
|
|
9667
|
-
|
|
9668
|
-
where :math:`x_{i}, x_{j}` are two different row vectors in the input.
|
|
9669
|
-
|
|
9670
|
-
Args:
|
|
9671
|
-
p (float): p value for the p norm distance to calculate between each vector pair ∈[0,∞]. Default: 2.0.
|
|
9672
|
-
|
|
9673
|
-
Inputs:
|
|
9674
|
-
- **x** (Tensor) - Input tensor with dtype of float16 or float32 and shape of :math:`(N, M)`.
|
|
9675
|
-
|
|
9676
|
-
Outputs:
|
|
9677
|
-
Tensor, has the same dtype as `x`, whose shape is :math:`(N * (N - 1) / 2)`.
|
|
9678
|
-
|
|
9679
|
-
Raises:
|
|
9680
|
-
TypeError: If `x` is not a Tensor.
|
|
9681
|
-
TypeError: If dtype of `x` is not float16, float32 or float64.
|
|
9682
|
-
TypeError: If `p` is not a float.
|
|
9683
|
-
ValueError: If `p` is a negative float.
|
|
9684
|
-
ValueError: If dimension of `x` is not 2.
|
|
9727
|
+
Refer to :func:`mindspore.ops.pdist` for more details.
|
|
9685
9728
|
|
|
9686
9729
|
Supported Platforms:
|
|
9687
|
-
``
|
|
9730
|
+
``GPU`` ``CPU``
|
|
9688
9731
|
|
|
9689
9732
|
Examples:
|
|
9690
|
-
>>> from mindspore import Tensor
|
|
9691
|
-
>>> from mindspore.ops.operations.nn_ops import Pdist
|
|
9733
|
+
>>> from mindspore import Tensor, ops
|
|
9692
9734
|
>>> import numpy as np
|
|
9693
9735
|
>>> x = Tensor(np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]]).astype(np.float32))
|
|
9694
|
-
>>> op = Pdist(p=2.0)
|
|
9736
|
+
>>> op = ops.Pdist(p=2.0)
|
|
9695
9737
|
>>> y = op(x)
|
|
9696
9738
|
>>> print(y)
|
|
9697
9739
|
[1.4142135 2.828427 1.4142135]
|
|
@@ -9743,7 +9785,7 @@ class UpsampleNearest3D(Primitive):
|
|
|
9743
9785
|
ValueError: If size of `output_size` is not equal 3 when `output_size` is specified.
|
|
9744
9786
|
|
|
9745
9787
|
Supported Platforms:
|
|
9746
|
-
|
|
9788
|
+
|
|
9747
9789
|
|
|
9748
9790
|
Examples:
|
|
9749
9791
|
>>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
|
|
@@ -9776,10 +9818,10 @@ class UpsampleNearest3D(Primitive):
|
|
|
9776
9818
|
scales = []
|
|
9777
9819
|
validator.check_value_type('output_size', output_size, [tuple, list], self.name)
|
|
9778
9820
|
for item in output_size:
|
|
9779
|
-
validator.check_int(item, 0,
|
|
9821
|
+
validator.check_int(item, 0, validator.GT, 'output_size_item', self.name)
|
|
9780
9822
|
validator.check_value_type('scales', scales, [tuple, list], self.name)
|
|
9781
9823
|
for item in scales:
|
|
9782
|
-
validator.check_float(item, 0,
|
|
9824
|
+
validator.check_float(item, 0, validator.GT, 'scales_item', self.name)
|
|
9783
9825
|
self.add_prim_attr('output_size', output_size)
|
|
9784
9826
|
self.add_prim_attr('scales', scales)
|
|
9785
9827
|
|
|
@@ -9844,16 +9886,12 @@ class SparseApplyAdagradDA(Primitive):
|
|
|
9844
9886
|
conversion of Parameter is not supported.
|
|
9845
9887
|
|
|
9846
9888
|
Supported Platforms:
|
|
9847
|
-
``CPU``
|
|
9889
|
+
``GPU`` ``CPU``
|
|
9848
9890
|
|
|
9849
9891
|
Examples:
|
|
9850
|
-
>>>
|
|
9851
|
-
>>>
|
|
9852
|
-
>>>
|
|
9853
|
-
>>> import mindspore.ops.operations.nn_ops as nn_ops
|
|
9854
|
-
>>> var = Tensor(np.array([[1,2], [1,2]]).astype(np.float32))
|
|
9855
|
-
>>> grad_accum = Tensor(np.array([[2,1], [3,1]]).astype(np.float32))
|
|
9856
|
-
>>> grad_square_accum = Tensor(np.array([[4,1], [5,1]]).astype(np.float32))
|
|
9892
|
+
>>> var = Parameter(Tensor(np.array([[1,2], [1,2]]).astype(np.float32)))
|
|
9893
|
+
>>> grad_accum = Parameter(Tensor(np.array([[2,1], [3,1]]).astype(np.float32)))
|
|
9894
|
+
>>> grad_square_accum = Parameter(Tensor(np.array([[4,1], [5,1]]).astype(np.float32)))
|
|
9857
9895
|
>>> grad = Tensor(np.array([[5,1], [6,1]]).astype(np.float32))
|
|
9858
9896
|
>>> indices = Tensor(np.array([0, 1], dtype=np.int32))
|
|
9859
9897
|
>>> lr = Tensor(2, mstype.float32)
|
|
@@ -9869,9 +9907,9 @@ class SparseApplyAdagradDA(Primitive):
|
|
|
9869
9907
|
"""
|
|
9870
9908
|
|
|
9871
9909
|
__mindspore_signature__ = (
|
|
9872
|
-
sig.make_sig('var', dtype=sig.sig_dtype.T),
|
|
9873
|
-
sig.make_sig('grad_accum', dtype=sig.sig_dtype.T),
|
|
9874
|
-
sig.make_sig('grad_square_accum', dtype=sig.sig_dtype.T),
|
|
9910
|
+
sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
9911
|
+
sig.make_sig('grad_accum', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
9912
|
+
sig.make_sig('grad_square_accum', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
9875
9913
|
sig.make_sig('grad', dtype=sig.sig_dtype.T),
|
|
9876
9914
|
sig.make_sig('indices', dtype=sig.sig_dtype.T1),
|
|
9877
9915
|
sig.make_sig('lr', dtype=sig.sig_dtype.T),
|
|
@@ -9941,7 +9979,7 @@ class SparseApplyMomentum(Primitive):
|
|
|
9941
9979
|
is not supported.
|
|
9942
9980
|
|
|
9943
9981
|
Supported Platforms:
|
|
9944
|
-
``CPU``
|
|
9982
|
+
``GPU`` ``CPU``
|
|
9945
9983
|
|
|
9946
9984
|
Examples:
|
|
9947
9985
|
>>> import mindspore.ops.operations.nn_ops as nn_ops
|
|
@@ -10025,7 +10063,7 @@ class SparseApplyProximalGradientDescent(Primitive):
|
|
|
10025
10063
|
is not supported.
|
|
10026
10064
|
|
|
10027
10065
|
Supported Platforms:
|
|
10028
|
-
``CPU``
|
|
10066
|
+
``GPU`` ``CPU``
|
|
10029
10067
|
|
|
10030
10068
|
Examples:
|
|
10031
10069
|
>>> import mindspore.ops.operations.nn_ops as nn_ops
|
|
@@ -10043,7 +10081,7 @@ class SparseApplyProximalGradientDescent(Primitive):
|
|
|
10043
10081
|
"""
|
|
10044
10082
|
|
|
10045
10083
|
__mindspore_signature__ = (
|
|
10046
|
-
sig.make_sig('var', dtype=sig.sig_dtype.T),
|
|
10084
|
+
sig.make_sig('var', sig.sig_rw.RW_WRITE, dtype=sig.sig_dtype.T),
|
|
10047
10085
|
sig.make_sig('alpha', dtype=sig.sig_dtype.T),
|
|
10048
10086
|
sig.make_sig('l1', dtype=sig.sig_dtype.T),
|
|
10049
10087
|
sig.make_sig('l2', dtype=sig.sig_dtype.T),
|
|
@@ -10104,7 +10142,7 @@ class NuclearNorm(Primitive):
|
|
|
10104
10142
|
x_rank is the dimension of Tensor `x`.
|
|
10105
10143
|
|
|
10106
10144
|
Supported Platforms:
|
|
10107
|
-
``CPU``
|
|
10145
|
+
``Ascend`` ``CPU``
|
|
10108
10146
|
|
|
10109
10147
|
Examples:
|
|
10110
10148
|
>>> input_x = Tensor(np.array([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]],
|
|
@@ -10139,7 +10177,7 @@ class NuclearNorm(Primitive):
|
|
|
10139
10177
|
"""Initialize NuclearNorm."""
|
|
10140
10178
|
validator.check_value_type("dim", dim, [list, tuple, type(None)], self.name)
|
|
10141
10179
|
if dim is not None:
|
|
10142
|
-
validator.check_int(len(dim), 2,
|
|
10180
|
+
validator.check_int(len(dim), 2, validator.EQ, 'length of dim_size', self.name)
|
|
10143
10181
|
validator.check_is_int(dim[0], "dim[0]", self.name)
|
|
10144
10182
|
validator.check_is_int(dim[1], "dim[1]", self.name)
|
|
10145
10183
|
else:
|
|
@@ -10148,44 +10186,27 @@ class NuclearNorm(Primitive):
|
|
|
10148
10186
|
|
|
10149
10187
|
|
|
10150
10188
|
class GLU(Primitive):
|
|
10151
|
-
r"""
|
|
10152
|
-
|
|
10153
|
-
.. math ::
|
|
10154
|
-
\begin{array}{ll} \\
|
|
10155
|
-
\text{GLU}(a, b) = a \otimes \sigma(b)
|
|
10156
|
-
\end{array}
|
|
10157
|
-
where `input` is split in half along `dim` to form `a` and `b`,
|
|
10158
|
-
σ is the sigmoid function and ⊗ is the element-wise product between matrices.
|
|
10159
|
-
|
|
10160
|
-
Args:
|
|
10161
|
-
axis (int): Dimension on which to split the input.
|
|
10162
|
-
The value of `axis` must be in the range [-rank(`x`), rank(`x`)). Default: -1.
|
|
10163
|
-
|
|
10164
|
-
Inputs:
|
|
10165
|
-
- **x** (Tensor) - Input tensor. `x.shape[axis]` must be even.
|
|
10189
|
+
r"""
|
|
10190
|
+
Computes GLU (Gated Linear Unit activation function) of input tensors.
|
|
10166
10191
|
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
With the same shape as `x`, except for the dimension of `axis`, y.shape[axis] = x.shape[axis] / 2.
|
|
10192
|
+
.. warning::
|
|
10193
|
+
This is an experimental API that is subject to change or deletion.
|
|
10170
10194
|
|
|
10171
|
-
|
|
10172
|
-
TypeError: If data type of `x` is not one of the following: float16, float32, float64.
|
|
10173
|
-
TypeError: If data type of `axis` is not int.
|
|
10174
|
-
ValueError: If `axis` is not in the range [-rank(`x`), rank(`x`)).
|
|
10175
|
-
ValueError: If the dimension of the `x` is not equal or greater than 1.
|
|
10176
|
-
ValueError: If `x.shape[axis]` is not even.
|
|
10195
|
+
Refer to :func:`mindspore.ops.glu` for more details.
|
|
10177
10196
|
|
|
10178
10197
|
Supported Platforms:
|
|
10179
10198
|
``Ascend`` ``CPU``
|
|
10180
10199
|
|
|
10181
10200
|
Examples:
|
|
10182
|
-
>>> from mindspore
|
|
10201
|
+
>>> from mindspore import ops, Tensor
|
|
10202
|
+
>>> from mindspore import dtype as mstype
|
|
10203
|
+
>>> import numpy as np
|
|
10183
10204
|
>>> axis = 0
|
|
10184
10205
|
>>> x = Tensor(np.array([0.3220, 0.9545, 0.7879, 0.0975, 0.3698,
|
|
10185
10206
|
... 0.5135, 0.5740, 0.3435, 0.1895, 0.8764,
|
|
10186
10207
|
... 0.4980, 0.9673, 0.9879, 0.6988, 0.9022,
|
|
10187
10208
|
... 0.9304, 0.1558, 0.0153, 0.1559, 0.9852]).reshape([2, 2, 5]), mstype.float32)
|
|
10188
|
-
>>> glu =
|
|
10209
|
+
>>> glu = ops.GLU(axis=axis)
|
|
10189
10210
|
>>> y = glu(x)
|
|
10190
10211
|
>>> print(y)
|
|
10191
10212
|
[[[0.20028052 0.6916126 0.57412136 0.06512236 0.26307625]
|
|
@@ -10201,19 +10222,18 @@ class GLU(Primitive):
|
|
|
10201
10222
|
class FractionalMaxPoolWithFixedKsize(Primitive):
|
|
10202
10223
|
r"""
|
|
10203
10224
|
Applies a 2D fractional max pooling to an input signal composed of multiple input planes.
|
|
10204
|
-
The max-pooling operation is applied in kH
|
|
10205
|
-
the target output size
|
|
10206
|
-
|
|
10225
|
+
The max-pooling operation is applied in :math:`(kH, kW)` regions by a stochastic step size determined by
|
|
10226
|
+
the target output size `output_shape`.
|
|
10227
|
+
|
|
10228
|
+
The number of output features is equal to the number of input planes.
|
|
10207
10229
|
|
|
10208
10230
|
Fractional MaxPooling is described in the paper `Fractional Max-Pooling <https://arxiv.org/pdf/1412.6071>`_.
|
|
10209
10231
|
|
|
10210
10232
|
Args:
|
|
10211
|
-
ksize (Union[int, tuple[int]]):
|
|
10212
|
-
|
|
10213
|
-
|
|
10214
|
-
|
|
10215
|
-
output_shape can be a tuple, or a single H for H x H.
|
|
10216
|
-
specifying the size (H, W) of the output tensor.
|
|
10233
|
+
ksize (Union[int, tuple[int]]): Size of the pooling window. `ksize` can be a tuple of two values
|
|
10234
|
+
specify a shape :math:`(k_H, k_W)`, or a single int `K` for :math:`(K, K)`.
|
|
10235
|
+
output_shape (Union[int, tuple[int]]): The target output shape. `output_shape` can be a
|
|
10236
|
+
tuple of two values specify a shape :math:`(H_{out}, W_{out})`, or a single float `S` for :math:`(S, S)`.
|
|
10217
10237
|
data_format (str, optional): The optional value for data format, is 'NCHW'.
|
|
10218
10238
|
Default: "NCHW".
|
|
10219
10239
|
|
|
@@ -10225,7 +10245,7 @@ class FractionalMaxPoolWithFixedKsize(Primitive):
|
|
|
10225
10245
|
|
|
10226
10246
|
Outputs:
|
|
10227
10247
|
- **y** (Tensor) - Has the same type as the `input_x`.
|
|
10228
|
-
Has the shape :math:`(N, C,
|
|
10248
|
+
Has the shape :math:`(N, C, H_{out}, W_{out})`.
|
|
10229
10249
|
- **argmax** (Tensor) -A tensor whose data type must be int64. Has the same shape as the `y`.
|
|
10230
10250
|
|
|
10231
10251
|
Raises:
|
|
@@ -10277,3 +10297,129 @@ class FractionalMaxPoolWithFixedKsize(Primitive):
|
|
|
10277
10297
|
self.add_prim_attr("output_shape", self.output_shape)
|
|
10278
10298
|
self.data_format = validator.check_string(data_format, ['NCHW'], 'data_format', self.name)
|
|
10279
10299
|
self.init_prim_io_names(inputs=['input_x', 'random_samples'], outputs=['y', 'argmax'])
|
|
10300
|
+
|
|
10301
|
+
|
|
10302
|
+
class ChannelShuffle(Primitive):
|
|
10303
|
+
r"""
|
|
10304
|
+
Divide the channels in a tensor of shape (*, C, H, W) into g groups and
|
|
10305
|
+
rearrange them as (*, C/g, g, H*W), while keeping the original tensor shapes.
|
|
10306
|
+
|
|
10307
|
+
.. warning::
|
|
10308
|
+
This is an experimental API that is subject to change or deletion.
|
|
10309
|
+
|
|
10310
|
+
Refer to :func:`mindspore.ops.channel_shuffle` for more detail.
|
|
10311
|
+
|
|
10312
|
+
Supported Platforms:
|
|
10313
|
+
``Ascend`` ``CPU``
|
|
10314
|
+
|
|
10315
|
+
Examples:
|
|
10316
|
+
>>> group = 2
|
|
10317
|
+
>>> x = Tensor(np.arange(1 * 4 * 2 * 2).reshape(1, 4, 2, 2).astype(np.int16))
|
|
10318
|
+
>>> channel_shuffle_func = ops.ChannelShuffle(group)
|
|
10319
|
+
>>> y = channel_shuffle_func(x)
|
|
10320
|
+
>>> print(y)
|
|
10321
|
+
[[[[ 0 1]
|
|
10322
|
+
[ 2 3]]
|
|
10323
|
+
[[ 8 9]
|
|
10324
|
+
[10 11]]
|
|
10325
|
+
[[ 4 5]
|
|
10326
|
+
[ 6 7]]
|
|
10327
|
+
[[12 13]
|
|
10328
|
+
[14 15]]]]
|
|
10329
|
+
"""
|
|
10330
|
+
|
|
10331
|
+
@prim_attr_register
|
|
10332
|
+
def __init__(self, group):
|
|
10333
|
+
"""Initialize ChannelShuffle"""
|
|
10334
|
+
if not isinstance(group, int):
|
|
10335
|
+
raise ValueError(f"For '{self.name}', attr 'group' must be an positive int number")
|
|
10336
|
+
self.init_prim_io_names(inputs=['x'], outputs=['y'])
|
|
10337
|
+
|
|
10338
|
+
|
|
10339
|
+
class MaxPoolWithArgmaxV2(Primitive):
|
|
10340
|
+
r"""
|
|
10341
|
+
Performs max pooling on the input Tensor and returns both max values and indices.
|
|
10342
|
+
|
|
10343
|
+
Typically the input is of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})`, MaxPool outputs
|
|
10344
|
+
regional maximum in the :math:`(H_{in}, W_{in})`-dimension. Given kernel size
|
|
10345
|
+
:math:`ks = (h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1)`, the operation is as follows:
|
|
10346
|
+
|
|
10347
|
+
.. math::
|
|
10348
|
+
\text{output}(N_i, C_j, h, w) = \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
|
|
10349
|
+
\text{input}(N_i, C_j, s_0 \times h + m, s_1 \times w + n)
|
|
10350
|
+
|
|
10351
|
+
Args:
|
|
10352
|
+
kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value and argmax
|
|
10353
|
+
value, is an int number that represents height and width of the kernel, or a tuple of
|
|
10354
|
+
two int numbers that represent height and width respectively.
|
|
10355
|
+
strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
|
|
10356
|
+
not only the height of movement but also the width of movement, or a tuple of two int numbers that
|
|
10357
|
+
represent height and width of movement respectively. Default: None, meaning that `strides = kernel_size`.
|
|
10358
|
+
pads (Union[int, tuple[int]]): An int number that represents the depth, height and width of movement are both
|
|
10359
|
+
strides, or a tuple of three int numbers that represent depth, height and width of movement respectively.
|
|
10360
|
+
dilation (Union[int, tuple[int]]): Default: '(1, 1)'.
|
|
10361
|
+
ceil_mode (bool): Whether to use ceil instead of floor to calculate output shape. Default: False.
|
|
10362
|
+
argmax_type (mindspore.dtype) : The dtype for argmax. Default: mstype.int64.
|
|
10363
|
+
|
|
10364
|
+
Inputs:
|
|
10365
|
+
- **x** (Tensor) - Tensor of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})` with data type of int8,
|
|
10366
|
+
int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32 or float64.
|
|
10367
|
+
|
|
10368
|
+
Outputs:
|
|
10369
|
+
Tuple of 2 Tensors, representing the maxpool result and where the max values are generated.
|
|
10370
|
+
|
|
10371
|
+
- **output** (Tensor) - Maxpooling result, with shape :math:`(N_{out}, C_{out}, H_{out}, W_{out})`.
|
|
10372
|
+
It has the same data type as `x`.
|
|
10373
|
+
- **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int32 or int64.
|
|
10374
|
+
|
|
10375
|
+
Raises:
|
|
10376
|
+
TypeError: If `x` is not a Tensor.
|
|
10377
|
+
ValueError: If length of shape of `x` is not equal to 4.
|
|
10378
|
+
TypeError: If `kernel_size` , `strides` , `pads` or `dilation` is not int or tuple.
|
|
10379
|
+
ValueError: If `kernel_size`, `strides` or `dilation` is less than 1.
|
|
10380
|
+
ValueError: If `pads` is less than 0.
|
|
10381
|
+
ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
|
|
10382
|
+
TypeError: If `ceil_mode` is not bool.
|
|
10383
|
+
|
|
10384
|
+
Supported Platforms:
|
|
10385
|
+
``Ascend`` ``GPU`` ``CPU``
|
|
10386
|
+
|
|
10387
|
+
Examples:
|
|
10388
|
+
>>> x = Tensor(np.arange(20 * 16 * 50 * 32).reshape((20, 16, 50, 32)), mindspore.float32)
|
|
10389
|
+
>>> maxpool_arg_v2_op = ops.MaxPoolWithArgmaxV2(kernel_size=(3, 2), strides=(2, 1))
|
|
10390
|
+
>>> output_tensor, argmax = maxpool_arg_v2_op(x)
|
|
10391
|
+
>>> print(output_tensor.shape)
|
|
10392
|
+
(20, 16, 24, 31)
|
|
10393
|
+
>>> pirnt(argmax.shape)
|
|
10394
|
+
(20, 16, 24, 31)
|
|
10395
|
+
"""
|
|
10396
|
+
|
|
10397
|
+
@prim_attr_register
|
|
10398
|
+
def __init__(self, kernel_size, strides=None, pads=0, dilation=(1, 1,), ceil_mode=False, argmax_type=mstype.int64):
|
|
10399
|
+
"""Initialize MaxPoolWithArgmaxV2."""
|
|
10400
|
+
self.init_prim_io_names(inputs=["x"], outputs=["output", "argmax"])
|
|
10401
|
+
validator.check_value_type("ceil_mode", ceil_mode, bool, self.name)
|
|
10402
|
+
self.ceil_mode = ceil_mode
|
|
10403
|
+
validator.check_value_type("argmax_type", argmax_type, [mstype.Type], self.name)
|
|
10404
|
+
argmax_type_valid_values = (mstype.int32, mstype.int64)
|
|
10405
|
+
validator.check_type_name("argmax_type", argmax_type, argmax_type_valid_values, self.name)
|
|
10406
|
+
if argmax_type == mstype.int32:
|
|
10407
|
+
self.add_prim_attr("argmax_type", 3)
|
|
10408
|
+
elif argmax_type == mstype.int64:
|
|
10409
|
+
self.add_prim_attr("argmax_type", 4)
|
|
10410
|
+
else:
|
|
10411
|
+
raise ValueError(
|
|
10412
|
+
f"For '{self.name}', the 'argmax_type' must be mstype.int32 or mstype.int64, but got {argmax_type}.")
|
|
10413
|
+
self.kernel_size = _check_positive_int_or_tuple("kernel_size", kernel_size, self.name, ret_four=True,
|
|
10414
|
+
allow_four=True)
|
|
10415
|
+
if strides is None:
|
|
10416
|
+
strides = kernel_size
|
|
10417
|
+
self.strides = _check_positive_int_or_tuple("strides", strides, self.name, ret_four=True, allow_four=True)
|
|
10418
|
+
self.pads = _check_positive_int_or_tuple("pads", pads, self.name, ret_four=True, allow_four=True,
|
|
10419
|
+
strict_positive=False)
|
|
10420
|
+
self.dilation = _check_positive_int_or_tuple("dilation", dilation, self.name, ret_four=True, allow_four=True)
|
|
10421
|
+
self.add_prim_attr("kernel_size", self.kernel_size)
|
|
10422
|
+
self.add_prim_attr("strides", self.strides)
|
|
10423
|
+
self.add_prim_attr("pads", self.pads)
|
|
10424
|
+
self.add_prim_attr("dilation", self.dilation)
|
|
10425
|
+
self.add_prim_attr("ceil_mode", self.ceil_mode)
|