mindspore 2.0.0a0__cp39-cp39-win_amd64.whl → 2.0.0rc1__cp39-cp39-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.

Files changed (655) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/__init__.py +4 -2
  3. mindspore/_c_dataengine.cp39-win_amd64.pyd +0 -0
  4. mindspore/_c_expression.cp39-win_amd64.pyd +0 -0
  5. mindspore/_c_mindrecord.cp39-win_amd64.pyd +0 -0
  6. mindspore/_check_jit_forbidden_api.py +102 -0
  7. mindspore/_checkparam.py +1066 -1001
  8. mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +4 -3
  9. mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +50 -48
  10. mindspore/_extends/parallel_compile/akg_compiler/util.py +9 -4
  11. mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +4 -4
  12. mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +9 -4
  13. mindspore/_extends/parse/__init__.py +5 -3
  14. mindspore/_extends/parse/namespace.py +16 -1
  15. mindspore/_extends/parse/parser.py +107 -22
  16. mindspore/_extends/parse/resources.py +0 -7
  17. mindspore/_extends/parse/standard_method.py +885 -413
  18. mindspore/amp.py +52 -57
  19. mindspore/boost/boost.py +2 -2
  20. mindspore/boost/boost_cell_wrapper.py +38 -20
  21. mindspore/boost/dim_reduce.py +3 -3
  22. mindspore/boost/group_loss_scale_manager.py +1 -1
  23. mindspore/common/__init__.py +4 -6
  24. mindspore/common/_decorator.py +2 -0
  25. mindspore/common/_register_for_adapter.py +55 -0
  26. mindspore/common/_stub_tensor.py +201 -0
  27. mindspore/common/_utils.py +41 -7
  28. mindspore/common/api.py +215 -141
  29. mindspore/common/dtype.py +8 -1
  30. mindspore/common/dump.py +2 -2
  31. mindspore/common/initializer.py +4 -2
  32. mindspore/common/jit_config.py +17 -13
  33. mindspore/common/mutable.py +33 -13
  34. mindspore/common/parameter.py +23 -21
  35. mindspore/common/seed.py +8 -24
  36. mindspore/common/sparse_tensor.py +62 -41
  37. mindspore/common/tensor.py +852 -1154
  38. mindspore/communication/__init__.py +2 -2
  39. mindspore/communication/_comm_helper.py +11 -4
  40. mindspore/communication/management.py +22 -21
  41. mindspore/config/op_info.config +501 -1008
  42. mindspore/context.py +201 -23
  43. mindspore/dataset/__init__.py +6 -6
  44. mindspore/dataset/audio/__init__.py +7 -7
  45. mindspore/dataset/audio/transforms.py +670 -30
  46. mindspore/dataset/audio/utils.py +47 -4
  47. mindspore/dataset/audio/validators.py +223 -1
  48. mindspore/dataset/callback/ds_callback.py +2 -2
  49. mindspore/dataset/core/config.py +210 -14
  50. mindspore/dataset/core/validator_helpers.py +2 -2
  51. mindspore/{parallel/nn/layers.py → dataset/debug/__init__.py} +7 -8
  52. mindspore/dataset/debug/debug_hook.py +65 -0
  53. mindspore/dataset/debug/pre_defined_hook.py +67 -0
  54. mindspore/dataset/engine/__init__.py +7 -3
  55. mindspore/dataset/engine/cache_client.py +1 -1
  56. mindspore/dataset/engine/datasets.py +322 -66
  57. mindspore/dataset/engine/datasets_audio.py +80 -76
  58. mindspore/dataset/engine/datasets_standard_format.py +51 -38
  59. mindspore/dataset/engine/datasets_text.py +232 -118
  60. mindspore/dataset/engine/datasets_user_defined.py +41 -17
  61. mindspore/dataset/engine/datasets_vision.py +746 -225
  62. mindspore/dataset/engine/graphdata.py +75 -10
  63. mindspore/dataset/engine/iterators.py +45 -5
  64. mindspore/dataset/engine/offload.py +48 -28
  65. mindspore/dataset/engine/validators.py +117 -8
  66. mindspore/dataset/text/__init__.py +6 -5
  67. mindspore/dataset/text/transforms.py +86 -3
  68. mindspore/dataset/text/utils.py +6 -4
  69. mindspore/dataset/text/validators.py +25 -0
  70. mindspore/dataset/transforms/__init__.py +3 -2
  71. mindspore/dataset/transforms/c_transforms.py +1 -1
  72. mindspore/dataset/transforms/transforms.py +2 -2
  73. mindspore/dataset/utils/__init__.py +2 -1
  74. mindspore/dataset/utils/line_reader.py +121 -0
  75. mindspore/dataset/vision/__init__.py +2 -3
  76. mindspore/dataset/vision/c_transforms.py +9 -9
  77. mindspore/dataset/vision/py_transforms.py +5 -5
  78. mindspore/dataset/vision/py_transforms_util.py +2 -0
  79. mindspore/dataset/vision/transforms.py +160 -161
  80. mindspore/dataset/vision/utils.py +3 -3
  81. mindspore/experimental/map_parameter.py +38 -26
  82. mindspore/include/OWNERS +0 -1
  83. mindspore/include/api/callback/callback.h +9 -13
  84. mindspore/include/api/callback/ckpt_saver.h +2 -2
  85. mindspore/include/api/callback/loss_monitor.h +2 -2
  86. mindspore/include/api/callback/lr_scheduler.h +5 -5
  87. mindspore/include/api/callback/time_monitor.h +2 -2
  88. mindspore/include/api/callback/train_accuracy.h +4 -6
  89. mindspore/include/api/cfg.h +19 -6
  90. mindspore/include/api/context.h +44 -9
  91. mindspore/include/api/delegate.h +1 -1
  92. mindspore/include/api/metrics/accuracy.h +2 -2
  93. mindspore/include/api/metrics/metrics.h +4 -3
  94. mindspore/include/api/model.h +9 -4
  95. mindspore/include/api/model_parallel_runner.h +2 -2
  96. mindspore/include/api/net.h +12 -11
  97. mindspore/include/api/serialization.h +19 -3
  98. mindspore/include/api/types.h +3 -3
  99. mindspore/include/dataset/constants.h +7 -0
  100. mindspore/include/dataset/text.h +59 -0
  101. mindspore/jpeg62.dll +0 -0
  102. mindspore/log.py +1 -1
  103. mindspore/mindrecord/filereader.py +18 -0
  104. mindspore/mindrecord/filewriter.py +197 -34
  105. mindspore/mindrecord/shardreader.py +9 -0
  106. mindspore/mindrecord/shardwriter.py +1 -1
  107. mindspore/mindrecord/tools/cifar100_to_mr.py +3 -3
  108. mindspore/mindrecord/tools/cifar10_to_mr.py +3 -3
  109. mindspore/mindrecord/tools/csv_to_mr.py +3 -3
  110. mindspore/mindrecord/tools/imagenet_to_mr.py +16 -11
  111. mindspore/mindrecord/tools/mnist_to_mr.py +2 -2
  112. mindspore/mindrecord/tools/tfrecord_to_mr.py +6 -6
  113. mindspore/mindspore_backend.dll +0 -0
  114. mindspore/mindspore_common.dll +0 -0
  115. mindspore/mindspore_core.dll +0 -0
  116. mindspore/mindspore_glog.dll +0 -0
  117. mindspore/mindspore_shared_lib.dll +0 -0
  118. mindspore/nn/__init__.py +0 -4
  119. mindspore/nn/cell.py +204 -132
  120. mindspore/nn/dynamic_lr.py +1 -1
  121. mindspore/nn/grad/cell_grad.py +7 -6
  122. mindspore/nn/layer/__init__.py +5 -4
  123. mindspore/nn/layer/activation.py +40 -89
  124. mindspore/nn/layer/basic.py +255 -624
  125. mindspore/nn/layer/channel_shuffle.py +7 -6
  126. mindspore/nn/layer/combined.py +1 -1
  127. mindspore/nn/layer/container.py +41 -4
  128. mindspore/nn/layer/conv.py +64 -28
  129. mindspore/nn/layer/dense.py +9 -8
  130. mindspore/nn/layer/embedding.py +27 -25
  131. mindspore/nn/layer/image.py +53 -46
  132. mindspore/nn/layer/math.py +97 -105
  133. mindspore/nn/layer/normalization.py +117 -86
  134. mindspore/nn/layer/padding.py +185 -95
  135. mindspore/nn/layer/pooling.py +817 -414
  136. mindspore/nn/layer/rnn_cells.py +10 -15
  137. mindspore/nn/layer/rnns.py +37 -38
  138. mindspore/nn/layer/thor_layer.py +11 -12
  139. mindspore/nn/layer/timedistributed.py +5 -5
  140. mindspore/nn/layer/transformer.py +701 -0
  141. mindspore/nn/learning_rate_schedule.py +8 -8
  142. mindspore/nn/loss/__init__.py +5 -4
  143. mindspore/nn/loss/loss.py +334 -199
  144. mindspore/nn/optim/ada_grad.py +6 -6
  145. mindspore/nn/optim/adadelta.py +2 -3
  146. mindspore/nn/optim/adafactor.py +4 -5
  147. mindspore/nn/optim/adam.py +126 -62
  148. mindspore/nn/optim/adamax.py +3 -4
  149. mindspore/nn/optim/adasum.py +6 -6
  150. mindspore/nn/optim/asgd.py +2 -2
  151. mindspore/nn/optim/ftrl.py +67 -38
  152. mindspore/nn/optim/lamb.py +4 -5
  153. mindspore/nn/optim/lars.py +2 -2
  154. mindspore/nn/optim/lazyadam.py +43 -4
  155. mindspore/nn/optim/momentum.py +6 -5
  156. mindspore/nn/optim/optimizer.py +3 -1
  157. mindspore/nn/optim/proximal_ada_grad.py +2 -2
  158. mindspore/nn/optim/rmsprop.py +1 -1
  159. mindspore/nn/optim/rprop.py +8 -9
  160. mindspore/nn/optim/sgd.py +19 -13
  161. mindspore/nn/optim/thor.py +10 -15
  162. mindspore/nn/probability/__init__.py +0 -2
  163. mindspore/nn/probability/bijector/bijector.py +4 -4
  164. mindspore/nn/probability/bijector/invert.py +1 -1
  165. mindspore/nn/probability/bijector/softplus.py +2 -2
  166. mindspore/nn/probability/bnn_layers/dense_variational.py +1 -1
  167. mindspore/nn/probability/bnn_layers/layer_distribution.py +2 -2
  168. mindspore/nn/probability/distribution/_utils/utils.py +9 -15
  169. mindspore/nn/probability/distribution/bernoulli.py +3 -3
  170. mindspore/nn/probability/distribution/beta.py +1 -1
  171. mindspore/nn/probability/distribution/categorical.py +5 -7
  172. mindspore/nn/probability/distribution/cauchy.py +3 -3
  173. mindspore/nn/probability/distribution/distribution.py +2 -2
  174. mindspore/nn/probability/distribution/exponential.py +2 -2
  175. mindspore/nn/probability/distribution/gamma.py +3 -3
  176. mindspore/nn/probability/distribution/geometric.py +1 -1
  177. mindspore/nn/probability/distribution/gumbel.py +3 -3
  178. mindspore/nn/probability/distribution/half_normal.py +15 -11
  179. mindspore/nn/probability/distribution/laplace.py +16 -13
  180. mindspore/nn/probability/distribution/logistic.py +2 -2
  181. mindspore/nn/probability/distribution/normal.py +1 -1
  182. mindspore/nn/probability/distribution/poisson.py +1 -1
  183. mindspore/nn/probability/distribution/student_t.py +20 -15
  184. mindspore/nn/probability/distribution/transformed_distribution.py +4 -4
  185. mindspore/nn/probability/distribution/uniform.py +2 -2
  186. mindspore/nn/reinforcement/_tensors_queue.py +3 -3
  187. mindspore/nn/reinforcement/tensor_array.py +2 -2
  188. mindspore/nn/sparse/sparse.py +2 -2
  189. mindspore/nn/wrap/cell_wrapper.py +27 -10
  190. mindspore/nn/wrap/grad_reducer.py +2 -2
  191. mindspore/nn/wrap/loss_scale.py +40 -24
  192. mindspore/numpy/array_creations.py +33 -22
  193. mindspore/numpy/array_ops.py +35 -30
  194. mindspore/numpy/logic_ops.py +6 -27
  195. mindspore/numpy/math_ops.py +22 -19
  196. mindspore/numpy/utils.py +1 -1
  197. mindspore/numpy/utils_const.py +108 -58
  198. mindspore/opencv_core452.dll +0 -0
  199. mindspore/opencv_imgcodecs452.dll +0 -0
  200. mindspore/opencv_imgproc452.dll +0 -0
  201. mindspore/ops/_constants.py +0 -6
  202. mindspore/ops/_grad/__init__.py +2 -1
  203. mindspore/ops/_grad/grad_array_ops.py +86 -117
  204. mindspore/ops/_grad/grad_base.py +23 -1
  205. mindspore/ops/_grad/grad_clip_ops.py +2 -3
  206. mindspore/ops/_grad/grad_comm_ops.py +34 -24
  207. mindspore/ops/_grad/grad_implementations.py +9 -45
  208. mindspore/ops/_grad/grad_inner_ops.py +47 -4
  209. mindspore/ops/_grad/grad_math_ops.py +142 -117
  210. mindspore/ops/_grad/grad_nn_ops.py +71 -165
  211. mindspore/ops/_grad/grad_sequence_ops.py +296 -0
  212. mindspore/ops/_grad/grad_sparse.py +7 -6
  213. mindspore/ops/_grad_experimental/__init__.py +1 -0
  214. mindspore/ops/_grad_experimental/grad_array_ops.py +150 -15
  215. mindspore/ops/_grad_experimental/grad_image_ops.py +16 -7
  216. mindspore/ops/_grad_experimental/grad_inner_ops.py +1 -22
  217. mindspore/ops/_grad_experimental/grad_linalg_ops.py +4 -11
  218. mindspore/ops/_grad_experimental/grad_math_ops.py +210 -89
  219. mindspore/ops/_grad_experimental/grad_nn_ops.py +26 -22
  220. mindspore/ops/_grad_experimental/grad_scalar_ops.py +112 -0
  221. mindspore/ops/_grad_experimental/grad_sparse_ops.py +49 -8
  222. mindspore/ops/_op_impl/_custom_op/batch_matmul_impl.py +1 -1
  223. mindspore/ops/_op_impl/_custom_op/batchnorm_fold.py +2 -2
  224. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2.py +2 -2
  225. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad.py +2 -2
  226. mindspore/ops/_op_impl/_custom_op/batchnorm_fold2_grad_reduce.py +4 -4
  227. mindspore/ops/_op_impl/_custom_op/batchnorm_fold_grad.py +3 -3
  228. mindspore/ops/_op_impl/_custom_op/cholesky_trsm_impl.py +1 -1
  229. mindspore/ops/_op_impl/_custom_op/correction_mul.py +2 -2
  230. mindspore/ops/_op_impl/_custom_op/correction_mul_grad.py +2 -2
  231. mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +1 -5
  232. mindspore/ops/_op_impl/_custom_op/dsd_impl.py +1 -1
  233. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel.py +2 -2
  234. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad.py +2 -2
  235. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perchannel_grad_reduce.py +2 -2
  236. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer.py +2 -2
  237. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad.py +2 -2
  238. mindspore/ops/_op_impl/_custom_op/fake_learned_scale_quant_perlayer_grad_reduce.py +2 -2
  239. mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel.py +2 -2
  240. mindspore/ops/_op_impl/_custom_op/fake_quant_perchannel_grad.py +2 -2
  241. mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer.py +2 -2
  242. mindspore/ops/_op_impl/_custom_op/fake_quant_perlayer_grad.py +2 -2
  243. mindspore/ops/_op_impl/_custom_op/fused_abs_max1_impl.py +1 -1
  244. mindspore/ops/_op_impl/_custom_op/img2col_impl.py +1 -1
  245. mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_left_impl.py +2 -2
  246. mindspore/ops/_op_impl/_custom_op/matmul_cube_dense_right_impl.py +1 -1
  247. mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_left_cast_impl.py +1 -1
  248. mindspore/ops/_op_impl/_custom_op/matmul_cube_fracz_right_mul_impl.py +1 -1
  249. mindspore/ops/_op_impl/_custom_op/matmul_cube_impl.py +2 -2
  250. mindspore/ops/_op_impl/_custom_op/matmul_dds_impl.py +0 -4
  251. mindspore/ops/_op_impl/_custom_op/matrix_combine_impl.py +1 -1
  252. mindspore/ops/_op_impl/_custom_op/minmax_update_perchannel.py +2 -2
  253. mindspore/ops/_op_impl/_custom_op/minmax_update_perlayer.py +2 -2
  254. mindspore/ops/_op_impl/_custom_op/transpose02314_impl.py +1 -1
  255. mindspore/ops/_op_impl/aicpu/__init__.py +236 -4
  256. mindspore/ops/_op_impl/aicpu/abs.py +36 -0
  257. mindspore/ops/_op_impl/aicpu/{adaptive_avg_pool_2d_v1.py → adaptive_avg_pool_2d.py} +6 -5
  258. mindspore/ops/_op_impl/aicpu/adaptive_avg_pool_2d_grad.py +34 -0
  259. mindspore/ops/_op_impl/aicpu/add.py +43 -0
  260. mindspore/ops/_op_impl/aicpu/addcdiv.py +0 -32
  261. mindspore/ops/_op_impl/aicpu/addcmul.py +0 -84
  262. mindspore/ops/_op_impl/aicpu/affine_grid_grad.py +35 -0
  263. mindspore/ops/_op_impl/aicpu/batch_matmul.py +43 -43
  264. mindspore/ops/_op_impl/aicpu/bernoulli.py +48 -0
  265. mindspore/{compression/common/__init__.py → ops/_op_impl/aicpu/bessel_i0.py} +15 -8
  266. mindspore/ops/_op_impl/aicpu/channel_shuffle.py +40 -0
  267. mindspore/ops/_op_impl/aicpu/conj.py +11 -0
  268. mindspore/ops/_op_impl/aicpu/cumulative_logsumexp.py +0 -3
  269. mindspore/ops/_op_impl/aicpu/deformable_offsets.py +38 -0
  270. mindspore/ops/_op_impl/aicpu/deformable_offsets_grad.py +43 -0
  271. mindspore/ops/_op_impl/aicpu/{adaptive_avg_pool_2d_grad_v1.py → digamma.py} +7 -9
  272. mindspore/ops/_op_impl/aicpu/flatten.py +1 -0
  273. mindspore/ops/_op_impl/aicpu/fmax.py +36 -0
  274. mindspore/ops/_op_impl/aicpu/fmin.py +37 -0
  275. mindspore/ops/_op_impl/aicpu/fractional_max_pool3d_with_fixed_ksize.py +1 -1
  276. mindspore/ops/_op_impl/aicpu/fse_decode.py +43 -0
  277. mindspore/ops/_op_impl/aicpu/greater.py +41 -0
  278. mindspore/ops/_op_impl/aicpu/greater_equal.py +41 -0
  279. mindspore/ops/_op_impl/aicpu/index_put.py +50 -0
  280. mindspore/ops/_op_impl/aicpu/less.py +41 -0
  281. mindspore/{nn/probability/infer/variational/__init__.py → ops/_op_impl/aicpu/lgamma.py} +16 -10
  282. mindspore/ops/_op_impl/aicpu/mirror_pad.py +0 -4
  283. mindspore/ops/_op_impl/aicpu/mirror_pad_grad.py +0 -4
  284. mindspore/ops/_op_impl/aicpu/mul.py +3 -1
  285. mindspore/ops/_op_impl/aicpu/multinomial.py +14 -6
  286. mindspore/ops/_op_impl/aicpu/nllloss.py +38 -0
  287. mindspore/ops/_op_impl/aicpu/nllloss_grad.py +39 -0
  288. mindspore/ops/_op_impl/aicpu/ones_like.py +0 -2
  289. mindspore/ops/_op_impl/aicpu/polar.py +32 -0
  290. mindspore/ops/_op_impl/aicpu/polygamma.py +34 -0
  291. mindspore/ops/_op_impl/aicpu/quant_dtype_cast.py +40 -0
  292. mindspore/ops/_op_impl/aicpu/quantile.py +35 -0
  293. mindspore/ops/_op_impl/aicpu/ragged_tensor_to_sparse.py +73 -0
  294. mindspore/ops/_op_impl/aicpu/randperm_v2.py +41 -0
  295. mindspore/ops/_op_impl/aicpu/resize_bicubic.py +2 -8
  296. mindspore/ops/_op_impl/aicpu/resize_bicubic_grad.py +1 -1
  297. mindspore/ops/_op_impl/aicpu/resize_v2.py +68 -0
  298. mindspore/ops/_op_impl/aicpu/resize_v2_grad.py +68 -0
  299. mindspore/ops/_op_impl/aicpu/scatter_elements.py +4 -0
  300. mindspore/ops/_op_impl/aicpu/scatter_nd_update.py +2 -0
  301. mindspore/ops/_op_impl/aicpu/sequence_add.py +34 -0
  302. mindspore/ops/_op_impl/aicpu/sequence_add_offset.py +34 -0
  303. mindspore/ops/_op_impl/aicpu/sequence_addn.py +38 -0
  304. mindspore/ops/_op_impl/aicpu/smooth_l1_loss.py +35 -0
  305. mindspore/ops/_op_impl/aicpu/smooth_l1_loss_grad.py +37 -0
  306. mindspore/ops/_op_impl/aicpu/sparse_apply_adagrad_da.py +0 -24
  307. mindspore/ops/_op_impl/aicpu/sparse_cross.py +42 -0
  308. mindspore/ops/_op_impl/aicpu/sparse_slice.py +4 -0
  309. mindspore/ops/_op_impl/aicpu/sparse_slice_grad.py +6 -0
  310. mindspore/ops/_op_impl/aicpu/tensor_scatter_update.py +59 -0
  311. mindspore/ops/_op_impl/aicpu/trans_data.py +1 -0
  312. mindspore/ops/_op_impl/aicpu/tril_indices.py +34 -0
  313. mindspore/ops/_op_impl/aicpu/uniform.py +34 -0
  314. mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +1 -0
  315. mindspore/ops/_op_impl/aicpu/unique_consecutive.py +10 -2
  316. mindspore/ops/_op_impl/cpu/dynamic_shape.py +5 -1
  317. mindspore/ops/_op_impl/cpu/sparse_slice.py +4 -0
  318. mindspore/ops/_op_impl/cpu/sparse_slice_grad.py +6 -0
  319. mindspore/ops/_op_impl/cpu/tensor_shape.py +5 -1
  320. mindspore/ops/_op_impl/tbe/__init__.py +27 -611
  321. mindspore/ops/_op_impl/tbe/assign_add_ds.py +1 -0
  322. mindspore/ops/_op_impl/tbe/atomic_addr_clean.py +1 -1
  323. mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +1 -1
  324. mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +1 -0
  325. mindspore/ops/_op_impl/tbe/batch_to_space.py +1 -1
  326. mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +1 -1
  327. mindspore/ops/_op_impl/tbe/bn_infer_grad.py +4 -2
  328. mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -1
  329. mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -1
  330. mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +6 -4
  331. mindspore/ops/_op_impl/tbe/cast.py +0 -2
  332. mindspore/ops/_op_impl/tbe/cast_ds.py +3 -3
  333. mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +1 -0
  334. mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +2 -2
  335. mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +1 -1
  336. mindspore/ops/_op_impl/tbe/gather_nd.py +1 -0
  337. mindspore/ops/_op_impl/tbe/{index_add.py → inplace_index_add.py} +3 -6
  338. mindspore/ops/_op_impl/tbe/matmul_ds.py +2 -0
  339. mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +35 -0
  340. mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +35 -0
  341. mindspore/ops/_op_impl/tbe/scatter_mul.py +2 -0
  342. mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -2
  343. mindspore/ops/_op_impl/tbe/space_to_batch.py +1 -1
  344. mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +1 -1
  345. mindspore/ops/_op_impl/tbe/trans_data_ds.py +15 -5
  346. mindspore/ops/_register_for_op.py +1 -0
  347. mindspore/ops/_utils/__init__.py +1 -2
  348. mindspore/ops/_utils/utils.py +19 -40
  349. mindspore/ops/_vmap/vmap_array_ops.py +116 -38
  350. mindspore/ops/_vmap/vmap_base.py +16 -9
  351. mindspore/ops/_vmap/vmap_convolution_ops.py +7 -10
  352. mindspore/ops/_vmap/vmap_grad_math_ops.py +4 -4
  353. mindspore/ops/_vmap/vmap_grad_nn_ops.py +7 -5
  354. mindspore/ops/_vmap/vmap_image_ops.py +12 -5
  355. mindspore/ops/_vmap/vmap_math_ops.py +46 -5
  356. mindspore/ops/_vmap/vmap_nn_ops.py +15 -21
  357. mindspore/ops/_vmap/vmap_random_ops.py +1 -1
  358. mindspore/ops/bprop_mindir/AdaptiveAvgPool2D_bprop.mindir +0 -0
  359. mindspore/ops/bprop_mindir/AdaptiveMaxPool2D_bprop.mindir +0 -0
  360. mindspore/ops/bprop_mindir/AvgPool3D_bprop.mindir +150 -0
  361. mindspore/ops/bprop_mindir/AvgPool_bprop.mindir +66 -0
  362. mindspore/ops/bprop_mindir/BCEWithLogitsLoss_bprop.mindir +0 -0
  363. mindspore/ops/bprop_mindir/BatchNormGrad_bprop.mindir +0 -0
  364. mindspore/ops/bprop_mindir/BiasAddGrad_bprop.mindir +0 -0
  365. mindspore/ops/bprop_mindir/BinaryCrossEntropy_bprop.mindir +33 -0
  366. mindspore/ops/bprop_mindir/BroadcastTo_bprop.mindir +220 -106
  367. mindspore/ops/bprop_mindir/CTCLoss_bprop.mindir +0 -0
  368. mindspore/ops/bprop_mindir/Conv2DBackpropFilter_bprop.mindir +240 -0
  369. mindspore/ops/bprop_mindir/Conv2DBackpropInput_bprop.mindir +247 -0
  370. mindspore/ops/bprop_mindir/Conv2DTranspose_bprop.mindir +247 -0
  371. mindspore/ops/bprop_mindir/Conv3DTranspose_bprop.mindir +315 -0
  372. mindspore/ops/bprop_mindir/Conv3D_bprop.mindir +278 -0
  373. mindspore/ops/bprop_mindir/DeformableOffsets_bprop.mindir +58 -0
  374. mindspore/ops/bprop_mindir/DepthwiseConv2dNative_bprop.mindir +138 -0
  375. mindspore/ops/bprop_mindir/Dropout2D_bprop.mindir +0 -0
  376. mindspore/ops/bprop_mindir/Dropout3D_bprop.mindir +0 -0
  377. mindspore/ops/bprop_mindir/DropoutDoMask_bprop.mindir +22 -23
  378. mindspore/ops/bprop_mindir/DropoutGenMask_bprop.mindir +16 -17
  379. mindspore/ops/bprop_mindir/DropoutGrad_bprop.mindir +27 -0
  380. mindspore/ops/bprop_mindir/Dropout_bprop.mindir +0 -0
  381. mindspore/ops/bprop_mindir/DynamicGRUV2_bprop.mindir +0 -0
  382. mindspore/ops/bprop_mindir/DynamicRNN_bprop.mindir +0 -0
  383. mindspore/ops/bprop_mindir/Elu_bprop.mindir +16 -0
  384. mindspore/ops/bprop_mindir/EmbeddingLookup_bprop.mindir +0 -0
  385. mindspore/ops/bprop_mindir/ExpandDims_bprop.mindir +39 -41
  386. mindspore/ops/bprop_mindir/FastGeLU_bprop.mindir +16 -0
  387. mindspore/ops/bprop_mindir/Flatten_bprop.mindir +41 -43
  388. mindspore/ops/bprop_mindir/GatherNd_bprop.mindir +51 -57
  389. mindspore/ops/bprop_mindir/Gather_bprop.mindir +0 -0
  390. mindspore/ops/bprop_mindir/HSigmoid_bprop.mindir +16 -0
  391. mindspore/ops/bprop_mindir/HSwish_bprop.mindir +16 -0
  392. mindspore/ops/bprop_mindir/InstanceNorm_bprop.mindir +0 -0
  393. mindspore/ops/bprop_mindir/KLDivLoss_bprop.mindir +126 -0
  394. mindspore/ops/bprop_mindir/L2Loss_bprop.mindir +15 -0
  395. mindspore/ops/bprop_mindir/L2Normalize_bprop.mindir +30 -0
  396. mindspore/ops/bprop_mindir/LRN_bprop.mindir +43 -0
  397. mindspore/ops/bprop_mindir/LayerNormGrad_bprop.mindir +0 -0
  398. mindspore/ops/bprop_mindir/LogSoftmax_bprop.mindir +23 -0
  399. mindspore/ops/bprop_mindir/MaxPool3DGradGrad_bprop.mindir +74 -0
  400. mindspore/ops/bprop_mindir/MaxPool3DGrad_bprop.mindir +74 -0
  401. mindspore/ops/bprop_mindir/MaxPool3D_bprop.mindir +75 -0
  402. mindspore/ops/bprop_mindir/MaxPoolGradGrad_bprop.mindir +65 -0
  403. mindspore/ops/bprop_mindir/MaxPoolWithArgmax_bprop.mindir +0 -0
  404. mindspore/ops/bprop_mindir/MirrorPad_bprop.mindir +27 -0
  405. mindspore/ops/bprop_mindir/Mish_bprop.mindir +35 -0
  406. mindspore/ops/bprop_mindir/MulNoNan_bprop.mindir +0 -0
  407. mindspore/ops/bprop_mindir/NLLLoss_bprop.mindir +0 -0
  408. mindspore/ops/bprop_mindir/OneHot_bprop.mindir +24 -25
  409. mindspore/ops/bprop_mindir/PReLU_bprop.mindir +0 -0
  410. mindspore/ops/bprop_mindir/Pad_bprop.mindir +0 -0
  411. mindspore/ops/bprop_mindir/Padding_bprop.mindir +0 -0
  412. mindspore/ops/bprop_mindir/RNNTLoss_bprop.mindir +29 -0
  413. mindspore/ops/bprop_mindir/ROIAlign_bprop.mindir +82 -0
  414. mindspore/ops/bprop_mindir/ReLU6_bprop.mindir +16 -0
  415. mindspore/ops/bprop_mindir/ReLUV2_bprop.mindir +0 -0
  416. mindspore/ops/bprop_mindir/ReluGrad_bprop.mindir +18 -19
  417. mindspore/ops/bprop_mindir/Reshape_bprop.mindir +53 -53
  418. mindspore/ops/bprop_mindir/ResizeBilinear_bprop.mindir +29 -0
  419. mindspore/ops/bprop_mindir/ResizeNearestNeighbor_bprop.mindir +77 -85
  420. mindspore/ops/bprop_mindir/SeLU_bprop.mindir +21 -0
  421. mindspore/ops/bprop_mindir/SigmoidCrossEntropyWithLogits_bprop.mindir +21 -0
  422. mindspore/ops/bprop_mindir/SigmoidGrad_bprop.mindir +0 -0
  423. mindspore/ops/bprop_mindir/Sigmoid_bprop.mindir +16 -0
  424. mindspore/ops/bprop_mindir/SmoothL1Loss_bprop.mindir +36 -0
  425. mindspore/ops/bprop_mindir/SoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
  426. mindspore/ops/bprop_mindir/Softplus_bprop.mindir +16 -0
  427. mindspore/ops/bprop_mindir/Softsign_bprop.mindir +33 -0
  428. mindspore/ops/bprop_mindir/SparseSoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
  429. mindspore/ops/bprop_mindir/Squeeze_bprop.mindir +37 -39
  430. mindspore/ops/bprop_mindir/StridedSlice_bprop.mindir +70 -72
  431. mindspore/ops/bprop_mindir/TanhGrad_bprop.mindir +0 -0
  432. mindspore/ops/bprop_mindir/Tanh_bprop.mindir +66 -0
  433. mindspore/ops/bprop_mindir/Tile_bprop.mindir +0 -0
  434. mindspore/ops/bprop_mindir/TopK_bprop.mindir +0 -0
  435. mindspore/ops/bprop_mindir/TupleGetItem_bprop.mindir +17 -17
  436. mindspore/ops/bprop_mindir/UpsampleNearest3D_bprop.mindir +32 -0
  437. mindspore/ops/bprop_mindir/UpsampleTrilinear3D_bprop.mindir +38 -0
  438. mindspore/ops/bprop_mindir/generate_mindir.py +2 -0
  439. mindspore/ops/composite/__init__.py +7 -8
  440. mindspore/ops/composite/base.py +101 -47
  441. mindspore/ops/composite/math_ops.py +188 -158
  442. mindspore/ops/composite/multitype_ops/_compile_utils.py +415 -170
  443. mindspore/ops/composite/multitype_ops/_constexpr_utils.py +142 -87
  444. mindspore/ops/composite/multitype_ops/add_impl.py +6 -1
  445. mindspore/ops/composite/multitype_ops/div_impl.py +2 -3
  446. mindspore/ops/composite/multitype_ops/getitem_impl.py +31 -3
  447. mindspore/ops/composite/multitype_ops/greater_equal_impl.py +31 -0
  448. mindspore/ops/composite/multitype_ops/greater_impl.py +31 -0
  449. mindspore/ops/composite/multitype_ops/in_impl.py +9 -0
  450. mindspore/ops/composite/multitype_ops/less_equal_impl.py +31 -0
  451. mindspore/ops/composite/multitype_ops/less_impl.py +31 -0
  452. mindspore/ops/composite/multitype_ops/mul_impl.py +21 -5
  453. mindspore/ops/composite/multitype_ops/not_in_impl.py +9 -0
  454. mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -4
  455. mindspore/ops/composite/multitype_ops/setitem_impl.py +21 -3
  456. mindspore/ops/composite/multitype_ops/sub_impl.py +1 -1
  457. mindspore/ops/composite/multitype_ops/zeros_like_impl.py +35 -4
  458. mindspore/ops/function/__init__.py +152 -8
  459. mindspore/ops/function/array_func.py +2555 -674
  460. mindspore/ops/function/clip_func.py +209 -13
  461. mindspore/ops/function/debug_func.py +2 -2
  462. mindspore/ops/function/grad/__init__.py +2 -1
  463. mindspore/ops/function/grad/grad_func.py +147 -62
  464. mindspore/ops/function/image_func.py +54 -38
  465. mindspore/ops/function/linalg_func.py +167 -16
  466. mindspore/ops/function/math_func.py +4849 -1492
  467. mindspore/ops/function/nn_func.py +2573 -988
  468. mindspore/ops/function/other_func.py +115 -0
  469. mindspore/ops/function/parameter_func.py +3 -3
  470. mindspore/ops/function/random_func.py +790 -73
  471. mindspore/ops/function/sparse_func.py +98 -78
  472. mindspore/ops/function/sparse_unary_func.py +54 -53
  473. mindspore/ops/function/spectral_func.py +27 -24
  474. mindspore/ops/function/vmap_func.py +22 -2
  475. mindspore/ops/functional.py +97 -37
  476. mindspore/ops/op_info_register.py +70 -28
  477. mindspore/ops/operations/__init__.py +47 -14
  478. mindspore/ops/operations/_csr_ops.py +7 -7
  479. mindspore/ops/operations/_embedding_cache_ops.py +5 -5
  480. mindspore/ops/operations/_grad_ops.py +276 -187
  481. mindspore/ops/operations/_inner_ops.py +319 -113
  482. mindspore/ops/operations/_ms_kernel.py +10 -8
  483. mindspore/ops/operations/_ocr_ops.py +9 -9
  484. mindspore/ops/operations/_opaque_predicate_registry.py +4 -0
  485. mindspore/ops/operations/_quant_ops.py +137 -102
  486. mindspore/ops/operations/_rl_inner_ops.py +121 -60
  487. mindspore/ops/operations/_scalar_ops.py +466 -0
  488. mindspore/ops/operations/_sequence_ops.py +1004 -2
  489. mindspore/ops/operations/_tensor_array.py +10 -11
  490. mindspore/ops/operations/_thor_ops.py +1 -1
  491. mindspore/ops/operations/array_ops.py +801 -466
  492. mindspore/ops/operations/comm_ops.py +51 -49
  493. mindspore/ops/operations/control_ops.py +2 -2
  494. mindspore/ops/operations/custom_ops.py +123 -44
  495. mindspore/ops/operations/debug_ops.py +24 -24
  496. mindspore/ops/operations/image_ops.py +240 -153
  497. mindspore/ops/operations/inner_ops.py +34 -50
  498. mindspore/ops/operations/linalg_ops.py +31 -9
  499. mindspore/ops/operations/math_ops.py +988 -757
  500. mindspore/ops/operations/nn_ops.py +965 -819
  501. mindspore/ops/operations/other_ops.py +51 -40
  502. mindspore/ops/operations/random_ops.py +204 -122
  503. mindspore/ops/operations/rl_ops.py +8 -9
  504. mindspore/ops/operations/sparse_ops.py +254 -93
  505. mindspore/ops/operations/spectral_ops.py +35 -3
  506. mindspore/ops/primitive.py +111 -9
  507. mindspore/parallel/_auto_parallel_context.py +189 -83
  508. mindspore/parallel/_offload_context.py +185 -0
  509. mindspore/parallel/_parallel_serialization.py +99 -7
  510. mindspore/parallel/_ps_context.py +9 -5
  511. mindspore/parallel/_recovery_context.py +1 -1
  512. mindspore/parallel/_tensor.py +7 -1
  513. mindspore/{nn/transformer → parallel/_transformer}/__init__.py +6 -6
  514. mindspore/{nn/transformer → parallel/_transformer}/layers.py +6 -37
  515. mindspore/{nn/transformer → parallel/_transformer}/loss.py +4 -7
  516. mindspore/{nn/transformer → parallel/_transformer}/moe.py +20 -16
  517. mindspore/{nn/transformer → parallel/_transformer}/op_parallel_config.py +3 -3
  518. mindspore/{nn/transformer → parallel/_transformer}/transformer.py +48 -111
  519. mindspore/parallel/_utils.py +1 -2
  520. mindspore/parallel/algo_parameter_config.py +1 -1
  521. mindspore/parallel/checkpoint_transform.py +37 -34
  522. mindspore/parallel/shard.py +17 -18
  523. mindspore/profiler/common/validator/validate_path.py +2 -2
  524. mindspore/profiler/envprofiling.py +69 -47
  525. mindspore/profiler/parser/ascend_timeline_generator.py +49 -42
  526. mindspore/profiler/parser/base_timeline_generator.py +49 -56
  527. mindspore/profiler/parser/cpu_gpu_timeline_generator.py +98 -78
  528. mindspore/profiler/parser/hwts_log_parser.py +1 -1
  529. mindspore/profiler/parser/integrator.py +15 -14
  530. mindspore/profiler/parser/minddata_analyzer.py +2 -2
  531. mindspore/profiler/parser/msadvisor_analyzer.py +12 -25
  532. mindspore/profiler/parser/msadvisor_parser.py +2 -4
  533. mindspore/profiler/parser/optime_parser.py +17 -18
  534. mindspore/profiler/parser/profiler_info.py +2 -1
  535. mindspore/profiler/profiling.py +218 -186
  536. mindspore/rewrite/__init__.py +3 -1
  537. mindspore/rewrite/api/node.py +1 -114
  538. mindspore/rewrite/api/node_type.py +3 -0
  539. mindspore/rewrite/api/pattern_engine.py +31 -1
  540. mindspore/rewrite/api/scoped_value.py +4 -4
  541. mindspore/rewrite/api/symbol_tree.py +3 -78
  542. mindspore/rewrite/api/tree_node_helper.py +1 -1
  543. mindspore/rewrite/ast_creator_register.py +1 -0
  544. mindspore/rewrite/ast_helpers/__init__.py +2 -2
  545. mindspore/rewrite/ast_helpers/ast_creator.py +1 -2
  546. mindspore/rewrite/ast_helpers/ast_finder.py +65 -0
  547. mindspore/rewrite/ast_helpers/ast_modifier.py +11 -3
  548. mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +18 -2
  549. mindspore/rewrite/namespace.py +0 -2
  550. mindspore/rewrite/node.py +157 -11
  551. mindspore/rewrite/parsers/assign_parser.py +231 -53
  552. mindspore/rewrite/parsers/class_def_parser.py +187 -109
  553. mindspore/rewrite/parsers/for_parser.py +24 -14
  554. mindspore/rewrite/parsers/function_def_parser.py +21 -4
  555. mindspore/rewrite/parsers/if_parser.py +6 -2
  556. mindspore/rewrite/sparsify/__init__.py +0 -0
  557. mindspore/rewrite/sparsify/sparse_transformer.py +448 -0
  558. mindspore/rewrite/sparsify/sparsify.py +109 -0
  559. mindspore/rewrite/sparsify/utils.py +173 -0
  560. mindspore/rewrite/symbol_tree.py +256 -133
  561. mindspore/rewrite/symbol_tree_builder.py +38 -1
  562. mindspore/run_check/_check_version.py +69 -63
  563. mindspore/run_check/run_check.py +2 -1
  564. mindspore/tinyxml2.dll +0 -0
  565. mindspore/train/__init__.py +1 -1
  566. mindspore/train/_utils.py +28 -5
  567. mindspore/train/amp.py +273 -102
  568. mindspore/train/callback/_backup_and_restore.py +5 -5
  569. mindspore/train/callback/_callback.py +2 -2
  570. mindspore/train/callback/_checkpoint.py +3 -3
  571. mindspore/train/callback/_early_stop.py +3 -3
  572. mindspore/train/callback/_lambda_callback.py +2 -2
  573. mindspore/train/callback/_landscape.py +29 -31
  574. mindspore/train/callback/_loss_monitor.py +3 -3
  575. mindspore/train/callback/_on_request_exit.py +3 -3
  576. mindspore/train/callback/_reduce_lr_on_plateau.py +4 -4
  577. mindspore/train/callback/_summary_collector.py +23 -16
  578. mindspore/train/callback/_time_monitor.py +3 -3
  579. mindspore/train/checkpoint_pb2.py +68 -8
  580. mindspore/train/data_sink.py +15 -3
  581. mindspore/train/dataset_helper.py +10 -15
  582. mindspore/train/loss_scale_manager.py +8 -11
  583. mindspore/train/metrics/__init__.py +1 -1
  584. mindspore/train/metrics/bleu_score.py +1 -1
  585. mindspore/train/metrics/confusion_matrix.py +1 -1
  586. mindspore/train/metrics/cosine_similarity.py +1 -1
  587. mindspore/train/metrics/dice.py +2 -2
  588. mindspore/train/metrics/fbeta.py +1 -1
  589. mindspore/train/metrics/hausdorff_distance.py +4 -3
  590. mindspore/train/metrics/mean_surface_distance.py +2 -2
  591. mindspore/train/metrics/occlusion_sensitivity.py +1 -1
  592. mindspore/train/metrics/perplexity.py +1 -1
  593. mindspore/train/metrics/precision.py +1 -1
  594. mindspore/train/metrics/recall.py +1 -1
  595. mindspore/train/metrics/roc.py +2 -2
  596. mindspore/train/metrics/root_mean_square_surface_distance.py +2 -2
  597. mindspore/train/mind_ir_pb2.py +116 -37
  598. mindspore/train/model.py +45 -28
  599. mindspore/train/serialization.py +295 -188
  600. mindspore/train/summary/_summary_adapter.py +1 -1
  601. mindspore/train/summary/summary_record.py +43 -13
  602. mindspore/train/train_thor/convert_utils.py +2 -2
  603. mindspore/train/train_thor/dataset_helper.py +3 -3
  604. mindspore/turbojpeg.dll +0 -0
  605. mindspore/version.py +1 -1
  606. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/METADATA +3 -2
  607. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/RECORD +610 -541
  608. mindspore/compression/__init__.py +0 -19
  609. mindspore/compression/common/constant.py +0 -124
  610. mindspore/compression/export/__init__.py +0 -19
  611. mindspore/compression/export/quant_export.py +0 -515
  612. mindspore/compression/quant/__init__.py +0 -28
  613. mindspore/compression/quant/qat.py +0 -634
  614. mindspore/compression/quant/quant_utils.py +0 -462
  615. mindspore/compression/quant/quantizer.py +0 -68
  616. mindspore/nn/layer/quant.py +0 -1868
  617. mindspore/nn/layer/rnn_utils.py +0 -90
  618. mindspore/nn/probability/dpn/__init__.py +0 -22
  619. mindspore/nn/probability/dpn/vae/__init__.py +0 -25
  620. mindspore/nn/probability/dpn/vae/cvae.py +0 -140
  621. mindspore/nn/probability/dpn/vae/vae.py +0 -124
  622. mindspore/nn/probability/infer/__init__.py +0 -22
  623. mindspore/nn/probability/infer/variational/elbo.py +0 -70
  624. mindspore/nn/probability/infer/variational/svi.py +0 -84
  625. mindspore/nn/probability/toolbox/__init__.py +0 -22
  626. mindspore/nn/probability/toolbox/anomaly_detection.py +0 -99
  627. mindspore/nn/probability/toolbox/uncertainty_evaluation.py +0 -364
  628. mindspore/nn/probability/transforms/__init__.py +0 -22
  629. mindspore/nn/probability/transforms/transform_bnn.py +0 -262
  630. mindspore/nn/probability/zhusuan/__init__.py +0 -18
  631. mindspore/nn/probability/zhusuan/framework/__init__.py +0 -18
  632. mindspore/nn/probability/zhusuan/framework/bn.py +0 -95
  633. mindspore/nn/probability/zhusuan/variational/__init__.py +0 -18
  634. mindspore/nn/probability/zhusuan/variational/elbo.py +0 -46
  635. mindspore/ops/_op_impl/aicpu/parallel_concat.py +0 -42
  636. mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
  637. mindspore/ops/bprop_mindir/AssignAdd_bprop.mindir +0 -19
  638. mindspore/ops/bprop_mindir/Cast_bprop.mindir +0 -19
  639. mindspore/ops/bprop_mindir/LogicalOr_bprop.mindir +0 -19
  640. mindspore/ops/bprop_mindir/MatMul_bprop.mindir +0 -0
  641. mindspore/ops/bprop_mindir/ReLU_bprop.mindir +0 -17
  642. mindspore/ops/bprop_mindir/Transpose_bprop.mindir +0 -0
  643. mindspore/ops/bprop_mindir/UpdateState_bprop.mindir +0 -15
  644. mindspore/ops/composite/array_ops.py +0 -241
  645. mindspore/ops/composite/clip_ops.py +0 -134
  646. mindspore/ops/composite/random_ops.py +0 -426
  647. mindspore/ops/composite/vmap_ops.py +0 -38
  648. mindspore/parallel/nn/__init__.py +0 -42
  649. mindspore/parallel/nn/loss.py +0 -22
  650. mindspore/parallel/nn/moe.py +0 -21
  651. mindspore/parallel/nn/op_parallel_config.py +0 -22
  652. mindspore/parallel/nn/transformer.py +0 -31
  653. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/WHEEL +0 -0
  654. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/entry_points.txt +0 -0
  655. {mindspore-2.0.0a0.dist-info → mindspore-2.0.0rc1.dist-info}/top_level.txt +0 -0
@@ -18,14 +18,14 @@ from __future__ import absolute_import
18
18
  from mindspore.ops import operations as P
19
19
  from mindspore.ops import functional as F
20
20
  import mindspore.ops as ops
21
- from mindspore._checkparam import Rel, Validator as validator
22
- from mindspore.ops.primitive import constexpr
21
+ from mindspore._checkparam import _check_3d_int_or_tuple
22
+ from mindspore import _checkparam as validator
23
+ from mindspore.ops.primitive import constexpr, _primexpr
23
24
  from mindspore.common.tensor import Tensor
24
25
  import mindspore.context as context
25
26
  from mindspore.common import dtype as mstype
26
27
  from mindspore.ops.operations.nn_ops import AdaptiveMaxPool2D
27
28
  from mindspore.ops.operations.nn_ops import AdaptiveMaxPool3D, AdaptiveAvgPool3D
28
- from mindspore.ops.operations.nn_ops import MaxPool3DWithArgmax
29
29
  from mindspore.nn.cell import Cell
30
30
 
31
31
  __all__ = ['AvgPool3d', 'MaxPool3d', 'AvgPool2d', 'MaxPool2d', 'AvgPool1d', 'MaxPool1d', 'FractionalMaxPool2d',
@@ -41,7 +41,7 @@ class _PoolNd(Cell):
41
41
  """Initialize _PoolNd."""
42
42
  super(_PoolNd, self).__init__()
43
43
  validator.check_value_type('pad_mode', pad_mode, [str], self.cls_name)
44
- self.pad_mode = validator.check_string(pad_mode.upper(), ['VALID', 'SAME'], 'pad_mode', self.cls_name)
44
+ self.pad_mode = validator.check_string(pad_mode.upper(), ['VALID', 'SAME', 'PAD'], 'pad_mode', self.cls_name)
45
45
  self.format = validator.check_string(data_format, ['NCHW', 'NHWC'], 'format', self.cls_name)
46
46
  if context.get_context("device_target") != "GPU" and self.format == "NHWC":
47
47
  raise ValueError(f"For '{self.cls_name}, the 'NHWC' format only support in GPU target, but got device "
@@ -50,17 +50,17 @@ class _PoolNd(Cell):
50
50
  def _check_int_or_tuple(arg_name, arg_value):
51
51
  validator.check_value_type(arg_name, arg_value, [int, tuple], self.cls_name)
52
52
  error_msg = f"For '{self.cls_name}', the '{arg_name}' must be an positive int number or " \
53
- f"a tuple of two positive int numbers, but got {arg_value}"
53
+ f"a tuple, but got {arg_value}"
54
54
  if isinstance(arg_value, int):
55
55
  if arg_value <= 0:
56
56
  raise ValueError(error_msg)
57
- elif len(arg_value) == 2:
57
+ else:
58
58
  for item in arg_value:
59
59
  if isinstance(item, int) and item > 0:
60
60
  continue
61
61
  raise ValueError(error_msg)
62
- else:
63
- raise ValueError(error_msg)
62
+ if len(arg_value) == 1:
63
+ return arg_value[0]
64
64
  return arg_value
65
65
 
66
66
  self.kernel_size = _check_int_or_tuple('kernel_size', kernel_size)
@@ -73,19 +73,24 @@ class _PoolNd(Cell):
73
73
  return 'kernel_size={kernel_size}, stride={stride}, pad_mode={pad_mode}'.format(**self.__dict__)
74
74
 
75
75
 
76
- @constexpr
76
+ @_primexpr
77
77
  def _shape_check(in_shape, prim_name=None):
78
78
  msg_prefix = f"For '{prim_name}', the" if prim_name else "The"
79
- if len(in_shape) != 3:
80
- raise ValueError(f"{msg_prefix} input must has 3 dim, but got {len(in_shape)}")
79
+
80
+ def _check():
81
+ if len(in_shape) != 3:
82
+ raise ValueError(f"{msg_prefix} input must has 3 dim, but got {len(in_shape)}")
83
+
84
+ _check()
81
85
 
82
86
 
83
87
  class LPPool1d(Cell):
84
88
  r"""
85
- Applies a 1D power lp pooling over an input signal composed of several input planes.
89
+ Applying 1D LPPooling operation on an input Tensor can be regarded as forming a 1D input plane.
86
90
 
87
- Typically the input is of shape :math:`(N, C, L_{in})` or :math:`(C, L_{in})`, the output is of shape
88
- :math:`(N, C, L_{in})` or :math:`(C, L_{in})`, with the same shape as input, the operation is as follows.
91
+ Typically the input is of shape :math:`(N_{in}, C_{in}, L_{in})` or :math:`(C_{in}, L_{in})``, the output is of
92
+ shape :math:`(N_{out}, C_{out}, L_{out})` or :math:`(C_{out}, L_{out})`, with the same shape as input,
93
+ the operation is as follows.
89
94
 
90
95
  .. math::
91
96
  f(X) = \sqrt[p]{\sum_{x \in X} x^{p}}
@@ -93,8 +98,9 @@ class LPPool1d(Cell):
93
98
  Args:
94
99
  norm_type (Union[int, float]): Type of normalization, represents p in the formula, can not be 0.
95
100
 
96
- - if p = 1, one gets Sum Pooling (which is proportional to Average Pooling),
97
- - if p = :math:`\infty`, one gets Max Pooling.
101
+ - if p = 1, the result is the sum of the elements within the pooling kernel(proportional to average
102
+ pooling).
103
+ - if p = :math:`\infty`, the result is the result of maximum pooling.
98
104
 
99
105
  kernel_size (int): The size of kernel window.
100
106
  stride (int): The distance of kernel moving, an int number that represents
@@ -102,11 +108,15 @@ class LPPool1d(Cell):
102
108
  ceil_mode (bool): Whether to use ceil or floor to calculate output shape. Default: False.
103
109
 
104
110
  Inputs:
105
- - **x** (Tensor) - Tensor of shape :math:`(N, C, L_{in})` or :math:`(C, L_{in})`.
111
+ - **x** (Tensor) - Tensor of shape :math:`(N_{in}, C_{in}, L_{in})` or :math:`(C_{in}, L_{in})`.
106
112
 
107
113
  Outputs:
108
- - **output** (Tensor) - LPPool1d result, with shape :math:`(N, C, L_{in})` or :math:`(C, L_{in})`,
109
- It has the same data type as `x`.
114
+ - **output** (Tensor) - LPPool1d result, with shape :math:`(N_{out}, C_{out}, L_{out})` or
115
+ :math:`(C_{out}, L_{out})`, it has the same data type as `x`, where
116
+
117
+ .. math::
118
+ L_{out} = \left\lfloor\frac{L_{in} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor
119
+
110
120
 
111
121
  Raises:
112
122
  TypeError: If `x` is not an Tensor.
@@ -151,7 +161,7 @@ class LPPool1d(Cell):
151
161
 
152
162
  class LPPool2d(Cell):
153
163
  r"""
154
- Applies a 2D power lp pooling over an input signal composed of several input planes.
164
+ Applying 2D LPPooling operation on an input Tensor can be regarded as forming a 1D input plane.
155
165
 
156
166
  Typically the input is of shape :math:`(N, C, H_{in}, W_{in})`, the output is of shape
157
167
  :math:`(N, C, H_{in}, W_{in})`, with the same shape as input, the operation is as follows.
@@ -162,8 +172,9 @@ class LPPool2d(Cell):
162
172
  Args:
163
173
  norm_type(Union[int, float]) - Type of normalization, represents p in the formula, can not be 0.
164
174
 
165
- - if p = 1, one gets Sum Pooling (which is proportional to Average Pooling),
166
- - if p = :math:`\infty`, one gets Max Pooling.
175
+ - if p = 1, the result is the sum of the elements within the pooling kernel(proportional to average
176
+ pooling).
177
+ - if p = :math:`\infty`, the result is the result of maximum pooling.
167
178
 
168
179
  kernel_size(Union[int, tuple[int]]): The size of kernel window.
169
180
  The data type of kernel_size must be int and the value represents the height and width,
@@ -179,7 +190,13 @@ class LPPool2d(Cell):
179
190
 
180
191
  Outputs:
181
192
  - **output** (Tensor) - LPPool2d result, with shape :math:`(N, C, H_{in}, W_{in})`,
182
- It has the same data type as `x`.
193
+ It has the same data type as `x`, where
194
+
195
+ .. math::
196
+ H_{out} = \left\lfloor\frac{H_{in} - \text{kernel_size}[0]}{\text{stride}[0]} + 1\right\rfloor
197
+
198
+ .. math::
199
+ W_{out} = \left\lfloor\frac{W_{in} - \text{kernel_size}[1]}{\text{stride}[1]} + 1\right\rfloor
183
200
 
184
201
  Raises:
185
202
  TypeError: If `x` is not an Tensor.
@@ -229,7 +246,37 @@ class LPPool2d(Cell):
229
246
  self.stride, self.ceil_mode)
230
247
 
231
248
 
232
- class MaxPool3d(Cell):
249
+ def _check_maxpool_padding(padding, nd, cls_name):
250
+ """Calculate maxpool padding before call primitive"""
251
+ validator.check_value_type('padding', padding, (int, tuple, list), cls_name)
252
+ if isinstance(padding, int):
253
+ return (0,) * (3 - nd) + (padding,) * nd
254
+ if isinstance(padding, (tuple, list)):
255
+ validator.check_non_negative_int_sequence(padding, "padding", cls_name)
256
+ if len(padding) == 1:
257
+ return (0,) * (3 - nd) + tuple(padding * nd)
258
+ if len(padding) != nd:
259
+ raise ValueError(f"For {cls_name}, the length of padding must equal to {nd}, but got {len(padding)}.")
260
+ return (0,) * (3 - nd) + tuple(padding)
261
+ return padding
262
+
263
+
264
+ def _cal_dilation(dilation, nd, cls_name):
265
+ """check the dilation"""
266
+ if isinstance(dilation, int):
267
+ return dilation
268
+ if isinstance(dilation, tuple):
269
+ if len(dilation) == 1:
270
+ return dilation[0]
271
+ if len(dilation) == nd:
272
+ return (3 - nd) * (1,) + dilation
273
+ if nd == 1:
274
+ raise ValueError(f"For {cls_name}, the length of 'dilation' must be 1, but got {len(dilation)}.")
275
+ raise ValueError(f"For {cls_name}, the length of 'dilation' must be 1 or {nd}, but got {len(dilation)}.")
276
+ raise ValueError(f"For {cls_name}, the 'dilation' must be int or tuple, but got {type(dilation)}.")
277
+
278
+
279
+ class MaxPool3d(_PoolNd):
233
280
  r"""
234
281
  3D max pooling operation.
235
282
 
@@ -246,29 +293,46 @@ class MaxPool3d(Cell):
246
293
 
247
294
  Args:
248
295
  kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
249
- is an int number that represents depth, height and width of the kernel, or a tuple
296
+ is an int number or a single element tuple that represents depth, height and width of the kernel, or a tuple
250
297
  of three int numbers that represent depth, height and width respectively.
251
- The value must be a positive integer.
252
- stride (Union[int, tuple[int]]): The moving stride of pooling operation, an int number that represents
253
- the moving stride of pooling kernel in the directions of depth, height and the width,
298
+ The value must be a positive integer. Default: 1.
299
+ stride (Union[int, tuple[int]]): The moving stride of pooling operation, an int number or a single element tuple
300
+ that represents the moving stride of pooling kernel in the directions of depth, height and the width,
254
301
  or a tuple of three int numbers that represent depth, height and width of movement respectively.
255
302
  The value must be a positive integer. If the value is None, the default value `kernel_size` is used.
256
- padding (Union[int, tuple[int]]): Pooling padding length. An int number that represents the depth,
257
- height and width of movement are both stride, or a tuple of three int numbers that represent depth,
258
- height and width of movement respectively. The value cannot be negative. Default: 0.
259
- dilation (Union[int, tuple[int]]): Control the spacing of elements in the pooling kernel. Default: 1.
303
+ Default: 1.
304
+ pad_mode (str): The optional value for pad mode, is "same", "valid" or "pad", not case sensitive.
305
+ Default: "valid".
306
+
307
+ - same: The output shape is the same as the input shape evenly divided by `stride`.
308
+
309
+ - valid: The possible largest height and width of output
310
+ will be returned without padding. Extra pixels will be discarded.
311
+
312
+ - pad: pads the input. Pads the top, bottom, left, and right sides of the input with `padding` number of
313
+ zeros. If this mode is set, `padding` must be greater than or equal to 0.
314
+
315
+ padding (Union(int, tuple[int], list[int])): Pooling padding value. Default: 0.
316
+ `padding` can only be an integer or a tuple/list containing one or three integers.
317
+ If `padding` is an integer or a tuple/list containing one integer, it will be padded in six directions of
318
+ front, back, top, bottom, left and right of the input. If `padding` is a tuple/list containing three
319
+ integers, it will be padded in front and back of the input `padding[0]` times, up and down `padding[1]`
320
+ times, and left and right of the input `padding[2]` times.
321
+ dilation (Union(int, tuple[int])): The spacing between the elements of the kernel in convolution,
322
+ used to increase the receptive field of the pooling operation. If it is a tuple, it must contain one or
323
+ three integers. Default: 1.
260
324
  return_indices (bool): If True, output is a Tuple of 2 Tensors, representing the maxpool result and where
261
325
  the max values are generated. Otherwise, only the maxpool result is returned. Default: False.
262
326
  ceil_mode (bool): Whether to use ceil or floor to calculate output shape. Default: False.
263
327
 
264
328
  Inputs:
265
329
  - **x** (Tensor) - Tensor of shape :math:`(N_{in}, C_{in}, D_{in}, H_{in}, W_{in})` or
266
- :math:`(C_{in}, D_{in}, H_{in}, W_{in})` with data type of int8, int16, int32,
267
- int64, uint8, uint16, uint32, uint64, float16, float32 or float64.
330
+ :math:`(C_{in}, D_{in}, H_{in}, W_{in})`.
268
331
 
269
332
  Outputs:
270
- If `return_indices` is False, output is a Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})`, or
271
- :math:`(C_{out}, D_{out}, H_{out}, W_{out})`. It has the same data type as `x`.
333
+ If `return_indices` is False, output is a Tensor, with shape
334
+ :math:`(N_{out}, C_{out}, D_{out}, H_{out}, W_{out})` or :math:`(C_{out}, D_{out}, H_{out}, W_{out})`.
335
+ It has the same data type as `x`.
272
336
 
273
337
  If `return_indices` is True, output is a Tuple of 2 Tensors, representing the maxpool result and where
274
338
  the max values are generated.
@@ -277,72 +341,84 @@ class MaxPool3d(Cell):
277
341
  :math:`(C_{out}, D_{out}, H_{out}, W_{out})`. It has the same data type as `x`.
278
342
  - **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64.
279
343
 
344
+ If `pad_mode` is in `pad` mode, the output shape calculation formula is as follows:
345
+
346
+ .. math::
347
+ D_{out} = \left\lfloor\frac{D_{in} + 2 \times \text{padding}[0] - \text{dilation}[0] \times
348
+ (\text{kernel_size}[0] - 1) - 1}{\text{stride}[0]} + 1\right\rfloor
349
+
350
+ .. math::
351
+ H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[1] - \text{dilation}[1] \times
352
+ (\text{kernel_size}[1] - 1) - 1}{\text{stride}[1]} + 1\right\rfloor
353
+
354
+ .. math::
355
+ W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] - \text{dilation}[2] \times
356
+ (\text{kernel_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor
357
+
280
358
  Raises:
281
- TypeError: If `x` is not a Tensor.
282
- ValueError: If length of shape of `x` is not equal to 5.
359
+ ValueError: If length of shape of `x` is not equal to 4 or 5.
283
360
  TypeError: If `kernel_size` , `stride` , `padding` or `dilation` is neither an int nor a tuple.
284
361
  ValueError: If `kernel_size` or `stride` is less than 1.
285
- ValueError: If `padding` is less than 0.
362
+ ValueError: If the `padding` parameter is neither an integer nor a tuple of length 3.
363
+ ValueError: If `pad_mode` is not set to 'pad', setting return_indices to True or dilation to a value
364
+ other than 1.
365
+ ValueError: If `padding` is non-zero when `pad_mode` is not 'pad'.
286
366
 
287
367
  Supported Platforms:
288
- ``GPU``
368
+ ``Ascend`` ``GPU`` ``CPU``
289
369
 
290
370
  Examples:
291
371
  >>> import mindspore as ms
292
372
  >>> import mindspore.nn as nn
293
373
  >>> import numpy as np
294
- >>> pool1 = nn.MaxPool3d(kernel_size=3, stride=1, padding=1)
295
- >>> pool2 = nn.MaxPool3d(kernel_size=3, stride=1, padding=1, return_indices=True)
296
- >>> x = ms.Tensor(np.random.randint(0, 10, [1, 2, 2, 2, 2]), ms.float32)
297
- >>> output1 = pool1(x)
298
- >>> print(output1)
299
- [[[[[8. 8.]
300
- [8. 8.]]
301
- [[8. 8.]
302
- [8. 8.]]]
303
- [[[9. 9.]
304
- [9. 9.]]
305
- [[9. 9.]
306
- [9. 9.]]]]]
374
+ >>> np_x = np.random.randint(0, 10, [5, 3, 4, 6, 7])
375
+ >>> x = Tensor(np_x, ms.float32)
376
+ >>> pool1 = nn.MaxPool3d(kernel_size=2, stride=1, pad_mode='pad', padding=1, dilation=3, return_indices=True)
377
+ >>> output = pool1(x)
378
+ >>> print(output[0].shape)
379
+ (5, 3, 3, 5, 6)
380
+ >>> print(output[1].shape)
381
+ (5, 3, 3, 5, 6)
382
+ >>> pool2 = nn.MaxPool3d(kernel_size=2, stride=1, pad_mode='pad', padding=1, dilation=3, return_indices=False)
307
383
  >>> output2 = pool2(x)
308
- >>> print(output2)
309
- (Tensor(shape=[1, 2, 2, 2, 2], dtype=Float32, value=
310
- [[[[[8.00000000e+000, 8.00000000e+000],
311
- [8.00000000e+000, 8.00000000e+000]],
312
- [[8.00000000e+000, 8.00000000e+000],
313
- [8.00000000e+000, 8.00000000e+000]]],
314
- [[[9.00000000e+000, 9.00000000e+000],
315
- [9.00000000e+000, 9.00000000e+000]],
316
- [[9.00000000e+000, 9.00000000e+000],
317
- [9.00000000e+000, 9.00000000e+000]]]]]), Tensor(shape=[1, 2, 2, 2, 2], dtype=Int64, value=
318
- [[[[[7, 7],
319
- [7, 7]],
320
- [[7, 7],
321
- [7, 7]]],
322
- [[[2, 2],
323
- [2, 2]],
324
- [[2, 2],
325
- [2, 2]]]]]))
384
+ >>> print(output2.shape)
385
+ (5, 3, 3, 5, 6)
326
386
  """
327
387
 
328
- def __init__(self, kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False):
388
+ def __init__(self, kernel_size=1, stride=1, pad_mode="valid", padding=0, dilation=1, return_indices=False,
389
+ ceil_mode=False):
329
390
  """Initialize MaxPool3d."""
330
- super(MaxPool3d, self).__init__()
331
- stride = stride if (stride is not None) else kernel_size
391
+ super(MaxPool3d, self).__init__(kernel_size, stride, pad_mode)
332
392
  self.return_indices = return_indices
333
- self.max_pool = MaxPool3DWithArgmax(kernel_size, stride, padding, dilation, ceil_mode)
334
- self.expand_dims = P.ExpandDims()
393
+ padding = _check_maxpool_padding(padding, 3, self.cls_name)
394
+ _check_3d_int_or_tuple("padding", padding, self.cls_name, greater_zero=False, ret_five=False)
395
+ if dilation != 1 or return_indices:
396
+ self.only_pad = True
397
+ if pad_mode.upper() != "PAD":
398
+ raise ValueError(f"For {self.cls_name}, the pad_mode must be 'pad' when dilation is not 1 "
399
+ f"or return_indices is True, but got pad_mode:{pad_mode}.")
400
+ self.max_pool = P.MaxPool3DWithArgmax(ksize=kernel_size, strides=stride, pads=padding,
401
+ dilation=dilation, ceil_mode=ceil_mode)
402
+ else:
403
+ self.only_pad = False
404
+ ceil_mode = None if not ceil_mode else True
405
+ self.max_pool = P.MaxPool3D(kernel_size=kernel_size, strides=stride, pad_mode=pad_mode, pad_list=padding,
406
+ ceil_mode=ceil_mode)
335
407
 
336
408
  def construct(self, x):
337
- _shape = x.shape
338
- if len(x.shape) == 4:
339
- x = self.expand_dims(x, 0)
340
- output_tensor, argmax = self.max_pool(x)
341
- output_tensor = output_tensor.reshape(_shape)
342
- argmax = argmax.reshape(_shape)
343
- if self.return_indices:
344
- return output_tensor, argmax
345
- return output_tensor
409
+ expand_batch = False
410
+ if x.ndim == 4:
411
+ x = x.unsqueeze(0)
412
+ expand_batch = True
413
+ out = self.max_pool(x)
414
+ if expand_batch:
415
+ if isinstance(out, tuple):
416
+ out = (out[0].squeeze(0), out[1].squeeze(0))
417
+ else:
418
+ out = out.squeeze(0)
419
+ if self.only_pad and not self.return_indices:
420
+ return out[0]
421
+ return out
346
422
 
347
423
 
348
424
  class MaxPool2d(_PoolNd):
@@ -351,45 +427,82 @@ class MaxPool2d(_PoolNd):
351
427
 
352
428
  Typically the input is of shape :math:`(N_{in}, C_{in}, H_{in}, W_{in})`, MaxPool2d outputs
353
429
  regional maximum in the :math:`(H_{in}, W_{in})`-dimension. Given kernel size
354
- :math:`ks = (h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1)`, the operation is as follows.
430
+ :math:`(h_{ker}, w_{ker})` and stride :math:`(s_0, s_1)`, the operation is as follows.
355
431
 
356
432
  .. math::
357
433
  \text{output}(N_i, C_j, h, w) = \max_{m=0, \ldots, h_{ker}-1} \max_{n=0, \ldots, w_{ker}-1}
358
434
  \text{input}(N_i, C_j, s_0 \times h + m, s_1 \times w + n)
359
435
 
360
- Note:
361
- pad_mode for training only supports "same" and "valid".
362
-
363
436
  Args:
364
437
  kernel_size (Union[int, tuple[int]]): The size of kernel used to take the max value,
365
- is an int number that represents height and width are both kernel_size,
438
+ is an int number or a single element tuple that represents height and width are both kernel_size,
366
439
  or a tuple of two int numbers that represent height and width respectively.
367
440
  Default: 1.
368
- stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
369
- the height and width of movement are both stride, or a tuple of two int numbers that
441
+ stride (Union[int, tuple[int]]): The distance of kernel moving, an int number or a single element tuple that
442
+ represents the height and width of movement are both stride, or a tuple of two int numbers that
370
443
  represent height and width of movement respectively. Default: 1.
371
- pad_mode (str): The optional value for pad mode, is "same" or "valid", not case sensitive.
444
+ pad_mode (str): The optional value for pad mode, is "same", "valid" or "pad", not case sensitive.
372
445
  Default: "valid".
373
446
 
374
447
  - same: The output shape is the same as the input shape evenly divided by `stride`.
375
448
 
376
449
  - valid: The possible largest height and width of output
377
450
  will be returned without padding. Extra pixels will be discarded.
451
+
452
+ - pad: pads the input. Pads the top, bottom, left, and right sides of the input with `padding` number of
453
+ zeros. If this mode is set, `padding` must be greater than or equal to 0.
454
+
455
+ padding (Union(int, tuple[int], list[int])): Specifies the padding value of the pooling operation. Default: 0.
456
+ `padding` can only be an integer or a tuple/list containing one or two integers. If `padding` is an integer
457
+ or a tuple/list containing one integer, it will be padded `padding` times in the four directions of the
458
+ input. If `padding` is a tuple/list containing two integers, it will be padded `padding[0]` times in the
459
+ up-down direction of the input and `padding[1]` times in the left-right direction of the input.
460
+ dilation (Union(int, tuple[int])): The spacing between the elements of the kernel in convolution,
461
+ used to increase the receptive field of the pooling operation. If it is a tuple, it must contain one or two
462
+ integers. Default: 1.
463
+ return_indices (bool): If True, the function will return both the result of max pooling and the indices of the
464
+ max elements. Default: False.
465
+ ceil_mode (bool): If True, use ceil to compute the output shape instead of floor. Default: False.
378
466
  data_format (str): The optional value for data format, is 'NHWC' or 'NCHW'.
379
467
  Default: 'NCHW'.
380
468
 
381
469
  Inputs:
382
- - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
470
+ - **x** (Tensor) - Tensor of shape :math:`(N,C_{in},H_{in},W_{in})` or :math:`(C_{in},H_{in},W_{in})`.
383
471
 
384
472
  Outputs:
385
- Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})`.
473
+ If `return_indices` is False, output is a Tensor, with shape :math:`(N, C, H_{out}, W_{out})` or
474
+ :math:`(C_{out}, H_{out}, W_{out})`. It has the same data type as `x`.
475
+
476
+ If `return_indices` is True, output is a Tuple of 2 Tensors, representing the maxpool result and where
477
+ the max values are generated.
478
+
479
+ - **output** (Tensor) - Maxpooling result, with shape :math:`(N_{out}, C_{out}, H_{out}, W_{out})` or
480
+ :math:`(C_{out}, H_{out}, W_{out})`. It has the same data type as `x`.
481
+ - **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64.
482
+
483
+ If `pad_mode` is in `pad` mode, the output shape calculation formula is as follows:
484
+
485
+ .. math::
486
+ H_{out} = \left\lfloor\frac{H_{in} + 2 * \text{padding[0]} - \text{dilation[0]}
487
+ \times (\text{kernel_size[0]} - 1) - 1}{\text{stride[0]}} + 1\right\rfloor
488
+
489
+ .. math::
490
+ W_{out} = \left\lfloor\frac{W_{in} + 2 * \text{padding[1]} - \text{dilation[1]}
491
+ \times (\text{kernel_size[1]} - 1) - 1}{\text{stride[1]}} + 1\right\rfloor
386
492
 
387
493
  Raises:
388
494
  TypeError: If `kernel_size` or `stride` is neither int nor tuple.
389
495
  ValueError: If `pad_mode` is neither 'valid' nor 'same' with not case sensitive.
390
496
  ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
391
497
  ValueError: If `kernel_size` or `stride` is less than 1.
392
- ValueError: If length of shape of `x` is not equal to 4.
498
+ ValueError: If length of shape of `x` is not equal to 3 or 4.
499
+ ValueError: If `pad_mode` is not 'pad', `padding`, `dilation`, `return_indices`, `ceil_mode` parameters are not
500
+ set to their default values.
501
+ ValueError: If the length of the tuple/list `padding` parameter is not 2.
502
+ ValueError: If The length of the tuple dilation parameter is not 2.
503
+ ValueError: If dilation parameter is neither an integer nor a tuple.
504
+ ValueError: If `pad_mode` is 'pad' and `data_format` is 'NHWC'.
505
+ ValueError: If `padding` is non-zero when `pad_mode` is not 'pad'.
393
506
 
394
507
  Supported Platforms:
395
508
  ``Ascend`` ``GPU`` ``CPU``
@@ -400,18 +513,71 @@ class MaxPool2d(_PoolNd):
400
513
  >>> output = pool(x)
401
514
  >>> print(output.shape)
402
515
  (1, 2, 2, 2)
516
+ >>> np_x = np.random.randint(0, 10, [5, 3, 4, 5])
517
+ >>> x = Tensor(np_x, mindspore.float32)
518
+ >>> pool2 = nn.MaxPool2d(kernel_size=2, stride=1, pad_mode='pad', padding=1, dilation=1, return_indices=True)
519
+ >>> output = pool2(x)
520
+ >>> print(output[0].shape)
521
+ (5, 3, 5, 6)
522
+ >>> print(output[1].shape)
523
+ (5, 3, 5, 6)
403
524
  """
404
525
 
405
- def __init__(self, kernel_size=1, stride=1, pad_mode="valid", data_format="NCHW"):
526
+ def __init__(self, kernel_size=1, stride=1, pad_mode="valid", padding=0, dilation=1, return_indices=False,
527
+ ceil_mode=False, data_format="NCHW"):
406
528
  """Initialize MaxPool2d."""
407
529
  super(MaxPool2d, self).__init__(kernel_size, stride, pad_mode, data_format)
408
- self.max_pool = P.MaxPool(kernel_size=self.kernel_size,
409
- strides=self.stride,
410
- pad_mode=self.pad_mode,
411
- data_format=self.format)
530
+ self.return_indices = return_indices
531
+ if pad_mode.upper() == 'PAD':
532
+ if self.format == "NHWC":
533
+ raise ValueError(f"For '{self.cls_name}, the 'NHWC' format are not support when 'pad_mode' is 'pad'.")
534
+ self.use_pad = True
535
+ if isinstance(self.kernel_size, tuple):
536
+ _check_tuple_length(self.kernel_size, 'kernel_size', 2, self.cls_name)
537
+ kernel_size = (1,) + self.kernel_size
538
+ elif isinstance(self.kernel_size, int):
539
+ kernel_size = (1, self.kernel_size, self.kernel_size)
540
+ if isinstance(self.stride, tuple):
541
+ _check_tuple_length(self.stride, 'stride', 2, self.cls_name)
542
+ stride = (1,) + self.stride
543
+ elif isinstance(self.stride, int):
544
+ stride = (1, self.stride, self.stride)
545
+ self.padding = _check_maxpool_padding(padding, 2, self.cls_name)
546
+ dilation = _cal_dilation(dilation, 2, self.cls_name)
547
+ self.max_pool = P.MaxPool3DWithArgmax(ksize=kernel_size, strides=stride, pads=self.padding,
548
+ dilation=dilation, ceil_mode=ceil_mode)
549
+ else:
550
+ self.use_pad = False
551
+ if padding != 0 or dilation != 1 or return_indices or ceil_mode:
552
+ raise ValueError(f"For MaxPool1d, the parameter 'padding', 'dilation', 'return_indices', 'ceil_mode' "
553
+ f"can not be set to non-default value when pad_mode is not 'pad', "
554
+ f"but got pad_mode:{pad_mode}.")
555
+ self.max_pool = P.MaxPool(kernel_size=self.kernel_size,
556
+ strides=self.stride,
557
+ pad_mode=self.pad_mode,
558
+ data_format=self.format)
412
559
 
413
560
  def construct(self, x):
414
- out = self.max_pool(x)
561
+ expand_batch = False
562
+ if x.ndim == 3:
563
+ x = x.unsqueeze(0)
564
+ expand_batch = True
565
+ if self.use_pad:
566
+ x = x.unsqueeze(2)
567
+ out = self.max_pool(x)
568
+ if isinstance(out, tuple):
569
+ out = out[0].squeeze(2), out[1].squeeze(2)
570
+ else:
571
+ out = out.squeeze(2)
572
+ else:
573
+ out = self.max_pool(x)
574
+ if expand_batch:
575
+ if isinstance(out, tuple):
576
+ out = (out[0].squeeze(0), out[1].squeeze(0))
577
+ else:
578
+ out = out.squeeze(0)
579
+ if self.use_pad and not self.return_indices:
580
+ return out[0]
415
581
  return out
416
582
 
417
583
 
@@ -420,21 +586,18 @@ class MaxPool1d(_PoolNd):
420
586
  Applies a 1D max pooling over an input Tensor which can be regarded as a composition of 1D planes.
421
587
 
422
588
  Typically the input is of shape :math:`(N_{in}, C_{in}, L_{in})`, MaxPool1d outputs
423
- regional maximum in the :math:`(L_{in})`-dimension. Given kernel size
424
- :math:`ks = (l_{ker})` and stride :math:`s = (s_0)`, the operation is as follows:
589
+ regional maximum in the :math:`(L_{in})`-dimension. Given `kernel size`
590
+ :math:`ks = (l_{ker})` and `stride` :math:`s = (s_0)`, the operation is as follows:
425
591
 
426
592
  .. math::
427
593
  \text{output}(N_i, C_j, l) = \max_{n=0, \ldots, l_{ker}-1}
428
594
  \text{input}(N_i, C_j, s_0 \times l + n)
429
595
 
430
- Note:
431
- pad_mode for training only supports "same" and "valid".
432
-
433
596
  Args:
434
597
  kernel_size (int): The size of kernel used to take the max value, Default: 1.
435
598
  stride (int): The distance of kernel moving, an int number that represents
436
599
  the width of movement is stride, Default: 1.
437
- pad_mode (str): The optional value for pad mode, is "same" or "valid", not case sensitive.
600
+ pad_mode (str): The optional value for pad mode, is "same", "valid" or "pad", not case sensitive.
438
601
  Default: "valid".
439
602
 
440
603
  - same: Adopts the way of completion. The total number of padding will be calculated in horizontal
@@ -444,62 +607,165 @@ class MaxPool1d(_PoolNd):
444
607
  - valid: Adopts the way of discarding. The possible largest height and width of output
445
608
  will be returned without padding. Extra pixels will be discarded.
446
609
 
610
+ - pad: Performs padding on the input. Adds padding size of zeros to both ends of the input.
611
+ If this mode is set, padding must be greater than or equal to 0.
612
+
613
+ padding (Union(int, tuple[int], list[int])): Padding value for the pooling. Default value is 0.
614
+ padding can only be an integer or a tuple/list containing a single integer, in which case padding times or
615
+ padding[0] times are padded on both sides of the input.
616
+ dilation (Union(int, tuple[int])): The spacing between the elements of the kernel in convolution,
617
+ used to increase the receptive field of the pooling operation. If it is a tuple, its length can only be 1.
618
+ Default: 1.
619
+ return_indices (bool): If True, the function will return both the result of max pooling and the indices of the
620
+ max elements. Default: False.
621
+ ceil_mode (bool): If True, use ceil to compute the output shape instead of floor. Default: False.
622
+
447
623
  Inputs:
448
- - **x** (Tensor) - Tensor of shape :math:`(N, C, L_{in})`.
624
+ - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, L_{in})` or :math:`(C_{in}, L_{in})`.
449
625
 
450
626
  Outputs:
451
- Tensor of shape :math:`(N, C, L_{out})`.
627
+ If `return_indices` is False, output is a Tensor, with shape :math:`(N, C_{out}, L_{out})` or
628
+ :math:`(C_{out}, L_{out})`. It has the same data type as `x`.
629
+
630
+ If `return_indices` is True, output is a Tuple of 2 Tensors, representing the maxpool result and where
631
+ the max values are generated.
632
+
633
+ - **output** (Tensor) - Maxpooling result, with shape :math:`(N, C_{out}, L_{out})` or
634
+ :math:`(C_{out}, L_{out})`. It has the same data type as `x`.
635
+ - **argmax** (Tensor) - Index corresponding to the maximum value. Data type is int64.
636
+
637
+ If `pad_mode` is in `pad` mode, the output shape calculation formula is as follows:
638
+
639
+ .. math::
640
+ L_{out} = \left\lfloor \frac{L_{in} + 2 \times \text{padding} - \text{dilation}
641
+ \times (\text{kernel_size} - 1) - 1}{\text{stride}} + 1\right\rfloor
452
642
 
453
643
  Raises:
454
644
  TypeError: If `kernel_size` or `strides` is not an int.
455
- ValueError: If `pad_mode` is neither 'valid' nor 'same' with not case sensitive.
645
+ ValueError: If `pad_mode` is not 'valid', 'same' or 'pad', case-insensitive.
456
646
  ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
457
647
  ValueError: If `kernel_size` or `strides` is less than 1.
458
- ValueError: If length of shape of `x` is not equal to 3.
648
+ ValueError: If length of shape of `x` is not equal to 2 or 3.
649
+ ValueError: If `pad_mode` is not 'pad', `padding`, `dilation`, `return_indices`, `ceil_mode` parameters are not
650
+ set to their default values.
651
+ ValueError: If the length of the tuple/list `padding` parameter is not 1.
652
+ ValueError: If The length of the tuple dilation parameter is not 1.
653
+ ValueError: If dilation parameter is neither an integer nor a tuple.
654
+ ValueError: If `padding` is non-zero when `pad_mode` is not 'pad'.
459
655
 
460
656
  Supported Platforms:
461
657
  ``Ascend`` ``GPU`` ``CPU``
462
658
 
463
659
  Examples:
464
- >>> max_pool = nn.MaxPool1d(kernel_size=3, stride=1)
660
+ >>> mpool1 = nn.MaxPool1d(kernel_size=3, stride=1)
465
661
  >>> x = Tensor(np.random.randint(0, 10, [1, 2, 4]), mindspore.float32)
466
- >>> output = max_pool(x)
662
+ >>> output = mpool1(x)
467
663
  >>> result = output.shape
468
664
  >>> print(result)
469
665
  (1, 2, 2)
666
+ >>> np_x = np.random.randint(0, 10, [5, 3, 4])
667
+ >>> x = Tensor(np_x, mindspore.float32)
668
+ >>> mpool2 = nn.MaxPool1d(kernel_size=2, stride=1, pad_mode='pad', padding=1, dilation=1, return_indices=True)
669
+ >>> output = mpool2(x)
670
+ >>> print(output[0].shape)
671
+ (5, 3, 5)
672
+ >>> print(output[1].shape)
673
+ (5, 3, 5)
470
674
  """
471
675
 
472
- def __init__(self, kernel_size=1, stride=1, pad_mode="valid"):
676
+ def __init__(self, kernel_size=1, stride=1, pad_mode="valid", padding=0, dilation=1, return_indices=False,
677
+ ceil_mode=False):
473
678
  """Initialize MaxPool1d."""
474
679
  super(MaxPool1d, self).__init__(kernel_size, stride, pad_mode)
475
- validator.check_value_type('kernel_size', kernel_size, [int], self.cls_name)
476
- validator.check_value_type('stride', stride, [int], self.cls_name)
477
- validator.check_value_type('pad_mode', pad_mode, [str], self.cls_name)
478
- self.pad_mode = validator.check_string(pad_mode.upper(), ['VALID', 'SAME'], 'pad_mode', self.cls_name)
479
- validator.check_int(kernel_size, 1, Rel.GE, "kernel_size", self.cls_name)
480
- validator.check_int(stride, 1, Rel.GE, "stride", self.cls_name)
680
+ validator.check_int(kernel_size, 1, validator.GE, "kernel_size", self.cls_name)
681
+ validator.check_int(stride, 1, validator.GE, "stride", self.cls_name)
481
682
  self.kernel_size = (1, kernel_size)
482
683
  self.stride = (1, stride)
483
- self.max_pool = P.MaxPool(kernel_size=self.kernel_size,
484
- strides=self.stride,
485
- pad_mode=self.pad_mode)
486
- self.shape = F.shape
487
- self.reduce_mean = P.ReduceMean(keep_dims=True)
488
- self.expand = P.ExpandDims()
489
- self.squeeze = P.Squeeze(2)
684
+ self.return_indices = return_indices
685
+ if pad_mode.upper() == "PAD":
686
+ self.use_pad = True
687
+ self.kernel_size = (1, 1, kernel_size)
688
+ self.stride = (1, 1, stride)
689
+ self.padding = _check_maxpool_padding(padding, 1, self.cls_name)
690
+ dilation = _cal_dilation(dilation, 1, self.cls_name)
691
+ self.max_pool = P.MaxPool3DWithArgmax(ksize=self.kernel_size, strides=self.stride, pads=self.padding,
692
+ dilation=dilation, ceil_mode=ceil_mode)
693
+
694
+ else:
695
+ self.use_pad = False
696
+ if padding != 0 or dilation != 1 or return_indices or ceil_mode:
697
+ raise ValueError(f"For MaxPool1d, the parameter 'padding', 'dilation', 'return_indices', 'ceil_mode' "
698
+ f"can not be set to non-default value when pad_mode is not 'pad', "
699
+ f"but got pad_mode:{pad_mode}.")
700
+ self.max_pool = P.MaxPool(kernel_size=self.kernel_size,
701
+ strides=self.stride,
702
+ pad_mode=self.pad_mode)
703
+ self.shape = F.shape
704
+ self.reduce_mean = P.ReduceMean(keep_dims=True)
705
+ self.expand = P.ExpandDims()
706
+ self.squeeze = P.Squeeze(2)
490
707
 
491
708
  def construct(self, x):
492
- _shape_check(self.shape(x), self.cls_name)
493
- x = self.expand(x, 2)
494
- output = self.max_pool(x)
495
- output = self.squeeze(output)
709
+ expand_batch = False
710
+ if x.ndim == 2:
711
+ x = x.unsqueeze(0)
712
+ expand_batch = True
713
+ if self.use_pad:
714
+ x = x.unsqueeze(2).unsqueeze(3)
715
+ output = self.max_pool(x)
716
+ if isinstance(output, tuple):
717
+ output = output[0].squeeze(3).squeeze(2), output[1].squeeze(3).squeeze(2)
718
+ else:
719
+ output = output.squeeze(3).squeeze(2)
720
+ else:
721
+ _shape_check(self.shape(x), self.cls_name)
722
+ x = self.expand(x, 2)
723
+ output = self.max_pool(x)
724
+ output = self.squeeze(output)
725
+ if expand_batch:
726
+ if isinstance(output, tuple):
727
+ output = (output[0].squeeze(0), output[1].squeeze(0))
728
+ else:
729
+ output = output.squeeze(0)
730
+ if self.use_pad and not self.return_indices:
731
+ return output[0]
496
732
  return output
497
733
 
498
734
 
499
- class AvgPool3d(Cell):
735
+ def _cal_padding(padding, cls_name, nd):
736
+ """Calculate padding before call primitive"""
737
+ validator.check_value_type('padding', padding, (int, tuple, list), cls_name)
738
+ if isinstance(padding, int):
739
+ padding = (0, 0) * (3 - nd) + (padding,) * nd * 2
740
+ elif isinstance(padding, (tuple, list)):
741
+ validator.check_non_negative_int_sequence(padding, "padding", cls_name)
742
+ if len(padding) == nd:
743
+ padding_start = (0, 0) * (3 - nd)
744
+ padding_end = tuple(padding[i // 2] for i in range(nd * 2))
745
+ padding = padding_start + padding_end
746
+ elif len(padding) == 1:
747
+ padding = (0, 0) * (3 - nd) + tuple(padding * nd * 2)
748
+ else:
749
+ if nd == 1:
750
+ raise ValueError(f"For {cls_name}, the padding must be a int or tuple/list contains one int, "
751
+ f"but got tuple/list with length:{len(padding)}.")
752
+ raise ValueError(f"For {cls_name}, the padding must be a int or tuple/list contains 1 or {nd} int, "
753
+ f"but got tuple/list with length:{len(padding)}.")
754
+ return padding
755
+
756
+
757
+ def _check_tuple_length(arg_name, prim_name, length, cls_name):
758
+ """check the tuple length"""
759
+ if len(arg_name) != length:
760
+ raise ValueError(f"For {cls_name}, the length of {prim_name} must be equal to {length}, "
761
+ f"but got {len(arg_name)}.")
762
+ return arg_name
763
+
764
+
765
+ class AvgPool3d(_PoolNd):
500
766
  r"""
501
767
  Applies a 3D average pooling over an input Tensor which can be regarded as a composition of 3D input planes.
502
- Typically the input is of shape :math:`(N, C, D_{in}, H_{in}, W_{in})`, and AvgPool3D outputs
768
+ Typically, the input is of shape :math:`(N_{in}, C_{in}, D_{in}, H_{in}, W_{in})`, and AvgPool3D outputs
503
769
  regional average in the :math:`(D_{in}, H_{in}, W_{in})`-dimension. Given kernel size
504
770
  is :math:`ks = (d_{ker}, h_{ker}, w_{ker})` and stride :math:`s = (s_0, s_1, s_2)`, the operation is as follows.
505
771
 
@@ -512,23 +778,38 @@ class AvgPool3d(Cell):
512
778
  \text{input}(N_i, C_j, s_0 \times d + l, s_1 \times h + m, s_2 \times w + n)
513
779
 
514
780
  Args:
515
- kernel_size (Union[int, tuple[int]]): The size of kernel used to take the average value,
516
- can be an int number that represents depth, height and width, or a tuple
517
- of three int numbers that represent depth, height and width respectively.
518
- The value must be a positive integer.
519
- stride (Union[int, tuple[int]]): The distance of kernel moving, can be an int number that represents
520
- the depth, height and width of movement, or a tuple of three int numbers that
521
- represent depth, height and width of movement respectively. The value must be a positive integer.
522
- If the value is None, the default value `kernel_size` is used.
523
- padding (Union(int, tuple[int])): The padding value to be filled. Default: 0. The value cannot be negative.
524
- If `padding` is an integer, the paddings of head, tail, top, bottom, left and right are the same,
525
- equal to padding.
526
- If `padding` is a tuple of six integers, the padding of head, tail, top, bottom, left and right
527
- equal to padding[0], padding[1], padding[2], padding[3], padding[4] and padding[5] correspondingly.
528
- ceil_mode (bool): If True, use ceil to compute the output shape instead of floor. Default: False.
529
- count_include_pad (bool): If True, averaging calculation will include the zero-padding. Default: True.
530
- divisor_override (int): If specified, it will be used as divisor in the averaging calculation,
531
- otherwise kernel_size will be used. Default: None.
781
+ kernel_size (Union[int, tuple[int]], optional): The size of kernel used to take the average value,
782
+ can be an int number or a single element tuple that represents depth, height and width, or a tuple of three
783
+ positive integers that represent depth, height and width respectively. Default: 1.
784
+ stride (Union[int, tuple[int]], optional): The distance of kernel moving, can be a positive int or a single
785
+ element tuple that represents the depth, height and width of movement, or a tuple of three positive integers
786
+ that represents depth, height and width of movement respectively. If the value is None, the default value
787
+ `kernel_size` is used. Default: 1.
788
+ pad_mode (str, optional): Specifies the padding method of pooling, optional values are "same", "valid" or "pad",
789
+ case insensitive. Default: "valid".
790
+
791
+ - same: The depth, height and width of the output is the same as the value after the input is divided
792
+ by stride.
793
+
794
+ - valid: Returns the output obtained by effective calculation without padding.
795
+ The excess pixels that do not meet the calculation will be discarded.
796
+
797
+ - pad: Pads the input. Fill the front, back, top, and bottom of the input with 0s of size `padding`.
798
+ If this mode is set, `padding` must be greater than or equal to 0.
799
+
800
+ padding (Union(int, tuple[int], list[int]), optional): Pooling padding value, only 'pad' mode can be set to
801
+ non-zero. Default: 0. Only the following paddings are supported:
802
+
803
+ - `padding` is an integer or a tuple/list containing one integer, it will be padded in six directions of
804
+ front, back, top, bottom, left and right of the input.
805
+
806
+ - `padding` is a tuple/list containing three integers, it will be padded in front and back of the input
807
+ `padding[0]` times, up and down `padding[1]` times, and left and right of the input `padding[2]` times.
808
+
809
+ ceil_mode (bool, optional): If True, use ceil to compute the output shape instead of floor. Default: False.
810
+ count_include_pad (bool, optional): If True, averaging calculation will include the zero-padding. Default: True.
811
+ divisor_override (int, optional): If it is specified as a non-zero parameter, this parameter will be used as the
812
+ divisor in the average calculation. Otherwise, `kernel_size` will be used as the divisor. Default: None.
532
813
 
533
814
  Inputs:
534
815
  - **x** (Tensor) - Tensor of shape :math:`(N, C, D_{in}, H_{in}, W_{in})` or
@@ -537,53 +818,74 @@ class AvgPool3d(Cell):
537
818
 
538
819
  Outputs:
539
820
  Tensor, with shape :math:`(N, C, D_{out}, H_{out}, W_{out})` or
540
- :math:`(C, D_{in}, H_{in}, W_{in})`, with the same data type as `x`.
821
+ :math:`(C, D_{out}, H_{out}, W_{out})`, with the same data type as `x`.
822
+
823
+ If `pad_mode` is in `pad` mode, the output shape calculation formula is as follows:
824
+
825
+ .. math::
826
+ D_{out} = \left\lfloor\frac{D_{in} + 2 \times \text{padding}[0] -
827
+ \text{kernel_size}[0]}{\text{stride}[0]} + 1\right\rfloor
828
+
829
+ .. math::
830
+ H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[1] -
831
+ \text{kernel_size}[1]}{\text{stride}[1]} + 1\right\rfloor
832
+
833
+ .. math::
834
+ W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] -
835
+ \text{kernel_size}[2]}{\text{stride}[2]} + 1\right\rfloor
541
836
 
542
837
  Raises:
543
- TypeError: If `kernel_size`, `stride` or `padding` is neither an int nor a tuple.
838
+ TypeError: If `kernel_size` is neither an int nor a tuple.
839
+ TypeError: If `stride` is neither an int nor a tuple.
840
+ TypeError: If `padding` is neither an int nor a tuple/list.
544
841
  TypeError: If `ceil_mode` or `count_include_pad` is not a bool.
545
- TypeError: If `data_format` is not a string.
546
842
  TypeError: If `divisor_override` is not an int.
547
843
  ValueError: If numbers in `kernel_size` or `stride` are not positive.
548
844
  ValueError: If `kernel_size` or `stride` is a tuple whose length is not equal to 3.
549
- ValueError: If `padding` is a tuple whose length is not equal to 6.
845
+ ValueError: If `padding` is a tuple/list whose length is neither 1 nor 3.
550
846
  ValueError: If element of `padding` is less than 0.
551
- ValueError: If length of shape of `x` is not equal to 5.
847
+ ValueError: If length of shape of `x` is neither 4 nor 5.
848
+ ValueError: If `divisor_override` is less than or equal to 0.
849
+ ValueError: If `padding` is non-zero when `pad_mode` is not 'pad'.
552
850
 
553
851
  Supported Platforms:
554
- ``Ascend`` ``CPU``
852
+ ``Ascend`` ``GPU`` ``CPU``
555
853
 
556
854
  Examples:
557
855
  >>> import mindspore as ms
558
856
  >>> import mindspore.nn as nn
559
- >>> import numpy as np
857
+ >>> import mindspore.ops as ops
560
858
  >>> pool = nn.AvgPool3d(kernel_size=3, stride=1)
561
- >>> x = ms.Tensor(np.random.randint(0, 10, [1, 2, 4, 4, 5]), ms.float32)
859
+ >>> x = ops.randn(1, 2, 4, 4, 5).astype(ms.float32)
562
860
  >>> output = pool(x)
563
861
  >>> print(output.shape)
564
862
  (1, 2, 2, 2, 3)
863
+ >>> x1 = ops.randn(6, 5, 7, 7, 5).astype(ms.float32)
864
+ >>> pool2 = nn.AvgPool3d(4, stride=2, pad_mode='pad', padding=(2, 2, 1), divisor_override=10)
865
+ >>> output2 = pool2(x1)
866
+ >>> print(output2.shape)
867
+ (6, 5, 4, 4, 2)
565
868
  """
566
869
 
567
- def __init__(self, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True,
870
+ def __init__(self, kernel_size=1, stride=1, pad_mode="valid", padding=0, ceil_mode=False, count_include_pad=True,
568
871
  divisor_override=None):
569
872
  """Initialize AvgPool3d."""
570
- super(AvgPool3d, self).__init__()
571
- stride = stride if (stride is not None) else kernel_size
572
- if not divisor_override:
573
- divisor_override = 0
574
- self.avg_pool = P.AvgPool3D(kernel_size, stride, "pad", padding, ceil_mode, count_include_pad,
873
+ super(AvgPool3d, self).__init__(kernel_size, stride, pad_mode)
874
+ padding = _cal_padding(padding, self.cls_name, 3)
875
+ if divisor_override is not None and divisor_override <= 0:
876
+ raise ValueError(f"For '{self.cls_name}', the 'divisor_override' must be > 0, but got {divisor_override}.")
877
+ divisor_override = 0 if divisor_override is None else divisor_override
878
+ self.avg_pool = P.AvgPool3D(self.kernel_size, self.stride, pad_mode, padding, ceil_mode, count_include_pad,
575
879
  divisor_override)
576
- self.squeeze = P.Squeeze(0)
577
- self.expand_dims = P.ExpandDims()
578
880
 
579
881
  def construct(self, x):
580
- _is_squeeze = False
882
+ expand_batch = False
581
883
  if len(x.shape) == 4:
582
- x = self.expand_dims(x, 0)
583
- _is_squeeze = True
884
+ x = x.unsqueeze(0)
885
+ expand_batch = True
584
886
  out = self.avg_pool(x)
585
- if _is_squeeze:
586
- out = self.squeeze(out)
887
+ if expand_batch:
888
+ out = out.squeeze(0)
587
889
  return out
588
890
 
589
891
 
@@ -599,69 +901,147 @@ class AvgPool2d(_PoolNd):
599
901
  \text{output}(N_i, C_j, h, w) = \frac{1}{h_{ker} * w_{ker}} \sum_{m=0}^{h_{ker}-1} \sum_{n=0}^{w_{ker}-1}
600
902
  \text{input}(N_i, C_j, s_0 \times h + m, s_1 \times w + n)
601
903
 
602
- Note:
603
- pad_mode for training only supports "same" and "valid".
604
-
605
904
  Args:
606
905
  kernel_size (Union[int, tuple[int]]): The size of kernel used to take the average value.
607
- The data type of kernel_size must be int and the value represents the height and width,
608
- or a tuple of two int numbers that represent height and width respectively.
906
+ The data type of kernel_size must be int or a single element tuple and the value represents the height
907
+ and width, or a tuple of two int numbers that represent height and width respectively.
609
908
  Default: 1.
610
- stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
611
- the height and width of movement are both strides, or a tuple of two int numbers that
909
+ stride (Union[int, tuple[int]]): The distance of kernel moving, an int number or a single element tuple that
910
+ represents the height and width of movement are both strides, or a tuple of two int numbers that
612
911
  represent height and width of movement respectively. Default: 1.
613
- pad_mode (str): The optional value for pad mode, is "same" or "valid", not case sensitive.
614
- Default: "valid".
912
+ pad_mode (str) - Specifies the padding method of pooling, optional values are "same", "valid" or "pad",
913
+ case insensitive. Default: "valid".
615
914
 
616
- - same: Adopts the way of completion. The height and width of the output will be the same as
617
- the input. The total number of padding will be calculated in horizontal and vertical
618
- directions and evenly distributed to top and bottom, left and right if possible.
619
- Otherwise, the last extra padding will be done from the bottom and the right side.
915
+ - same: The height and width of the output is the same as the value after the input is divided by stride.
620
916
 
621
- - valid: Adopts the way of discarding. The possible largest height and width of output
622
- will be returned without padding. Extra pixels will be discarded.
917
+ - valid: Returns the output obtained by effective calculation without padding.
918
+ The excess pixels that do not meet the calculation will be discarded.
919
+
920
+ - pad: pads the input. Pads the top, bottom, left, and right sides of the input with `padding` number of
921
+ zeros. If this mode is set, `padding` must be greater than or equal to 0.
922
+
923
+ padding (Union(int, tuple[int], list[int])): Pooling padding value, only 'pad' mode can be set to non-zero.
924
+ Default: 0. `padding` can only be an integer or a tuple/list containing one or two integers.
925
+ If `padding` is an integer or a tuple/list containing one integer, it will be padded `padding` times in the
926
+ four directions of the input. If `padding` is a tuple/list containing two integers, it will be padded
927
+ `padding[0]` times in the up-down direction of the input and `padding[1]` times in the left-right direction
928
+ of the input.
929
+ ceil_mode (bool): If True, use ceil to compute the output shape instead of floor. Default: False.
930
+ count_include_pad (bool): If True, averaging calculation will include the zero-padding. Default: True.
931
+ divisor_override (int): If it is specified as a non-zero parameter, this parameter will be used as the divisor
932
+ in the average calculation. Otherwise, `kernel_size` will be used as the divisor. Default: None.
623
933
  data_format (str): The optional value for data format, is 'NHWC' or 'NCHW'.
624
934
  Default: 'NCHW'.
625
935
 
626
-
627
936
  Inputs:
628
- - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`.
937
+ - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})` or :math:`(C_{in}, H_{in}, W_{in})`.
629
938
 
630
939
  Outputs:
631
- Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})`.
940
+ Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})` or :math:`(C_{out}, H_{out}, W_{out})`.
941
+
942
+ If `pad_mode` is in `pad` mode, the output shape calculation formula is as follows:
943
+
944
+ .. math::
945
+ H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[0] -
946
+ \text{kernel_size}[0]}{\text{stride}[0]} + 1\right\rfloor
947
+
948
+ .. math::
949
+ W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[1] -
950
+ \text{kernel_size}[1]}{\text{stride}[1]} + 1\right\rfloor
632
951
 
633
952
  Raises:
634
953
  TypeError: If `kernel_size` or `strides` is neither int nor tuple.
635
- ValueError: If `pad_mode` is neither 'valid' nor 'same' with not case sensitive.
954
+ ValueError: If `pad_mode` is not 'valid' ,'same' or 'pad' with not case sensitive.
636
955
  ValueError: If `data_format` is neither 'NCHW' nor 'NHWC'.
956
+ ValueError: If `padding`, `ceil_mode`, `count_include_pad`, or `divisor_override` is used
957
+ or `pad_mode` is `pad` when `data_format` is 'NHWC'.
637
958
  ValueError: If `kernel_size` or `strides` is less than 1.
638
- ValueError: If length of shape of `x` is not equal to 4.
959
+ ValueError: If length of `padding` tuple/list is not 1 or 2.
960
+ ValueError: If length of shape of `x` is not equal to 3 or 4.
961
+ ValueError: If `divisor_override` is less than or equal to 0.
962
+ ValueError: If `padding` is non-zero when `pad_mode` is not 'pad'.
639
963
 
640
964
  Supported Platforms:
641
965
  ``Ascend`` ``GPU`` ``CPU``
642
966
 
643
967
  Examples:
968
+ >>> import mindspore as ms
969
+ >>> import mindspore.nn as nn
970
+ >>> import mindspore.ops as ops
971
+ >>> import numpy as np
644
972
  >>> pool = nn.AvgPool2d(kernel_size=3, stride=1)
645
- >>> x = Tensor(np.random.randint(0, 10, [1, 2, 4, 4]), mindspore.float32)
973
+ >>> x = ms.Tensor(np.random.randint(0, 10, [1, 2, 4, 4]), ms.float32)
646
974
  >>> output = pool(x)
647
975
  >>> print(output.shape)
648
976
  (1, 2, 2, 2)
977
+ >>> x = ops.randn(6, 6, 8, 8)
978
+ >>> pool2 = nn.AvgPool2d(4, stride=1, pad_mode='pad', padding=2, divisor_override=5)
979
+ >>> output2 = pool2(x)
980
+ >>> print(output2.shape)
981
+ (6, 6, 9, 9)
649
982
  """
650
983
 
651
984
  def __init__(self,
652
985
  kernel_size=1,
653
986
  stride=1,
654
987
  pad_mode="valid",
988
+ padding=0,
989
+ ceil_mode=False,
990
+ count_include_pad=True,
991
+ divisor_override=None,
655
992
  data_format="NCHW"):
656
993
  """Initialize AvgPool2d."""
657
994
  super(AvgPool2d, self).__init__(kernel_size, stride, pad_mode, data_format)
658
- self.avg_pool = P.AvgPool(kernel_size=self.kernel_size,
659
- strides=self.stride,
660
- pad_mode=self.pad_mode,
661
- data_format=self.format)
995
+ if pad_mode.upper() == 'PAD' or padding != 0 or ceil_mode or not count_include_pad \
996
+ or divisor_override is not None:
997
+ if self.format == "NHWC":
998
+ raise ValueError(f"For '{self.cls_name}, the 'NHWC' format are not support when 'pad_mode' is 'pad' or "
999
+ f"'padding' is not 0 or 'ceil_mode' is not False or 'count_include_pad' is not True"
1000
+ f"or divisor_override is not None, but got pade_mode:{pad_mode}, padding:{padding}, "
1001
+ f"ceil_mode:{ceil_mode}, count_include_pad:{count_include_pad}, "
1002
+ f"divisor_override:{divisor_override}.")
1003
+ self.is_expand = True
1004
+ if divisor_override is not None and divisor_override <= 0:
1005
+ raise ValueError(
1006
+ f"For '{self.cls_name}', the 'divisor_override' must be > 0, but got {divisor_override}.")
1007
+ divisor_override = 0 if divisor_override is None else divisor_override
1008
+ padding = _cal_padding(padding, self.cls_name, 2)
1009
+
1010
+ if isinstance(self.kernel_size, tuple):
1011
+ _check_tuple_length(self.kernel_size, 'kernel_size', 2, self.cls_name)
1012
+ kernel_size = (1,) + self.kernel_size
1013
+ elif isinstance(self.kernel_size, int):
1014
+ kernel_size = (1, self.kernel_size, self.kernel_size)
1015
+
1016
+ if isinstance(self.stride, tuple):
1017
+ _check_tuple_length(self.stride, 'stride', 2, self.cls_name)
1018
+ stride = (1,) + self.stride
1019
+ elif isinstance(self.stride, int):
1020
+ stride = (1, self.stride, self.stride)
1021
+ self.avg_pool = P.AvgPool3D(kernel_size=kernel_size, strides=stride, pad_mode=pad_mode, pad=padding,
1022
+ ceil_mode=ceil_mode,
1023
+ count_include_pad=count_include_pad, divisor_override=divisor_override)
1024
+ else:
1025
+ self.is_expand = False
1026
+ self.avg_pool = P.AvgPool(kernel_size=self.kernel_size,
1027
+ strides=self.stride,
1028
+ pad_mode=self.pad_mode,
1029
+ data_format=self.format)
662
1030
 
663
1031
  def construct(self, x):
664
- return self.avg_pool(x)
1032
+ expand_batch = False
1033
+ if x.ndim == 3:
1034
+ x = x.unsqueeze(0)
1035
+ expand_batch = True
1036
+ if self.is_expand:
1037
+ x = x.unsqueeze(2)
1038
+ out = self.avg_pool(x)
1039
+ res = out.squeeze(2)
1040
+ else:
1041
+ res = self.avg_pool(x)
1042
+ if expand_batch:
1043
+ res = res.squeeze(0)
1044
+ return res
665
1045
 
666
1046
 
667
1047
  class AvgPool1d(_PoolNd):
@@ -669,95 +1049,134 @@ class AvgPool1d(_PoolNd):
669
1049
  Applies a 1D average pooling over an input Tensor which can be regarded as a composition of 1D input planes.
670
1050
 
671
1051
  Typically the input is of shape :math:`(N_{in}, C_{in}, L_{in})`, AvgPool1d outputs
672
- regional average in the :math:`(L_{in})`-dimension. Given kernel size
673
- :math:`ks = l_{ker}` and stride :math:`s = s_0`, the operation is as follows:
1052
+ regional average in the :math:`(L_{in})`-dimension. Given `kernel_size`
1053
+ :math:`l_{ker}` and `stride` :math:`s_0`, the operation is as follows:
674
1054
 
675
1055
  .. math::
676
1056
  \text{output}(N_i, C_j, l) = \frac{1}{l_{ker}} \sum_{n=0}^{l_{ker}-1}
677
1057
  \text{input}(N_i, C_j, s_0 \times l + n)
678
1058
 
679
- Note:
680
- pad_mode for training only supports "same" and "valid".
681
-
682
1059
  Args:
683
1060
  kernel_size (int): The size of kernel window used to take the average value, Default: 1.
684
1061
  stride (int): The distance of kernel moving, an int number that represents
685
1062
  the width of movement is strides, Default: 1.
686
- pad_mode (str): The optional value for pad mode, is "same" or "valid", not case sensitive.
687
- Default: "valid".
1063
+ pad_mode (str) - Specifies the padding method of pooling, optional values are "same", "valid" or "pad",
1064
+ case insensitive. Default: "valid".
688
1065
 
689
- - same: Adopts the way of completion. The height and width of the output will be the same as
690
- the input. The total number of padding will be calculated in horizontal and vertical
691
- directions and evenly distributed to top and bottom, left and right if possible.
692
- Otherwise, the last extra padding will be done from the bottom and the right side.
1066
+ - same: The width of the output is the same as the value after the input is divided by stride.
693
1067
 
694
- - valid: Adopts the way of discarding. The possible largest height and width of output
695
- will be returned without padding. Extra pixels will be discarded.
1068
+ - valid: Returns the output obtained by effective calculation without padding.
1069
+ The excess pixels that do not meet the calculation will be discarded.
1070
+
1071
+ - pad: Performs padding on the input. Adds padding size of zeros to both ends of the input.
1072
+ If this mode is set, padding must be greater than or equal to 0.
696
1073
 
1074
+ padding (Union(int, tuple[int], list[int])): Pooling padding value, only 'pad' mode can be set to non-zero.
1075
+ Default: 0. padding can only be an integer or a tuple/list containing a single integer, in which case
1076
+ padding times or padding[0] times are padded on both sides of the input.
1077
+ ceil_mode (bool): If True, use ceil to compute the output shape instead of floor. Default: False.
1078
+ count_include_pad (bool): If True, averaging calculation will include the zero-padding. Default: True.
697
1079
 
698
1080
  Inputs:
699
- - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, L_{in})`.
1081
+ - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, L_{in})` or :math:`(C_{in}, L_{in})`.
700
1082
 
701
1083
  Outputs:
702
- Tensor of shape :math:`(N, C_{out}, L_{out})`.
1084
+ Tensor of shape :math:`(N, C_{out}, L_{out})` or :math:`(C_{out}, L_{out})`.
1085
+
1086
+ If `pad_mode` is in `pad` mode, the output shape calculation formula is as follows:
1087
+
1088
+ .. math::
1089
+ L_{out} = \left\lfloor \frac{L_{in} +
1090
+ 2 \times \text{padding} - \text{kernel_size}}{\text{stride}} + 1\right\rfloor
703
1091
 
704
1092
  Raises:
705
1093
  TypeError: If `kernel_size` or `stride` is not an int.
706
- ValueError: If `pad_mode` is neither 'same' nor 'valid' with not case sensitive.
1094
+ ValueError: If `pad_mode` is not 'valid' ,'same' or 'pad' with not case sensitive.
707
1095
  ValueError: If `kernel_size` or `strides` is less than 1.
708
- ValueError: If length of shape of `x` is not equal to 3.
1096
+ ValueError: If length of `padding` tuple/list is not 1.
1097
+ ValueError: If length of shape of `x` is not equal to 2 or 3.
1098
+ ValueError: If `padding` is non-zero when `pad_mode` is not 'pad'.
709
1099
 
710
1100
  Supported Platforms:
711
1101
  ``Ascend`` ``GPU`` ``CPU``
712
1102
 
713
1103
  Examples:
1104
+ >>> import mindspore as ms
1105
+ >>> import mindspore.nn as nn
1106
+ >>> import mindspore.ops as ops
1107
+ >>> import numpy as np
714
1108
  >>> pool = nn.AvgPool1d(kernel_size=6, stride=1)
715
- >>> x = Tensor(np.random.randint(0, 10, [1, 3, 6]), mindspore.float32)
1109
+ >>> x = ms.Tensor(np.random.randint(0, 10, [1, 3, 6]), ms.float32)
716
1110
  >>> output = pool(x)
717
1111
  >>> result = output.shape
718
1112
  >>> print(result)
719
1113
  (1, 3, 1)
1114
+ >>> pool2 = nn.AvgPool1d(4, stride=1, ceil_mode=True, pad_mode='pad', padding=2)
1115
+ >>> x1 = ops.randn(6, 6, 8)
1116
+ >>> output = pool2(x1)
1117
+ >>> print(output.shape)
1118
+ (6, 6, 9)
720
1119
  """
721
1120
 
722
1121
  def __init__(self,
723
1122
  kernel_size=1,
724
1123
  stride=1,
725
- pad_mode="valid"):
1124
+ pad_mode="valid",
1125
+ padding=0,
1126
+ ceil_mode=False,
1127
+ count_include_pad=True):
726
1128
  """Initialize AvgPool1d."""
727
- validator.check_value_type('kernel_size', kernel_size, [int], self.cls_name)
728
- validator.check_value_type('stride', stride, [int], self.cls_name)
729
- validator.check_value_type('pad_mode', pad_mode, [str], self.cls_name)
730
- self.pad_mode = validator.check_string(pad_mode.upper(), ['VALID', 'SAME'], 'pad_mode', self.cls_name)
731
- validator.check_int(kernel_size, 1, Rel.GE, "kernel_size", self.cls_name)
732
- validator.check_int(stride, 1, Rel.GE, "stride", self.cls_name)
733
1129
  super(AvgPool1d, self).__init__(kernel_size, stride, pad_mode)
734
- self.kernel_size = (1, kernel_size)
735
- self.stride = (1, stride)
736
- self.avg_pool = P.AvgPool(kernel_size=self.kernel_size,
737
- strides=self.stride,
738
- pad_mode=self.pad_mode)
739
- self.shape = F.shape
740
- self.reduce_mean = P.ReduceMean(keep_dims=True)
741
- self.slice = P.Slice()
742
- self.expand = P.ExpandDims()
743
- self.squeeze = P.Squeeze(2)
1130
+ validator.check_int(self.kernel_size, 1, validator.GE, "kernel_size", self.cls_name)
1131
+ validator.check_int(self.stride, 1, validator.GE, "stride", self.cls_name)
1132
+ if pad_mode.upper() == 'PAD' or padding != 0 or ceil_mode or not count_include_pad:
1133
+ padding = _cal_padding(padding, self.cls_name, 1)
1134
+ self.is_expand_3d = True
1135
+ kernel_size = (1, 1, self.kernel_size)
1136
+ stride = (1, 1, self.stride)
1137
+ self.avg_pool = P.AvgPool3D(kernel_size=kernel_size, strides=stride, pad_mode=pad_mode, pad=padding,
1138
+ ceil_mode=ceil_mode,
1139
+ count_include_pad=count_include_pad)
1140
+ else:
1141
+ self.is_expand_3d = False
1142
+ self.kernel_size = (1, self.kernel_size)
1143
+ self.stride = (1, self.stride)
1144
+ self.avg_pool = P.AvgPool(kernel_size=self.kernel_size,
1145
+ strides=self.stride,
1146
+ pad_mode=self.pad_mode)
1147
+ self.shape = F.shape
1148
+ self.reduce_mean = P.ReduceMean(keep_dims=True)
1149
+ self.slice = P.Slice()
1150
+ self.expand = P.ExpandDims()
1151
+ self.squeeze = P.Squeeze(2)
744
1152
 
745
1153
  def construct(self, x):
746
- x = F.depend(x, _shape_check(self.shape(x), self.cls_name))
747
- batch, channel, width = self.shape(x)
748
- if width == self.kernel_size[1]:
749
- x = self.reduce_mean(x, 2)
750
- elif width - self.kernel_size[1] < self.stride[1]:
751
- x = self.slice(x, (0, 0, 0), (batch, channel, self.kernel_size[1]))
752
- x = self.reduce_mean(x, 2)
753
- else:
754
- x = self.expand(x, 2)
1154
+ expand_batch = False
1155
+ if x.ndim == 2:
1156
+ x = x.unsqueeze(0)
1157
+ expand_batch = True
1158
+ if self.is_expand_3d:
1159
+ x = x.unsqueeze(2).unsqueeze(3)
755
1160
  x = self.avg_pool(x)
756
- x = self.squeeze(x)
1161
+ x = x.squeeze(3).squeeze(2)
1162
+ else:
1163
+ _shape_check(self.shape(x), self.cls_name)
1164
+ batch, channel, width = self.shape(x)
1165
+ if width == self.kernel_size[1]:
1166
+ x = self.reduce_mean(x, 2)
1167
+ elif width - self.kernel_size[1] < self.stride[1]:
1168
+ x = self.slice(x, (0, 0, 0), (batch, channel, self.kernel_size[1]))
1169
+ x = self.reduce_mean(x, 2)
1170
+ else:
1171
+ x = self.expand(x, 2)
1172
+ x = self.avg_pool(x)
1173
+ x = self.squeeze(x)
1174
+ if expand_batch:
1175
+ x = x.squeeze(0)
757
1176
  return x
758
1177
 
759
1178
 
760
- @constexpr
1179
+ @_primexpr
761
1180
  def _adaptive_shape_check(in_shape, output_size, prim_name):
762
1181
  """Check shape."""
763
1182
  msg_prefix = "For {}, the".format(prim_name)
@@ -796,18 +1215,18 @@ class AdaptiveAvgPool1d(Cell):
796
1215
  output_size (int): the target output size :math:`L_{out}`.
797
1216
 
798
1217
  Inputs:
799
- - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, L_{in})`, with float16 or float32 data type.
1218
+ - **input** (Tensor) - Tensor of shape :math:`(N, C_{in}, L_{in})`, with float16 or float32 data type.
800
1219
 
801
1220
  Outputs:
802
- Tensor of shape :math:`(N, C_{in}, L_{out})`, has the same type as `x`.
1221
+ Tensor of shape :math:`(N, C_{in}, L_{out})`, has the same type as `input`.
803
1222
 
804
1223
  Raises:
805
1224
  TypeError: If `output_size` is not an int.
806
- TypeError: If `x` is neither float16 nor float32.
1225
+ TypeError: If `input` is neither float16 nor float32.
807
1226
  ValueError: If `output_size` is less than 1.
808
- ValueError: If length of shape of `x` is not equal to 3.
809
- ValueError: If the last dimension of `x` is smaller than `output_size`.
810
- ValueError: If the last dimension of `x` is not divisible by `output_size`.
1227
+ ValueError: If length of shape of `input` is not equal to 3.
1228
+ ValueError: If the last dimension of `input` is smaller than `output_size`.
1229
+ ValueError: If the last dimension of `input` is not divisible by `output_size`.
811
1230
 
812
1231
 
813
1232
  Supported Platforms:
@@ -818,8 +1237,8 @@ class AdaptiveAvgPool1d(Cell):
818
1237
  >>> from mindspore import Tensor, nn
819
1238
  >>> import numpy as np
820
1239
  >>> pool = nn.AdaptiveAvgPool1d(output_size=2)
821
- >>> x = Tensor(np.random.randint(0, 10, [1, 3, 6]), mindspore.float32)
822
- >>> output = pool(x)
1240
+ >>> input = Tensor(np.random.randint(0, 10, [1, 3, 6]), mindspore.float32)
1241
+ >>> output = pool(input)
823
1242
  >>> result = output.shape
824
1243
  >>> print(result)
825
1244
  (1, 3, 2)
@@ -829,30 +1248,30 @@ class AdaptiveAvgPool1d(Cell):
829
1248
  """Initialize AdaptiveAvgPool1d."""
830
1249
  super(AdaptiveAvgPool1d, self).__init__()
831
1250
  validator.check_value_type('output_size', output_size, [int], self.cls_name)
832
- validator.check_int(output_size, 1, Rel.GE, "output_size", self.cls_name)
1251
+ validator.check_int(output_size, 1, validator.GE, "output_size", self.cls_name)
833
1252
  self.shape = F.shape
834
1253
  self.expand = P.ExpandDims()
835
1254
  self.squeeze = P.Squeeze(2)
836
1255
  self.output_size = output_size
837
1256
  self.dtype = P.DType()
838
1257
 
839
- def construct(self, x):
840
- _adaptive_shape_check(self.shape(x), self.output_size, self.cls_name)
841
- _adaptive_dtype_check(self.dtype(x), self.cls_name)
1258
+ def construct(self, input):
1259
+ _adaptive_shape_check(self.shape(input), self.output_size, self.cls_name)
1260
+ _adaptive_dtype_check(self.dtype(input), self.cls_name)
842
1261
 
843
- _, _, width = self.shape(x)
1262
+ _, _, width = self.shape(input)
844
1263
  stride = width // self.output_size
845
1264
  kernel_size = width - (self.output_size - 1) * stride
846
1265
 
847
1266
  stride = (1, width // self.output_size)
848
1267
  kernel_size = (1, kernel_size)
849
1268
 
850
- x = self.expand(x, 2)
1269
+ input = self.expand(input, 2)
851
1270
  avg_pool = P.AvgPool(kernel_size=kernel_size, strides=stride)
852
- x = avg_pool(x)
853
- x = self.squeeze(x)
1271
+ input = avg_pool(input)
1272
+ input = self.squeeze(input)
854
1273
 
855
- return x
1274
+ return input
856
1275
 
857
1276
 
858
1277
  class AdaptiveAvgPool2d(Cell):
@@ -880,7 +1299,7 @@ class AdaptiveAvgPool2d(Cell):
880
1299
  If it is None, it means the output size is the same as the input size.
881
1300
 
882
1301
  Inputs:
883
- - **x** (Tensor) - The input of AdaptiveAvgPool2d, which is a 3D or 4D tensor,
1302
+ - **input** (Tensor) - The input of AdaptiveAvgPool2d, which is a 3D or 4D tensor,
884
1303
  with float16, float32 or float64 data type.
885
1304
 
886
1305
  Outputs:
@@ -888,9 +1307,9 @@ class AdaptiveAvgPool2d(Cell):
888
1307
 
889
1308
  Raises:
890
1309
  ValueError: If `output_size` is a tuple and the length of `output_size` is not 2.
891
- TypeError: If `x` is not a Tensor.
892
- TypeError: If dtype of `x` is not float16, float32 or float64.
893
- ValueError: If the dimension of `x` is less than or equal to the dimension of `output_size`.
1310
+ TypeError: If `input` is not a Tensor.
1311
+ TypeError: If dtype of `input` is not float16, float32 or float64.
1312
+ ValueError: If the dimension of `input` is less than or equal to the dimension of `output_size`.
894
1313
 
895
1314
  Supported Platforms:
896
1315
  ``GPU``
@@ -911,8 +1330,8 @@ class AdaptiveAvgPool2d(Cell):
911
1330
  super(AdaptiveAvgPool2d, self).__init__()
912
1331
  self.adaptive_avgpool2d = P.AdaptiveAvgPool2D(output_size)
913
1332
 
914
- def construct(self, x):
915
- return self.adaptive_avgpool2d(x)
1333
+ def construct(self, input):
1334
+ return self.adaptive_avgpool2d(input)
916
1335
 
917
1336
 
918
1337
  class AdaptiveAvgPool3d(Cell):
@@ -921,14 +1340,14 @@ class AdaptiveAvgPool3d(Cell):
921
1340
  That is, for any input size, the size of the specified output is :math:`(D, H, W)`.
922
1341
  The number of output features is equal to the number of input planes.
923
1342
 
924
- Suppose the last 3 dimension size of x is :math:`(inD, inH, inW)`, then the last 3 dimension size of output is
1343
+ Suppose the last 3 dimension size of input is :math:`(inD, inH, inW)`, then the last 3 dimension size of output is
925
1344
  :math:`(outD, outH, outW)`.
926
1345
 
927
1346
  .. math::
928
1347
  \begin{array}{ll} \\
929
1348
  \forall \quad od \in [0,outD-1], oh \in [0,outH-1], ow \in [0,outW-1]\\
930
1349
  output[od,oh,ow] = \\
931
- \qquad mean(x[istartD:iendD+1,istartH:iendH+1,istartW:iendW+1])\\
1350
+ \qquad mean(input[istartD:iendD+1,istartH:iendH+1,istartW:iendW+1])\\
932
1351
  where,\\
933
1352
  \qquad istartD= \left\lceil \frac{od * inD}{outD} \right\rceil \\
934
1353
  \qquad iendD=\left\lfloor \frac{(od+1)* inD}{outD} \right\rfloor \\
@@ -940,24 +1359,24 @@ class AdaptiveAvgPool3d(Cell):
940
1359
 
941
1360
  Args:
942
1361
  output_size (Union[int, tuple]): The target output size. `ouput_size` can be a tuple :math:`(D, H, W)`,
943
- or an int D for :math:`(D, D, D)`. :math:`(D)`, :math:`(H)` and :math:`(W)` can be int or None
1362
+ or an int D for :math:`(D, D, D)`. :math:`D`, :math:`H` and :math:`W` can be int or None
944
1363
  which means the output size is the same as that of the input.
945
1364
 
946
1365
  Inputs:
947
- - **x** (Tensor) - The input of AdaptiveAvgPool3d, which is a 5D or 4D Tensor,
1366
+ - **input** (Tensor) - The input of AdaptiveAvgPool3d, which is a 5D or 4D Tensor,
948
1367
  with float16, float32 or float64 data type.
949
1368
 
950
1369
  Outputs:
951
- Tensor, with the same type as the `x`.
1370
+ Tensor, with the same type as the `input`.
952
1371
 
953
1372
  Raises:
954
- TypeError: If `x` is not a Tensor.
955
- TypeError: If dtype of `x` is not float16, float32 or float64.
956
- ValueError: If the dimension of `x` is not 4D or 5D.
1373
+ TypeError: If `input` is not a Tensor.
1374
+ TypeError: If dtype of `input` is not float16, float32 or float64.
1375
+ ValueError: If the dimension of `input` is not 4D or 5D.
957
1376
  ValueError: If `output_size` value is not positive.
958
1377
 
959
1378
  Supported Platforms:
960
- ``GPU``
1379
+ ``Ascend`` ``GPU`` ``CPU``
961
1380
 
962
1381
  Examples:
963
1382
  >>> # case 1: output_size=(3, 3, 4)
@@ -991,8 +1410,8 @@ class AdaptiveAvgPool3d(Cell):
991
1410
  super(AdaptiveAvgPool3d, self).__init__()
992
1411
  self.adaptive_avg_pool3d = AdaptiveAvgPool3D(output_size)
993
1412
 
994
- def construct(self, x):
995
- return self.adaptive_avg_pool3d(x)
1413
+ def construct(self, input):
1414
+ return self.adaptive_avg_pool3d(input)
996
1415
 
997
1416
 
998
1417
  class AdaptiveMaxPool1d(Cell):
@@ -1043,7 +1462,7 @@ class AdaptiveMaxPool1d(Cell):
1043
1462
  def __init__(self, output_size):
1044
1463
  """Initialize AdaptiveMaxPool1d."""
1045
1464
  super(AdaptiveMaxPool1d, self).__init__()
1046
- validator.check_int(output_size, 1, Rel.GE, "output_size", self.cls_name)
1465
+ validator.check_int(output_size, 1, validator.GE, "output_size", self.cls_name)
1047
1466
  validator.check_value_type('output_size', output_size, [int], self.cls_name)
1048
1467
  self.expand = P.ExpandDims()
1049
1468
  self.squeeze = P.Squeeze(2)
@@ -1092,43 +1511,41 @@ class AdaptiveMaxPool2d(Cell):
1092
1511
  \end{align}
1093
1512
 
1094
1513
  Note:
1095
- Ascend platform only supports float16 type for input_x.
1514
+ Ascend platform only supports float16 type for input.
1096
1515
 
1097
1516
  Args:
1098
- output_size (Union[int, tuple]): The target output size is H x W.
1099
- ouput_size can be a tuple, or a single H for H x H, and H and W can be int or None
1100
- which means the output size is the same as the input.
1101
-
1517
+ output_size (Union[int, tuple]): The target output size. `ouput_size` can be a tuple :math:`(H, W)`,
1518
+ or an int H for :math:`(H, H)`. :math:`H` and :math:`W` can be int or None.
1519
+ If it is None, it means the output size is the same as the input size.
1102
1520
  return_indices (bool): If `return_indices` is True, the indices of max value would be output.
1103
1521
  Default: False.
1104
1522
 
1105
1523
  Inputs:
1106
- - **input_x** (Tensor) - The input of AdaptiveMaxPool2d, which is a 3D or 4D tensor,
1524
+ - **input** (Tensor) - The input of AdaptiveMaxPool2d, which is a 3D or 4D tensor,
1107
1525
  with float16, float32 or float64 data type.
1108
1526
 
1109
1527
  Outputs:
1110
- Tensor, with the same type as the `input_x`.
1111
-
1112
- Shape of the output is `input_x_shape[:len(input_x_shape) - len(out_shape)] + out_shape`.
1528
+ Tensor, with the same type as the `input`.
1529
+ Shape of the output is `input_shape[:len(input_shape) - len(out_shape)] + out_shape`.
1113
1530
 
1114
1531
  Raises:
1115
1532
  TypeError: If `output_size` is not int or tuple.
1116
- TypeError: If `input_x` is not a tensor.
1533
+ TypeError: If `input` is not a tensor.
1117
1534
  TypeError: If `return_indices` is not a bool.
1118
- TypeError: If dtype of `input_x` is not float16, float32 or float64.
1535
+ TypeError: If dtype of `input` is not float16, float32 or float64.
1119
1536
  ValueError: If `output_size` is a tuple and the length of `output_size` is not 2.
1120
- ValueError: If the dimension of `input_x` is not NCHW or CHW.
1537
+ ValueError: If the dimension of `input` is not NCHW or CHW.
1121
1538
 
1122
1539
  Supported Platforms:
1123
1540
  ``Ascend`` ``GPU`` ``CPU``
1124
1541
 
1125
1542
  Examples:
1126
1543
  >>> # case 1: output_size=(None, 2)
1127
- >>> input_x = Tensor(np.array([[[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
1544
+ >>> input = Tensor(np.array([[[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
1128
1545
  ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]],
1129
1546
  ... [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]]]), mindspore.float32)
1130
1547
  >>> adaptive_max_pool_2d = nn.AdaptiveMaxPool2d((None, 2))
1131
- >>> output = adaptive_max_pool_2d(input_x)
1548
+ >>> output = adaptive_max_pool_2d(input)
1132
1549
  >>> print(output)
1133
1550
  [[[[2. 3.]
1134
1551
  [5. 6.]
@@ -1141,7 +1558,7 @@ class AdaptiveMaxPool2d(Cell):
1141
1558
  [8. 9.]]]]
1142
1559
  >>> # case 2: output_size=2
1143
1560
  >>> adaptive_max_pool_2d = nn.AdaptiveMaxPool2d(2)
1144
- >>> output = adaptive_max_pool_2d(input_x)
1561
+ >>> output = adaptive_max_pool_2d(input)
1145
1562
  >>> print(output)
1146
1563
  [[[[5. 6.]
1147
1564
  [8. 9.]]
@@ -1151,7 +1568,7 @@ class AdaptiveMaxPool2d(Cell):
1151
1568
  [8. 9.]]]]
1152
1569
  >>> # case 3: output_size=(1, 2)
1153
1570
  >>> adaptive_max_pool_2d = nn.AdaptiveMaxPool2d((1, 2))
1154
- >>> output = adaptive_max_pool_2d(input_x)
1571
+ >>> output = adaptive_max_pool_2d(input)
1155
1572
  >>> print(output)
1156
1573
  [[[[8. 9.]]
1157
1574
  [[8. 9.]]
@@ -1161,51 +1578,51 @@ class AdaptiveMaxPool2d(Cell):
1161
1578
  def __init__(self, output_size, return_indices=False):
1162
1579
  """Initialize AdaptiveMaxPool2d."""
1163
1580
  super(AdaptiveMaxPool2d, self).__init__()
1164
- self.adaptive_max_pool2d = AdaptiveMaxPool2D(output_size, return_indices)
1581
+ validator.check_value_type('return_indices', return_indices, [bool], self.cls_name)
1582
+ self.adaptive_max_pool2d = AdaptiveMaxPool2D(output_size)
1583
+ self.return_indices = return_indices
1165
1584
 
1166
- def construct(self, input_x):
1167
- return self.adaptive_max_pool2d(input_x)
1585
+ def construct(self, input):
1586
+ output = self.adaptive_max_pool2d(input)
1587
+ if self.return_indices:
1588
+ return output
1589
+ return output[0]
1168
1590
 
1169
1591
 
1170
1592
  class AdaptiveMaxPool3d(Cell):
1171
1593
  r"""
1172
- Applies a 3D adaptive max pooling over an input signal composed of several input planes.
1173
-
1174
- The output is of size :math:`(D, H, W)`, for any input size.
1175
- The number of output features is equal to the number of input planes.
1594
+ Calculates the 3D adaptive max pooling for an input Tensor.
1595
+ That is, for any input size, the size of the specified output is :math:`(D, H, W)`.
1176
1596
 
1177
1597
  Args:
1178
- output_size (Union[int, tuple]): The target output size is :math:`(D, H, W)`.
1179
- `ouput_size` can be a tuple with 3 elements, or a single D for :math:`(D, D, D)`. :math:`D`,
1180
- :math:`H` and :math:`W` can be int or None which means the output size is the same as that of
1181
- the input.
1182
- return_indices (bool): If `return_indices` is True, the indices of max value would be output.
1183
- Default: False.
1598
+ output_size (Union[int, tuple]): The specified output size, which is a positive integer that represents depth,
1599
+ height and width, or a tuple of three positive integers that represent depth, height and width respectively.
1600
+ If it is None, the output size and input size of the corresponding dimension are the same.
1601
+ return_indices (bool, optional): If `return_indices` is True, the indices of max value would be output.
1602
+ Otherwise, the indices will not be returned. Default: False.
1184
1603
 
1185
1604
  Inputs:
1186
- - **x** (Tensor) - Tensor, has shape of :math:`(C, D, H, W)` or :math:`(N, C, D, H, W)` . The suppoerted dtypes
1187
- are int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32 and float64 data type.
1605
+ - **input** (Tensor) - Tensor, has shape of :math:`(C, D, H, W)` or :math:`(N, C, D, H, W)`.
1188
1606
 
1189
1607
  Outputs:
1190
- - **y** (Tensor) - Tensor, has the same number of dims and data type as the `x` .
1608
+ - **y** (Tensor) - Tensor, has the same number of dims and data type as the `input` .
1191
1609
  - **argmax** (Tensor) - Tensor, the indices of the maximum values along with the outputs, has the same shape as
1192
1610
  `y` and a dtype of int32. Return this only when `return_indices` is True.
1193
1611
 
1194
1612
  Raises:
1195
- TypeError: If `x` is not a Tensor.
1196
- ValueError: If the dimensions number of `x` is not 4 or 5.
1197
- TypeError: If dtype of `x` is not int8, int16, int32, int64, uint8, uint16, uint32, uint64,
1198
- float16, float32 or float64.
1613
+ TypeError: If `input` is not a Tensor.
1614
+ ValueError: If the dimensions number of `input` is not 4 or 5.
1615
+ TypeError: If dtype of `input` is not int, uint or float.
1199
1616
  ValueError: If `output_size` is neither an int nor a tuple with shape (3,).
1200
1617
 
1201
1618
  Supported Platforms:
1202
1619
  ``GPU`` ``CPU``
1203
1620
 
1204
1621
  Examples:
1205
- >>> x = Tensor(np.arange(0,36).reshape((1, 3, 3, 4)).astype(np.float32))
1622
+ >>> input = Tensor(np.arange(0,36).reshape((1, 3, 3, 4)).astype(np.float32))
1206
1623
  >>> output_size = (1, 1, 2)
1207
1624
  >>> net = nn.AdaptiveMaxPool3d(output_size, True)
1208
- >>> output = net(x)
1625
+ >>> output = net(input)
1209
1626
  >>> print(output[0].asnumpy())
1210
1627
  [[[[33. 35.]]]]
1211
1628
  >>> print(output[1].asnumpy())
@@ -1219,8 +1636,8 @@ class AdaptiveMaxPool3d(Cell):
1219
1636
  self.return_indices = return_indices
1220
1637
  self.adaptive_max_pool3d = AdaptiveMaxPool3D()
1221
1638
 
1222
- def construct(self, x):
1223
- output = self.adaptive_max_pool3d(x, self.output_size)
1639
+ def construct(self, input):
1640
+ output = self.adaptive_max_pool3d(input, self.output_size)
1224
1641
  if self.return_indices:
1225
1642
  return output
1226
1643
  return output[0]
@@ -1228,12 +1645,11 @@ class AdaptiveMaxPool3d(Cell):
1228
1645
 
1229
1646
  class FractionalMaxPool2d(Cell):
1230
1647
  r"""
1231
- Applies a 2D fractional max pooling to an input signal composed of multiple input planes.
1232
- The max-pooling operation is applied in kH × kW regions by a stochastic step size determined by
1233
- the target output size. For any input size, the size of the specified output is H x W. The number
1234
- of output features is equal to the number of input planes.
1648
+ Applies the 2D FractionalMaxPool operatin over input. The output Tensor shape can be determined by either
1649
+ `output_size` or `output_ratio`, and the step size is determined by `_random_samples`.
1650
+ `output_size` or `output_ratio` cannot be used or set to None at the same time.
1235
1651
 
1236
- Fractional MaxPooling is described in the paper `Fractional Max-Pooling <https://arxiv.org/pdf/1412.6071>`_.
1652
+ Refer to the paper `Fractional MaxPooling by Ben Graham <https://arxiv.org/abs/1412.6071>`_ for more details.
1237
1653
 
1238
1654
  Args:
1239
1655
  kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
@@ -1241,43 +1657,38 @@ class FractionalMaxPool2d(Cell):
1241
1657
  of two int numbers that represent height and width respectively.
1242
1658
  The value must be a positive integer.
1243
1659
  output_size (Union[int, tuple[int]], optional): The Shape of the target `output_size`,
1244
- is an int number that represents height and width, or a tuple
1245
- of two int numbers that represent height and width respectively.
1246
- The value must be a positive integer.
1247
- Default: None.
1660
+ is a positive int that represents height and width, or a tuple of two positive integers that represent
1661
+ height and width respectively. The value must be a positive integer. If None, the shape of the target will
1662
+ be determined by `output_ratio`. Default: None.
1248
1663
  output_ratio (Union[float, tuple[float]], optional): The ratio of target output shape to input shape.
1249
1664
  Specifying the size of the output tensor by using a ratio of the input size.
1250
- Data type : float16, float32, double, and value is between (0, 1).
1251
- Default: None.
1252
- return_indices (bool, optional): If `return_indices` is True, the indices of max value would be output.
1253
- Default: False.
1254
- _random_samples (Tensor, optional): The random step of FractionalMaxPool2d, which is a 3D tensor.
1255
- Tensor of data type : float16, float32, double, and value is between (0, 1).
1256
- Supported shape :math:`(N, C, 2)`.
1257
- Default: None.
1665
+ Data type : float16, float32, float64, and value is between (0, 1). If None, the shape of the target will be
1666
+ determined by `output_size`. Default: None.
1667
+ return_indices (bool, optional): Whether to return the indices of max value. Default: False.
1668
+ _random_samples (Tensor, optional): The random step of FractionalMaxPool2d, a Tensor of shape :math:`(N, C, 2)`
1669
+ whose elements are within the range of :math:`(0, 1)`. Supported data type : float16, float32, float64.
1670
+ If None, no random step will be set. Default: None.
1258
1671
 
1259
1672
  Inputs:
1260
- - **input_x** (Tensor) - Tensor of shape :math:`(N, C, H_{in}, W_{in})`,
1673
+ - **input** (Tensor) - Tensor of shape :math:`(N, C, H_{in}, W_{in})`,
1261
1674
  with float16, float32, float64, int32, int64 data type.
1262
1675
 
1263
1676
  Outputs:
1264
- - **y** (Tensor) - Has the same type as the `input_x`.
1265
- Has the shape :math:`(N, C, H, W)`.
1266
-
1677
+ - **y** (Tensor) - Has the same type as the `input`. Has the shape :math:`(N, C, H, W)`.
1267
1678
  - **argmax** (Tensor) - The indices along with the outputs, which is a Tensor, with the same shape as the
1268
- `y` and int64 data type. It will output only when `return_indices` is True.
1679
+ `y` and int64 data type. It will be returned only when `return_indices` is True.
1269
1680
 
1270
1681
  Raises:
1271
- TypeError: If data type of `input_x` is not one of the following: float16, float32, float64, int32, int64.
1682
+ TypeError: If data type of `input` is not one of the following: float16, float32, float64, int32, int64.
1272
1683
  TypeError: If data type of `_random_samples` is not one of the following: float16, float32, float64.
1273
1684
  ValueError: If `kernel_size` is not a number and `kernel_size` is not a tuple of length 2.
1274
1685
  ValueError: If `output_size` is not a number and `output_size` is not a tuple of length 2.
1275
1686
  ValueError: If the sum of `kernel_size` , `output_size` and -1 is larger than the corresponding
1276
- dimension of `input_x`.
1687
+ dimension of `input`.
1277
1688
  ValueError: If the dimension of `_random_samples` is not 3.
1278
1689
  ValueError: if `output_size` and `output_ratio` are None at the same time.
1279
- ValueError: If the first dimension size of `input_x` and `_random_samples` is not equal.
1280
- ValueError: If the second dimension size of `input_x` and `_random_samples` is not equal.
1690
+ ValueError: If the first dimension size of `input` and `_random_samples` is not equal.
1691
+ ValueError: If the second dimension size of `input` and `_random_samples` is not equal.
1281
1692
  ValueError: If the third dimension size of `_random_samples` is not 2.
1282
1693
 
1283
1694
  Supported Platforms:
@@ -1289,7 +1700,7 @@ class FractionalMaxPool2d(Cell):
1289
1700
  >>> from mindspore import nn
1290
1701
  >>> from mindspore import Tensor
1291
1702
  >>> import mindspore.common.dtype as mstype
1292
- >>> input_x = Tensor(np.array([0.3220, 0.9545, 0.7879, 0.0975, 0.3698,
1703
+ >>> input = Tensor(np.array([0.3220, 0.9545, 0.7879, 0.0975, 0.3698,
1293
1704
  ... 0.5135, 0.5740, 0.3435, 0.1895, 0.8764,
1294
1705
  ... 0.9581, 0.4760, 0.9014, 0.8522, 0.3664,
1295
1706
  ... 0.4980, 0.9673, 0.9879, 0.6988, 0.9022,
@@ -1297,7 +1708,7 @@ class FractionalMaxPool2d(Cell):
1297
1708
  >>> _random_samples = Tensor(np.array([[[0.8, 0.8]]]), mstype.float32)
1298
1709
  >>> net = nn.FractionalMaxPool2d(kernel_size=2, output_size=(2, 2), _random_samples=_random_samples,
1299
1710
  ... return_indices=True)
1300
- >>> y, argmax = net(input_x)
1711
+ >>> y, argmax = net(input)
1301
1712
  >>> y
1302
1713
  [[[[0.9545 0.8764]
1303
1714
  [0.9673 0.9852]]]]
@@ -1306,7 +1717,7 @@ class FractionalMaxPool2d(Cell):
1306
1717
  [16 24]]]]
1307
1718
  >>> net = nn.FractionalMaxPool2d(kernel_size=2, output_ratio=(0.5, 0.5), _random_samples=_random_samples,
1308
1719
  ... return_indices=True)
1309
- >>> y, argmax = net(input_x)
1720
+ >>> y, argmax = net(input)
1310
1721
  >>> print(y)
1311
1722
  [[[[0.9545 0.8764]
1312
1723
  [0.9673 0.9852]]]]
@@ -1324,16 +1735,16 @@ class FractionalMaxPool2d(Cell):
1324
1735
  self.return_indices = return_indices
1325
1736
  self._random_samples = _random_samples
1326
1737
 
1327
- def construct(self, x):
1328
- return ops.fractional_max_pool2d(x, self.kernel_size, self.output_size, self.output_ratio, self.return_indices,
1329
- self._random_samples)
1738
+ def construct(self, input):
1739
+ return ops.fractional_max_pool2d(input, self.kernel_size, self.output_size, self.output_ratio,
1740
+ self.return_indices, self._random_samples)
1330
1741
 
1331
1742
 
1332
1743
  class FractionalMaxPool3d(Cell):
1333
1744
  r"""
1334
- This operator applies a 3D fractional max pooling over an input signal composed of several input planes.
1335
- The max-pooling operation is applied in kD x kH x kW regions by a stochastic step size determined
1336
- by the target output size.The number of output features is equal to the number of input planes.
1745
+ Applies the 3D FractionalMaxPool operatin over `input`. The output Tensor shape can be determined by either
1746
+ `output_size` or `output_ratio`, and the step size is determined by `_random_samples`.
1747
+ `output_size` or `output_ratio` cannot be used or set to None at the same time.
1337
1748
 
1338
1749
  Refer to the paper `Fractional MaxPooling by Ben Graham <https://arxiv.org/abs/1412.6071>`_ for more details.
1339
1750
 
@@ -1341,28 +1752,25 @@ class FractionalMaxPool3d(Cell):
1341
1752
  D the feature depth, H is the feature height, and W is the feature width.
1342
1753
 
1343
1754
  Args:
1344
- kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value,
1345
- is an int number that represents depth, height and width of the kernel, or a tuple
1346
- of three int numbers that represent depth, height and width respectively.
1347
- The value must be a positive integer.
1348
- output_size (Union[int, tuple[int]], optional): The Shape of the target `output_size`,
1349
- is an int number that represents depth, height and width, or a tuple
1350
- of three int numbers that represent depth, height and width respectively.
1351
- The value must be a positive integer.
1352
- Default: None.
1755
+ kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value, is a positive int
1756
+ that represents depth, height and width of the kernel, or a tuple of three positive integers that represent
1757
+ depth, height and width respectively.
1758
+ output_size (Union[int, tuple[int]], optional): The shape of the target `output_size`,
1759
+ is an int number that represents depth, height and width, or a tuple of three positive integers that
1760
+ represents depth, height and width respectively. If None, the shape of the target will be determined by
1761
+ `output_ratio`. Default: None.
1353
1762
  output_ratio (Union[float, tuple[float]], optional): The ratio of target output shape to input shape.
1354
1763
  Specifying the size of the output tensor by using a ratio of the input size.
1355
- Data type : float16, float32, double, and value is between (0, 1).
1356
- Default: None.
1357
- return_indices (bool, optional): If `return_indices` is True, the indices of max value would be output.
1358
- Default: False.
1359
- _random_samples (Tensor, optional): The random step of FractionalMaxPool3d, which is a 3D tensor.
1360
- Tensor of data type : float16, float32, double, and value is between (0, 1).
1361
- Supported shape :math:`(N, C, 3)`
1764
+ Data type : float16, float32, float64, and value is between (0, 1). If None, the shape of the target will be
1765
+ determined by `output_size`.Default: None.
1766
+ return_indices (bool, optional): Whether to return the indices of max value. Default: False.
1767
+ _random_samples (Tensor, optional): The random step of FractionalMaxPool2d, a Tensor of shape :math:`(N, C, 3)`
1768
+ whose elements are within the range of :math:`(0, 1)`. Supported data type : float16, float32, float64.
1769
+ If None, no random step will be set. Default: None.
1362
1770
 
1363
1771
  Inputs:
1364
- - **input_x** (Tensor) - The input of FractionalMaxPool3d, which is a 4D or 5D tensor.
1365
- Tensor of data type : float16, float32, double, int32, int64.
1772
+ - **input** (Tensor) - The input of FractionalMaxPool3d, which is a 4D or 5D tensor.
1773
+ Tensor of data type : float16, float32, float64, int32, int64.
1366
1774
  Supported shape :math:`(N, C, D_{in}, H_{in}, W_{in})` .
1367
1775
 
1368
1776
  Outputs:
@@ -1374,17 +1782,17 @@ class FractionalMaxPool3d(Cell):
1374
1782
  `y` and int32 data type. It will output only when `return_indices` is True.
1375
1783
 
1376
1784
  Raises:
1377
- TypeError: If `input_x` is not a 4D or 5D tensor.
1785
+ TypeError: If `input` is not a 4D or 5D tensor.
1378
1786
  TypeError: If `_random_samples` is not a 3D tensor.
1379
- TypeError: If data type of `imput_x` is not float16, float32, double, int32, int64.
1380
- TypeError: If dtype of `_random_samples` is not float16, float32, double.
1787
+ TypeError: If data type of `imput_x` is not float16, float32, float64, int32, int64.
1788
+ TypeError: If dtype of `_random_samples` is not float16, float32, float64.
1381
1789
  TypeError: If dtype of `argmax` is not int32, int64.
1382
1790
  ValueError: If `output_size` is a tuple and if `output_size` length is not 3.
1383
1791
  ValueError: If `kernel_size` is a tuple and if `kernel_size` length is not 3.
1384
1792
  ValueError: If numbers in `output_size` or `kernel_size` is not positive.
1385
1793
  ValueError: if `output_size` and `output_ratio` are None at the same time.
1386
- ValueError: If the first dimension size of `input_x` and `_random_samples` is not equal.
1387
- ValueError: If the second dimension size of `input_x` and `_random_samples` is not equal.
1794
+ ValueError: If the first dimension size of `input` and `_random_samples` is not equal.
1795
+ ValueError: If the second dimension size of `input` and `_random_samples` is not equal.
1388
1796
  ValueError: If the third dimension size of `_random_samples` is not 3.
1389
1797
 
1390
1798
  Supported Platforms:
@@ -1398,14 +1806,14 @@ class FractionalMaxPool3d(Cell):
1398
1806
  >>> x = Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
1399
1807
  ... .reshape([1, 1, 2, 2, 4]), mstype.float32)
1400
1808
  >>> _random_samples = Tensor(np.array([0.7, 0.7, 0.7]).reshape([1, 1, 3]), mstype.float32)
1401
- >>> net = nn.FractionalMaxPool3d(kernel_size=(1.0, 1.0, 1.0), output_size=(1, 1, 3),
1809
+ >>> net = nn.FractionalMaxPool3d(kernel_size=(1, 1, 1), output_size=(1, 1, 3),
1402
1810
  ... _random_samples=_random_samples, return_indices=True)
1403
1811
  >>> output, argmax = net(x)
1404
1812
  >>> print(output)
1405
1813
  [[[[[13. 14. 16.]]]]]
1406
1814
  >>> print(argmax)
1407
1815
  [[[[[12 13 15]]]]]
1408
- >>> net = nn.FractionalMaxPool3d(kernel_size=(1.0, 1.0, 1.0), output_ratio=(0.5, 0.5, 0.5),
1816
+ >>> net = nn.FractionalMaxPool3d(kernel_size=(1, 1, 1), output_ratio=(0.5, 0.5, 0.5),
1409
1817
  ... _random_samples=_random_samples, return_indices=True)
1410
1818
  >>> output, argmax = net(x)
1411
1819
  >>> print(output)
@@ -1423,21 +1831,19 @@ class FractionalMaxPool3d(Cell):
1423
1831
  self.return_indices = return_indices
1424
1832
  self._random_samples = _random_samples
1425
1833
 
1426
- def construct(self, x):
1427
- return ops.fractional_max_pool3d(x, self.kernel_size, self.output_size, self.output_ratio, self.return_indices,
1428
- self._random_samples)
1834
+ def construct(self, input):
1835
+ return ops.fractional_max_pool3d(input, self.kernel_size, self.output_size, self.output_ratio,
1836
+ self.return_indices, self._random_samples)
1429
1837
 
1430
1838
 
1431
1839
  class MaxUnpool1d(Cell):
1432
1840
  r"""
1433
- Computes a partial inverse of MaxPool1d.
1841
+ Computes the inverse of :class:`mindspore.nn.MaxPool1d`.
1434
1842
 
1435
- MaxPool1d is not fully invertible, since the non-maximal values are lost.
1843
+ MaxUnpool1d keeps the maximal value and set all position of non-maximal values to zero. Typically the input
1844
+ is of shape :math:`(N, C, H_{in})` or :math:`(C, H_{in})`, and the output is of shape
1845
+ :math:`(N, C, H_{out})` or :math:`(C, H_{out})`. The operation is as follows.
1436
1846
 
1437
- MaxUnpool1d takes in as input the output of MaxPool1d including the indices of the maximal values
1438
- and computes a partial inverse in which all non-maximal values are set to zero. Typically the input
1439
- is of shape :math:`(N, C, H_{in})` or :math:`(C, H_{in})`, and the output is of shape :math:`(N, C, H_{out}`
1440
- or :math:`(C, H_{out}`. The operation is as follows.
1441
1847
 
1442
1848
  .. math::
1443
1849
  \begin{array}{ll} \\
@@ -1447,7 +1853,7 @@ class MaxUnpool1d(Cell):
1447
1853
  Args:
1448
1854
  kernel_size (Union[int, tuple[int]]): The size of kernel used to take the maximum value.
1449
1855
  stride (Union[int, tuple[int]]): The distance of kernel moving,
1450
- If stride is 0, (0) or None, then stride equal to kernel_size. Default: None.
1856
+ If stride is None, then stride equal to kernel_size. Default: None.
1451
1857
  padding (Union[int, tuple[int]]): The pad value to be filled. Default: 0.
1452
1858
 
1453
1859
  Inputs:
@@ -1459,8 +1865,8 @@ class MaxUnpool1d(Cell):
1459
1865
  Data type must be in int32 or int64.
1460
1866
  - **output_size** (tuple[int], optional) - The output size. Default: None.
1461
1867
  If output_size == (), then the shape of output computed by kernel_size, stride and padding.
1462
- If output_size != (), then output_size must be :math:`(N, C, H)` or
1463
- :math:`(C, H)` and output_size must belong to
1868
+ If output_size != (), then output_size must be :math:`(N, C, H)` , :math:`(C, H)` or
1869
+ :math:`(H)` and output_size must belong to
1464
1870
  :math:`[(N, C, H_{out} - stride[0]), (N, C, H_{out} + stride[0])]`.
1465
1871
 
1466
1872
  Outputs:
@@ -1488,11 +1894,12 @@ class MaxUnpool1d(Cell):
1488
1894
  >>> print(output.asnumpy())
1489
1895
  [[0. 2. 0. 4. 0. 6. 0. 8.]]
1490
1896
  """
1897
+
1491
1898
  def __init__(self, kernel_size, stride=None, padding=0):
1492
1899
  """Initialize MaxUnpool1d."""
1493
1900
  super(MaxUnpool1d, self).__init__()
1494
- if not stride:
1495
- stride = 0
1901
+ if stride is None:
1902
+ stride = kernel_size
1496
1903
  self.kernel_size = kernel_size
1497
1904
  self.stride = stride
1498
1905
  self.padding = padding
@@ -1510,12 +1917,9 @@ class MaxUnpool1d(Cell):
1510
1917
 
1511
1918
  class MaxUnpool2d(Cell):
1512
1919
  r"""
1513
- Computes a partial inverse of MaxPool2d.
1514
-
1515
- MaxPool2d is not fully invertible, since the non-maximal values are lost.
1920
+ Computes the inverse of :class:`mindspore.nn.MaxPool2d`.
1516
1921
 
1517
- MaxUnpool2d takes in as input the output of MaxPool2d including the indices of the maximal values
1518
- and computes a partial inverse in which all non-maximal values are set to zero. Typically the input
1922
+ MaxUnpool2d keeps the maximal value and set all position of non-maximal values to zero. Typically the input
1519
1923
  is of shape :math:`(N, C, H_{in}, W_{in})` or :math:`(C, H_{in}, W_{in})`, and the output is of
1520
1924
  shape :math:`(N, C, H_{out}, W_{out})` or :math:`(C, H_{out}, W_{out})`. The operation is as follows.
1521
1925
 
@@ -1532,7 +1936,7 @@ class MaxUnpool2d(Cell):
1532
1936
  stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
1533
1937
  the height and width of movement are both stride, or a tuple of two int numbers that
1534
1938
  represent height and width of movement respectively.
1535
- If stride is 0, (0, 0) or None, then stride equal to kernel_size. Default: None.
1939
+ If stride is None, then stride equal to kernel_size. Default: None.
1536
1940
  padding (Union[int, tuple[int]]): The pad value to be filled. Default: 0. If `padding` is an integer,
1537
1941
  the paddings of height and width are the same, equal to padding. If `padding` is a tuple of two
1538
1942
  integers, the padding of height and width equal to padding[0] and padding[1] correspondingly.
@@ -1546,9 +1950,9 @@ class MaxUnpool2d(Cell):
1546
1950
  Data type must be in int32 or int64.
1547
1951
  - **output_size** (tuple[int], optional) - The output size. Default: None.
1548
1952
  If output_size == (), then the shape of output computed by kernel_size, stride and padding.
1549
- If output_size != (), then output_size must be :math:`(N, C, H, W)` and output_size must belong to
1550
- :math:`[(N, C, H_{out} - stride[0], W_{out} - stride[1]),
1551
- (N, C, H_{out} + stride[0], W_{out} + stride[1])]`.
1953
+ If output_size != (), then output_size must be :math:`(N, C, H, W)`, :math:`(C, H, W)` or
1954
+ :math:`(H, W)` and output_size must belong to
1955
+ :math:`[(N, C, H_{out} - stride[0], W_{out} - stride[1]), (N, C, H_{out} + stride[0], W_{out} + stride[1])]`.
1552
1956
 
1553
1957
  Outputs:
1554
1958
  Tensor, with shape :math:`(N, C, H_{out}, W_{out})` or :math:`(C, H_{out}, W_{out})`,
@@ -1577,11 +1981,12 @@ class MaxUnpool2d(Cell):
1577
1981
  [[[[0. 1.]
1578
1982
  [8. 9.]]]]
1579
1983
  """
1984
+
1580
1985
  def __init__(self, kernel_size, stride=None, padding=0):
1581
1986
  """Initialize MaxUnpool2d."""
1582
1987
  super(MaxUnpool2d, self).__init__()
1583
- if not stride:
1584
- stride = 0
1988
+ if stride is None:
1989
+ stride = kernel_size
1585
1990
  self.kernel_size = kernel_size
1586
1991
  self.stride = stride
1587
1992
  self.padding = padding
@@ -1599,12 +2004,9 @@ class MaxUnpool2d(Cell):
1599
2004
 
1600
2005
  class MaxUnpool3d(Cell):
1601
2006
  r"""
1602
- Computes a partial inverse of MaxPool3d.
1603
-
1604
- MaxPool3d is not fully invertible, since the non-maximal values are lost.
2007
+ Computes the inverse of :class:`mindspore.nn.MaxPool3d`.
1605
2008
 
1606
- MaxUnpool3d takes in as input the output of MaxPool3d including the indices of the maximal
1607
- values and computes a partial inverse in which all non-maximal values are set to zero.
2009
+ MaxUnpool3d keeps the maximal value and set all position of non-maximal values to zero.
1608
2010
  Typically the input is of shape :math:`(N, C, D_{in}, H_{in}, W_{in})` or :math:`(C, D_{in}, H_{in}, W_{in})`,
1609
2011
  and the output is of shape :math:`(N, C, D_{out}, H_{out}, W_{out})` or :math:`(C, D_{out}, H_{out}, W_{out})`.
1610
2012
  The operation is as follows.
@@ -1623,7 +2025,7 @@ class MaxUnpool3d(Cell):
1623
2025
  stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents
1624
2026
  the depth, height and width of movement are both stride, or a tuple of three int numbers that
1625
2027
  represent depth, height and width of movement respectively.
1626
- If stride is 0, (0, 0, 0) or None, then stride equal to kernel_size. Default: None.
2028
+ If stride is None, then stride equal to kernel_size. Default: None.
1627
2029
  padding (Union[int, tuple[int]]): The pad value to be filled. Default: 0. If `padding` is an integer,
1628
2030
  the paddings of depth, height and width are the same, equal to padding. If `padding` is a tuple of three
1629
2031
  integers, the padding of depth, height and width equal to padding[0], padding[1] and padding[2]
@@ -1638,8 +2040,8 @@ class MaxUnpool3d(Cell):
1638
2040
  Data type must be in int32 or int64.
1639
2041
  - **output_size** (tuple[int], optional) - The output size. Default: None.
1640
2042
  If output_size == (), then the shape of output computed by kernel_size, stride and padding.
1641
- If output_size != (), then output_size must be :math:`(N, C, D, H, W)` or :math:`(C, D, H, W)` and
1642
- output_size must belong to
2043
+ If output_size != (), then output_size must be :math:`(N, C, D, H, W)` , :math:`(C, D, H, W)` or
2044
+ :math:`(D, H, W)` and output_size must belong to
1643
2045
  :math:`[(N, C, D_{out} - stride[0], H_{out} - stride[1], W_{out} - stride[2]),
1644
2046
  (N, C, D_{out} + stride[0], H_{out} + stride[1], W_{out} + stride[2])]`.
1645
2047
 
@@ -1670,10 +2072,11 @@ class MaxUnpool3d(Cell):
1670
2072
  [[[[[0. 1.]
1671
2073
  [8. 9.]]]]]
1672
2074
  """
2075
+
1673
2076
  def __init__(self, kernel_size, stride=None, padding=0):
1674
2077
  super(MaxUnpool3d, self).__init__()
1675
- if not stride:
1676
- stride = 0
2078
+ if stride is None:
2079
+ stride = kernel_size
1677
2080
  self.kernel_size = kernel_size
1678
2081
  self.stride = stride
1679
2082
  self.padding = padding