mindspore 2.2.14__cp39-cp39-manylinux1_x86_64.whl → 2.3.0rc1__cp39-cp39-manylinux1_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/__init__.py +4 -4
- mindspore/_akg/akg/composite/build_module.py +155 -11
- mindspore/_akg/akg/config/repository.json +38 -0
- mindspore/_akg/akg/ms/info_version_adapt.py +29 -0
- mindspore/_akg/akg/tvm/contrib/nvcc.py +4 -1
- mindspore/_akg/akg/utils/ascend_profilier/path_manager.py +2 -1
- mindspore/_akg/akg/utils/composite_op_helper.py +4 -2
- mindspore/_akg/akg/utils/dump_ascend_meta.py +2 -2
- mindspore/_akg/akg/utils/gen_random.py +14 -8
- mindspore/_akg/akg/utils/op_dsl.py +11 -0
- mindspore/_akg/akg/utils/tbe_codegen_utils.py +5 -5
- mindspore/_c_dataengine.cpython-39-x86_64-linux-gnu.so +0 -0
- mindspore/_c_expression.cpython-39-x86_64-linux-gnu.so +0 -0
- mindspore/_c_mindrecord.cpython-39-x86_64-linux-gnu.so +0 -0
- mindspore/_checkparam.py +58 -0
- mindspore/_extends/builtin_operations.py +2 -1
- mindspore/_extends/graph_kernel/model/graph_parallel.py +16 -6
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +3 -16
- mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +16 -4
- mindspore/_extends/parallel_compile/akg_compiler/compiler.py +1 -0
- mindspore/_extends/parallel_compile/akg_compiler/gen_custom_op_files.py +96 -0
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +2 -1
- mindspore/_extends/parallel_compile/akg_compiler/util.py +5 -2
- mindspore/_extends/parse/__init__.py +18 -14
- mindspore/_extends/parse/compile_config.py +229 -0
- mindspore/_extends/parse/parser.py +155 -59
- mindspore/_extends/parse/resources.py +40 -7
- mindspore/_extends/parse/standard_method.py +124 -204
- mindspore/_extends/remote/kernel_build_server.py +2 -0
- mindspore/_mindspore_offline_debug.cpython-39-x86_64-linux-gnu.so +0 -0
- mindspore/_profiler.py +30 -0
- mindspore/amp.py +24 -18
- mindspore/bin/cache_admin +0 -0
- mindspore/bin/cache_server +0 -0
- mindspore/boost/boost_cell_wrapper.py +1 -1
- mindspore/boost/group_loss_scale_manager.py +1 -1
- mindspore/common/__init__.py +3 -1
- mindspore/common/_jit_fallback_utils.py +2 -3
- mindspore/common/_register_for_adapter.py +7 -0
- mindspore/common/_stub_tensor.py +6 -1
- mindspore/common/_utils.py +5 -17
- mindspore/common/api.py +91 -48
- mindspore/common/auto_dynamic_shape.py +27 -14
- mindspore/common/dtype.py +5 -4
- mindspore/common/dump.py +5 -4
- mindspore/common/initializer.py +1 -1
- mindspore/common/jit_config.py +20 -11
- mindspore/common/lazy_inline.py +58 -17
- mindspore/common/mindir_util.py +12 -2
- mindspore/common/mutable.py +79 -14
- mindspore/common/parameter.py +19 -4
- mindspore/common/seed.py +9 -9
- mindspore/common/sparse_tensor.py +251 -18
- mindspore/common/symbol.py +122 -0
- mindspore/common/tensor.py +321 -433
- mindspore/communication/__init__.py +3 -3
- mindspore/communication/_comm_helper.py +5 -0
- mindspore/communication/management.py +53 -38
- mindspore/config/op_info.config +22 -54
- mindspore/context.py +167 -59
- mindspore/dataset/__init__.py +5 -5
- mindspore/dataset/audio/__init__.py +6 -6
- mindspore/dataset/audio/transforms.py +711 -158
- mindspore/dataset/callback/ds_callback.py +2 -2
- mindspore/dataset/engine/cache_client.py +2 -2
- mindspore/dataset/engine/datasets.py +72 -38
- mindspore/dataset/engine/datasets_audio.py +14 -14
- mindspore/dataset/engine/datasets_standard_format.py +33 -3
- mindspore/dataset/engine/datasets_text.py +38 -38
- mindspore/dataset/engine/datasets_user_defined.py +7 -7
- mindspore/dataset/engine/datasets_vision.py +75 -71
- mindspore/dataset/engine/offload.py +5 -7
- mindspore/dataset/text/__init__.py +3 -3
- mindspore/dataset/text/transforms.py +408 -121
- mindspore/dataset/text/utils.py +9 -9
- mindspore/dataset/transforms/__init__.py +1 -1
- mindspore/dataset/transforms/transforms.py +261 -76
- mindspore/dataset/utils/browse_dataset.py +9 -9
- mindspore/dataset/vision/__init__.py +3 -3
- mindspore/dataset/vision/c_transforms.py +5 -5
- mindspore/dataset/vision/transforms.py +2264 -514
- mindspore/dataset/vision/utils.py +40 -9
- mindspore/dataset/vision/validators.py +7 -1
- mindspore/experimental/optim/__init__.py +12 -2
- mindspore/experimental/optim/adadelta.py +161 -0
- mindspore/experimental/optim/adagrad.py +168 -0
- mindspore/experimental/optim/adam.py +35 -34
- mindspore/experimental/optim/adamax.py +170 -0
- mindspore/experimental/optim/adamw.py +40 -16
- mindspore/experimental/optim/asgd.py +153 -0
- mindspore/experimental/optim/lr_scheduler.py +60 -119
- mindspore/experimental/optim/nadam.py +157 -0
- mindspore/experimental/optim/optimizer.py +15 -8
- mindspore/experimental/optim/radam.py +194 -0
- mindspore/experimental/optim/rmsprop.py +154 -0
- mindspore/experimental/optim/rprop.py +164 -0
- mindspore/experimental/optim/sgd.py +28 -19
- mindspore/hal/__init__.py +34 -0
- mindspore/hal/_ascend.py +57 -0
- mindspore/hal/_base.py +57 -0
- mindspore/hal/_cpu.py +56 -0
- mindspore/hal/_gpu.py +57 -0
- mindspore/hal/device.py +356 -0
- mindspore/hal/event.py +179 -0
- mindspore/hal/stream.py +337 -0
- mindspore/include/api/data_type.h +2 -2
- mindspore/include/api/dual_abi_helper.h +16 -3
- mindspore/include/api/model.h +1 -3
- mindspore/include/api/status.h +14 -0
- mindspore/include/c_api/model_c.h +173 -0
- mindspore/include/c_api/ms/base/types.h +1 -0
- mindspore/include/c_api/types_c.h +19 -0
- mindspore/include/dataset/execute.h +1 -3
- mindspore/include/mindapi/base/format.h +125 -23
- mindspore/include/mindapi/base/types.h +7 -0
- mindspore/lib/libdnnl.so.2 +0 -0
- mindspore/lib/libmindspore.so +0 -0
- mindspore/lib/libmindspore_backend.so +0 -0
- mindspore/lib/libmindspore_common.so +0 -0
- mindspore/lib/libmindspore_core.so +0 -0
- mindspore/lib/libmindspore_glog.so.0 +0 -0
- mindspore/lib/libmindspore_gpr.so.15 +0 -0
- mindspore/lib/libmindspore_grpc++.so.1 +0 -0
- mindspore/lib/libmindspore_grpc.so.15 +0 -0
- mindspore/lib/libmindspore_shared_lib.so +0 -0
- mindspore/lib/libmpi_adapter.so +0 -0
- mindspore/lib/libmpi_collective.so +0 -0
- mindspore/lib/libnnacl.so +0 -0
- mindspore/lib/libopencv_core.so.4.5 +0 -0
- mindspore/lib/libopencv_imgcodecs.so.4.5 +0 -0
- mindspore/lib/libopencv_imgproc.so.4.5 +0 -0
- mindspore/lib/libps_cache.so +0 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json +2044 -154
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/config/ascend910b/aic-ascend910b-ops-info.json +2044 -33
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/build_tbe_kernel.py +529 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/compiler.py +56 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/custom.py +1109 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/get_file_path.py +36 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/kv_cache_mgr.py +0 -2
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/ai_core/tbe/custom_aicore_ops_impl/tbe_topi.py +556 -0
- mindspore/lib/plugin/ascend/custom_aicore_ops/op_impl/vector_core/tbe/custom_aicore_ops_impl/kv_cache_mgr.py +0 -2
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_cpu_kernels.so +0 -0
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/config/cust_aicpu_kernel.json +6325 -1767
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_proto/libcust_op_proto.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_add_custom.h +49 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_decoder_kv_cache.h +59 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/include/aclnn_prompt_kv_cache.h +59 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_api/lib/libcust_opapi.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend310p/aic-ascend310p-ops-info.json +52 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json +232 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/config/ascend910b/aic-ascend910b-ops-info.json +232 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.cpp +81 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/add_custom.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/decoder_kv_cache.cpp +192 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/decoder_kv_cache.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/prompt_kv_cache.cpp +274 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/custom_ascendc_ops_impl/dynamic/prompt_kv_cache.py +134 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/lib/linux/x86_64/libcust_opmaster_rt2.0.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_impl/ai_core/tbe/op_tiling/liboptiling.so +0 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/inc/op_proto.h +39 -0
- mindspore/lib/plugin/ascend/custom_ascendc_ops/op_proto/lib/linux/x86_64/libcust_opsproto_rt2.0.so +0 -0
- mindspore/lib/plugin/ascend/libakg.so +0 -0
- mindspore/lib/plugin/ascend/libascend_collective.so +0 -0
- mindspore/lib/plugin/ascend/libdvpp_utils.so +0 -0
- mindspore/lib/plugin/ascend/libhccl_plugin.so +0 -0
- mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
- mindspore/lib/plugin/cpu/libakg.so +0 -0
- mindspore/lib/plugin/gpu/libcuda_ops.so.10 +0 -0
- mindspore/lib/plugin/gpu/libcuda_ops.so.11 +0 -0
- mindspore/lib/plugin/gpu10.1/libakg.so +0 -0
- mindspore/lib/plugin/gpu10.1/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu10.1/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/gpu11.1/libakg.so +0 -0
- mindspore/lib/plugin/gpu11.1/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu11.1/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/gpu11.6/libakg.so +0 -0
- mindspore/lib/plugin/gpu11.6/libnccl.so.2 +0 -0
- mindspore/lib/plugin/gpu11.6/libnvidia_collective.so +0 -0
- mindspore/lib/plugin/{libmindspore_ascend.so.1 → libmindspore_ascend.so.2} +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.10.1 +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.11.1 +0 -0
- mindspore/lib/plugin/libmindspore_gpu.so.11.6 +0 -0
- mindspore/mindrecord/__init__.py +5 -1
- mindspore/mindrecord/config.py +809 -0
- mindspore/mindrecord/filereader.py +25 -0
- mindspore/mindrecord/filewriter.py +74 -56
- mindspore/mindrecord/mindpage.py +40 -6
- mindspore/mindrecord/shardutils.py +3 -2
- mindspore/mindrecord/shardwriter.py +7 -0
- mindspore/mindrecord/tools/cifar100_to_mr.py +8 -13
- mindspore/mindrecord/tools/cifar10_to_mr.py +9 -15
- mindspore/mindrecord/tools/csv_to_mr.py +4 -9
- mindspore/mindrecord/tools/imagenet_to_mr.py +3 -8
- mindspore/mindrecord/tools/mnist_to_mr.py +7 -12
- mindspore/mindrecord/tools/tfrecord_to_mr.py +1 -6
- mindspore/multiprocessing/__init__.py +68 -0
- mindspore/nn/cell.py +86 -133
- mindspore/nn/dynamic_lr.py +2 -2
- mindspore/nn/layer/activation.py +79 -90
- mindspore/nn/layer/basic.py +4 -80
- mindspore/nn/layer/channel_shuffle.py +3 -16
- mindspore/nn/layer/container.py +3 -3
- mindspore/nn/layer/conv.py +71 -71
- mindspore/nn/layer/embedding.py +105 -44
- mindspore/nn/layer/image.py +4 -7
- mindspore/nn/layer/normalization.py +46 -38
- mindspore/nn/layer/padding.py +26 -39
- mindspore/nn/layer/pooling.py +13 -9
- mindspore/nn/layer/rnn_cells.py +5 -15
- mindspore/nn/layer/rnns.py +6 -5
- mindspore/nn/layer/thor_layer.py +1 -2
- mindspore/nn/layer/timedistributed.py +1 -1
- mindspore/nn/layer/transformer.py +52 -50
- mindspore/nn/learning_rate_schedule.py +6 -5
- mindspore/nn/loss/loss.py +43 -64
- mindspore/nn/optim/ada_grad.py +4 -2
- mindspore/nn/optim/adadelta.py +3 -1
- mindspore/nn/optim/adafactor.py +1 -1
- mindspore/nn/optim/adam.py +102 -181
- mindspore/nn/optim/adamax.py +4 -2
- mindspore/nn/optim/adasum.py +2 -2
- mindspore/nn/optim/asgd.py +4 -2
- mindspore/nn/optim/ftrl.py +31 -61
- mindspore/nn/optim/lamb.py +5 -3
- mindspore/nn/optim/lars.py +2 -2
- mindspore/nn/optim/lazyadam.py +6 -4
- mindspore/nn/optim/momentum.py +13 -25
- mindspore/nn/optim/optimizer.py +6 -3
- mindspore/nn/optim/proximal_ada_grad.py +4 -2
- mindspore/nn/optim/rmsprop.py +9 -3
- mindspore/nn/optim/rprop.py +4 -2
- mindspore/nn/optim/sgd.py +6 -5
- mindspore/nn/optim/thor.py +2 -2
- mindspore/nn/probability/distribution/_utils/custom_ops.py +2 -2
- mindspore/nn/probability/distribution/beta.py +2 -2
- mindspore/nn/probability/distribution/categorical.py +4 -6
- mindspore/nn/probability/distribution/cauchy.py +2 -2
- mindspore/nn/probability/distribution/exponential.py +1 -1
- mindspore/nn/probability/distribution/gumbel.py +2 -2
- mindspore/nn/probability/distribution/poisson.py +2 -2
- mindspore/nn/probability/distribution/uniform.py +2 -2
- mindspore/nn/reinforcement/_tensors_queue.py +13 -1
- mindspore/nn/wrap/__init__.py +2 -1
- mindspore/nn/wrap/cell_wrapper.py +33 -12
- mindspore/nn/wrap/grad_reducer.py +148 -8
- mindspore/nn/wrap/loss_scale.py +7 -7
- mindspore/numpy/__init__.py +2 -0
- mindspore/numpy/array_creations.py +2 -0
- mindspore/numpy/array_ops.py +1 -5
- mindspore/numpy/fft.py +431 -0
- mindspore/numpy/math_ops.py +54 -60
- mindspore/numpy/utils.py +3 -0
- mindspore/ops/__init__.py +5 -4
- mindspore/ops/_grad_experimental/grad_array_ops.py +4 -129
- mindspore/ops/_grad_experimental/grad_comm_ops.py +16 -22
- mindspore/ops/_grad_experimental/grad_math_ops.py +68 -283
- mindspore/ops/_grad_experimental/grad_nn_ops.py +0 -53
- mindspore/ops/_grad_experimental/grad_quant_ops.py +3 -3
- mindspore/ops/_grad_experimental/grad_sparse.py +1 -1
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +3 -3
- mindspore/ops/_op_impl/__init__.py +0 -1
- mindspore/ops/_op_impl/aicpu/gamma.py +2 -0
- mindspore/ops/_op_impl/aicpu/generate_eod_mask.py +1 -1
- mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +1 -3
- mindspore/ops/_op_impl/aicpu/poisson.py +2 -0
- mindspore/ops/_op_impl/cpu/__init__.py +1 -3
- mindspore/ops/_op_impl/cpu/adam.py +2 -2
- mindspore/ops/_op_impl/cpu/adam_weight_decay.py +3 -2
- mindspore/ops/_op_impl/cpu/maximum_grad.py +16 -14
- mindspore/ops/_op_impl/cpu/minimum_grad.py +8 -0
- mindspore/ops/_vmap/vmap_array_ops.py +137 -101
- mindspore/ops/_vmap/vmap_base.py +8 -1
- mindspore/ops/_vmap/vmap_grad_math_ops.py +95 -9
- mindspore/ops/_vmap/vmap_grad_nn_ops.py +102 -56
- mindspore/ops/_vmap/vmap_image_ops.py +70 -13
- mindspore/ops/_vmap/vmap_math_ops.py +74 -49
- mindspore/ops/_vmap/vmap_nn_ops.py +164 -89
- mindspore/ops/_vmap/vmap_other_ops.py +1 -1
- mindspore/ops/auto_generate/__init__.py +31 -0
- mindspore/ops/auto_generate/cpp_create_prim_instance_helper.py +133 -0
- mindspore/ops/auto_generate/gen_arg_dtype_cast.py +248 -0
- mindspore/ops/auto_generate/gen_arg_handler.py +147 -0
- mindspore/ops/auto_generate/gen_extend_func.py +130 -0
- mindspore/ops/auto_generate/gen_ops_def.py +4786 -0
- mindspore/ops/auto_generate/gen_ops_prim.py +8335 -0
- mindspore/ops/auto_generate/pyboost_inner_prim.py +77 -0
- mindspore/ops/composite/__init__.py +5 -2
- mindspore/ops/composite/base.py +118 -17
- mindspore/ops/composite/math_ops.py +9 -48
- mindspore/ops/composite/multitype_ops/_compile_utils.py +166 -601
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +15 -133
- mindspore/ops/composite/multitype_ops/add_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_and_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_or_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/bitwise_xor_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/div_impl.py +8 -0
- mindspore/ops/composite/multitype_ops/equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/floordiv_impl.py +8 -0
- mindspore/ops/composite/multitype_ops/getitem_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/greater_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/greater_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/in_impl.py +8 -2
- mindspore/ops/composite/multitype_ops/left_shift_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/less_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/less_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logic_not_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logical_and_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/logical_or_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/mod_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/mul_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/negative_impl.py +9 -3
- mindspore/ops/composite/multitype_ops/not_equal_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/not_in_impl.py +6 -1
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +2 -2
- mindspore/ops/composite/multitype_ops/pow_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/right_shift_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +32 -21
- mindspore/ops/composite/multitype_ops/sub_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +6 -3
- mindspore/ops/deprecated.py +14 -3
- mindspore/ops/extend/__init__.py +46 -0
- mindspore/ops/extend/array_func.py +152 -0
- mindspore/ops/extend/math_func.py +76 -0
- mindspore/ops/{_op_impl/tbe/atomic_addr_clean.py → extend/nn_func.py} +5 -15
- mindspore/ops/function/__init__.py +19 -11
- mindspore/ops/function/array_func.py +251 -1440
- mindspore/ops/function/clip_func.py +12 -13
- mindspore/ops/function/debug_func.py +1 -4
- mindspore/ops/function/fft_func.py +31 -0
- mindspore/ops/function/grad/grad_func.py +24 -17
- mindspore/ops/function/image_func.py +27 -21
- mindspore/ops/function/linalg_func.py +35 -68
- mindspore/ops/function/math_func.py +451 -2360
- mindspore/ops/function/nn_func.py +459 -780
- mindspore/ops/function/other_func.py +4 -5
- mindspore/ops/function/parameter_func.py +5 -93
- mindspore/ops/function/random_func.py +24 -80
- mindspore/ops/function/sparse_unary_func.py +9 -16
- mindspore/ops/function/spectral_func.py +1 -1
- mindspore/ops/function/vmap_func.py +14 -14
- mindspore/ops/functional.py +56 -62
- mindspore/ops/op_info_register.py +22 -19
- mindspore/ops/operations/__init__.py +19 -19
- mindspore/ops/operations/_grad_ops.py +20 -723
- mindspore/ops/operations/_inner_ops.py +178 -286
- mindspore/ops/operations/_scalar_ops.py +5 -480
- mindspore/ops/operations/_sequence_ops.py +4 -34
- mindspore/ops/operations/array_ops.py +99 -2491
- mindspore/ops/operations/comm_ops.py +38 -46
- mindspore/ops/operations/custom_ops.py +8 -8
- mindspore/ops/operations/debug_ops.py +100 -31
- mindspore/ops/operations/image_ops.py +1 -217
- mindspore/ops/operations/inner_ops.py +3 -38
- mindspore/ops/operations/linalg_ops.py +1 -49
- mindspore/{rewrite/ast_transformers → ops/operations/manually_defined}/__init__.py +11 -4
- mindspore/ops/operations/manually_defined/_inner.py +61 -0
- mindspore/ops/operations/manually_defined/ops_def.py +1391 -0
- mindspore/ops/operations/math_ops.py +703 -4601
- mindspore/ops/operations/nn_ops.py +374 -1748
- mindspore/ops/operations/other_ops.py +50 -42
- mindspore/ops/operations/random_ops.py +3 -52
- mindspore/ops/primitive.py +196 -96
- mindspore/ops_generate/__init__.py +27 -0
- mindspore/ops_generate/arg_dtype_cast.py +248 -0
- mindspore/ops_generate/arg_handler.py +147 -0
- mindspore/ops_generate/gen_aclnn_implement.py +266 -0
- mindspore/ops_generate/gen_ops.py +1062 -0
- mindspore/ops_generate/gen_ops_inner_prim.py +129 -0
- mindspore/ops_generate/gen_pyboost_func.py +932 -0
- mindspore/ops_generate/gen_utils.py +188 -0
- mindspore/ops_generate/op_proto.py +138 -0
- mindspore/ops_generate/pyboost_utils.py +364 -0
- mindspore/ops_generate/template.py +238 -0
- mindspore/parallel/__init__.py +5 -4
- mindspore/parallel/_auto_parallel_context.py +21 -76
- mindspore/parallel/_cell_wrapper.py +16 -9
- mindspore/parallel/_cost_model_context.py +1 -1
- mindspore/parallel/_dp_allreduce_fusion.py +159 -159
- mindspore/parallel/_parallel_serialization.py +30 -46
- mindspore/parallel/_ps_context.py +1 -1
- mindspore/parallel/_recovery_context.py +1 -1
- mindspore/parallel/_tensor.py +19 -7
- mindspore/parallel/_transformer/__init__.py +1 -1
- mindspore/parallel/_transformer/layers.py +1 -1
- mindspore/parallel/_transformer/loss.py +1 -1
- mindspore/parallel/_transformer/moe.py +1 -1
- mindspore/parallel/_transformer/op_parallel_config.py +1 -1
- mindspore/parallel/_transformer/transformer.py +1 -1
- mindspore/parallel/_utils.py +131 -6
- mindspore/parallel/algo_parameter_config.py +6 -6
- mindspore/parallel/checkpoint_transform.py +180 -196
- mindspore/parallel/cluster/__init__.py +15 -0
- mindspore/parallel/cluster/process_entity/__init__.py +18 -0
- mindspore/parallel/cluster/process_entity/_api.py +345 -0
- mindspore/parallel/cluster/process_entity/_utils.py +116 -0
- mindspore/parallel/cluster/run.py +139 -0
- mindspore/parallel/mpi/__init__.py +1 -1
- mindspore/parallel/mpi/_mpi_config.py +1 -1
- mindspore/parallel/parameter_broadcast.py +152 -0
- mindspore/parallel/shard.py +99 -2
- mindspore/profiler/common/util.py +20 -0
- mindspore/profiler/envprofiling.py +1 -1
- mindspore/{_extends/parallel_compile/tbe_compiler → profiler/parser/ascend_analysis}/__init__.py +1 -1
- mindspore/profiler/parser/ascend_analysis/constant.py +66 -0
- mindspore/profiler/parser/ascend_analysis/file_manager.py +77 -0
- mindspore/profiler/parser/ascend_analysis/function_event.py +146 -0
- mindspore/profiler/parser/ascend_analysis/fwk_cann_parser.py +108 -0
- mindspore/profiler/parser/ascend_analysis/fwk_file_parser.py +80 -0
- mindspore/profiler/parser/ascend_analysis/msprof_timeline_parser.py +52 -0
- mindspore/profiler/parser/ascend_analysis/profiler_info_parser.py +104 -0
- mindspore/profiler/parser/ascend_analysis/tlv_decoder.py +86 -0
- mindspore/profiler/parser/ascend_analysis/trace_event_manager.py +59 -0
- mindspore/profiler/parser/ascend_cluster_generator.py +14 -9
- mindspore/profiler/parser/ascend_communicate_generator.py +0 -1
- mindspore/profiler/parser/ascend_flops_generator.py +20 -4
- mindspore/profiler/parser/ascend_hccl_generator.py +25 -277
- mindspore/profiler/parser/ascend_msprof_exporter.py +112 -132
- mindspore/profiler/parser/ascend_msprof_generator.py +68 -285
- mindspore/profiler/parser/ascend_op_generator.py +75 -42
- mindspore/profiler/parser/ascend_timeline_generator.py +293 -135
- mindspore/profiler/parser/base_timeline_generator.py +6 -0
- mindspore/profiler/parser/framework_parser.py +3 -2
- mindspore/profiler/parser/integrator.py +3 -1
- mindspore/profiler/parser/msadvisor_analyzer.py +1 -1
- mindspore/profiler/parser/msadvisor_parser.py +1 -1
- mindspore/profiler/parser/profiler_info.py +5 -0
- mindspore/profiler/profiling.py +296 -166
- mindspore/rewrite/__init__.py +2 -13
- mindspore/rewrite/api/node.py +121 -35
- mindspore/rewrite/api/pattern_engine.py +2 -3
- mindspore/rewrite/api/scoped_value.py +16 -15
- mindspore/rewrite/api/symbol_tree.py +45 -29
- mindspore/rewrite/ast_helpers/__init__.py +3 -6
- mindspore/rewrite/ast_helpers/ast_converter.py +143 -0
- mindspore/rewrite/ast_helpers/ast_finder.py +48 -0
- mindspore/rewrite/ast_helpers/ast_flattener.py +268 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +160 -92
- mindspore/rewrite/common/__init__.py +1 -2
- mindspore/rewrite/common/config.py +24 -0
- mindspore/rewrite/common/{rewrite_elog.py → error_log.py} +39 -39
- mindspore/rewrite/{namer.py → common/namer.py} +63 -18
- mindspore/rewrite/common/namespace.py +118 -0
- mindspore/rewrite/node/__init__.py +5 -5
- mindspore/rewrite/node/call_function.py +23 -7
- mindspore/rewrite/node/cell_container.py +7 -3
- mindspore/rewrite/node/control_flow.py +53 -28
- mindspore/rewrite/node/node.py +212 -196
- mindspore/rewrite/node/node_manager.py +51 -22
- mindspore/rewrite/node/node_topological_manager.py +3 -23
- mindspore/rewrite/parsers/__init__.py +12 -0
- mindspore/rewrite/parsers/arguments_parser.py +8 -9
- mindspore/rewrite/parsers/assign_parser.py +635 -413
- mindspore/rewrite/parsers/attribute_parser.py +3 -4
- mindspore/rewrite/parsers/class_def_parser.py +107 -144
- mindspore/rewrite/parsers/constant_parser.py +5 -5
- mindspore/rewrite/parsers/container_parser.py +4 -6
- mindspore/rewrite/parsers/expr_parser.py +55 -0
- mindspore/rewrite/parsers/for_parser.py +31 -98
- mindspore/rewrite/parsers/function_def_parser.py +13 -5
- mindspore/rewrite/parsers/if_parser.py +28 -10
- mindspore/rewrite/parsers/module_parser.py +8 -182
- mindspore/rewrite/parsers/parser.py +1 -5
- mindspore/rewrite/parsers/parser_register.py +1 -1
- mindspore/rewrite/parsers/return_parser.py +5 -10
- mindspore/rewrite/parsers/while_parser.py +59 -0
- mindspore/rewrite/sparsify/utils.py +1 -1
- mindspore/rewrite/symbol_tree/__init__.py +20 -0
- mindspore/rewrite/{symbol_tree.py → symbol_tree/symbol_tree.py} +704 -185
- mindspore/rewrite/{symbol_tree_builder.py → symbol_tree/symbol_tree_builder.py} +8 -8
- mindspore/rewrite/{symbol_tree_dumper.py → symbol_tree/symbol_tree_dumper.py} +4 -4
- mindspore/run_check/_check_version.py +6 -14
- mindspore/run_check/run_check.py +1 -1
- mindspore/safeguard/rewrite_obfuscation.py +9 -19
- mindspore/scipy/__init__.py +2 -1
- mindspore/scipy/fft.py +133 -0
- mindspore/scipy/linalg.py +140 -55
- mindspore/scipy/ops.py +15 -71
- mindspore/scipy/ops_grad.py +5 -34
- mindspore/scipy/optimize/line_search.py +2 -2
- mindspore/scipy/optimize/minimize.py +1 -1
- mindspore/train/__init__.py +3 -2
- mindspore/train/_utils.py +178 -4
- mindspore/train/amp.py +167 -245
- mindspore/train/callback/_backup_and_restore.py +4 -4
- mindspore/train/callback/_callback.py +4 -4
- mindspore/train/callback/_checkpoint.py +39 -13
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_landscape.py +14 -8
- mindspore/train/callback/_loss_monitor.py +2 -2
- mindspore/train/callback/_on_request_exit.py +2 -2
- mindspore/train/callback/_reduce_lr_on_plateau.py +2 -2
- mindspore/train/callback/_summary_collector.py +7 -7
- mindspore/train/callback/_time_monitor.py +2 -2
- mindspore/train/data_sink.py +1 -1
- mindspore/train/dataset_helper.py +13 -4
- mindspore/train/loss_scale_manager.py +2 -2
- mindspore/train/metrics/accuracy.py +7 -7
- mindspore/train/metrics/confusion_matrix.py +8 -6
- mindspore/train/metrics/cosine_similarity.py +6 -4
- mindspore/train/metrics/error.py +2 -2
- mindspore/train/metrics/metric.py +3 -3
- mindspore/train/metrics/perplexity.py +2 -1
- mindspore/train/metrics/topk.py +2 -2
- mindspore/train/mind_ir_pb2.py +75 -6
- mindspore/train/model.py +24 -22
- mindspore/train/serialization.py +256 -132
- mindspore/train/summary/summary_record.py +51 -28
- mindspore/train/train_thor/convert_utils.py +3 -3
- mindspore/version.py +1 -1
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc1.dist-info}/METADATA +2 -2
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc1.dist-info}/RECORD +515 -1061
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc1.dist-info}/entry_points.txt +1 -0
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +0 -662
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +0 -377
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job.py +0 -201
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +0 -515
- mindspore/config/super_bar_config.json +0 -544
- mindspore/gen_ops.py +0 -273
- mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_aicpu_kernels.so +0 -0
- mindspore/lib/plugin/ascend/libmindspore_aicpu_kernels.so +0 -0
- mindspore/nn/layer/flash_attention.py +0 -189
- mindspore/ops/_op_impl/cpu/concat.py +0 -39
- mindspore/ops/_op_impl/cpu/tensor_shape.py +0 -42
- mindspore/ops/_op_impl/tbe/__init__.py +0 -47
- mindspore/ops/_op_impl/tbe/abs.py +0 -38
- mindspore/ops/_op_impl/tbe/abs_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/abs_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/abs_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/accumulate_n_v2.py +0 -41
- mindspore/ops/_op_impl/tbe/accumulate_n_v2_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/acos.py +0 -37
- mindspore/ops/_op_impl/tbe/acos_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/acos_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/acos_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/acosh.py +0 -37
- mindspore/ops/_op_impl/tbe/acosh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/acosh_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/acosh_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/act_ulq_clamp_max_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/act_ulq_clamp_min_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/acts_ulq.py +0 -45
- mindspore/ops/_op_impl/tbe/acts_ulq_input_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/adam_apply_one.py +0 -50
- mindspore/ops/_op_impl/tbe/adam_apply_one_assign.py +0 -53
- mindspore/ops/_op_impl/tbe/adam_apply_one_ds.py +0 -51
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay.py +0 -54
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_assign.py +0 -54
- mindspore/ops/_op_impl/tbe/adam_apply_one_with_decay_ds.py +0 -55
- mindspore/ops/_op_impl/tbe/adaptive_max_pool2d.py +0 -37
- mindspore/ops/_op_impl/tbe/add.py +0 -42
- mindspore/ops/_op_impl/tbe/add_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/add_n.py +0 -39
- mindspore/ops/_op_impl/tbe/add_n_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/addcdiv.py +0 -41
- mindspore/ops/_op_impl/tbe/addcdiv_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/addcmul.py +0 -43
- mindspore/ops/_op_impl/tbe/addcmul_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/apply_ada_max.py +0 -68
- mindspore/ops/_op_impl/tbe/apply_ada_max_ds.py +0 -69
- mindspore/ops/_op_impl/tbe/apply_adadelta.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_adadelta_ds.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_adagrad.py +0 -55
- mindspore/ops/_op_impl/tbe/apply_adagrad_d_a.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_adagrad_ds.py +0 -56
- mindspore/ops/_op_impl/tbe/apply_adagrad_v2.py +0 -48
- mindspore/ops/_op_impl/tbe/apply_adagrad_v2_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/apply_adam.py +0 -79
- mindspore/ops/_op_impl/tbe/apply_adam_ds.py +0 -80
- mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad.py +0 -60
- mindspore/ops/_op_impl/tbe/apply_adam_with_amsgrad_ds.py +0 -61
- mindspore/ops/_op_impl/tbe/apply_add_sign.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_add_sign_ds.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_centered_rms_prop.py +0 -77
- mindspore/ops/_op_impl/tbe/apply_centered_rms_prop_ds.py +0 -78
- mindspore/ops/_op_impl/tbe/apply_ftrl.py +0 -67
- mindspore/ops/_op_impl/tbe/apply_ftrl_ds.py +0 -68
- mindspore/ops/_op_impl/tbe/apply_gradient_descent.py +0 -44
- mindspore/ops/_op_impl/tbe/apply_gradient_descent_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/apply_keras_momentum.py +0 -49
- mindspore/ops/_op_impl/tbe/apply_momentum.py +0 -64
- mindspore/ops/_op_impl/tbe/apply_momentum_ds.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_power_sign.py +0 -65
- mindspore/ops/_op_impl/tbe/apply_power_sign_ds.py +0 -66
- mindspore/ops/_op_impl/tbe/apply_proximal_adagrad.py +0 -57
- mindspore/ops/_op_impl/tbe/apply_proximal_adagrad_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent.py +0 -54
- mindspore/ops/_op_impl/tbe/apply_proximal_gradient_descent_ds.py +0 -55
- mindspore/ops/_op_impl/tbe/apply_rms_prop.py +0 -52
- mindspore/ops/_op_impl/tbe/approximate_equal.py +0 -39
- mindspore/ops/_op_impl/tbe/approximate_equal_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/arg_max.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_max_with_value.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_max_with_value_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/arg_min.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_min_v2_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/arg_min_with_value.py +0 -38
- mindspore/ops/_op_impl/tbe/arg_min_with_value_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/asin.py +0 -37
- mindspore/ops/_op_impl/tbe/asin_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/asin_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/asin_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/asinh.py +0 -37
- mindspore/ops/_op_impl/tbe/asinh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/asinh_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/asinh_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/assign.py +0 -79
- mindspore/ops/_op_impl/tbe/assign_add.py +0 -59
- mindspore/ops/_op_impl/tbe/assign_add_ds.py +0 -60
- mindspore/ops/_op_impl/tbe/assign_ds.py +0 -80
- mindspore/ops/_op_impl/tbe/assign_sub.py +0 -55
- mindspore/ops/_op_impl/tbe/assign_sub_ds.py +0 -56
- mindspore/ops/_op_impl/tbe/atan.py +0 -37
- mindspore/ops/_op_impl/tbe/atan2.py +0 -38
- mindspore/ops/_op_impl/tbe/atan2_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/atan_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/atan_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/atan_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/atanh.py +0 -37
- mindspore/ops/_op_impl/tbe/atanh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/avg_pool.py +0 -43
- mindspore/ops/_op_impl/tbe/avg_pool_3d.py +0 -44
- mindspore/ops/_op_impl/tbe/avg_pool_3d_grad.py +0 -45
- mindspore/ops/_op_impl/tbe/avg_pool_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/avg_pool_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/avg_pool_grad_vm.py +0 -42
- mindspore/ops/_op_impl/tbe/basic_lstm_cell.py +0 -57
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad.py +0 -50
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_c_state_grad_v2.py +0 -51
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_input_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/basic_lstm_cell_weight_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/batch_matmul.py +0 -42
- mindspore/ops/_op_impl/tbe/batch_matmul_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/batch_matmul_v2.py +0 -47
- mindspore/ops/_op_impl/tbe/batch_to_space.py +0 -38
- mindspore/ops/_op_impl/tbe/batch_to_space_nd.py +0 -38
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/batch_to_space_nd_v2.py +0 -41
- mindspore/ops/_op_impl/tbe/batchnorm.py +0 -58
- mindspore/ops/_op_impl/tbe/batchnorm_grad.py +0 -58
- mindspore/ops/_op_impl/tbe/bce_with_logits_loss.py +0 -42
- mindspore/ops/_op_impl/tbe/bessel_i0e.py +0 -37
- mindspore/ops/_op_impl/tbe/bessel_i0e_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/bessel_i1e.py +0 -37
- mindspore/ops/_op_impl/tbe/bessel_i1e_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/bias_add.py +0 -38
- mindspore/ops/_op_impl/tbe/bias_add_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/bias_add_grad.py +0 -53
- mindspore/ops/_op_impl/tbe/binary_cross_entropy.py +0 -39
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/binary_cross_entropy_grad_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bitwise_and.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_and_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bitwise_or.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_or_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bitwise_xor.py +0 -39
- mindspore/ops/_op_impl/tbe/bitwise_xor_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bn_infer.py +0 -43
- mindspore/ops/_op_impl/tbe/bn_infer_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bn_infer_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/bn_infer_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/bn_inference.py +0 -50
- mindspore/ops/_op_impl/tbe/bn_training_reduce.py +0 -38
- mindspore/ops/_op_impl/tbe/bn_training_reduce_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/bn_training_reduce_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/bn_training_reduce_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/bn_training_update.py +0 -52
- mindspore/ops/_op_impl/tbe/bn_training_update_ds.py +0 -53
- mindspore/ops/_op_impl/tbe/bn_training_update_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/bn_training_update_grad_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/bn_training_update_v2.py +0 -48
- mindspore/ops/_op_impl/tbe/bn_training_update_v3.py +0 -51
- mindspore/ops/_op_impl/tbe/bounding_box_decode.py +0 -41
- mindspore/ops/_op_impl/tbe/bounding_box_decode_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/bounding_box_encode.py +0 -38
- mindspore/ops/_op_impl/tbe/broadcast_to.py +0 -40
- mindspore/ops/_op_impl/tbe/broadcast_to_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/cast.py +0 -55
- mindspore/ops/_op_impl/tbe/cast_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/cdist.py +0 -38
- mindspore/ops/_op_impl/tbe/cdist_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/ceil.py +0 -37
- mindspore/ops/_op_impl/tbe/ceil_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/celu.py +0 -39
- mindspore/ops/_op_impl/tbe/centralization.py +0 -39
- mindspore/ops/_op_impl/tbe/check_valid.py +0 -38
- mindspore/ops/_op_impl/tbe/check_valid_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum.py +0 -41
- mindspore/ops/_op_impl/tbe/clip_by_norm_no_div_sum_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/clip_by_value.py +0 -41
- mindspore/ops/_op_impl/tbe/clip_by_value_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/concat.py +0 -40
- mindspore/ops/_op_impl/tbe/concat_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/confusion_matrix.py +0 -63
- mindspore/ops/_op_impl/tbe/confusion_mul_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/confusion_softmax_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/confusion_transpose_d.py +0 -39
- mindspore/ops/_op_impl/tbe/conv2d.py +0 -47
- mindspore/ops/_op_impl/tbe/conv2d_backprop_filter.py +0 -42
- mindspore/ops/_op_impl/tbe/conv2d_backprop_filter_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/conv2d_backprop_input.py +0 -42
- mindspore/ops/_op_impl/tbe/conv2d_backprop_input_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/conv2d_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/conv2d_transpose.py +0 -48
- mindspore/ops/_op_impl/tbe/conv3d.py +0 -45
- mindspore/ops/_op_impl/tbe/conv3d_backprop_filter.py +0 -42
- mindspore/ops/_op_impl/tbe/conv3d_backprop_input.py +0 -42
- mindspore/ops/_op_impl/tbe/conv3d_transpose.py +0 -47
- mindspore/ops/_op_impl/tbe/conv3d_transpose_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/cos.py +0 -37
- mindspore/ops/_op_impl/tbe/cos_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/cosh.py +0 -37
- mindspore/ops/_op_impl/tbe/cosh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/ctc_loss_v2.py +0 -42
- mindspore/ops/_op_impl/tbe/ctc_loss_v2_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/cum_sum.py +0 -42
- mindspore/ops/_op_impl/tbe/cum_sum_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/cummin.py +0 -41
- mindspore/ops/_op_impl/tbe/cumprod.py +0 -42
- mindspore/ops/_op_impl/tbe/data_format_dim_map.py +0 -38
- mindspore/ops/_op_impl/tbe/data_format_dim_map_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/deformable_offsets.py +0 -45
- mindspore/ops/_op_impl/tbe/deformable_offsets_grad.py +0 -48
- mindspore/ops/_op_impl/tbe/depth_to_space_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/depthwise_conv2d.py +0 -44
- mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_filter.py +0 -41
- mindspore/ops/_op_impl/tbe/depthwise_conv2d_backprop_input.py +0 -41
- mindspore/ops/_op_impl/tbe/diag.py +0 -38
- mindspore/ops/_op_impl/tbe/diag_part.py +0 -38
- mindspore/ops/_op_impl/tbe/dilation.py +0 -40
- mindspore/ops/_op_impl/tbe/div.py +0 -41
- mindspore/ops/_op_impl/tbe/div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/div_no_nan.py +0 -41
- mindspore/ops/_op_impl/tbe/div_no_nan_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/dropout_do_mask.py +0 -38
- mindspore/ops/_op_impl/tbe/dropout_do_mask_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/dropout_do_mask_v3.py +0 -39
- mindspore/ops/_op_impl/tbe/dynamic_atomic_addr_clean.py +0 -34
- mindspore/ops/_op_impl/tbe/dynamic_gru_v2.py +0 -95
- mindspore/ops/_op_impl/tbe/dynamic_rnn.py +0 -82
- mindspore/ops/_op_impl/tbe/elu.py +0 -38
- mindspore/ops/_op_impl/tbe/elu_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/elu_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/elu_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/equal.py +0 -42
- mindspore/ops/_op_impl/tbe/equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/erf.py +0 -37
- mindspore/ops/_op_impl/tbe/erf_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/erfc.py +0 -37
- mindspore/ops/_op_impl/tbe/erfc_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/erfinv.py +0 -36
- mindspore/ops/_op_impl/tbe/exp.py +0 -40
- mindspore/ops/_op_impl/tbe/exp_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/expand_dims.py +0 -38
- mindspore/ops/_op_impl/tbe/expm1.py +0 -37
- mindspore/ops/_op_impl/tbe/expm1_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/extract_image_patches.py +0 -41
- mindspore/ops/_op_impl/tbe/extract_volume_patches.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_gradient.py +0 -43
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel.py +0 -39
- mindspore/ops/_op_impl/tbe/fake_quant_with_min_max_vars_per_channel_gradient.py +0 -43
- mindspore/ops/_op_impl/tbe/fast_gelu.py +0 -37
- mindspore/ops/_op_impl/tbe/fast_gelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/fast_gelu_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/fast_gelu_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/fill.py +0 -56
- mindspore/ops/_op_impl/tbe/fill_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/flatten.py +0 -48
- mindspore/ops/_op_impl/tbe/floor.py +0 -37
- mindspore/ops/_op_impl/tbe/floor_div.py +0 -41
- mindspore/ops/_op_impl/tbe/floor_div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/floor_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/floor_mod.py +0 -39
- mindspore/ops/_op_impl/tbe/floor_mod_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/fused_dbn_dw.py +0 -52
- mindspore/ops/_op_impl/tbe/fused_mul_add.py +0 -38
- mindspore/ops/_op_impl/tbe/fused_mul_add_n.py +0 -48
- mindspore/ops/_op_impl/tbe/fused_mul_add_n_l2loss.py +0 -53
- mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum.py +0 -57
- mindspore/ops/_op_impl/tbe/fused_mul_apply_momentum_extern.py +0 -67
- mindspore/ops/_op_impl/tbe/gather_nd.py +0 -52
- mindspore/ops/_op_impl/tbe/gather_nd_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/gather_v2.py +0 -56
- mindspore/ops/_op_impl/tbe/gather_v2_ds.py +0 -68
- mindspore/ops/_op_impl/tbe/gelu.py +0 -37
- mindspore/ops/_op_impl/tbe/gelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/gelu_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/gelu_grad_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/ger.py +0 -43
- mindspore/ops/_op_impl/tbe/ger_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/greater.py +0 -43
- mindspore/ops/_op_impl/tbe/greater_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/greater_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad.py +0 -51
- mindspore/ops/_op_impl/tbe/gru_v2_hidden_grad_cell.py +0 -52
- mindspore/ops/_op_impl/tbe/hard_swish.py +0 -37
- mindspore/ops/_op_impl/tbe/hard_swish_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/hard_swish_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/hard_swish_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/histogram_fixed_width.py +0 -40
- mindspore/ops/_op_impl/tbe/hshrink.py +0 -33
- mindspore/ops/_op_impl/tbe/hshrink_grad.py +0 -37
- mindspore/ops/_op_impl/tbe/hsigmoid.py +0 -45
- mindspore/ops/_op_impl/tbe/hsigmoid_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/ifmr.py +0 -47
- mindspore/ops/_op_impl/tbe/ifmr_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/im2col.py +0 -42
- mindspore/ops/_op_impl/tbe/in_top_k.py +0 -37
- mindspore/ops/_op_impl/tbe/inplace_add.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_index_add.py +0 -46
- mindspore/ops/_op_impl/tbe/inplace_sub.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_update.py +0 -39
- mindspore/ops/_op_impl/tbe/inplace_update_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/inv.py +0 -38
- mindspore/ops/_op_impl/tbe/inv_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/inv_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/inv_grad_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/invert.py +0 -37
- mindspore/ops/_op_impl/tbe/invert_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/iou.py +0 -38
- mindspore/ops/_op_impl/tbe/iou_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/is_close.py +0 -40
- mindspore/ops/_op_impl/tbe/kl_div_loss.py +0 -38
- mindspore/ops/_op_impl/tbe/kl_div_loss_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/kl_div_loss_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/l2_loss.py +0 -36
- mindspore/ops/_op_impl/tbe/l2_loss_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/l2_normalize.py +0 -38
- mindspore/ops/_op_impl/tbe/l2_normalize_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/lamb_apply_optimizer_assign.py +0 -55
- mindspore/ops/_op_impl/tbe/lamb_apply_weight_assign.py +0 -42
- mindspore/ops/_op_impl/tbe/lamb_next_mv.py +0 -59
- mindspore/ops/_op_impl/tbe/lamb_next_mv_with_decay.py +0 -59
- mindspore/ops/_op_impl/tbe/lamb_next_right.py +0 -44
- mindspore/ops/_op_impl/tbe/lamb_update_with_lr.py +0 -48
- mindspore/ops/_op_impl/tbe/lamb_update_with_lr_v2.py +0 -44
- mindspore/ops/_op_impl/tbe/lars_update.py +0 -50
- mindspore/ops/_op_impl/tbe/lars_update_ds.py +0 -51
- mindspore/ops/_op_impl/tbe/layer_norm.py +0 -46
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop.py +0 -44
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/layer_norm_beta_gamma_backprop_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/layer_norm_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/layer_norm_grad.py +0 -48
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop.py +0 -43
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2.py +0 -45
- mindspore/ops/_op_impl/tbe/layer_norm_x_backprop_v2_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/lerp.py +0 -38
- mindspore/ops/_op_impl/tbe/less.py +0 -41
- mindspore/ops/_op_impl/tbe/less_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/less_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/less_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/log.py +0 -40
- mindspore/ops/_op_impl/tbe/log1p.py +0 -37
- mindspore/ops/_op_impl/tbe/log1p_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/log_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/logical_and.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_and_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logical_not.py +0 -36
- mindspore/ops/_op_impl/tbe/logical_not_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_or.py +0 -37
- mindspore/ops/_op_impl/tbe/logical_or_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax.py +0 -37
- mindspore/ops/_op_impl/tbe/logsoftmax_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/logsoftmax_grad_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/lp_norm.py +0 -40
- mindspore/ops/_op_impl/tbe/lp_norm_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/lrn.py +0 -41
- mindspore/ops/_op_impl/tbe/lrn_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/lstm_input_grad.py +0 -51
- mindspore/ops/_op_impl/tbe/masked_fill.py +0 -40
- mindspore/ops/_op_impl/tbe/masked_fill_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/matmul.py +0 -53
- mindspore/ops/_op_impl/tbe/matmul_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/matmul_v2.py +0 -50
- mindspore/ops/_op_impl/tbe/matrix_diag.py +0 -45
- mindspore/ops/_op_impl/tbe/matrix_diag_part.py +0 -45
- mindspore/ops/_op_impl/tbe/matrix_set_diag.py +0 -46
- mindspore/ops/_op_impl/tbe/max_pool.py +0 -39
- mindspore/ops/_op_impl/tbe/max_pool3d.py +0 -44
- mindspore/ops/_op_impl/tbe/max_pool3d_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/max_pool3d_grad_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/max_pool_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/max_pool_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/max_pool_grad_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/max_pool_grad_grad_with_argmax.py +0 -41
- mindspore/ops/_op_impl/tbe/max_pool_grad_with_argmax.py +0 -42
- mindspore/ops/_op_impl/tbe/max_pool_with_argmax.py +0 -40
- mindspore/ops/_op_impl/tbe/maximum.py +0 -39
- mindspore/ops/_op_impl/tbe/maximum_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/maximum_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/maximum_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/mem_set.py +0 -38
- mindspore/ops/_op_impl/tbe/minimum.py +0 -40
- mindspore/ops/_op_impl/tbe/minimum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/minimum_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/minimum_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/mish.py +0 -37
- mindspore/ops/_op_impl/tbe/mod.py +0 -41
- mindspore/ops/_op_impl/tbe/mod_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/mul.py +0 -37
- mindspore/ops/_op_impl/tbe/mul_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/mul_no_nan.py +0 -39
- mindspore/ops/_op_impl/tbe/mul_no_nan_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/multilabel_margin_loss.py +0 -39
- mindspore/ops/_op_impl/tbe/neg.py +0 -39
- mindspore/ops/_op_impl/tbe/neg_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/new_im2col.py +0 -40
- mindspore/ops/_op_impl/tbe/nll_loss.py +0 -41
- mindspore/ops/_op_impl/tbe/nll_loss_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/nms_with_mask.py +0 -39
- mindspore/ops/_op_impl/tbe/not_equal.py +0 -41
- mindspore/ops/_op_impl/tbe/not_equal_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/npu_alloc_float_status.py +0 -34
- mindspore/ops/_op_impl/tbe/npu_clear_float_status.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_clear_float_status_v2.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_get_float_status.py +0 -35
- mindspore/ops/_op_impl/tbe/npu_get_float_status_v2.py +0 -35
- mindspore/ops/_op_impl/tbe/one_hot.py +0 -48
- mindspore/ops/_op_impl/tbe/one_hot_ds.py +0 -45
- mindspore/ops/_op_impl/tbe/ones_like.py +0 -40
- mindspore/ops/_op_impl/tbe/ones_like_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling.py +0 -40
- mindspore/ops/_op_impl/tbe/p_s_r_o_i_pooling_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/pack.py +0 -58
- mindspore/ops/_op_impl/tbe/pack_ds.py +0 -59
- mindspore/ops/_op_impl/tbe/pad_d.py +0 -40
- mindspore/ops/_op_impl/tbe/pad_d_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/parallel_concat.py +0 -70
- mindspore/ops/_op_impl/tbe/parallel_resize_bilinear.py +0 -45
- mindspore/ops/_op_impl/tbe/parallel_resize_bilinear_grad.py +0 -44
- mindspore/ops/_op_impl/tbe/pdist.py +0 -36
- mindspore/ops/_op_impl/tbe/pooling.py +0 -46
- mindspore/ops/_op_impl/tbe/population_count.py +0 -38
- mindspore/ops/_op_impl/tbe/pow.py +0 -41
- mindspore/ops/_op_impl/tbe/pow_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/prelu.py +0 -37
- mindspore/ops/_op_impl/tbe/prelu_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/prelu_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/range.py +0 -39
- mindspore/ops/_op_impl/tbe/real_div.py +0 -38
- mindspore/ops/_op_impl/tbe/real_div_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reciprocal.py +0 -36
- mindspore/ops/_op_impl/tbe/reciprocal_ds.py +0 -37
- mindspore/ops/_op_impl/tbe/reciprocal_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/reciprocal_grad_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_all.py +0 -38
- mindspore/ops/_op_impl/tbe/reduce_all_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_any.py +0 -38
- mindspore/ops/_op_impl/tbe/reduce_any_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_max.py +0 -43
- mindspore/ops/_op_impl/tbe/reduce_max_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_mean.py +0 -40
- mindspore/ops/_op_impl/tbe/reduce_mean_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/reduce_min.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_min_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_prod.py +0 -42
- mindspore/ops/_op_impl/tbe/reduce_prod_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/reduce_std.py +0 -44
- mindspore/ops/_op_impl/tbe/reduce_sum.py +0 -39
- mindspore/ops/_op_impl/tbe/reduce_sum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/relu.py +0 -39
- mindspore/ops/_op_impl/tbe/relu6.py +0 -38
- mindspore/ops/_op_impl/tbe/relu6_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/relu6_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/relu6_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/relu_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/relu_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/relu_grad_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_grad_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/relu_v2.py +0 -40
- mindspore/ops/_op_impl/tbe/relu_v2_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/renorm.py +0 -39
- mindspore/ops/_op_impl/tbe/resize_bilinear.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_bilinear_grad.py +0 -41
- mindspore/ops/_op_impl/tbe/resize_bilinear_v2.py +0 -43
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/reverse_v2_d.py +0 -37
- mindspore/ops/_op_impl/tbe/rint.py +0 -37
- mindspore/ops/_op_impl/tbe/rint_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/roi_align.py +0 -43
- mindspore/ops/_op_impl/tbe/roi_align_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/roi_align_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/roi_align_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/roll.py +0 -42
- mindspore/ops/_op_impl/tbe/round.py +0 -38
- mindspore/ops/_op_impl/tbe/round_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/rsqrt.py +0 -37
- mindspore/ops/_op_impl/tbe/rsqrt_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/rsqrt_grad.py +0 -40
- mindspore/ops/_op_impl/tbe/rsqrt_grad_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_add.py +0 -44
- mindspore/ops/_op_impl/tbe/scatter_div.py +0 -46
- mindspore/ops/_op_impl/tbe/scatter_max.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_min.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_mul.py +0 -44
- mindspore/ops/_op_impl/tbe/scatter_nd.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_nd_add.py +0 -45
- mindspore/ops/_op_impl/tbe/scatter_nd_d.py +0 -41
- mindspore/ops/_op_impl/tbe/scatter_nd_ds.py +0 -49
- mindspore/ops/_op_impl/tbe/scatter_nd_sub.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_nd_sub_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_nd_update.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_nd_update_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add.py +0 -39
- mindspore/ops/_op_impl/tbe/scatter_non_aliasing_add_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/scatter_sub.py +0 -47
- mindspore/ops/_op_impl/tbe/scatter_sub_ds.py +0 -48
- mindspore/ops/_op_impl/tbe/scatter_update.py +0 -43
- mindspore/ops/_op_impl/tbe/select.py +0 -38
- mindspore/ops/_op_impl/tbe/select_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/selu.py +0 -39
- mindspore/ops/_op_impl/tbe/selu_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/sgd.py +0 -62
- mindspore/ops/_op_impl/tbe/sigmoid.py +0 -37
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits.py +0 -41
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad.py +0 -42
- mindspore/ops/_op_impl/tbe/sigmoid_cross_entropy_with_logits_grad_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/sigmoid_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sigmoid_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/sigmoid_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/sign.py +0 -38
- mindspore/ops/_op_impl/tbe/sign_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/sin.py +0 -37
- mindspore/ops/_op_impl/tbe/sin_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sinh.py +0 -37
- mindspore/ops/_op_impl/tbe/sinh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/slice.py +0 -58
- mindspore/ops/_op_impl/tbe/smooth_l1_loss.py +0 -45
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_ds.py +0 -46
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad.py +0 -46
- mindspore/ops/_op_impl/tbe/smooth_l1_loss_grad_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/soft_margin_loss.py +0 -38
- mindspore/ops/_op_impl/tbe/soft_margin_loss_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/soft_shrink.py +0 -36
- mindspore/ops/_op_impl/tbe/soft_shrink_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax.py +0 -37
- mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax_cross_entropy_with_logits_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/softmax_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softmax_grad_ext.py +0 -42
- mindspore/ops/_op_impl/tbe/softmax_v2_with_dropout_do_mask_v3.py +0 -39
- mindspore/ops/_op_impl/tbe/softplus.py +0 -37
- mindspore/ops/_op_impl/tbe/softplus_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softplus_grad.py +0 -38
- mindspore/ops/_op_impl/tbe/softplus_grad_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/softsign.py +0 -37
- mindspore/ops/_op_impl/tbe/softsign_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sort.py +0 -38
- mindspore/ops/_op_impl/tbe/sort_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/space_to_batch.py +0 -38
- mindspore/ops/_op_impl/tbe/space_to_batch_nd.py +0 -38
- mindspore/ops/_op_impl/tbe/space_to_depth.py +0 -47
- mindspore/ops/_op_impl/tbe/sparse_apply_adadelta.py +0 -56
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad.py +0 -45
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_ds.py +0 -46
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2.py +0 -46
- mindspore/ops/_op_impl/tbe/sparse_apply_adagrad_v2_ds.py +0 -47
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d.py +0 -53
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_d_ds.py +0 -50
- mindspore/ops/_op_impl/tbe/sparse_apply_ftrl_v2.py +0 -50
- mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad.py +0 -66
- mindspore/ops/_op_impl/tbe/sparse_apply_proximal_adagrad_ds.py +0 -67
- mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop.py +0 -57
- mindspore/ops/_op_impl/tbe/sparse_apply_r_m_s_prop_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/sparse_gather_v2.py +0 -56
- mindspore/ops/_op_impl/tbe/sparse_gather_v2_ds.py +0 -58
- mindspore/ops/_op_impl/tbe/split_d.py +0 -38
- mindspore/ops/_op_impl/tbe/split_d_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/split_v.py +0 -39
- mindspore/ops/_op_impl/tbe/splitv.py +0 -39
- mindspore/ops/_op_impl/tbe/sqrt.py +0 -37
- mindspore/ops/_op_impl/tbe/sqrt_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/sqrt_grad.py +0 -43
- mindspore/ops/_op_impl/tbe/sqrt_grad_ds.py +0 -44
- mindspore/ops/_op_impl/tbe/square.py +0 -38
- mindspore/ops/_op_impl/tbe/square_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/square_sum_all.py +0 -40
- mindspore/ops/_op_impl/tbe/square_sum_all_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/square_sum_v1.py +0 -38
- mindspore/ops/_op_impl/tbe/square_sum_v1_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/square_sum_v2.py +0 -39
- mindspore/ops/_op_impl/tbe/squared_difference.py +0 -39
- mindspore/ops/_op_impl/tbe/squared_difference_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/squeeze.py +0 -37
- mindspore/ops/_op_impl/tbe/strided_read.py +0 -38
- mindspore/ops/_op_impl/tbe/strided_slice_d.py +0 -44
- mindspore/ops/_op_impl/tbe/strided_slice_ds.py +0 -71
- mindspore/ops/_op_impl/tbe/strided_slice_grad_d.py +0 -51
- mindspore/ops/_op_impl/tbe/strided_slice_grad_ds.py +0 -57
- mindspore/ops/_op_impl/tbe/strided_write.py +0 -38
- mindspore/ops/_op_impl/tbe/sub.py +0 -39
- mindspore/ops/_op_impl/tbe/sub_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/tan.py +0 -38
- mindspore/ops/_op_impl/tbe/tan_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/tanh.py +0 -37
- mindspore/ops/_op_impl/tbe/tanh_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/tanh_grad.py +0 -39
- mindspore/ops/_op_impl/tbe/tanh_grad_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/tensor_move.py +0 -49
- mindspore/ops/_op_impl/tbe/tensor_move_ds.py +0 -50
- mindspore/ops/_op_impl/tbe/tensor_scatter_update.py +0 -41
- mindspore/ops/_op_impl/tbe/tile.py +0 -37
- mindspore/ops/_op_impl/tbe/tile_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/top_k.py +0 -42
- mindspore/ops/_op_impl/tbe/top_k_ds.py +0 -43
- mindspore/ops/_op_impl/tbe/trans_data.py +0 -167
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +0 -180
- mindspore/ops/_op_impl/tbe/trans_data_rnn.py +0 -44
- mindspore/ops/_op_impl/tbe/transpose.py +0 -60
- mindspore/ops/_op_impl/tbe/transpose_d.py +0 -47
- mindspore/ops/_op_impl/tbe/transpose_nod.py +0 -60
- mindspore/ops/_op_impl/tbe/trunc.py +0 -39
- mindspore/ops/_op_impl/tbe/truncate_div.py +0 -41
- mindspore/ops/_op_impl/tbe/truncate_div_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/truncate_mod.py +0 -41
- mindspore/ops/_op_impl/tbe/truncate_mod_ds.py +0 -42
- mindspore/ops/_op_impl/tbe/unpack.py +0 -38
- mindspore/ops/_op_impl/tbe/unpack_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/unsorted_segment_max.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_max_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/unsorted_segment_min.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_min_ds.py +0 -40
- mindspore/ops/_op_impl/tbe/unsorted_segment_prod.py +0 -49
- mindspore/ops/_op_impl/tbe/unsorted_segment_prod_ds.py +0 -38
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum.py +0 -38
- mindspore/ops/_op_impl/tbe/unsorted_segment_sum_ds.py +0 -41
- mindspore/ops/_op_impl/tbe/wts_arq.py +0 -40
- mindspore/ops/_op_impl/tbe/xdivy.py +0 -38
- mindspore/ops/_op_impl/tbe/xdivy_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/xlogy.py +0 -38
- mindspore/ops/_op_impl/tbe/xlogy_ds.py +0 -39
- mindspore/ops/_op_impl/tbe/zeros_like.py +0 -41
- mindspore/ops/_op_impl/tbe/zeros_like_ds.py +0 -42
- mindspore/ops/_tracefunc.py +0 -241
- mindspore/ops/arg_dtype_cast.py +0 -54
- mindspore/rewrite/api/tree_node_helper.py +0 -60
- mindspore/rewrite/ast_creator_register.py +0 -37
- mindspore/rewrite/ast_helpers/ast_creator.py +0 -115
- mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +0 -267
- mindspore/rewrite/ast_transformers/remove_return_out_of_if.py +0 -228
- mindspore/rewrite/namespace.py +0 -53
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc1.dist-info}/WHEEL +0 -0
- {mindspore-2.2.14.dist-info → mindspore-2.3.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -105,6 +105,8 @@ class AdjustBrightness(ImageTensorOperation, PyTensorOperation):
|
|
|
105
105
|
"""
|
|
106
106
|
Adjust the brightness of the input image.
|
|
107
107
|
|
|
108
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
109
|
+
|
|
108
110
|
Args:
|
|
109
111
|
brightness_factor (float): How much to adjust the brightness, must be non negative.
|
|
110
112
|
``0`` gives a black image, ``1`` gives the original image,
|
|
@@ -119,17 +121,30 @@ class AdjustBrightness(ImageTensorOperation, PyTensorOperation):
|
|
|
119
121
|
``CPU`` ``Ascend``
|
|
120
122
|
|
|
121
123
|
Examples:
|
|
124
|
+
>>> import numpy as np
|
|
122
125
|
>>> import mindspore.dataset as ds
|
|
123
126
|
>>> import mindspore.dataset.vision as vision
|
|
124
127
|
>>>
|
|
125
|
-
>>>
|
|
126
|
-
>>>
|
|
127
|
-
>>>
|
|
128
|
-
|
|
128
|
+
>>> # Use the transform in dataset pipeline mode
|
|
129
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
130
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
131
|
+
>>> transforms_list = [vision.AdjustBrightness(brightness_factor=2.0)]
|
|
132
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
133
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
134
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
135
|
+
... break
|
|
136
|
+
(100, 100, 3) uint8
|
|
137
|
+
>>>
|
|
138
|
+
>>> # Use the transform in eager mode
|
|
139
|
+
>>> data = np.random.randint(0, 256, (20, 20, 3)) / 255.0
|
|
140
|
+
>>> data = data.astype(np.float32)
|
|
141
|
+
>>> output = vision.AdjustBrightness(2.666)(data)
|
|
142
|
+
>>> print(output.shape, output.dtype)
|
|
143
|
+
(20, 20, 3) float32
|
|
129
144
|
|
|
130
145
|
Tutorial Examples:
|
|
131
146
|
- `Illustration of vision transforms
|
|
132
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
147
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
133
148
|
"""
|
|
134
149
|
|
|
135
150
|
@check_adjust_brightness
|
|
@@ -142,28 +157,44 @@ class AdjustBrightness(ImageTensorOperation, PyTensorOperation):
|
|
|
142
157
|
"""
|
|
143
158
|
Set the device for the current operator execution.
|
|
144
159
|
|
|
160
|
+
- When the device is Ascend, input shape should be limited from [4, 6] to [8192, 4096].
|
|
161
|
+
|
|
145
162
|
Args:
|
|
146
163
|
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
147
|
-
``CPU`` . Default: ``CPU`` .
|
|
164
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
148
165
|
|
|
149
166
|
Raises:
|
|
150
167
|
TypeError: If `device_target` is not of type str.
|
|
151
|
-
ValueError: If `device_target` is not
|
|
168
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
152
169
|
|
|
153
170
|
Supported Platforms:
|
|
154
|
-
``CPU``
|
|
171
|
+
``CPU`` ``Ascend``
|
|
155
172
|
|
|
156
173
|
Examples:
|
|
174
|
+
>>> import numpy as np
|
|
157
175
|
>>> import mindspore.dataset as ds
|
|
158
176
|
>>> import mindspore.dataset.vision as vision
|
|
159
177
|
>>>
|
|
160
|
-
>>>
|
|
161
|
-
>>>
|
|
162
|
-
>>>
|
|
178
|
+
>>> # Use the transform in dataset pipeline mode
|
|
179
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
180
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
181
|
+
>>> transforms_list = [vision.AdjustBrightness(2.0).device("Ascend")]
|
|
182
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
183
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
184
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
185
|
+
... break
|
|
186
|
+
(100, 100, 3) uint8
|
|
187
|
+
>>>
|
|
188
|
+
>>> # Use the transform in eager mode
|
|
189
|
+
>>> data = np.random.randint(0, 256, (20, 20, 3)) / 255.0
|
|
190
|
+
>>> data = data.astype(np.float32)
|
|
191
|
+
>>> output = vision.AdjustBrightness(2.666).device("Ascend")(data)
|
|
192
|
+
>>> print(output.shape, output.dtype)
|
|
193
|
+
(20, 20, 3) float32
|
|
163
194
|
|
|
164
195
|
Tutorial Examples:
|
|
165
196
|
- `Illustration of vision transforms
|
|
166
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
197
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
167
198
|
"""
|
|
168
199
|
self.device_target = device_target
|
|
169
200
|
return self
|
|
@@ -188,6 +219,8 @@ class AdjustContrast(ImageTensorOperation, PyTensorOperation):
|
|
|
188
219
|
"""
|
|
189
220
|
Adjust the contrast of the input image.
|
|
190
221
|
|
|
222
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
223
|
+
|
|
191
224
|
Args:
|
|
192
225
|
contrast_factor (float): How much to adjust the contrast, must be non negative.
|
|
193
226
|
``0`` gives a solid gray image, ``1`` gives the original image,
|
|
@@ -202,17 +235,29 @@ class AdjustContrast(ImageTensorOperation, PyTensorOperation):
|
|
|
202
235
|
``CPU`` ``Ascend``
|
|
203
236
|
|
|
204
237
|
Examples:
|
|
238
|
+
>>> import numpy as np
|
|
205
239
|
>>> import mindspore.dataset as ds
|
|
206
240
|
>>> import mindspore.dataset.vision as vision
|
|
207
241
|
>>>
|
|
208
|
-
>>>
|
|
209
|
-
>>>
|
|
210
|
-
>>>
|
|
211
|
-
|
|
242
|
+
>>> # Use the transform in dataset pipeline mode
|
|
243
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
244
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
245
|
+
>>> transforms_list = [vision.AdjustContrast(contrast_factor=2.0)]
|
|
246
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
247
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
248
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
249
|
+
... break
|
|
250
|
+
(100, 100, 3) uint8
|
|
251
|
+
>>>
|
|
252
|
+
>>> # Use the transform in eager mode
|
|
253
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
254
|
+
>>> output = vision.AdjustContrast(2.0)(data)
|
|
255
|
+
>>> print(output.shape, output.dtype)
|
|
256
|
+
(2, 2, 3) uint8
|
|
212
257
|
|
|
213
258
|
Tutorial Examples:
|
|
214
259
|
- `Illustration of vision transforms
|
|
215
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
260
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
216
261
|
"""
|
|
217
262
|
|
|
218
263
|
@check_adjust_contrast
|
|
@@ -225,28 +270,43 @@ class AdjustContrast(ImageTensorOperation, PyTensorOperation):
|
|
|
225
270
|
"""
|
|
226
271
|
Set the device for the current operator execution.
|
|
227
272
|
|
|
273
|
+
- When the device is Ascend, input shape should be limited from [4, 6] to [8192, 4096].
|
|
274
|
+
|
|
228
275
|
Args:
|
|
229
276
|
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
230
|
-
``CPU`` . Default: ``CPU`` .
|
|
277
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
231
278
|
|
|
232
279
|
Raises:
|
|
233
280
|
TypeError: If `device_target` is not of type str.
|
|
234
|
-
ValueError: If `device_target` is not
|
|
281
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
235
282
|
|
|
236
283
|
Supported Platforms:
|
|
237
|
-
``CPU``
|
|
284
|
+
``CPU`` ``Ascend``
|
|
238
285
|
|
|
239
286
|
Examples:
|
|
287
|
+
>>> import numpy as np
|
|
240
288
|
>>> import mindspore.dataset as ds
|
|
241
289
|
>>> import mindspore.dataset.vision as vision
|
|
242
290
|
>>>
|
|
243
|
-
>>>
|
|
244
|
-
>>>
|
|
245
|
-
>>>
|
|
291
|
+
>>> # Use the transform in dataset pipeline mode
|
|
292
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
293
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
294
|
+
>>> transforms_list = [vision.AdjustContrast(0).device("Ascend")]
|
|
295
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
296
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
297
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
298
|
+
... break
|
|
299
|
+
(100, 100, 3) uint8
|
|
300
|
+
>>>
|
|
301
|
+
>>> # Use the transform in eager mode
|
|
302
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
303
|
+
>>> output = vision.AdjustContrast(2.0).device("Ascend")(data)
|
|
304
|
+
>>> print(output.shape, output.dtype)
|
|
305
|
+
(100, 100, 3) uint8
|
|
246
306
|
|
|
247
307
|
Tutorial Examples:
|
|
248
308
|
- `Illustration of vision transforms
|
|
249
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
309
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
250
310
|
"""
|
|
251
311
|
self.device_target = device_target
|
|
252
312
|
return self
|
|
@@ -295,17 +355,29 @@ class AdjustGamma(ImageTensorOperation, PyTensorOperation):
|
|
|
295
355
|
``CPU``
|
|
296
356
|
|
|
297
357
|
Examples:
|
|
358
|
+
>>> import numpy as np
|
|
298
359
|
>>> import mindspore.dataset as ds
|
|
299
360
|
>>> import mindspore.dataset.vision as vision
|
|
300
361
|
>>>
|
|
301
|
-
>>>
|
|
302
|
-
>>>
|
|
303
|
-
>>>
|
|
304
|
-
|
|
362
|
+
>>> # Use the transform in dataset pipeline mode
|
|
363
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
364
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
365
|
+
>>> transforms_list = [vision.AdjustGamma(gamma=10.0, gain=1.0)]
|
|
366
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
367
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
368
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
369
|
+
... break
|
|
370
|
+
(100, 100, 3) uint8
|
|
371
|
+
>>>
|
|
372
|
+
>>> # Use the transform in eager mode
|
|
373
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
374
|
+
>>> output = vision.AdjustGamma(gamma=0.1, gain=1.0)(data)
|
|
375
|
+
>>> print(output.shape, output.dtype)
|
|
376
|
+
(2, 2, 3) uint8
|
|
305
377
|
|
|
306
378
|
Tutorial Examples:
|
|
307
379
|
- `Illustration of vision transforms
|
|
308
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
380
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
309
381
|
"""
|
|
310
382
|
|
|
311
383
|
@check_adjust_gamma
|
|
@@ -335,6 +407,8 @@ class AdjustHue(ImageTensorOperation, PyTensorOperation):
|
|
|
335
407
|
"""
|
|
336
408
|
Adjust the hue of the input image.
|
|
337
409
|
|
|
410
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
411
|
+
|
|
338
412
|
Args:
|
|
339
413
|
hue_factor (float): How much to add to the hue channel,
|
|
340
414
|
must be in range of [-0.5, 0.5].
|
|
@@ -348,17 +422,29 @@ class AdjustHue(ImageTensorOperation, PyTensorOperation):
|
|
|
348
422
|
``CPU`` ``Ascend``
|
|
349
423
|
|
|
350
424
|
Examples:
|
|
425
|
+
>>> import numpy as np
|
|
351
426
|
>>> import mindspore.dataset as ds
|
|
352
427
|
>>> import mindspore.dataset.vision as vision
|
|
353
428
|
>>>
|
|
354
|
-
>>>
|
|
355
|
-
>>>
|
|
356
|
-
>>>
|
|
357
|
-
|
|
429
|
+
>>> # Use the transform in dataset pipeline mode
|
|
430
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
431
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
432
|
+
>>> transforms_list = [vision.AdjustHue(hue_factor=0.2)]
|
|
433
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
434
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
435
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
436
|
+
... break
|
|
437
|
+
(100, 100, 3) uint8
|
|
438
|
+
>>>
|
|
439
|
+
>>> # Use the transform in eager mode
|
|
440
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
441
|
+
>>> output = vision.AdjustHue(hue_factor=0.2)(data)
|
|
442
|
+
>>> print(output.shape, output.dtype)
|
|
443
|
+
(2, 2, 3) uint8
|
|
358
444
|
|
|
359
445
|
Tutorial Examples:
|
|
360
446
|
- `Illustration of vision transforms
|
|
361
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
447
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
362
448
|
"""
|
|
363
449
|
|
|
364
450
|
@check_adjust_hue
|
|
@@ -371,28 +457,43 @@ class AdjustHue(ImageTensorOperation, PyTensorOperation):
|
|
|
371
457
|
"""
|
|
372
458
|
Set the device for the current operator execution.
|
|
373
459
|
|
|
460
|
+
- When the device is Ascend, input shape should be limited from [4, 6] to [8192, 4096].
|
|
461
|
+
|
|
374
462
|
Args:
|
|
375
463
|
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
376
|
-
``CPU`` . Default: ``CPU`` .
|
|
464
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
377
465
|
|
|
378
466
|
Raises:
|
|
379
467
|
TypeError: If `device_target` is not of type str.
|
|
380
|
-
ValueError: If `device_target` is not
|
|
468
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
381
469
|
|
|
382
470
|
Supported Platforms:
|
|
383
|
-
``CPU``
|
|
471
|
+
``CPU`` ``Ascend``
|
|
384
472
|
|
|
385
473
|
Examples:
|
|
474
|
+
>>> import numpy as np
|
|
386
475
|
>>> import mindspore.dataset as ds
|
|
387
476
|
>>> import mindspore.dataset.vision as vision
|
|
388
477
|
>>>
|
|
389
|
-
>>>
|
|
390
|
-
>>>
|
|
391
|
-
>>>
|
|
478
|
+
>>> # Use the transform in dataset pipeline mode
|
|
479
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
480
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
481
|
+
>>> transforms_list = [vision.AdjustHue(0.5).device("Ascend")]
|
|
482
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
483
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
484
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
485
|
+
... break
|
|
486
|
+
(100, 100, 3) uint8
|
|
487
|
+
>>>
|
|
488
|
+
>>> # Use the transform in eager mode
|
|
489
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
490
|
+
>>> output = vision.AdjustHue(hue_factor=0.2).device("Ascend")(data)
|
|
491
|
+
>>> print(output.shape, output.dtype)
|
|
492
|
+
(100, 100, 3) uint8
|
|
392
493
|
|
|
393
494
|
Tutorial Examples:
|
|
394
495
|
- `Illustration of vision transforms
|
|
395
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
496
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
396
497
|
"""
|
|
397
498
|
self.device_target = device_target
|
|
398
499
|
return self
|
|
@@ -417,6 +518,8 @@ class AdjustSaturation(ImageTensorOperation, PyTensorOperation):
|
|
|
417
518
|
"""
|
|
418
519
|
Adjust the saturation of the input image.
|
|
419
520
|
|
|
521
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
522
|
+
|
|
420
523
|
Args:
|
|
421
524
|
saturation_factor (float): How much to adjust the saturation, must be non negative.
|
|
422
525
|
``0`` gives a black image, ``1`` gives the original image
|
|
@@ -432,17 +535,29 @@ class AdjustSaturation(ImageTensorOperation, PyTensorOperation):
|
|
|
432
535
|
``CPU`` ``Ascend``
|
|
433
536
|
|
|
434
537
|
Examples:
|
|
538
|
+
>>> import numpy as np
|
|
435
539
|
>>> import mindspore.dataset as ds
|
|
436
540
|
>>> import mindspore.dataset.vision as vision
|
|
437
541
|
>>>
|
|
438
|
-
>>>
|
|
439
|
-
>>>
|
|
440
|
-
>>>
|
|
441
|
-
|
|
542
|
+
>>> # Use the transform in dataset pipeline mode
|
|
543
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
544
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
545
|
+
>>> transforms_list = [vision.AdjustSaturation(saturation_factor=2.0)]
|
|
546
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
547
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
548
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
549
|
+
... break
|
|
550
|
+
(100, 100, 3) uint8
|
|
551
|
+
>>>
|
|
552
|
+
>>> # Use the transform in eager mode
|
|
553
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
554
|
+
>>> output = vision.AdjustSaturation(saturation_factor=2.0)(data)
|
|
555
|
+
>>> print(output.shape, output.dtype)
|
|
556
|
+
(2, 2, 3) uint8
|
|
442
557
|
|
|
443
558
|
Tutorial Examples:
|
|
444
559
|
- `Illustration of vision transforms
|
|
445
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
560
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
446
561
|
"""
|
|
447
562
|
|
|
448
563
|
@check_adjust_saturation
|
|
@@ -455,28 +570,43 @@ class AdjustSaturation(ImageTensorOperation, PyTensorOperation):
|
|
|
455
570
|
"""
|
|
456
571
|
Set the device for the current operator execution.
|
|
457
572
|
|
|
573
|
+
- When the device is Ascend, input shape should be limited from [4, 6] to [8192, 4096].
|
|
574
|
+
|
|
458
575
|
Args:
|
|
459
576
|
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
460
|
-
``CPU`` . Default: ``CPU`` .
|
|
577
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
461
578
|
|
|
462
579
|
Raises:
|
|
463
580
|
TypeError: If `device_target` is not of type str.
|
|
464
|
-
ValueError: If `device_target` is not
|
|
581
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
465
582
|
|
|
466
583
|
Supported Platforms:
|
|
467
|
-
``CPU``
|
|
584
|
+
``CPU`` ``Ascend``
|
|
468
585
|
|
|
469
586
|
Examples:
|
|
587
|
+
>>> import numpy as np
|
|
470
588
|
>>> import mindspore.dataset as ds
|
|
471
589
|
>>> import mindspore.dataset.vision as vision
|
|
472
590
|
>>>
|
|
473
|
-
>>>
|
|
474
|
-
>>>
|
|
475
|
-
>>>
|
|
591
|
+
>>> # Use the transform in dataset pipeline mode
|
|
592
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
593
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
594
|
+
>>> transforms_list = [vision.AdjustSaturation(2.0).device("Ascend")]
|
|
595
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
596
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
597
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
598
|
+
... break
|
|
599
|
+
(100, 100, 3) uint8
|
|
600
|
+
>>>
|
|
601
|
+
>>> # Use the transform in eager mode
|
|
602
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
603
|
+
>>> output = vision.AdjustSaturation(saturation_factor=2.0).device("Ascend")(data)
|
|
604
|
+
>>> print(output.shape, output.dtype)
|
|
605
|
+
(100, 100, 3) uint8
|
|
476
606
|
|
|
477
607
|
Tutorial Examples:
|
|
478
608
|
- `Illustration of vision transforms
|
|
479
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
609
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
480
610
|
"""
|
|
481
611
|
self.device_target = device_target
|
|
482
612
|
return self
|
|
@@ -515,17 +645,30 @@ class AdjustSharpness(ImageTensorOperation):
|
|
|
515
645
|
``CPU``
|
|
516
646
|
|
|
517
647
|
Examples:
|
|
648
|
+
>>> import numpy as np
|
|
518
649
|
>>> import mindspore.dataset as ds
|
|
519
650
|
>>> import mindspore.dataset.vision as vision
|
|
520
651
|
>>>
|
|
521
|
-
>>>
|
|
522
|
-
>>>
|
|
523
|
-
>>>
|
|
524
|
-
|
|
652
|
+
>>> # Use the transform in dataset pipeline mode
|
|
653
|
+
>>> # create a dataset that reads all files in dataset_dir with 8 threads
|
|
654
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
655
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
656
|
+
>>> transforms_list = [vision.AdjustSharpness(sharpness_factor=2.0)]
|
|
657
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
658
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
659
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
660
|
+
... break
|
|
661
|
+
(100, 100, 3) uint8
|
|
662
|
+
>>>
|
|
663
|
+
>>> # Use the transform in eager mode
|
|
664
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((3, 4))
|
|
665
|
+
>>> output = vision.AdjustSharpness(sharpness_factor=0)(data)
|
|
666
|
+
>>> print(output.shape, output.dtype)
|
|
667
|
+
(3, 4) uint8
|
|
525
668
|
|
|
526
669
|
Tutorial Examples:
|
|
527
670
|
- `Illustration of vision transforms
|
|
528
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
671
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
529
672
|
"""
|
|
530
673
|
|
|
531
674
|
@check_adjust_sharpness
|
|
@@ -542,9 +685,12 @@ class Affine(ImageTensorOperation):
|
|
|
542
685
|
"""
|
|
543
686
|
Apply Affine transformation to the input image, keeping the center of the image unchanged.
|
|
544
687
|
|
|
688
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
689
|
+
|
|
545
690
|
Args:
|
|
546
691
|
degrees (float): Rotation angle in degrees between -180 and 180, clockwise direction.
|
|
547
|
-
translate (Sequence[float, float]): The horizontal and vertical translations, must be a sequence of size 2
|
|
692
|
+
translate (Sequence[float, float]): The horizontal and vertical translations, must be a sequence of size 2
|
|
693
|
+
and value between -1 and 1.
|
|
548
694
|
scale (float): Scaling factor, which must be positive.
|
|
549
695
|
shear (Union[float, Sequence[float, float]]): Shear angle value in degrees between -180 to 180.
|
|
550
696
|
If float is provided, shear along the x axis with this value, without shearing along the y axis;
|
|
@@ -569,21 +715,32 @@ class Affine(ImageTensorOperation):
|
|
|
569
715
|
``CPU``
|
|
570
716
|
|
|
571
717
|
Examples:
|
|
718
|
+
>>> import numpy as np
|
|
572
719
|
>>> import mindspore.dataset as ds
|
|
573
720
|
>>> import mindspore.dataset.vision as vision
|
|
574
721
|
>>> from mindspore.dataset.vision import Inter
|
|
575
722
|
>>>
|
|
576
|
-
>>>
|
|
723
|
+
>>> # Use the transform in dataset pipeline mode
|
|
724
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
725
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
577
726
|
>>> affine_op = vision.Affine(degrees=15, translate=[0.2, 0.2], scale=1.1, shear=[1.0, 1.0],
|
|
578
727
|
... resample=Inter.BILINEAR)
|
|
579
|
-
>>>
|
|
728
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[affine_op], input_columns=["image"])
|
|
729
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
730
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
731
|
+
... break
|
|
732
|
+
(100, 100, 3) uint8
|
|
580
733
|
>>>
|
|
581
|
-
>>>
|
|
582
|
-
>>>
|
|
734
|
+
>>> # Use the transform in eager mode
|
|
735
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
736
|
+
>>> output = vision.Affine(degrees=15, translate=[0.2, 0.2], scale=1.1,
|
|
737
|
+
... shear=[1.0, 1.0], resample=Inter.BILINEAR)(data)
|
|
738
|
+
>>> print(output.shape, output.dtype)
|
|
739
|
+
(2, 2, 3) uint8
|
|
583
740
|
|
|
584
741
|
Tutorial Examples:
|
|
585
742
|
- `Illustration of vision transforms
|
|
586
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
743
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
587
744
|
"""
|
|
588
745
|
|
|
589
746
|
@check_affine
|
|
@@ -604,9 +761,58 @@ class Affine(ImageTensorOperation):
|
|
|
604
761
|
self.fill_value = fill_value
|
|
605
762
|
self.implementation = Implementation.C
|
|
606
763
|
|
|
764
|
+
@check_device_target
|
|
765
|
+
def device(self, device_target="CPU"):
|
|
766
|
+
"""
|
|
767
|
+
Set the device for the current operator execution.
|
|
768
|
+
|
|
769
|
+
- When the device is Ascend, input shape should be limited from [4, 6] to [32768, 32768].
|
|
770
|
+
|
|
771
|
+
Args:
|
|
772
|
+
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
773
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
774
|
+
|
|
775
|
+
Raises:
|
|
776
|
+
TypeError: If `device_target` is not of type str.
|
|
777
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
778
|
+
|
|
779
|
+
Supported Platforms:
|
|
780
|
+
``CPU`` ``Ascend``
|
|
781
|
+
|
|
782
|
+
Examples:
|
|
783
|
+
>>> import numpy as np
|
|
784
|
+
>>> import mindspore.dataset as ds
|
|
785
|
+
>>> import mindspore.dataset.vision as vision
|
|
786
|
+
>>> from mindspore.dataset.vision import Inter
|
|
787
|
+
>>>
|
|
788
|
+
>>> # Use the transform in dataset pipeline mode
|
|
789
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
790
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
791
|
+
>>> affine_op = vision.Affine(degrees=15, translate=[0.2, 0.2], scale=1.1,
|
|
792
|
+
... shear=[1.0, 1.0], resample=Inter.BILINEAR).device("Ascend")
|
|
793
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[affine_op], input_columns=["image"])
|
|
794
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
795
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
796
|
+
... break
|
|
797
|
+
(100, 100, 3) uint8
|
|
798
|
+
>>>
|
|
799
|
+
>>> # Use the transform in eager mode
|
|
800
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
801
|
+
>>> output = vision.Affine(degrees=15, translate=[0.2, 0.2], scale=1.1,
|
|
802
|
+
... shear=[1.0, 1.0], resample=Inter.BILINEAR).device("Ascend")(data)
|
|
803
|
+
>>> print(output.shape, output.dtype)
|
|
804
|
+
(100, 100, 3) uint8
|
|
805
|
+
|
|
806
|
+
Tutorial Examples:
|
|
807
|
+
- `Illustration of vision transforms
|
|
808
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
809
|
+
"""
|
|
810
|
+
self.device_target = device_target
|
|
811
|
+
return self
|
|
812
|
+
|
|
607
813
|
def parse(self):
|
|
608
814
|
return cde.AffineOperation(self.degrees, self.translate, self.scale_, self.shear,
|
|
609
|
-
Inter.to_c_type(self.resample), self.fill_value)
|
|
815
|
+
Inter.to_c_type(self.resample), self.fill_value, self.device_target)
|
|
610
816
|
|
|
611
817
|
|
|
612
818
|
class AutoAugment(ImageTensorOperation):
|
|
@@ -644,21 +850,32 @@ class AutoAugment(ImageTensorOperation):
|
|
|
644
850
|
``CPU``
|
|
645
851
|
|
|
646
852
|
Examples:
|
|
853
|
+
>>> import numpy as np
|
|
647
854
|
>>> import mindspore.dataset as ds
|
|
648
855
|
>>> import mindspore.dataset.vision as vision
|
|
649
856
|
>>> from mindspore.dataset.vision import AutoAugmentPolicy, Inter
|
|
650
857
|
>>>
|
|
651
|
-
>>>
|
|
652
|
-
|
|
653
|
-
...
|
|
858
|
+
>>> # Use the transform in dataset pipeline mode
|
|
859
|
+
>>> transforms_list = [vision.AutoAugment(policy=AutoAugmentPolicy.IMAGENET,
|
|
860
|
+
... interpolation=Inter.NEAREST,
|
|
861
|
+
... fill_value=0)]
|
|
862
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
863
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
864
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
865
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
866
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
867
|
+
... break
|
|
868
|
+
(100, 100, 3) uint8
|
|
654
869
|
>>>
|
|
655
|
-
>>>
|
|
656
|
-
>>>
|
|
657
|
-
|
|
870
|
+
>>> # Use the transform in eager mode
|
|
871
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
872
|
+
>>> output = vision.AutoAugment()(data)
|
|
873
|
+
>>> print(output.shape, output.dtype)
|
|
874
|
+
(100, 100, 3) uint8
|
|
658
875
|
|
|
659
876
|
Tutorial Examples:
|
|
660
877
|
- `Illustration of vision transforms
|
|
661
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
878
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
662
879
|
"""
|
|
663
880
|
|
|
664
881
|
@check_auto_augment
|
|
@@ -698,17 +915,29 @@ class AutoContrast(ImageTensorOperation, PyTensorOperation):
|
|
|
698
915
|
``CPU``
|
|
699
916
|
|
|
700
917
|
Examples:
|
|
918
|
+
>>> import numpy as np
|
|
701
919
|
>>> import mindspore.dataset as ds
|
|
702
920
|
>>> import mindspore.dataset.vision as vision
|
|
703
921
|
>>>
|
|
704
|
-
>>>
|
|
705
|
-
>>>
|
|
706
|
-
>>>
|
|
707
|
-
|
|
922
|
+
>>> # Use the transform in dataset pipeline mode
|
|
923
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
924
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
925
|
+
>>> transforms_list = [vision.AutoContrast(cutoff=10.0, ignore=[10, 20])]
|
|
926
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
927
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
928
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
929
|
+
... break
|
|
930
|
+
(100, 100, 3) uint8
|
|
931
|
+
>>>
|
|
932
|
+
>>> # Use the transform in eager mode
|
|
933
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
934
|
+
>>> output = vision.AutoContrast(cutoff=10.0, ignore=[10, 20])(data)
|
|
935
|
+
>>> print(output.shape, output.dtype)
|
|
936
|
+
(2, 2, 3) uint8
|
|
708
937
|
|
|
709
938
|
Tutorial Examples:
|
|
710
939
|
- `Illustration of vision transforms
|
|
711
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
940
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
712
941
|
"""
|
|
713
942
|
|
|
714
943
|
@check_auto_contrast
|
|
@@ -758,20 +987,44 @@ class BoundingBoxAugment(ImageTensorOperation):
|
|
|
758
987
|
``CPU``
|
|
759
988
|
|
|
760
989
|
Examples:
|
|
990
|
+
>>> import numpy as np
|
|
761
991
|
>>> import mindspore.dataset as ds
|
|
762
992
|
>>> import mindspore.dataset.vision as vision
|
|
763
993
|
>>>
|
|
764
|
-
>>>
|
|
994
|
+
>>> # Use the transform in dataset pipeline mode
|
|
995
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
996
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
997
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32))
|
|
998
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func],
|
|
999
|
+
... input_columns=["image"],
|
|
1000
|
+
... output_columns=["image", "bbox"])
|
|
765
1001
|
>>> # set bounding box operation with ratio of 1 to apply rotation on all bounding boxes
|
|
766
1002
|
>>> bbox_aug_op = vision.BoundingBoxAugment(vision.RandomRotation(90), 1)
|
|
767
1003
|
>>> # map to apply ops
|
|
768
|
-
>>>
|
|
1004
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[bbox_aug_op],
|
|
769
1005
|
... input_columns=["image", "bbox"],
|
|
770
1006
|
... output_columns=["image", "bbox"])
|
|
1007
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1008
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1009
|
+
... print(item["bbox"].shape, item["bbox"].dtype)
|
|
1010
|
+
... break
|
|
1011
|
+
(100, 100, 3) float32
|
|
1012
|
+
(1, 4) float32
|
|
1013
|
+
>>>
|
|
1014
|
+
>>> # Use the transform in eager mode
|
|
1015
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((3, 4))
|
|
1016
|
+
>>> data = data.astype(np.float32)
|
|
1017
|
+
>>> func = lambda img, bboxes: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(bboxes.dtype))
|
|
1018
|
+
>>> func_data, func_bboxes = func(data, data)
|
|
1019
|
+
>>> output = vision.BoundingBoxAugment(transforms.Fill(100), 1.0)(func_data, func_bboxes)
|
|
1020
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
1021
|
+
(3, 4) float32
|
|
1022
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
1023
|
+
(1, 4) float32
|
|
771
1024
|
|
|
772
1025
|
Tutorial Examples:
|
|
773
1026
|
- `Illustration of vision transforms
|
|
774
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1027
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
775
1028
|
"""
|
|
776
1029
|
|
|
777
1030
|
@check_bounding_box_augment_cpp
|
|
@@ -809,23 +1062,40 @@ class CenterCrop(ImageTensorOperation, PyTensorOperation):
|
|
|
809
1062
|
``CPU``
|
|
810
1063
|
|
|
811
1064
|
Examples:
|
|
1065
|
+
>>> import numpy as np
|
|
812
1066
|
>>> import mindspore.dataset as ds
|
|
813
1067
|
>>> import mindspore.dataset.vision as vision
|
|
814
1068
|
>>>
|
|
815
|
-
>>>
|
|
1069
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1070
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1071
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
816
1072
|
>>>
|
|
817
1073
|
>>> # crop image to a square
|
|
818
|
-
>>> transforms_list1 = [vision.
|
|
819
|
-
>>>
|
|
820
|
-
|
|
1074
|
+
>>> transforms_list1 = [vision.CenterCrop(50)]
|
|
1075
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list1, input_columns=["image"])
|
|
1076
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1077
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1078
|
+
... break
|
|
1079
|
+
(50, 50, 3) uint8
|
|
1080
|
+
>>>
|
|
821
1081
|
>>> # crop image to portrait style
|
|
822
|
-
>>>
|
|
823
|
-
>>>
|
|
824
|
-
|
|
1082
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1083
|
+
>>> transforms_list2 = [vision.CenterCrop((60, 40))]
|
|
1084
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list2, input_columns=["image"])
|
|
1085
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1086
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1087
|
+
... break
|
|
1088
|
+
(60, 40, 3) uint8
|
|
1089
|
+
>>>
|
|
1090
|
+
>>> # Use the transform in eager mode
|
|
1091
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
1092
|
+
>>> output = vision.CenterCrop(1)(data)
|
|
1093
|
+
>>> print(output.shape, output.dtype)
|
|
1094
|
+
(1, 1, 3) uint8
|
|
825
1095
|
|
|
826
1096
|
Tutorial Examples:
|
|
827
1097
|
- `Illustration of vision transforms
|
|
828
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1098
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
829
1099
|
"""
|
|
830
1100
|
|
|
831
1101
|
@check_center_crop
|
|
@@ -907,23 +1177,39 @@ class ConvertColor(ImageTensorOperation):
|
|
|
907
1177
|
``CPU``
|
|
908
1178
|
|
|
909
1179
|
Examples:
|
|
1180
|
+
>>> import numpy as np
|
|
910
1181
|
>>> import mindspore.dataset as ds
|
|
911
1182
|
>>> import mindspore.dataset.vision as vision
|
|
912
1183
|
>>>
|
|
913
|
-
>>>
|
|
1184
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1185
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1186
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
914
1187
|
>>>
|
|
915
1188
|
>>> # Convert RGB images to GRAY images
|
|
916
1189
|
>>> convert_op = vision.ConvertColor(vision.ConvertMode.COLOR_RGB2GRAY)
|
|
917
|
-
>>>
|
|
918
|
-
|
|
1190
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=convert_op, input_columns=["image"])
|
|
1191
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1192
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1193
|
+
... break
|
|
1194
|
+
(100, 100) uint8
|
|
919
1195
|
>>> # Convert RGB images to BGR images
|
|
1196
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
920
1197
|
>>> convert_op = vision.ConvertColor(vision.ConvertMode.COLOR_RGB2BGR)
|
|
921
|
-
>>>
|
|
922
|
-
|
|
1198
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=convert_op, input_columns=["image"])
|
|
1199
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1200
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1201
|
+
... break
|
|
1202
|
+
(100, 100, 3) uint8
|
|
1203
|
+
>>>
|
|
1204
|
+
>>> # Use the transform in eager mode
|
|
1205
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
1206
|
+
>>> output = vision.ConvertColor(vision.ConvertMode.COLOR_RGB2GRAY)(data)
|
|
1207
|
+
>>> print(output.shape, output.dtype)
|
|
1208
|
+
(2, 2) uint8
|
|
923
1209
|
|
|
924
1210
|
Tutorial Examples:
|
|
925
1211
|
- `Illustration of vision transforms
|
|
926
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1212
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
927
1213
|
"""
|
|
928
1214
|
|
|
929
1215
|
@check_convert_color
|
|
@@ -940,6 +1226,8 @@ class Crop(ImageTensorOperation):
|
|
|
940
1226
|
"""
|
|
941
1227
|
Crop the input image at a specific location.
|
|
942
1228
|
|
|
1229
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
1230
|
+
|
|
943
1231
|
Args:
|
|
944
1232
|
coordinates(sequence): Coordinates of the upper left corner of the cropping image. Must be a sequence of two
|
|
945
1233
|
values, in the form of (top, left).
|
|
@@ -959,19 +1247,30 @@ class Crop(ImageTensorOperation):
|
|
|
959
1247
|
``CPU``
|
|
960
1248
|
|
|
961
1249
|
Examples:
|
|
1250
|
+
>>> import numpy as np
|
|
962
1251
|
>>> import mindspore.dataset as ds
|
|
963
1252
|
>>> import mindspore.dataset.vision as vision
|
|
964
1253
|
>>>
|
|
965
|
-
>>>
|
|
966
|
-
>>>
|
|
1254
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1255
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1256
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
967
1257
|
>>> crop_op = vision.Crop((0, 0), 32)
|
|
968
|
-
>>> transforms_list = [
|
|
969
|
-
>>>
|
|
970
|
-
|
|
1258
|
+
>>> transforms_list = [crop_op]
|
|
1259
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1260
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1261
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1262
|
+
... break
|
|
1263
|
+
(32, 32, 3) uint8
|
|
1264
|
+
>>>
|
|
1265
|
+
>>> # Use the transform in eager mode
|
|
1266
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
1267
|
+
>>> output = vision.Crop((0, 0), 1)(data)
|
|
1268
|
+
>>> print(output.shape, output.dtype)
|
|
1269
|
+
(1, 1, 3) uint8
|
|
971
1270
|
|
|
972
1271
|
Tutorial Examples:
|
|
973
1272
|
- `Illustration of vision transforms
|
|
974
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1273
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
975
1274
|
"""
|
|
976
1275
|
|
|
977
1276
|
@check_crop
|
|
@@ -983,8 +1282,55 @@ class Crop(ImageTensorOperation):
|
|
|
983
1282
|
self.size = size
|
|
984
1283
|
self.implementation = Implementation.C
|
|
985
1284
|
|
|
1285
|
+
@check_device_target
|
|
1286
|
+
def device(self, device_target="CPU"):
|
|
1287
|
+
"""
|
|
1288
|
+
Set the device for the current operator execution.
|
|
1289
|
+
|
|
1290
|
+
- When the device is Ascend, input/output shape should be limited from [4, 6] to [32768, 32768].
|
|
1291
|
+
|
|
1292
|
+
Args:
|
|
1293
|
+
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
1294
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
1295
|
+
|
|
1296
|
+
Raises:
|
|
1297
|
+
TypeError: If `device_target` is not of type str.
|
|
1298
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
1299
|
+
|
|
1300
|
+
Supported Platforms:
|
|
1301
|
+
``CPU`` ``Ascend``
|
|
1302
|
+
|
|
1303
|
+
Examples:
|
|
1304
|
+
>>> import numpy as np
|
|
1305
|
+
>>> import mindspore.dataset as ds
|
|
1306
|
+
>>> import mindspore.dataset.vision as vision
|
|
1307
|
+
>>>
|
|
1308
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1309
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1310
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1311
|
+
>>> crop_op = vision.Crop((0, 0), (100, 75)).device("Ascend")
|
|
1312
|
+
>>> transforms_list = [crop_op]
|
|
1313
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1314
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1315
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1316
|
+
... break
|
|
1317
|
+
(100, 75, 3) uint8
|
|
1318
|
+
>>>
|
|
1319
|
+
>>> # Use the transform in eager mode
|
|
1320
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
1321
|
+
>>> output = vision.Crop((0, 0), 64).device("Ascend")(data)
|
|
1322
|
+
>>> print(output.shape, output.dtype)
|
|
1323
|
+
(64, 64, 3) uint8
|
|
1324
|
+
|
|
1325
|
+
Tutorial Examples:
|
|
1326
|
+
- `Illustration of vision transforms
|
|
1327
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1328
|
+
"""
|
|
1329
|
+
self.device_target = device_target
|
|
1330
|
+
return self
|
|
1331
|
+
|
|
986
1332
|
def parse(self):
|
|
987
|
-
return cde.CropOperation(self.coordinates, self.size)
|
|
1333
|
+
return cde.CropOperation(self.coordinates, self.size, self.device_target)
|
|
988
1334
|
|
|
989
1335
|
|
|
990
1336
|
class CutMixBatch(ImageTensorOperation):
|
|
@@ -1011,23 +1357,44 @@ class CutMixBatch(ImageTensorOperation):
|
|
|
1011
1357
|
``CPU``
|
|
1012
1358
|
|
|
1013
1359
|
Examples:
|
|
1360
|
+
>>> import numpy as np
|
|
1014
1361
|
>>> import mindspore.dataset as ds
|
|
1015
|
-
>>> import mindspore.dataset.vision as vision
|
|
1016
1362
|
>>> import mindspore.dataset.transforms as transforms
|
|
1363
|
+
>>> import mindspore.dataset.vision as vision
|
|
1017
1364
|
>>> from mindspore.dataset.vision import ImageBatchFormat
|
|
1018
1365
|
>>>
|
|
1019
|
-
>>>
|
|
1366
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1367
|
+
>>> data = np.random.randint(0, 255, size=(28, 28, 3)).astype(np.uint8)
|
|
1368
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1369
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(
|
|
1370
|
+
... operations=lambda img: (data, np.random.randint(0, 5, (3, 1))),
|
|
1371
|
+
... input_columns=["image"],
|
|
1372
|
+
... output_columns=["image", "label"])
|
|
1020
1373
|
>>> onehot_op = transforms.OneHot(num_classes=10)
|
|
1021
|
-
>>>
|
|
1022
|
-
... input_columns=["label"])
|
|
1374
|
+
>>> numpy_slices_dataset= numpy_slices_dataset.map(operations=onehot_op, input_columns=["label"])
|
|
1023
1375
|
>>> cutmix_batch_op = vision.CutMixBatch(ImageBatchFormat.NHWC, 1.0, 0.5)
|
|
1024
|
-
>>>
|
|
1025
|
-
>>>
|
|
1376
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.batch(5)
|
|
1377
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=cutmix_batch_op,
|
|
1026
1378
|
... input_columns=["image", "label"])
|
|
1379
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1380
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1381
|
+
... print(item["label"].shape, item["label"].dtype)
|
|
1382
|
+
... break
|
|
1383
|
+
(5, 28, 28, 3) uint8
|
|
1384
|
+
(5, 3, 10) float32
|
|
1385
|
+
>>>
|
|
1386
|
+
>>> # Use the transform in eager mode
|
|
1387
|
+
>>> data = np.random.randint(0, 255, (3, 3, 10, 10)).astype(np.uint8)
|
|
1388
|
+
>>> label = np.array([[0, 1], [1, 0], [1, 0]])
|
|
1389
|
+
>>> output = vision.CutMixBatch(vision.ImageBatchFormat.NCHW, 1.0, 1.0)(data, label)
|
|
1390
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
1391
|
+
(3, 3, 10, 10) uint8
|
|
1392
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
1393
|
+
(3, 2) float32
|
|
1027
1394
|
|
|
1028
1395
|
Tutorial Examples:
|
|
1029
1396
|
- `Illustration of vision transforms
|
|
1030
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1397
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1031
1398
|
"""
|
|
1032
1399
|
|
|
1033
1400
|
@check_cut_mix_batch_c
|
|
@@ -1064,17 +1431,29 @@ class CutOut(ImageTensorOperation):
|
|
|
1064
1431
|
``CPU``
|
|
1065
1432
|
|
|
1066
1433
|
Examples:
|
|
1434
|
+
>>> import numpy as np
|
|
1067
1435
|
>>> import mindspore.dataset as ds
|
|
1068
1436
|
>>> import mindspore.dataset.vision as vision
|
|
1069
1437
|
>>>
|
|
1070
|
-
>>>
|
|
1071
|
-
>>>
|
|
1072
|
-
>>>
|
|
1073
|
-
|
|
1438
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1439
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1440
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1441
|
+
>>> transforms_list = [vision.CutOut(80, num_patches=10)]
|
|
1442
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1443
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1444
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1445
|
+
... break
|
|
1446
|
+
(100, 100, 3) uint8
|
|
1447
|
+
>>>
|
|
1448
|
+
>>> # Use the transform in eager mode
|
|
1449
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
1450
|
+
>>> output = vision.CutOut(20)(data)
|
|
1451
|
+
>>> print(output.shape, output.dtype)
|
|
1452
|
+
(100, 100, 3) uint8
|
|
1074
1453
|
|
|
1075
1454
|
Tutorial Examples:
|
|
1076
1455
|
- `Illustration of vision transforms
|
|
1077
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1456
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1078
1457
|
"""
|
|
1079
1458
|
|
|
1080
1459
|
@check_cutout_new
|
|
@@ -1095,6 +1474,8 @@ class Decode(ImageTensorOperation, PyTensorOperation):
|
|
|
1095
1474
|
Decode the input image in RGB mode.
|
|
1096
1475
|
Supported image formats: JPEG, BMP, PNG, TIFF, GIF(need `to_pil=True` ), WEBP(need `to_pil=True` ).
|
|
1097
1476
|
|
|
1477
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
1478
|
+
|
|
1098
1479
|
Args:
|
|
1099
1480
|
to_pil (bool, optional): Whether to decode the image to the PIL data type. If ``True``,
|
|
1100
1481
|
the image will be decoded to the PIL data type, otherwise it will be decoded to the
|
|
@@ -1109,23 +1490,53 @@ class Decode(ImageTensorOperation, PyTensorOperation):
|
|
|
1109
1490
|
``CPU`` ``Ascend``
|
|
1110
1491
|
|
|
1111
1492
|
Examples:
|
|
1493
|
+
>>> import os
|
|
1494
|
+
>>> import numpy as np
|
|
1495
|
+
>>> from PIL import Image, ImageDraw
|
|
1112
1496
|
>>> import mindspore.dataset as ds
|
|
1113
1497
|
>>> import mindspore.dataset.vision as vision
|
|
1114
1498
|
>>>
|
|
1115
|
-
>>> #
|
|
1116
|
-
>>>
|
|
1117
|
-
|
|
1118
|
-
|
|
1499
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1500
|
+
>>> class MyDataset:
|
|
1501
|
+
... def __init__(self):
|
|
1502
|
+
... self.data = []
|
|
1503
|
+
... img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
1504
|
+
... draw = ImageDraw.Draw(img)
|
|
1505
|
+
... draw.ellipse(((0, 0), (100, 100)), fill=(255, 0, 0), outline=(255, 0, 0), width=5)
|
|
1506
|
+
... img.save("./1.jpg")
|
|
1507
|
+
... data = np.fromfile("./1.jpg", np.uint8)
|
|
1508
|
+
... self.data.append(data)
|
|
1509
|
+
...
|
|
1510
|
+
... def __getitem__(self, index):
|
|
1511
|
+
... return self.data[0]
|
|
1512
|
+
...
|
|
1513
|
+
... def __len__(self):
|
|
1514
|
+
... return 5
|
|
1119
1515
|
>>>
|
|
1120
|
-
>>>
|
|
1121
|
-
>>>
|
|
1516
|
+
>>> my_dataset = MyDataset()
|
|
1517
|
+
>>> generator_dataset = ds.GeneratorDataset(my_dataset, column_names="image")
|
|
1122
1518
|
>>> transforms_list = [vision.Decode(), vision.RandomHorizontalFlip()]
|
|
1123
|
-
>>>
|
|
1124
|
-
|
|
1519
|
+
>>> generator_dataset = generator_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1520
|
+
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1521
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1522
|
+
... break
|
|
1523
|
+
(300, 300, 3) uint8
|
|
1524
|
+
>>> os.remove("./1.jpg")
|
|
1525
|
+
>>>
|
|
1526
|
+
>>> # Use the transform in eager mode
|
|
1527
|
+
>>> img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
1528
|
+
>>> draw = ImageDraw.Draw(img)
|
|
1529
|
+
>>> draw.polygon([(50, 50), (150, 50), (100, 150)], fill=(0, 255, 0), outline=(0, 255, 0))
|
|
1530
|
+
>>> img.save("./2.jpg")
|
|
1531
|
+
>>> data = np.fromfile("./2.jpg", np.uint8)
|
|
1532
|
+
>>> output = vision.Decode()(data)
|
|
1533
|
+
>>> print(output.shape, output.dtype)
|
|
1534
|
+
(300, 300, 3) uint8
|
|
1535
|
+
>>> os.remove("./2.jpg")
|
|
1125
1536
|
|
|
1126
1537
|
Tutorial Examples:
|
|
1127
1538
|
- `Illustration of vision transforms
|
|
1128
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1539
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1129
1540
|
"""
|
|
1130
1541
|
|
|
1131
1542
|
@check_decode
|
|
@@ -1159,31 +1570,71 @@ class Decode(ImageTensorOperation, PyTensorOperation):
|
|
|
1159
1570
|
|
|
1160
1571
|
Args:
|
|
1161
1572
|
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
1162
|
-
``CPU`` . Default: ``CPU`` .
|
|
1573
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
1163
1574
|
|
|
1164
1575
|
Raises:
|
|
1165
1576
|
TypeError: If `device_target` is not of type str.
|
|
1166
|
-
ValueError: If `device_target` is not
|
|
1577
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
1167
1578
|
|
|
1168
1579
|
Supported Platforms:
|
|
1169
|
-
``CPU``
|
|
1580
|
+
``CPU`` ``Ascend``
|
|
1170
1581
|
|
|
1171
1582
|
Examples:
|
|
1583
|
+
>>> import os
|
|
1584
|
+
>>> import numpy as np
|
|
1585
|
+
>>> from PIL import Image, ImageDraw
|
|
1172
1586
|
>>> import mindspore.dataset as ds
|
|
1173
1587
|
>>> import mindspore.dataset.vision as vision
|
|
1174
1588
|
>>> from mindspore.dataset.vision import Inter
|
|
1175
1589
|
>>>
|
|
1590
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1591
|
+
>>> class MyDataset:
|
|
1592
|
+
... def __init__(self):
|
|
1593
|
+
... self.data = []
|
|
1594
|
+
... img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
1595
|
+
... draw = ImageDraw.Draw(img)
|
|
1596
|
+
... draw.ellipse(((0, 0), (100, 100)), fill=(255, 0, 0), outline=(255, 0, 0), width=5)
|
|
1597
|
+
... img.save("./1.jpg")
|
|
1598
|
+
... data = np.fromfile("./1.jpg", np.uint8)
|
|
1599
|
+
... self.data.append(data)
|
|
1600
|
+
...
|
|
1601
|
+
... def __getitem__(self, index):
|
|
1602
|
+
... return self.data[0]
|
|
1603
|
+
...
|
|
1604
|
+
... def __len__(self):
|
|
1605
|
+
... return 5
|
|
1606
|
+
>>>
|
|
1607
|
+
>>> my_dataset = MyDataset()
|
|
1608
|
+
>>> generator_dataset = ds.GeneratorDataset(my_dataset, column_names="image")
|
|
1176
1609
|
>>> decode_op = vision.Decode().device("Ascend")
|
|
1177
1610
|
>>> resize_op = vision.Resize([100, 75], Inter.BICUBIC)
|
|
1178
1611
|
>>> transforms_list = [decode_op, resize_op]
|
|
1179
|
-
>>>
|
|
1180
|
-
>>>
|
|
1181
|
-
...
|
|
1612
|
+
>>> generator_dataset = generator_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1613
|
+
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1614
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1615
|
+
... break
|
|
1616
|
+
(100, 75, 3) uint8
|
|
1617
|
+
>>> os.remove("./1.jpg")
|
|
1618
|
+
>>>
|
|
1619
|
+
>>> # Use the transform in eager mode
|
|
1620
|
+
>>> img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
1621
|
+
>>> draw = ImageDraw.Draw(img)
|
|
1622
|
+
>>> draw.polygon([(50, 50), (150, 50), (100, 150)], fill=(0, 255, 0), outline=(0, 255, 0))
|
|
1623
|
+
>>> img.save("./2.jpg")
|
|
1624
|
+
>>> data = np.fromfile("./2.jpg", np.uint8)
|
|
1625
|
+
>>> output = vision.Decode().device("Ascend")(data)
|
|
1626
|
+
>>> print(output.shape, output.dtype)
|
|
1627
|
+
(300, 300, 3) uint8
|
|
1628
|
+
>>> os.remove("./2.jpg")
|
|
1182
1629
|
|
|
1183
1630
|
Tutorial Examples:
|
|
1184
1631
|
- `Illustration of vision transforms
|
|
1185
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1632
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1186
1633
|
"""
|
|
1634
|
+
if self.implementation == Implementation.PY and device_target == "Ascend":
|
|
1635
|
+
raise ValueError("The transform \"Decode(to_pil=True)\" cannot be performed on Ascend device, " +
|
|
1636
|
+
"please set \"to_pil=False\".")
|
|
1637
|
+
|
|
1187
1638
|
self.device_target = device_target
|
|
1188
1639
|
return self
|
|
1189
1640
|
|
|
@@ -1214,17 +1665,29 @@ class Equalize(ImageTensorOperation, PyTensorOperation):
|
|
|
1214
1665
|
``CPU``
|
|
1215
1666
|
|
|
1216
1667
|
Examples:
|
|
1668
|
+
>>> import numpy as np
|
|
1217
1669
|
>>> import mindspore.dataset as ds
|
|
1218
1670
|
>>> import mindspore.dataset.vision as vision
|
|
1219
1671
|
>>>
|
|
1220
|
-
>>>
|
|
1221
|
-
>>>
|
|
1222
|
-
>>>
|
|
1223
|
-
|
|
1672
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1673
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1674
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1675
|
+
>>> transforms_list = [vision.Equalize()]
|
|
1676
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1677
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1678
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1679
|
+
... break
|
|
1680
|
+
(100, 100, 3) uint8
|
|
1681
|
+
>>>
|
|
1682
|
+
>>> # Use the transform in eager mode
|
|
1683
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
1684
|
+
>>> output = vision.Equalize()(data)
|
|
1685
|
+
>>> print(output.shape, output.dtype)
|
|
1686
|
+
(2, 2, 3) uint8
|
|
1224
1687
|
|
|
1225
1688
|
Tutorial Examples:
|
|
1226
1689
|
- `Illustration of vision transforms
|
|
1227
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1690
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1228
1691
|
"""
|
|
1229
1692
|
|
|
1230
1693
|
def __init__(self):
|
|
@@ -1280,17 +1743,29 @@ class Erase(ImageTensorOperation):
|
|
|
1280
1743
|
``CPU``
|
|
1281
1744
|
|
|
1282
1745
|
Examples:
|
|
1746
|
+
>>> import numpy as np
|
|
1283
1747
|
>>> import mindspore.dataset as ds
|
|
1284
1748
|
>>> import mindspore.dataset.vision as vision
|
|
1285
1749
|
>>>
|
|
1286
|
-
>>>
|
|
1287
|
-
>>>
|
|
1288
|
-
>>>
|
|
1289
|
-
|
|
1750
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1751
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1752
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1753
|
+
>>> transforms_list = [vision.Erase(10,10,10,10)]
|
|
1754
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1755
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1756
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1757
|
+
... break
|
|
1758
|
+
(100, 100, 3) uint8
|
|
1759
|
+
>>>
|
|
1760
|
+
>>> # Use the transform in eager mode
|
|
1761
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
1762
|
+
>>> output = vision.Erase(0, 0, 2, 1)(data)
|
|
1763
|
+
>>> print(output.shape, output.dtype)
|
|
1764
|
+
(2, 2, 3) uint8
|
|
1290
1765
|
|
|
1291
1766
|
Tutorial Examples:
|
|
1292
1767
|
- `Illustration of vision transforms
|
|
1293
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1768
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1294
1769
|
"""
|
|
1295
1770
|
|
|
1296
1771
|
@check_erase
|
|
@@ -1326,23 +1801,59 @@ class FiveCrop(PyTensorOperation):
|
|
|
1326
1801
|
``CPU``
|
|
1327
1802
|
|
|
1328
1803
|
Examples:
|
|
1804
|
+
>>> import os
|
|
1805
|
+
>>> import numpy as np
|
|
1806
|
+
>>> from PIL import Image, ImageDraw
|
|
1329
1807
|
>>> import mindspore.dataset as ds
|
|
1330
1808
|
>>> import mindspore.dataset.vision as vision
|
|
1331
|
-
>>> import numpy
|
|
1332
1809
|
>>> from mindspore.dataset.transforms import Compose
|
|
1333
1810
|
>>>
|
|
1811
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1812
|
+
>>> class MyDataset:
|
|
1813
|
+
... def __init__(self):
|
|
1814
|
+
... self.data = []
|
|
1815
|
+
... img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
1816
|
+
... draw = ImageDraw.Draw(img)
|
|
1817
|
+
... draw.ellipse(((0, 0), (100, 100)), fill=(255, 0, 0), outline=(255, 0, 0), width=5)
|
|
1818
|
+
... img.save("./1.jpg")
|
|
1819
|
+
... data = np.fromfile("./1.jpg", np.uint8)
|
|
1820
|
+
... self.data.append(data)
|
|
1821
|
+
...
|
|
1822
|
+
... def __getitem__(self, index):
|
|
1823
|
+
... return self.data[0]
|
|
1824
|
+
...
|
|
1825
|
+
... def __len__(self):
|
|
1826
|
+
... return 5
|
|
1827
|
+
>>>
|
|
1828
|
+
>>> my_dataset = MyDataset()
|
|
1829
|
+
>>> generator_dataset = ds.GeneratorDataset(my_dataset, column_names="image")
|
|
1334
1830
|
>>> transforms_list = Compose([vision.Decode(to_pil=True),
|
|
1335
1831
|
... vision.FiveCrop(size=200),
|
|
1336
1832
|
... # 4D stack of 5 images
|
|
1337
|
-
... lambda *images:
|
|
1833
|
+
... lambda *images: np.stack([vision.ToTensor()(image) for image in images])])
|
|
1338
1834
|
>>> # apply the transform to dataset through map function
|
|
1339
|
-
>>>
|
|
1340
|
-
>>>
|
|
1341
|
-
...
|
|
1835
|
+
>>> generator_dataset = generator_dataset.map(operations=transforms_list, input_columns="image")
|
|
1836
|
+
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1837
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1838
|
+
... break
|
|
1839
|
+
(5, 3, 200, 200) float32
|
|
1840
|
+
>>> os.remove("./1.jpg")
|
|
1841
|
+
>>>
|
|
1842
|
+
>>> # Use the transform in eager mode
|
|
1843
|
+
>>> img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
1844
|
+
>>> draw = ImageDraw.Draw(img)
|
|
1845
|
+
>>> draw.polygon([(50, 50), (150, 50), (100, 150)], fill=(0, 255, 0), outline=(0, 255, 0))
|
|
1846
|
+
>>> img.save("./2.jpg")
|
|
1847
|
+
>>> data = Image.open("./2.jpg")
|
|
1848
|
+
>>> output = vision.FiveCrop(size=20)(data)
|
|
1849
|
+
>>> print(np.array(output).shape, np.array(output).dtype)
|
|
1850
|
+
(5,) object
|
|
1851
|
+
>>> os.remove("./2.jpg")
|
|
1852
|
+
|
|
1342
1853
|
|
|
1343
1854
|
Tutorial Examples:
|
|
1344
1855
|
- `Illustration of vision transforms
|
|
1345
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1856
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1346
1857
|
"""
|
|
1347
1858
|
|
|
1348
1859
|
@check_five_crop
|
|
@@ -1369,6 +1880,8 @@ class GaussianBlur(ImageTensorOperation):
|
|
|
1369
1880
|
r"""
|
|
1370
1881
|
Blur input image with the specified Gaussian kernel.
|
|
1371
1882
|
|
|
1883
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
1884
|
+
|
|
1372
1885
|
Args:
|
|
1373
1886
|
kernel_size (Union[int, Sequence[int, int]]): The size of the Gaussian kernel. Must be positive and odd.
|
|
1374
1887
|
If the input type is int, the value will be used as both the width and height of the Gaussian kernel.
|
|
@@ -1394,17 +1907,29 @@ class GaussianBlur(ImageTensorOperation):
|
|
|
1394
1907
|
``CPU``
|
|
1395
1908
|
|
|
1396
1909
|
Examples:
|
|
1910
|
+
>>> import numpy as np
|
|
1397
1911
|
>>> import mindspore.dataset as ds
|
|
1398
1912
|
>>> import mindspore.dataset.vision as vision
|
|
1399
1913
|
>>>
|
|
1400
|
-
>>>
|
|
1401
|
-
>>>
|
|
1402
|
-
>>>
|
|
1403
|
-
|
|
1914
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1915
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1916
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1917
|
+
>>> transforms_list = [vision.GaussianBlur(3, 3)]
|
|
1918
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1919
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1920
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1921
|
+
... break
|
|
1922
|
+
(100, 100, 3) uint8
|
|
1923
|
+
>>>
|
|
1924
|
+
>>> # Use the transform in eager mode
|
|
1925
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
1926
|
+
>>> output = vision.GaussianBlur(3, 3)(data)
|
|
1927
|
+
>>> print(output.shape, output.dtype)
|
|
1928
|
+
(2, 2, 3) uint8
|
|
1404
1929
|
|
|
1405
1930
|
Tutorial Examples:
|
|
1406
1931
|
- `Illustration of vision transforms
|
|
1407
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
1932
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1408
1933
|
"""
|
|
1409
1934
|
|
|
1410
1935
|
@check_gaussian_blur
|
|
@@ -1420,8 +1945,60 @@ class GaussianBlur(ImageTensorOperation):
|
|
|
1420
1945
|
self.sigma = sigma
|
|
1421
1946
|
self.implementation = Implementation.C
|
|
1422
1947
|
|
|
1948
|
+
@check_device_target
|
|
1949
|
+
def device(self, device_target="CPU"):
|
|
1950
|
+
"""
|
|
1951
|
+
Set the device for the current operator execution.
|
|
1952
|
+
|
|
1953
|
+
- When the device is Ascend, the parameter `kernel_size` only supports values 1, 3, and 5.
|
|
1954
|
+
input shape should be limited from [4, 6] to [8192, 4096].
|
|
1955
|
+
|
|
1956
|
+
Args:
|
|
1957
|
+
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
1958
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
1959
|
+
|
|
1960
|
+
Raises:
|
|
1961
|
+
TypeError: If `device_target` is not of type str.
|
|
1962
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
1963
|
+
|
|
1964
|
+
Supported Platforms:
|
|
1965
|
+
``CPU`` ``Ascend``
|
|
1966
|
+
|
|
1967
|
+
Examples:
|
|
1968
|
+
>>> import numpy as np
|
|
1969
|
+
>>> import mindspore.dataset as ds
|
|
1970
|
+
>>> import mindspore.dataset.vision as vision
|
|
1971
|
+
>>>
|
|
1972
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1973
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
1974
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1975
|
+
>>> blur_op = vision.GaussianBlur(3, 3).device("Ascend")
|
|
1976
|
+
>>> transforms_list = [blur_op]
|
|
1977
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1978
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
1979
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
1980
|
+
... break
|
|
1981
|
+
(100, 100, 3) uint8
|
|
1982
|
+
>>>
|
|
1983
|
+
>>> # Use the transform in eager mode
|
|
1984
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
1985
|
+
>>> output = vision.GaussianBlur(3, 3).device("Ascend")(data)
|
|
1986
|
+
>>> print(output.shape, output.dtype)
|
|
1987
|
+
(100, 100, 3) uint8
|
|
1988
|
+
|
|
1989
|
+
Tutorial Examples:
|
|
1990
|
+
- `Illustration of vision transforms
|
|
1991
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1992
|
+
"""
|
|
1993
|
+
self.device_target = device_target
|
|
1994
|
+
if device_target == "Ascend":
|
|
1995
|
+
for k in self.kernel_size:
|
|
1996
|
+
if k not in [1, 3, 5]:
|
|
1997
|
+
raise RuntimeError("When target is Ascend, `kernel_size` only supports values 1, 3, and 5.")
|
|
1998
|
+
return self
|
|
1999
|
+
|
|
1423
2000
|
def parse(self):
|
|
1424
|
-
return cde.GaussianBlurOperation(self.kernel_size, self.sigma)
|
|
2001
|
+
return cde.GaussianBlurOperation(self.kernel_size, self.sigma, self.device_target)
|
|
1425
2002
|
|
|
1426
2003
|
|
|
1427
2004
|
class Grayscale(PyTensorOperation):
|
|
@@ -1440,21 +2017,57 @@ class Grayscale(PyTensorOperation):
|
|
|
1440
2017
|
``CPU``
|
|
1441
2018
|
|
|
1442
2019
|
Examples:
|
|
2020
|
+
>>> import os
|
|
2021
|
+
>>> import numpy as np
|
|
2022
|
+
>>> from PIL import Image, ImageDraw
|
|
1443
2023
|
>>> import mindspore.dataset as ds
|
|
1444
2024
|
>>> import mindspore.dataset.vision as vision
|
|
1445
2025
|
>>> from mindspore.dataset.transforms import Compose
|
|
1446
2026
|
>>>
|
|
2027
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2028
|
+
>>> class MyDataset:
|
|
2029
|
+
... def __init__(self):
|
|
2030
|
+
... self.data = []
|
|
2031
|
+
... img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
2032
|
+
... draw = ImageDraw.Draw(img)
|
|
2033
|
+
... draw.ellipse(((0, 0), (100, 100)), fill=(255, 0, 0), outline=(255, 0, 0), width=5)
|
|
2034
|
+
... img.save("./1.jpg")
|
|
2035
|
+
... data = np.fromfile("./1.jpg", np.uint8)
|
|
2036
|
+
... self.data.append(data)
|
|
2037
|
+
...
|
|
2038
|
+
... def __getitem__(self, index):
|
|
2039
|
+
... return self.data[0]
|
|
2040
|
+
...
|
|
2041
|
+
... def __len__(self):
|
|
2042
|
+
... return 5
|
|
2043
|
+
>>>
|
|
2044
|
+
>>> my_dataset = MyDataset()
|
|
2045
|
+
>>> generator_dataset = ds.GeneratorDataset(my_dataset, column_names="image")
|
|
1447
2046
|
>>> transforms_list = Compose([vision.Decode(to_pil=True),
|
|
1448
2047
|
... vision.Grayscale(3),
|
|
1449
2048
|
... vision.ToTensor()])
|
|
1450
2049
|
>>> # apply the transform to dataset through map function
|
|
1451
|
-
>>>
|
|
1452
|
-
>>>
|
|
1453
|
-
...
|
|
2050
|
+
>>> generator_dataset = generator_dataset.map(operations=transforms_list, input_columns="image")
|
|
2051
|
+
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2052
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2053
|
+
... break
|
|
2054
|
+
(3, 300, 300) float32
|
|
2055
|
+
>>> os.remove("./1.jpg")
|
|
2056
|
+
>>>
|
|
2057
|
+
>>> # Use the transform in eager mode
|
|
2058
|
+
>>> img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
2059
|
+
>>> draw = ImageDraw.Draw(img)
|
|
2060
|
+
>>> draw.polygon([(50, 50), (150, 50), (100, 150)], fill=(0, 255, 0), outline=(0, 255, 0))
|
|
2061
|
+
>>> img.save("./2.jpg")
|
|
2062
|
+
>>> data = Image.open("./2.jpg")
|
|
2063
|
+
>>> output = vision.Grayscale(3)(data)
|
|
2064
|
+
>>> print(np.array(output).shape, np.array(output).dtype)
|
|
2065
|
+
(300, 300, 3) uint8
|
|
2066
|
+
>>> os.remove("./2.jpg")
|
|
1454
2067
|
|
|
1455
2068
|
Tutorial Examples:
|
|
1456
2069
|
- `Illustration of vision transforms
|
|
1457
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2070
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1458
2071
|
"""
|
|
1459
2072
|
|
|
1460
2073
|
@check_num_channels
|
|
@@ -1488,25 +2101,84 @@ class HorizontalFlip(ImageTensorOperation):
|
|
|
1488
2101
|
``CPU``
|
|
1489
2102
|
|
|
1490
2103
|
Examples:
|
|
2104
|
+
>>> import numpy as np
|
|
1491
2105
|
>>> import mindspore.dataset as ds
|
|
1492
2106
|
>>> import mindspore.dataset.vision as vision
|
|
1493
2107
|
>>>
|
|
1494
|
-
>>>
|
|
1495
|
-
>>>
|
|
1496
|
-
>>>
|
|
1497
|
-
|
|
2108
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2109
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2110
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2111
|
+
>>> transforms_list = [vision.HorizontalFlip()]
|
|
2112
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
2113
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2114
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2115
|
+
... break
|
|
2116
|
+
(100, 100, 3) uint8
|
|
2117
|
+
>>>
|
|
2118
|
+
>>> # Use the transform in eager mode
|
|
2119
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
2120
|
+
>>> output = vision.HorizontalFlip()(data)
|
|
2121
|
+
>>> print(output.shape, output.dtype)
|
|
2122
|
+
(2, 2, 3) uint8
|
|
1498
2123
|
|
|
1499
2124
|
Tutorial Examples:
|
|
1500
2125
|
- `Illustration of vision transforms
|
|
1501
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2126
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1502
2127
|
"""
|
|
1503
2128
|
|
|
1504
2129
|
def __init__(self):
|
|
1505
2130
|
super().__init__()
|
|
1506
2131
|
self.implementation = Implementation.C
|
|
1507
2132
|
|
|
2133
|
+
@check_device_target
|
|
2134
|
+
def device(self, device_target="CPU"):
|
|
2135
|
+
"""
|
|
2136
|
+
Set the device for the current operator execution.
|
|
2137
|
+
|
|
2138
|
+
- When the device is Ascend, input shape should be limited from [4, 6] to [8192, 4096].
|
|
2139
|
+
|
|
2140
|
+
Args:
|
|
2141
|
+
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
2142
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
2143
|
+
|
|
2144
|
+
Raises:
|
|
2145
|
+
TypeError: If `device_target` is not of type str.
|
|
2146
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
2147
|
+
|
|
2148
|
+
Supported Platforms:
|
|
2149
|
+
``CPU`` ``Ascend``
|
|
2150
|
+
|
|
2151
|
+
Examples:
|
|
2152
|
+
>>> import numpy as np
|
|
2153
|
+
>>> import mindspore.dataset as ds
|
|
2154
|
+
>>> import mindspore.dataset.vision as vision
|
|
2155
|
+
>>>
|
|
2156
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2157
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2158
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2159
|
+
>>> horizontal_flip_op = vision.HorizontalFlip().device("Ascend")
|
|
2160
|
+
>>> transforms_list = [horizontal_flip_op]
|
|
2161
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
2162
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2163
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2164
|
+
... break
|
|
2165
|
+
(100, 100, 3) uint8
|
|
2166
|
+
>>>
|
|
2167
|
+
>>> # Use the transform in eager mode
|
|
2168
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
2169
|
+
>>> output = vision.HorizontalFlip().device("Ascend")(data)
|
|
2170
|
+
>>> print(output.shape, output.dtype)
|
|
2171
|
+
(100, 100, 3) uint8
|
|
2172
|
+
|
|
2173
|
+
Tutorial Examples:
|
|
2174
|
+
- `Illustration of vision transforms
|
|
2175
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2176
|
+
"""
|
|
2177
|
+
self.device_target = device_target
|
|
2178
|
+
return self
|
|
2179
|
+
|
|
1508
2180
|
def parse(self):
|
|
1509
|
-
return cde.HorizontalFlipOperation()
|
|
2181
|
+
return cde.HorizontalFlipOperation(self.device_target)
|
|
1510
2182
|
|
|
1511
2183
|
|
|
1512
2184
|
class HsvToRgb(PyTensorOperation):
|
|
@@ -1524,22 +2196,33 @@ class HsvToRgb(PyTensorOperation):
|
|
|
1524
2196
|
``CPU``
|
|
1525
2197
|
|
|
1526
2198
|
Examples:
|
|
2199
|
+
>>> import numpy as np
|
|
1527
2200
|
>>> import mindspore.dataset as ds
|
|
1528
2201
|
>>> import mindspore.dataset.vision as vision
|
|
1529
2202
|
>>> from mindspore.dataset.transforms import Compose
|
|
1530
2203
|
>>>
|
|
1531
|
-
>>>
|
|
1532
|
-
|
|
2204
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2205
|
+
>>> transforms_list = Compose([vision.CenterCrop(20),
|
|
1533
2206
|
... vision.ToTensor(),
|
|
1534
2207
|
... vision.HsvToRgb()])
|
|
1535
2208
|
>>> # apply the transform to dataset through map function
|
|
1536
|
-
>>>
|
|
1537
|
-
>>>
|
|
1538
|
-
|
|
2209
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2210
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2211
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
2212
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2213
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2214
|
+
... break
|
|
2215
|
+
(3, 20, 20) float64
|
|
2216
|
+
>>>
|
|
2217
|
+
>>> # Use the transform in eager mode
|
|
2218
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
2219
|
+
>>> output = vision.HsvToRgb(is_hwc=True)(data)
|
|
2220
|
+
>>> print(output.shape, output.dtype)
|
|
2221
|
+
(2, 2, 3) float64
|
|
1539
2222
|
|
|
1540
2223
|
Tutorial Examples:
|
|
1541
2224
|
- `Illustration of vision transforms
|
|
1542
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2225
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1543
2226
|
"""
|
|
1544
2227
|
|
|
1545
2228
|
@check_hsv_to_rgb
|
|
@@ -1578,20 +2261,31 @@ class HWC2CHW(ImageTensorOperation):
|
|
|
1578
2261
|
``CPU`` ``GPU`` ``Ascend``
|
|
1579
2262
|
|
|
1580
2263
|
Examples:
|
|
2264
|
+
>>> import numpy as np
|
|
1581
2265
|
>>> import mindspore.dataset as ds
|
|
1582
2266
|
>>> import mindspore.dataset.vision as vision
|
|
1583
2267
|
>>>
|
|
1584
|
-
>>>
|
|
1585
|
-
>>>
|
|
1586
|
-
|
|
1587
|
-
|
|
2268
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2269
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2270
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2271
|
+
>>> transforms_list = [vision.RandomHorizontalFlip(0.75),
|
|
2272
|
+
... vision.RandomCrop(64),
|
|
1588
2273
|
... vision.HWC2CHW()]
|
|
1589
|
-
>>>
|
|
1590
|
-
|
|
2274
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
2275
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2276
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2277
|
+
... break
|
|
2278
|
+
(3, 64, 64) uint8
|
|
2279
|
+
>>>
|
|
2280
|
+
>>> # Use the transform in eager mode
|
|
2281
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
2282
|
+
>>> output = vision.HWC2CHW()(data)
|
|
2283
|
+
>>> print(output.shape, output.dtype)
|
|
2284
|
+
(3, 2, 2) uint8
|
|
1591
2285
|
|
|
1592
2286
|
Tutorial Examples:
|
|
1593
2287
|
- `Illustration of vision transforms
|
|
1594
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2288
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1595
2289
|
"""
|
|
1596
2290
|
|
|
1597
2291
|
def __init__(self):
|
|
@@ -1617,17 +2311,29 @@ class Invert(ImageTensorOperation, PyTensorOperation):
|
|
|
1617
2311
|
``CPU``
|
|
1618
2312
|
|
|
1619
2313
|
Examples:
|
|
2314
|
+
>>> import numpy as np
|
|
1620
2315
|
>>> import mindspore.dataset as ds
|
|
1621
2316
|
>>> import mindspore.dataset.vision as vision
|
|
1622
2317
|
>>>
|
|
1623
|
-
>>>
|
|
1624
|
-
>>>
|
|
1625
|
-
>>>
|
|
1626
|
-
|
|
2318
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2319
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2320
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2321
|
+
>>> transforms_list = [vision.Invert()]
|
|
2322
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
2323
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2324
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2325
|
+
... break
|
|
2326
|
+
(100, 100, 3) uint8
|
|
2327
|
+
>>>
|
|
2328
|
+
>>> # Use the transform in eager mode
|
|
2329
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 2, 3))
|
|
2330
|
+
>>> output = vision.Invert()(data)
|
|
2331
|
+
>>> print(output.shape, output.dtype)
|
|
2332
|
+
(2, 2, 3) uint8
|
|
1627
2333
|
|
|
1628
2334
|
Tutorial Examples:
|
|
1629
2335
|
- `Illustration of vision transforms
|
|
1630
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2336
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1631
2337
|
"""
|
|
1632
2338
|
|
|
1633
2339
|
def __init__(self):
|
|
@@ -1671,27 +2377,39 @@ class LinearTransformation(PyTensorOperation):
|
|
|
1671
2377
|
``CPU``
|
|
1672
2378
|
|
|
1673
2379
|
Examples:
|
|
2380
|
+
>>> import numpy as np
|
|
1674
2381
|
>>> import mindspore.dataset as ds
|
|
1675
2382
|
>>> import mindspore.dataset.vision as vision
|
|
1676
|
-
>>> import numpy as np
|
|
1677
2383
|
>>> from mindspore.dataset.transforms import Compose
|
|
1678
2384
|
>>>
|
|
2385
|
+
>>> # Use the transform in dataset pipeline mode
|
|
1679
2386
|
>>> height, width = 32, 32
|
|
1680
2387
|
>>> dim = 3 * height * width
|
|
1681
2388
|
>>> transformation_matrix = np.ones([dim, dim])
|
|
1682
2389
|
>>> mean_vector = np.zeros(dim)
|
|
1683
|
-
>>> transforms_list = Compose([vision.
|
|
1684
|
-
... vision.Resize((height,width)),
|
|
2390
|
+
>>> transforms_list = Compose([vision.Resize((height,width)),
|
|
1685
2391
|
... vision.ToTensor(),
|
|
1686
2392
|
... vision.LinearTransformation(transformation_matrix, mean_vector)])
|
|
1687
2393
|
>>> # apply the transform to dataset through map function
|
|
1688
|
-
>>>
|
|
1689
|
-
>>>
|
|
1690
|
-
|
|
2394
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2395
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2396
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
2397
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2398
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2399
|
+
... break
|
|
2400
|
+
(3, 32, 32) float64
|
|
2401
|
+
>>>
|
|
2402
|
+
>>> # Use the transform in eager mode
|
|
2403
|
+
>>> data = np.random.randn(10, 10, 3)
|
|
2404
|
+
>>> transformation_matrix = np.random.randn(300, 300)
|
|
2405
|
+
>>> mean_vector = np.random.randn(300,)
|
|
2406
|
+
>>> output = vision.LinearTransformation(transformation_matrix, mean_vector)(data)
|
|
2407
|
+
>>> print(output.shape, output.dtype)
|
|
2408
|
+
(10, 10, 3) float64
|
|
1691
2409
|
|
|
1692
2410
|
Tutorial Examples:
|
|
1693
2411
|
- `Illustration of vision transforms
|
|
1694
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2412
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1695
2413
|
"""
|
|
1696
2414
|
|
|
1697
2415
|
@check_linear_transform
|
|
@@ -1741,28 +2459,45 @@ class MixUp(PyTensorOperation):
|
|
|
1741
2459
|
``CPU``
|
|
1742
2460
|
|
|
1743
2461
|
Examples:
|
|
2462
|
+
>>> import numpy as np
|
|
1744
2463
|
>>> import mindspore.dataset as ds
|
|
1745
2464
|
>>> import mindspore.dataset.vision as vision
|
|
1746
2465
|
>>> import mindspore.dataset.transforms as transforms
|
|
1747
2466
|
>>>
|
|
1748
|
-
>>>
|
|
1749
|
-
>>>
|
|
1750
|
-
>>>
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
...
|
|
2467
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2468
|
+
>>> data = np.random.randint(0, 255, size=(64, 64, 3)).astype(np.uint8)
|
|
2469
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2470
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(
|
|
2471
|
+
... operations=lambda img: (data, np.random.randint(0, 5, (3, 1))),
|
|
2472
|
+
... input_columns=["image"],
|
|
2473
|
+
... output_columns=["image", "label"])
|
|
2474
|
+
>>> # ont hot decode the label
|
|
2475
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms.OneHot(10), input_columns="label")
|
|
1755
2476
|
>>> # batch the samples
|
|
1756
|
-
>>>
|
|
1757
|
-
>>> image_folder_dataset = image_folder_dataset.batch(batch_size=batch_size)
|
|
2477
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.batch(batch_size=4)
|
|
1758
2478
|
>>> # finally mix up the images and labels
|
|
1759
|
-
>>>
|
|
1760
|
-
... operations=vision.MixUp(batch_size=
|
|
2479
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(
|
|
2480
|
+
... operations=vision.MixUp(batch_size=1, alpha=0.2),
|
|
1761
2481
|
... input_columns=["image", "label"])
|
|
2482
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2483
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2484
|
+
... print(item["label"].shape, item["label"].dtype)
|
|
2485
|
+
... break
|
|
2486
|
+
(4, 64, 64, 3) float64
|
|
2487
|
+
(4, 3, 10) float64
|
|
2488
|
+
>>>
|
|
2489
|
+
>>> # Use the transform in eager mode
|
|
2490
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
2491
|
+
>>> label = np.array([[0, 1]])
|
|
2492
|
+
>>> output = vision.MixUp(batch_size=2, alpha=0.2, is_single=False)(data, label)
|
|
2493
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
2494
|
+
(2, 100, 100, 3) float64
|
|
2495
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
2496
|
+
(2, 2) float64
|
|
1762
2497
|
|
|
1763
2498
|
Tutorial Examples:
|
|
1764
2499
|
- `Illustration of vision transforms
|
|
1765
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2500
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1766
2501
|
"""
|
|
1767
2502
|
|
|
1768
2503
|
@check_mix_up
|
|
@@ -1820,22 +2555,44 @@ class MixUpBatch(ImageTensorOperation):
|
|
|
1820
2555
|
``CPU``
|
|
1821
2556
|
|
|
1822
2557
|
Examples:
|
|
2558
|
+
>>> import numpy as np
|
|
1823
2559
|
>>> import mindspore.dataset as ds
|
|
1824
2560
|
>>> import mindspore.dataset.vision as vision
|
|
1825
2561
|
>>> import mindspore.dataset.transforms as transforms
|
|
1826
2562
|
>>>
|
|
1827
|
-
>>>
|
|
2563
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2564
|
+
>>> data = np.random.randint(0, 255, size=(64, 64, 3)).astype(np.uint8)
|
|
2565
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2566
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(
|
|
2567
|
+
... operations=lambda img: (data, np.random.randint(0, 5, (3, 1))),
|
|
2568
|
+
... input_columns=["image"],
|
|
2569
|
+
... output_columns=["image", "label"])
|
|
1828
2570
|
>>> onehot_op = transforms.OneHot(num_classes=10)
|
|
1829
|
-
>>>
|
|
2571
|
+
>>> numpy_slices_dataset= numpy_slices_dataset.map(operations=onehot_op,
|
|
1830
2572
|
... input_columns=["label"])
|
|
1831
2573
|
>>> mixup_batch_op = vision.MixUpBatch(alpha=0.9)
|
|
1832
|
-
>>>
|
|
1833
|
-
>>>
|
|
2574
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.batch(5)
|
|
2575
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=mixup_batch_op,
|
|
1834
2576
|
... input_columns=["image", "label"])
|
|
2577
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2578
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2579
|
+
... print(item["label"].shape, item["label"].dtype)
|
|
2580
|
+
... break
|
|
2581
|
+
(5, 64, 64, 3) uint8
|
|
2582
|
+
(5, 3, 10) float32
|
|
2583
|
+
>>>
|
|
2584
|
+
>>> # Use the transform in eager mode
|
|
2585
|
+
>>> data = np.random.randint(0, 255, (2, 10, 10, 3)).astype(np.uint8)
|
|
2586
|
+
>>> label = np.array([[0, 1], [1, 0]])
|
|
2587
|
+
>>> output = vision.MixUpBatch(1)(data, label)
|
|
2588
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
2589
|
+
(2, 10, 10, 3) uint8
|
|
2590
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
2591
|
+
(2, 2) float32
|
|
1835
2592
|
|
|
1836
2593
|
Tutorial Examples:
|
|
1837
2594
|
- `Illustration of vision transforms
|
|
1838
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2595
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1839
2596
|
"""
|
|
1840
2597
|
|
|
1841
2598
|
@check_mix_up_batch_c
|
|
@@ -1853,6 +2610,8 @@ class Normalize(ImageTensorOperation):
|
|
|
1853
2610
|
Normalize the input image with respect to mean and standard deviation. This operation will normalize
|
|
1854
2611
|
the input image with: output[channel] = (input[channel] - mean[channel]) / std[channel], where channel >= 1.
|
|
1855
2612
|
|
|
2613
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
2614
|
+
|
|
1856
2615
|
Note:
|
|
1857
2616
|
This operation is executed on the CPU by default, but it is also supported
|
|
1858
2617
|
to be executed on the GPU or Ascend via heterogeneous acceleration.
|
|
@@ -1877,19 +2636,30 @@ class Normalize(ImageTensorOperation):
|
|
|
1877
2636
|
``CPU`` ``GPU`` ``Ascend``
|
|
1878
2637
|
|
|
1879
2638
|
Examples:
|
|
2639
|
+
>>> import numpy as np
|
|
1880
2640
|
>>> import mindspore.dataset as ds
|
|
1881
2641
|
>>> import mindspore.dataset.vision as vision
|
|
1882
2642
|
>>>
|
|
1883
|
-
>>>
|
|
1884
|
-
>>>
|
|
2643
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2644
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2645
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1885
2646
|
>>> normalize_op = vision.Normalize(mean=[121.0, 115.0, 100.0], std=[70.0, 68.0, 71.0], is_hwc=True)
|
|
1886
|
-
>>>
|
|
1887
|
-
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
|
|
2647
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[normalize_op],
|
|
1888
2648
|
... input_columns=["image"])
|
|
2649
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2650
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2651
|
+
... break
|
|
2652
|
+
(100, 100, 3) float32
|
|
2653
|
+
>>>
|
|
2654
|
+
>>> # Use the transform in eager mode
|
|
2655
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
2656
|
+
>>> output = vision.Normalize(mean=[121.0, 115.0, 100.0], std=[70.0, 68.0, 71.0])(data)
|
|
2657
|
+
>>> print(output.shape, output.dtype)
|
|
2658
|
+
(100, 100, 3) float32
|
|
1889
2659
|
|
|
1890
2660
|
Tutorial Examples:
|
|
1891
2661
|
- `Illustration of vision transforms
|
|
1892
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2662
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1893
2663
|
"""
|
|
1894
2664
|
|
|
1895
2665
|
@check_normalize
|
|
@@ -1906,34 +2676,49 @@ class Normalize(ImageTensorOperation):
|
|
|
1906
2676
|
"""
|
|
1907
2677
|
Set the device for the current operator execution.
|
|
1908
2678
|
|
|
2679
|
+
- When the device is CPU, input type support `uint8`/`float32`/`float64`, input channel support 1/2/3.
|
|
2680
|
+
- When the device is Ascend, input type supports `uint8`/`float32`, input channel supports 1/3.
|
|
2681
|
+
input shape should be limited from [4, 6] to [8192, 4096].
|
|
2682
|
+
|
|
1909
2683
|
Args:
|
|
1910
2684
|
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
1911
|
-
``CPU`` . Default: ``CPU`` .
|
|
2685
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
1912
2686
|
|
|
1913
2687
|
Raises:
|
|
1914
2688
|
TypeError: If `device_target` is not of type str.
|
|
1915
|
-
ValueError: If `device_target` is not
|
|
2689
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
1916
2690
|
|
|
1917
2691
|
Supported Platforms:
|
|
1918
|
-
``CPU``
|
|
2692
|
+
``CPU`` ``Ascend``
|
|
1919
2693
|
|
|
1920
2694
|
Examples:
|
|
2695
|
+
>>> import numpy as np
|
|
1921
2696
|
>>> import mindspore.dataset as ds
|
|
1922
2697
|
>>> import mindspore.dataset.vision as vision
|
|
1923
2698
|
>>> from mindspore.dataset.vision import Inter
|
|
1924
2699
|
>>>
|
|
1925
|
-
>>>
|
|
2700
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2701
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2702
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1926
2703
|
>>> resize_op = vision.Resize([100, 75], Inter.BICUBIC)
|
|
1927
|
-
>>> transforms_list = [
|
|
1928
|
-
>>>
|
|
1929
|
-
>>> image_folder_dataset = image_folder_dataset.map(operations=transforms_list,
|
|
1930
|
-
... input_columns=["image"])
|
|
2704
|
+
>>> transforms_list = [resize_op]
|
|
2705
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
1931
2706
|
>>> normalize_op = vision.Normalize(mean=[121.0, 115.0, 100.0], std=[70.0, 68.0, 71.0]).device("Ascend")
|
|
1932
|
-
>>>
|
|
2707
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=normalize_op, input_columns=["image"])
|
|
2708
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2709
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2710
|
+
... break
|
|
2711
|
+
(100, 75, 3) float32
|
|
2712
|
+
>>>
|
|
2713
|
+
>>> # Use the transform in eager mode
|
|
2714
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
2715
|
+
>>> output = vision.Normalize(mean=[121.0, 115.0, 100.0], std=[70.0, 68.0, 71.0]).device("Ascend")(data)
|
|
2716
|
+
>>> print(output.shape, output.dtype)
|
|
2717
|
+
(100, 100, 3) float32
|
|
1933
2718
|
|
|
1934
2719
|
Tutorial Examples:
|
|
1935
2720
|
- `Illustration of vision transforms
|
|
1936
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2721
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
1937
2722
|
"""
|
|
1938
2723
|
self.device_target = device_target
|
|
1939
2724
|
return self
|
|
@@ -1952,8 +2737,8 @@ class NormalizePad(ImageTensorOperation):
|
|
|
1952
2737
|
std (sequence): List or tuple of standard deviations for each channel, with respect to channel order.
|
|
1953
2738
|
The standard deviation values must be in range (0.0, 255.0].
|
|
1954
2739
|
dtype (str, optional): Set the output data type of normalized image. Default: ``"float32"``.
|
|
1955
|
-
is_hwc (bool, optional):
|
|
1956
|
-
``True`` -
|
|
2740
|
+
is_hwc (bool, optional): Specify the format of input image.
|
|
2741
|
+
``True`` - HW(C) format, ``False`` - CHW format. Default: ``True``.
|
|
1957
2742
|
|
|
1958
2743
|
Raises:
|
|
1959
2744
|
TypeError: If `mean` is not of type sequence.
|
|
@@ -1968,17 +2753,28 @@ class NormalizePad(ImageTensorOperation):
|
|
|
1968
2753
|
``CPU``
|
|
1969
2754
|
|
|
1970
2755
|
Examples:
|
|
2756
|
+
>>> import numpy as np
|
|
1971
2757
|
>>> import mindspore.dataset as ds
|
|
1972
2758
|
>>> import mindspore.dataset.vision as vision
|
|
1973
2759
|
>>>
|
|
1974
|
-
>>>
|
|
1975
|
-
>>>
|
|
2760
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2761
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2762
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
1976
2763
|
>>> normalize_pad_op = vision.NormalizePad(mean=[121.0, 115.0, 100.0],
|
|
1977
2764
|
... std=[70.0, 68.0, 71.0],
|
|
1978
2765
|
... dtype="float32")
|
|
1979
|
-
>>> transforms_list = [
|
|
1980
|
-
>>>
|
|
1981
|
-
|
|
2766
|
+
>>> transforms_list = [normalize_pad_op]
|
|
2767
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
2768
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2769
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2770
|
+
... break
|
|
2771
|
+
(100, 100, 4) float32
|
|
2772
|
+
>>>
|
|
2773
|
+
>>> # Use the transform in eager mode
|
|
2774
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
2775
|
+
>>> output = vision.NormalizePad(mean=[121.0, 115.0, 100.0], std=[70.0, 68.0, 71.0], dtype="float32")(data)
|
|
2776
|
+
>>> print(output.shape, output.dtype)
|
|
2777
|
+
(100, 100, 4) float32
|
|
1982
2778
|
"""
|
|
1983
2779
|
|
|
1984
2780
|
@check_normalizepad
|
|
@@ -1999,6 +2795,8 @@ class Pad(ImageTensorOperation, PyTensorOperation):
|
|
|
1999
2795
|
"""
|
|
2000
2796
|
Pad the image according to padding parameters.
|
|
2001
2797
|
|
|
2798
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
2799
|
+
|
|
2002
2800
|
Args:
|
|
2003
2801
|
padding (Union[int, Sequence[int, int], Sequence[int, int, int, int]]): The number of pixels
|
|
2004
2802
|
to pad each border of the image.
|
|
@@ -2036,17 +2834,29 @@ class Pad(ImageTensorOperation, PyTensorOperation):
|
|
|
2036
2834
|
``CPU``
|
|
2037
2835
|
|
|
2038
2836
|
Examples:
|
|
2837
|
+
>>> import numpy as np
|
|
2039
2838
|
>>> import mindspore.dataset as ds
|
|
2040
2839
|
>>> import mindspore.dataset.vision as vision
|
|
2041
2840
|
>>>
|
|
2042
|
-
>>>
|
|
2043
|
-
>>>
|
|
2044
|
-
>>>
|
|
2045
|
-
|
|
2841
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2842
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2843
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2844
|
+
>>> transforms_list = [vision.Pad([100, 100, 100, 100])]
|
|
2845
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
2846
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2847
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2848
|
+
... break
|
|
2849
|
+
(300, 300, 3) uint8
|
|
2850
|
+
>>>
|
|
2851
|
+
>>> # Use the transform in eager mode
|
|
2852
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
2853
|
+
>>> output = vision.Pad([100, 100, 100, 100])(data)
|
|
2854
|
+
>>> print(output.shape, output.dtype)
|
|
2855
|
+
(300, 300, 3) uint8
|
|
2046
2856
|
|
|
2047
2857
|
Tutorial Examples:
|
|
2048
2858
|
- `Illustration of vision transforms
|
|
2049
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2859
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2050
2860
|
"""
|
|
2051
2861
|
|
|
2052
2862
|
@check_pad
|
|
@@ -2060,8 +2870,55 @@ class Pad(ImageTensorOperation, PyTensorOperation):
|
|
|
2060
2870
|
self.random = False
|
|
2061
2871
|
self.padding_mode = padding_mode
|
|
2062
2872
|
|
|
2873
|
+
@check_device_target
|
|
2874
|
+
def device(self, device_target="CPU"):
|
|
2875
|
+
"""
|
|
2876
|
+
Set the device for the current operator execution.
|
|
2877
|
+
|
|
2878
|
+
- When the device is Ascend, input/output shape should be limited from [4, 6] to [32768, 32768].
|
|
2879
|
+
|
|
2880
|
+
Args:
|
|
2881
|
+
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
2882
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
2883
|
+
|
|
2884
|
+
Raises:
|
|
2885
|
+
TypeError: If `device_target` is not of type str.
|
|
2886
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
2887
|
+
|
|
2888
|
+
Supported Platforms:
|
|
2889
|
+
``CPU`` ``Ascend``
|
|
2890
|
+
|
|
2891
|
+
Examples:
|
|
2892
|
+
>>> import numpy as np
|
|
2893
|
+
>>> import mindspore.dataset as ds
|
|
2894
|
+
>>> import mindspore.dataset.vision as vision
|
|
2895
|
+
>>>
|
|
2896
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2897
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2898
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2899
|
+
>>> pad_op = vision.Pad([100, 100, 100, 100]).device("Ascend")
|
|
2900
|
+
>>> transforms_list = [pad_op]
|
|
2901
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
2902
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2903
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2904
|
+
... break
|
|
2905
|
+
(300, 300, 3) uint8
|
|
2906
|
+
>>>
|
|
2907
|
+
>>> # Use the transform in eager mode
|
|
2908
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
2909
|
+
>>> output = vision.Pad([100, 100, 100, 100]).device("Ascend")(data)
|
|
2910
|
+
>>> print(output.shape, output.dtype)
|
|
2911
|
+
(300, 300, 3) uint8
|
|
2912
|
+
|
|
2913
|
+
Tutorial Examples:
|
|
2914
|
+
- `Illustration of vision transforms
|
|
2915
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2916
|
+
"""
|
|
2917
|
+
self.device_target = device_target
|
|
2918
|
+
return self
|
|
2919
|
+
|
|
2063
2920
|
def parse(self):
|
|
2064
|
-
return cde.PadOperation(self.padding, self.fill_value, Border.to_c_type(self.padding_mode))
|
|
2921
|
+
return cde.PadOperation(self.padding, self.fill_value, Border.to_c_type(self.padding_mode), self.device_target)
|
|
2065
2922
|
|
|
2066
2923
|
def _execute_py(self, img):
|
|
2067
2924
|
"""
|
|
@@ -2114,17 +2971,29 @@ class PadToSize(ImageTensorOperation):
|
|
|
2114
2971
|
``CPU``
|
|
2115
2972
|
|
|
2116
2973
|
Examples:
|
|
2974
|
+
>>> import numpy as np
|
|
2117
2975
|
>>> import mindspore.dataset as ds
|
|
2118
2976
|
>>> import mindspore.dataset.vision as vision
|
|
2119
2977
|
>>>
|
|
2120
|
-
>>>
|
|
2121
|
-
>>>
|
|
2122
|
-
>>>
|
|
2123
|
-
|
|
2978
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2979
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
2980
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2981
|
+
>>> transforms_list = [vision.PadToSize([256, 256])]
|
|
2982
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
2983
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
2984
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
2985
|
+
... break
|
|
2986
|
+
(256, 256, 3) uint8
|
|
2987
|
+
>>>
|
|
2988
|
+
>>> # Use the transform in eager mode
|
|
2989
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
2990
|
+
>>> output = vision.PadToSize([256, 256])(data)
|
|
2991
|
+
>>> print(output.shape, output.dtype)
|
|
2992
|
+
(256, 256, 3) uint8
|
|
2124
2993
|
|
|
2125
2994
|
Tutorial Examples:
|
|
2126
2995
|
- `Illustration of vision transforms
|
|
2127
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
2996
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2128
2997
|
"""
|
|
2129
2998
|
|
|
2130
2999
|
@check_pad_to_size
|
|
@@ -2167,23 +3036,35 @@ class Perspective(ImageTensorOperation, PyTensorOperation):
|
|
|
2167
3036
|
``CPU``
|
|
2168
3037
|
|
|
2169
3038
|
Examples:
|
|
3039
|
+
>>> import numpy as np
|
|
2170
3040
|
>>> import mindspore.dataset as ds
|
|
2171
3041
|
>>> import mindspore.dataset.vision as vision
|
|
2172
|
-
>>> from mindspore.dataset.transforms import Compose
|
|
2173
3042
|
>>> from mindspore.dataset.vision import Inter
|
|
2174
3043
|
>>>
|
|
3044
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2175
3045
|
>>> start_points = [[0, 63], [63, 63], [63, 0], [0, 0]]
|
|
2176
3046
|
>>> end_points = [[0, 32], [32, 32], [32, 0], [0, 0]]
|
|
2177
|
-
>>> transforms_list =
|
|
2178
|
-
... vision.Perspective(start_points, end_points, Inter.BILINEAR)])
|
|
3047
|
+
>>> transforms_list = [vision.Perspective(start_points, end_points, Inter.BILINEAR)]
|
|
2179
3048
|
>>> # apply the transform to dataset through map function
|
|
2180
|
-
>>>
|
|
2181
|
-
>>>
|
|
2182
|
-
|
|
3049
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3050
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3051
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
3052
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3053
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3054
|
+
... break
|
|
3055
|
+
(100, 100, 3) uint8
|
|
3056
|
+
>>>
|
|
3057
|
+
>>> # Use the transform in eager mode
|
|
3058
|
+
>>> start_points = [[0, 63], [63, 63], [63, 0], [0, 0]]
|
|
3059
|
+
>>> end_points = [[0, 32], [32, 32], [32, 0], [0, 0]]
|
|
3060
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3061
|
+
>>> output = vision.Perspective(start_points, end_points, Inter.BILINEAR)(data)
|
|
3062
|
+
>>> print(output.shape, output.dtype)
|
|
3063
|
+
(100, 100, 3) uint8
|
|
2183
3064
|
|
|
2184
3065
|
Tutorial Examples:
|
|
2185
3066
|
- `Illustration of vision transforms
|
|
2186
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3067
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2187
3068
|
"""
|
|
2188
3069
|
|
|
2189
3070
|
@check_perspective
|
|
@@ -2198,10 +3079,63 @@ class Perspective(ImageTensorOperation, PyTensorOperation):
|
|
|
2198
3079
|
self.implementation = Implementation.PY
|
|
2199
3080
|
self.random = False
|
|
2200
3081
|
|
|
3082
|
+
@check_device_target
|
|
3083
|
+
def device(self, device_target="CPU"):
|
|
3084
|
+
"""
|
|
3085
|
+
Set the device for the current operator execution.
|
|
3086
|
+
|
|
3087
|
+
- When the device is Ascend, input shape should be limited from [6, 10] to [8192, 4096].
|
|
3088
|
+
|
|
3089
|
+
Args:
|
|
3090
|
+
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
3091
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
3092
|
+
|
|
3093
|
+
Raises:
|
|
3094
|
+
TypeError: If `device_target` is not of type str.
|
|
3095
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
3096
|
+
|
|
3097
|
+
Supported Platforms:
|
|
3098
|
+
``CPU`` ``Ascend``
|
|
3099
|
+
|
|
3100
|
+
Examples:
|
|
3101
|
+
>>> import numpy as np
|
|
3102
|
+
>>> import mindspore.dataset as ds
|
|
3103
|
+
>>> import mindspore.dataset.vision as vision
|
|
3104
|
+
>>> from mindspore.dataset.vision import Inter
|
|
3105
|
+
>>>
|
|
3106
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3107
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3108
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3109
|
+
>>> start_points = [[0, 63], [63, 63], [63, 0], [0, 0]]
|
|
3110
|
+
>>> end_points = [[0, 32], [32, 32], [32, 0], [0, 0]]
|
|
3111
|
+
>>> perspective_op = vision.Perspective(start_points, end_points).device("Ascend")
|
|
3112
|
+
>>> transforms_list = [perspective_op]
|
|
3113
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3114
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3115
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3116
|
+
... break
|
|
3117
|
+
(100, 100, 3) uint8
|
|
3118
|
+
>>>
|
|
3119
|
+
>>> # Use the transform in eager mode
|
|
3120
|
+
>>> start_points = [[0, 63], [63, 63], [63, 0], [0, 0]]
|
|
3121
|
+
>>> end_points = [[0, 32], [32, 32], [32, 0], [0, 0]]
|
|
3122
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3123
|
+
>>> output = vision.Perspective(start_points, end_points, Inter.BILINEAR).device("Ascend")(data)
|
|
3124
|
+
>>> print(output.shape, output.dtype)
|
|
3125
|
+
(100, 100, 3) uint8
|
|
3126
|
+
|
|
3127
|
+
Tutorial Examples:
|
|
3128
|
+
- `Illustration of vision transforms
|
|
3129
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3130
|
+
"""
|
|
3131
|
+
self.device_target = device_target
|
|
3132
|
+
return self
|
|
3133
|
+
|
|
2201
3134
|
def parse(self):
|
|
2202
3135
|
if self.interpolation == Inter.ANTIALIAS:
|
|
2203
3136
|
raise TypeError("Current Interpolation is not supported with NumPy input.")
|
|
2204
|
-
return cde.PerspectiveOperation(self.start_points, self.end_points,
|
|
3137
|
+
return cde.PerspectiveOperation(self.start_points, self.end_points,
|
|
3138
|
+
Inter.to_c_type(self.interpolation), self.device_target)
|
|
2205
3139
|
|
|
2206
3140
|
def _execute_py(self, img):
|
|
2207
3141
|
"""
|
|
@@ -2232,17 +3166,29 @@ class Posterize(ImageTensorOperation):
|
|
|
2232
3166
|
RuntimeError: If shape of the input image is not <H, W> or <H, W, C>.
|
|
2233
3167
|
|
|
2234
3168
|
Examples:
|
|
3169
|
+
>>> import numpy as np
|
|
2235
3170
|
>>> import mindspore.dataset as ds
|
|
2236
3171
|
>>> import mindspore.dataset.vision as vision
|
|
2237
3172
|
>>>
|
|
2238
|
-
>>>
|
|
2239
|
-
>>>
|
|
2240
|
-
>>>
|
|
2241
|
-
|
|
3173
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3174
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3175
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3176
|
+
>>> transforms_list = [vision.Posterize(4)]
|
|
3177
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3178
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3179
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3180
|
+
... break
|
|
3181
|
+
(100, 100, 3) uint8
|
|
3182
|
+
>>>
|
|
3183
|
+
>>> # Use the transform in eager mode
|
|
3184
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3185
|
+
>>> output = vision.Posterize(4)(data)
|
|
3186
|
+
>>> print(output.shape, output.dtype)
|
|
3187
|
+
(100, 100, 3) uint8
|
|
2242
3188
|
|
|
2243
3189
|
Tutorial Examples:
|
|
2244
3190
|
- `Illustration of vision transforms
|
|
2245
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3191
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2246
3192
|
"""
|
|
2247
3193
|
|
|
2248
3194
|
@check_posterize
|
|
@@ -2292,16 +3238,30 @@ class RandAugment(ImageTensorOperation):
|
|
|
2292
3238
|
``CPU``
|
|
2293
3239
|
|
|
2294
3240
|
Examples:
|
|
3241
|
+
>>> import numpy as np
|
|
2295
3242
|
>>> import mindspore.dataset as ds
|
|
2296
3243
|
>>> import mindspore.dataset.vision as vision
|
|
3244
|
+
>>> from mindspore.dataset.vision import Inter
|
|
3245
|
+
>>>
|
|
3246
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3247
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3248
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3249
|
+
>>> transforms_list = [vision.RandAugment()]
|
|
3250
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3251
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3252
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3253
|
+
... break
|
|
3254
|
+
(100, 100, 3) uint8
|
|
2297
3255
|
>>>
|
|
2298
|
-
>>>
|
|
2299
|
-
>>>
|
|
2300
|
-
>>>
|
|
3256
|
+
>>> # Use the transform in eager mode
|
|
3257
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3258
|
+
>>> output = vision.RandAugment(interpolation=Inter.BILINEAR, fill_value=255)(data)
|
|
3259
|
+
>>> print(output.shape, output.dtype)
|
|
3260
|
+
(100, 100, 3) uint8
|
|
2301
3261
|
|
|
2302
3262
|
Tutorial Examples:
|
|
2303
3263
|
- `Illustration of vision transforms
|
|
2304
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3264
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2305
3265
|
"""
|
|
2306
3266
|
|
|
2307
3267
|
@check_rand_augment
|
|
@@ -2343,17 +3303,29 @@ class RandomAdjustSharpness(ImageTensorOperation):
|
|
|
2343
3303
|
``CPU``
|
|
2344
3304
|
|
|
2345
3305
|
Examples:
|
|
3306
|
+
>>> import numpy as np
|
|
2346
3307
|
>>> import mindspore.dataset as ds
|
|
2347
3308
|
>>> import mindspore.dataset.vision as vision
|
|
2348
3309
|
>>>
|
|
2349
|
-
>>>
|
|
2350
|
-
>>>
|
|
2351
|
-
>>>
|
|
2352
|
-
|
|
3310
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3311
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3312
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3313
|
+
>>> transforms_list = [vision.RandomAdjustSharpness(2.0, 0.5)]
|
|
3314
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3315
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3316
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3317
|
+
... break
|
|
3318
|
+
(100, 100, 3) uint8
|
|
3319
|
+
>>>
|
|
3320
|
+
>>> # Use the transform in eager mode
|
|
3321
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3322
|
+
>>> output = vision.RandomAdjustSharpness(2.0, 1.0)(data)
|
|
3323
|
+
>>> print(output.shape, output.dtype)
|
|
3324
|
+
(100, 100, 3) uint8
|
|
2353
3325
|
|
|
2354
3326
|
Tutorial Examples:
|
|
2355
3327
|
- `Illustration of vision transforms
|
|
2356
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3328
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2357
3329
|
"""
|
|
2358
3330
|
|
|
2359
3331
|
@check_random_adjust_sharpness
|
|
@@ -2419,23 +3391,35 @@ class RandomAffine(ImageTensorOperation, PyTensorOperation):
|
|
|
2419
3391
|
``CPU``
|
|
2420
3392
|
|
|
2421
3393
|
Examples:
|
|
3394
|
+
>>> import numpy as np
|
|
2422
3395
|
>>> import mindspore.dataset as ds
|
|
2423
3396
|
>>> import mindspore.dataset.vision as vision
|
|
2424
3397
|
>>> from mindspore.dataset.vision import Inter
|
|
2425
3398
|
>>>
|
|
2426
|
-
>>>
|
|
3399
|
+
>>> # Use the transform in dataset pipeline mode
|
|
2427
3400
|
>>> random_affine_op = vision.RandomAffine(degrees=15,
|
|
2428
3401
|
... translate=(-0.1, 0.1, 0, 0),
|
|
2429
3402
|
... scale=(0.9, 1.1),
|
|
2430
3403
|
... resample=Inter.NEAREST)
|
|
2431
|
-
>>> transforms_list = [
|
|
2432
|
-
>>>
|
|
2433
|
-
>>>
|
|
2434
|
-
|
|
3404
|
+
>>> transforms_list = [random_affine_op]
|
|
3405
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3406
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3407
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3408
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3409
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3410
|
+
... break
|
|
3411
|
+
(100, 100, 3) uint8
|
|
3412
|
+
>>>
|
|
3413
|
+
>>> # Use the transform in eager mode
|
|
3414
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3415
|
+
>>> output = vision.RandomAffine(degrees=15, translate=(-0.1, 0.1, 0, 0),
|
|
3416
|
+
... scale=(0.9, 1.1), resample=Inter.NEAREST)(data)
|
|
3417
|
+
>>> print(output.shape, output.dtype)
|
|
3418
|
+
(100, 100, 3) uint8
|
|
2435
3419
|
|
|
2436
3420
|
Tutorial Examples:
|
|
2437
3421
|
- `Illustration of vision transforms
|
|
2438
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3422
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2439
3423
|
"""
|
|
2440
3424
|
|
|
2441
3425
|
@check_random_affine
|
|
@@ -2532,17 +3516,29 @@ class RandomAutoContrast(ImageTensorOperation):
|
|
|
2532
3516
|
``CPU``
|
|
2533
3517
|
|
|
2534
3518
|
Examples:
|
|
3519
|
+
>>> import numpy as np
|
|
2535
3520
|
>>> import mindspore.dataset as ds
|
|
2536
3521
|
>>> import mindspore.dataset.vision as vision
|
|
2537
3522
|
>>>
|
|
2538
|
-
>>>
|
|
2539
|
-
>>>
|
|
2540
|
-
>>>
|
|
2541
|
-
|
|
3523
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3524
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3525
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3526
|
+
>>> transforms_list = [vision.RandomAutoContrast(cutoff=0.0, ignore=None, prob=0.5)]
|
|
3527
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3528
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3529
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3530
|
+
... break
|
|
3531
|
+
(100, 100, 3) uint8
|
|
3532
|
+
>>>
|
|
3533
|
+
>>> # Use the transform in eager mode
|
|
3534
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3535
|
+
>>> output = vision.RandomAutoContrast(cutoff=0.0, ignore=None, prob=1.0)(data)
|
|
3536
|
+
>>> print(output.shape, output.dtype)
|
|
3537
|
+
(100, 100, 3) uint8
|
|
2542
3538
|
|
|
2543
3539
|
Tutorial Examples:
|
|
2544
3540
|
- `Illustration of vision transforms
|
|
2545
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3541
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2546
3542
|
"""
|
|
2547
3543
|
|
|
2548
3544
|
@check_random_auto_contrast
|
|
@@ -2580,17 +3576,29 @@ class RandomColor(ImageTensorOperation, PyTensorOperation):
|
|
|
2580
3576
|
``CPU``
|
|
2581
3577
|
|
|
2582
3578
|
Examples:
|
|
3579
|
+
>>> import numpy as np
|
|
2583
3580
|
>>> import mindspore.dataset as ds
|
|
2584
3581
|
>>> import mindspore.dataset.vision as vision
|
|
2585
3582
|
>>>
|
|
2586
|
-
>>>
|
|
2587
|
-
>>>
|
|
2588
|
-
>>>
|
|
2589
|
-
|
|
3583
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3584
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3585
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3586
|
+
>>> transforms_list = [vision.RandomColor((0.5, 2.0))]
|
|
3587
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3588
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3589
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3590
|
+
... break
|
|
3591
|
+
(100, 100, 3) uint8
|
|
3592
|
+
>>>
|
|
3593
|
+
>>> # Use the transform in eager mode
|
|
3594
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3595
|
+
>>> output = vision.RandomColor((0.1, 1.9))(data)
|
|
3596
|
+
>>> print(output.shape, output.dtype)
|
|
3597
|
+
(100, 100, 3) uint8
|
|
2590
3598
|
|
|
2591
3599
|
Tutorial Examples:
|
|
2592
3600
|
- `Illustration of vision transforms
|
|
2593
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3601
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2594
3602
|
"""
|
|
2595
3603
|
|
|
2596
3604
|
@check_positive_degrees
|
|
@@ -2655,21 +3663,32 @@ class RandomColorAdjust(ImageTensorOperation, PyTensorOperation):
|
|
|
2655
3663
|
``CPU`` ``GPU`` ``Ascend``
|
|
2656
3664
|
|
|
2657
3665
|
Examples:
|
|
3666
|
+
>>> import numpy as np
|
|
2658
3667
|
>>> import mindspore.dataset as ds
|
|
2659
3668
|
>>> import mindspore.dataset.vision as vision
|
|
2660
3669
|
>>>
|
|
2661
|
-
>>>
|
|
2662
|
-
>>>
|
|
3670
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3671
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3672
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
2663
3673
|
>>> transform_op = vision.RandomColorAdjust(brightness=(0.5, 1),
|
|
2664
3674
|
... contrast=(0.4, 1),
|
|
2665
3675
|
... saturation=(0.3, 1))
|
|
2666
|
-
>>> transforms_list = [
|
|
2667
|
-
>>>
|
|
2668
|
-
|
|
3676
|
+
>>> transforms_list = [transform_op]
|
|
3677
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3678
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3679
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3680
|
+
... break
|
|
3681
|
+
(100, 100, 3) uint8
|
|
3682
|
+
>>>
|
|
3683
|
+
>>> # Use the transform in eager mode
|
|
3684
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3685
|
+
>>> output = vision.RandomColorAdjust(brightness=(0.5, 1), contrast=(0.4, 1), saturation=(0.3, 1))(data)
|
|
3686
|
+
>>> print(output.shape, output.dtype)
|
|
3687
|
+
(100, 100, 3) uint8
|
|
2669
3688
|
|
|
2670
3689
|
Tutorial Examples:
|
|
2671
3690
|
- `Illustration of vision transforms
|
|
2672
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3691
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2673
3692
|
"""
|
|
2674
3693
|
|
|
2675
3694
|
@check_random_color_adjust
|
|
@@ -2766,20 +3785,31 @@ class RandomCrop(ImageTensorOperation, PyTensorOperation):
|
|
|
2766
3785
|
``CPU``
|
|
2767
3786
|
|
|
2768
3787
|
Examples:
|
|
3788
|
+
>>> import numpy as np
|
|
2769
3789
|
>>> import mindspore.dataset as ds
|
|
2770
3790
|
>>> import mindspore.dataset.vision as vision
|
|
2771
3791
|
>>> from mindspore.dataset.vision import Border
|
|
2772
3792
|
>>>
|
|
2773
|
-
>>>
|
|
2774
|
-
>>> random_crop_op = vision.RandomCrop(
|
|
2775
|
-
>>> transforms_list = [
|
|
2776
|
-
>>>
|
|
2777
|
-
>>>
|
|
2778
|
-
|
|
3793
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3794
|
+
>>> random_crop_op = vision.RandomCrop(64, [16, 16, 16, 16], padding_mode=Border.EDGE)
|
|
3795
|
+
>>> transforms_list = [random_crop_op]
|
|
3796
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
3797
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3798
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3799
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3800
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3801
|
+
... break
|
|
3802
|
+
(64, 64, 3) uint8
|
|
3803
|
+
>>>
|
|
3804
|
+
>>> # Use the transform in eager mode
|
|
3805
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
3806
|
+
>>> output = vision.RandomCrop(8, [10, 10, 10, 10], padding_mode=Border.EDGE)(data)
|
|
3807
|
+
>>> print(output.shape, output.dtype)
|
|
3808
|
+
(8, 8, 3) uint8
|
|
2779
3809
|
|
|
2780
3810
|
Tutorial Examples:
|
|
2781
3811
|
- `Illustration of vision transforms
|
|
2782
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3812
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2783
3813
|
"""
|
|
2784
3814
|
|
|
2785
3815
|
@check_random_crop
|
|
@@ -2852,22 +3882,59 @@ class RandomCropDecodeResize(ImageTensorOperation):
|
|
|
2852
3882
|
``CPU``
|
|
2853
3883
|
|
|
2854
3884
|
Examples:
|
|
3885
|
+
>>> import os
|
|
3886
|
+
>>> import numpy as np
|
|
3887
|
+
>>> from PIL import Image, ImageDraw
|
|
2855
3888
|
>>> import mindspore.dataset as ds
|
|
2856
3889
|
>>> import mindspore.dataset.vision as vision
|
|
2857
3890
|
>>> from mindspore.dataset.vision import Inter
|
|
2858
3891
|
>>>
|
|
3892
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3893
|
+
>>> class MyDataset:
|
|
3894
|
+
... def __init__(self):
|
|
3895
|
+
... self.data = []
|
|
3896
|
+
... img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
3897
|
+
... draw = ImageDraw.Draw(img)
|
|
3898
|
+
... draw.ellipse(((0, 0), (100, 100)), fill=(255, 0, 0), outline=(255, 0, 0), width=5)
|
|
3899
|
+
... img.save("./1.jpg")
|
|
3900
|
+
... data = np.fromfile("./1.jpg", np.uint8)
|
|
3901
|
+
... self.data.append(data)
|
|
3902
|
+
...
|
|
3903
|
+
... def __getitem__(self, index):
|
|
3904
|
+
... return self.data[0]
|
|
3905
|
+
...
|
|
3906
|
+
... def __len__(self):
|
|
3907
|
+
... return 5
|
|
3908
|
+
>>>
|
|
3909
|
+
>>> my_dataset = MyDataset()
|
|
3910
|
+
>>> generator_dataset = ds.GeneratorDataset(my_dataset, column_names="image")
|
|
2859
3911
|
>>> resize_crop_decode_op = vision.RandomCropDecodeResize(size=(50, 75),
|
|
2860
3912
|
... scale=(0.25, 0.5),
|
|
2861
3913
|
... interpolation=Inter.NEAREST,
|
|
2862
3914
|
... max_attempts=5)
|
|
2863
3915
|
>>> transforms_list = [resize_crop_decode_op]
|
|
2864
|
-
>>>
|
|
2865
|
-
>>>
|
|
2866
|
-
...
|
|
3916
|
+
>>> generator_dataset = generator_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
3917
|
+
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
3918
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
3919
|
+
... break
|
|
3920
|
+
(50, 75, 3) uint8
|
|
3921
|
+
>>> os.remove("./1.jpg")
|
|
3922
|
+
>>>
|
|
3923
|
+
>>> # Use the transform in eager mode
|
|
3924
|
+
>>> img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
3925
|
+
>>> draw = ImageDraw.Draw(img)
|
|
3926
|
+
>>> draw.polygon([(50, 50), (150, 50), (100, 150)], fill=(0, 255, 0), outline=(0, 255, 0))
|
|
3927
|
+
>>> img.save("./2.jpg")
|
|
3928
|
+
>>> data = np.fromfile("./2.jpg", np.uint8)
|
|
3929
|
+
>>> output = vision.RandomCropDecodeResize(size=(50, 75), scale=(0, 10.0), ratio=(0.5, 0.5),
|
|
3930
|
+
... interpolation=Inter.BILINEAR, max_attempts=1)(data)
|
|
3931
|
+
>>> print(np.array(output).shape, np.array(output).dtype)
|
|
3932
|
+
(50, 75, 3) uint8
|
|
3933
|
+
>>> os.remove("./2.jpg")
|
|
2867
3934
|
|
|
2868
3935
|
Tutorial Examples:
|
|
2869
3936
|
- `Illustration of vision transforms
|
|
2870
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
3937
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2871
3938
|
"""
|
|
2872
3939
|
|
|
2873
3940
|
@check_random_resize_crop
|
|
@@ -2948,19 +4015,40 @@ class RandomCropWithBBox(ImageTensorOperation):
|
|
|
2948
4015
|
``CPU``
|
|
2949
4016
|
|
|
2950
4017
|
Examples:
|
|
4018
|
+
>>> import numpy as np
|
|
2951
4019
|
>>> import mindspore.dataset as ds
|
|
2952
4020
|
>>> import mindspore.dataset.vision as vision
|
|
2953
4021
|
>>>
|
|
2954
|
-
>>>
|
|
2955
|
-
>>>
|
|
2956
|
-
>>>
|
|
2957
|
-
>>>
|
|
2958
|
-
>>>
|
|
2959
|
-
... input_columns=["image"]
|
|
4022
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4023
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
4024
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4025
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32))
|
|
4026
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func],
|
|
4027
|
+
... input_columns=["image"],
|
|
4028
|
+
... output_columns=["image", "bbox"])
|
|
4029
|
+
>>> random_crop_with_bbox_op = vision.RandomCropWithBBox([64, 64], [20, 20, 20, 20])
|
|
4030
|
+
>>> transforms_list = [random_crop_with_bbox_op]
|
|
4031
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image", "bbox"])
|
|
4032
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4033
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4034
|
+
... print(item["bbox"].shape, item["bbox"].dtype)
|
|
4035
|
+
... break
|
|
4036
|
+
(64, 64, 3) float32
|
|
4037
|
+
(1, 4) float32
|
|
4038
|
+
>>>
|
|
4039
|
+
>>> # Use the transform in eager mode
|
|
4040
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
4041
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(data.dtype))
|
|
4042
|
+
>>> func_data, func_bboxes = func(data)
|
|
4043
|
+
>>> output = vision.RandomCropWithBBox([64, 64], [20, 20, 20, 20])(func_data, func_bboxes)
|
|
4044
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
4045
|
+
(64, 64, 3) float32
|
|
4046
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
4047
|
+
(1, 4) float32
|
|
2960
4048
|
|
|
2961
4049
|
Tutorial Examples:
|
|
2962
4050
|
- `Illustration of vision transforms
|
|
2963
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4051
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
2964
4052
|
"""
|
|
2965
4053
|
|
|
2966
4054
|
@check_random_crop
|
|
@@ -3006,17 +4094,29 @@ class RandomEqualize(ImageTensorOperation):
|
|
|
3006
4094
|
``CPU``
|
|
3007
4095
|
|
|
3008
4096
|
Examples:
|
|
4097
|
+
>>> import numpy as np
|
|
3009
4098
|
>>> import mindspore.dataset as ds
|
|
3010
4099
|
>>> import mindspore.dataset.vision as vision
|
|
3011
4100
|
>>>
|
|
3012
|
-
>>>
|
|
3013
|
-
>>>
|
|
3014
|
-
>>>
|
|
3015
|
-
|
|
4101
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4102
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
4103
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4104
|
+
>>> transforms_list = [vision.RandomEqualize(0.5)]
|
|
4105
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
4106
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4107
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4108
|
+
... break
|
|
4109
|
+
(100, 100, 3) uint8
|
|
4110
|
+
>>>
|
|
4111
|
+
>>> # Use the transform in eager mode
|
|
4112
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
4113
|
+
>>> output = vision.RandomEqualize(1.0)(data)
|
|
4114
|
+
>>> print(output.shape, output.dtype)
|
|
4115
|
+
(100, 100, 3) uint8
|
|
3016
4116
|
|
|
3017
4117
|
Tutorial Examples:
|
|
3018
4118
|
- `Illustration of vision transforms
|
|
3019
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4119
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3020
4120
|
"""
|
|
3021
4121
|
|
|
3022
4122
|
@check_prob
|
|
@@ -3069,21 +4169,32 @@ class RandomErasing(PyTensorOperation):
|
|
|
3069
4169
|
``CPU``
|
|
3070
4170
|
|
|
3071
4171
|
Examples:
|
|
4172
|
+
>>> import numpy as np
|
|
3072
4173
|
>>> import mindspore.dataset as ds
|
|
3073
4174
|
>>> import mindspore.dataset.vision as vision
|
|
3074
4175
|
>>> from mindspore.dataset.transforms import Compose
|
|
3075
4176
|
>>>
|
|
3076
|
-
>>>
|
|
3077
|
-
|
|
4177
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4178
|
+
>>> transforms_list = Compose([vision.ToTensor(),
|
|
3078
4179
|
... vision.RandomErasing(value='random')])
|
|
3079
4180
|
>>> # apply the transform to dataset through map function
|
|
3080
|
-
>>>
|
|
3081
|
-
>>>
|
|
3082
|
-
|
|
4181
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
4182
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4183
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
4184
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4185
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4186
|
+
... break
|
|
4187
|
+
(3, 100, 100) float32
|
|
4188
|
+
>>>
|
|
4189
|
+
>>> # Use the transform in eager mode
|
|
4190
|
+
>>> data = np.random.randint(254, 255, size=(3, 100, 100)).astype(np.uint8)
|
|
4191
|
+
>>> output = vision.RandomErasing(prob=1.0, max_attempts=1)(data)
|
|
4192
|
+
>>> print(output.shape, output.dtype)
|
|
4193
|
+
(3, 100, 100) uint8
|
|
3083
4194
|
|
|
3084
4195
|
Tutorial Examples:
|
|
3085
4196
|
- `Illustration of vision transforms
|
|
3086
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4197
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3087
4198
|
"""
|
|
3088
4199
|
|
|
3089
4200
|
@check_random_erasing
|
|
@@ -3131,21 +4242,57 @@ class RandomGrayscale(PyTensorOperation):
|
|
|
3131
4242
|
``CPU``
|
|
3132
4243
|
|
|
3133
4244
|
Examples:
|
|
4245
|
+
>>> import os
|
|
4246
|
+
>>> import numpy as np
|
|
4247
|
+
>>> from PIL import Image, ImageDraw
|
|
3134
4248
|
>>> import mindspore.dataset as ds
|
|
3135
4249
|
>>> import mindspore.dataset.vision as vision
|
|
3136
4250
|
>>> from mindspore.dataset.transforms import Compose
|
|
3137
4251
|
>>>
|
|
4252
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4253
|
+
>>> class MyDataset:
|
|
4254
|
+
... def __init__(self):
|
|
4255
|
+
... self.data = []
|
|
4256
|
+
... img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
4257
|
+
... draw = ImageDraw.Draw(img)
|
|
4258
|
+
... draw.ellipse(((0, 0), (100, 100)), fill=(255, 0, 0), outline=(255, 0, 0), width=5)
|
|
4259
|
+
... img.save("./1.jpg")
|
|
4260
|
+
... data = np.fromfile("./1.jpg", np.uint8)
|
|
4261
|
+
... self.data.append(data)
|
|
4262
|
+
...
|
|
4263
|
+
... def __getitem__(self, index):
|
|
4264
|
+
... return self.data[0]
|
|
4265
|
+
...
|
|
4266
|
+
... def __len__(self):
|
|
4267
|
+
... return 5
|
|
4268
|
+
>>>
|
|
4269
|
+
>>> my_dataset = MyDataset()
|
|
4270
|
+
>>> generator_dataset = ds.GeneratorDataset(my_dataset, column_names="image")
|
|
3138
4271
|
>>> transforms_list = Compose([vision.Decode(to_pil=True),
|
|
3139
4272
|
... vision.RandomGrayscale(0.3),
|
|
3140
4273
|
... vision.ToTensor()])
|
|
3141
4274
|
>>> # apply the transform to dataset through map function
|
|
3142
|
-
>>>
|
|
3143
|
-
>>>
|
|
3144
|
-
...
|
|
4275
|
+
>>> generator_dataset = generator_dataset.map(operations=transforms_list, input_columns="image")
|
|
4276
|
+
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4277
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4278
|
+
... break
|
|
4279
|
+
(3, 300, 300) float32
|
|
4280
|
+
>>> os.remove("./1.jpg")
|
|
4281
|
+
>>>
|
|
4282
|
+
>>> # Use the transform in eager mode
|
|
4283
|
+
>>> img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
4284
|
+
>>> draw = ImageDraw.Draw(img)
|
|
4285
|
+
>>> draw.polygon([(50, 50), (150, 50), (100, 150)], fill=(0, 255, 0), outline=(0, 255, 0))
|
|
4286
|
+
>>> img.save("./2.jpg")
|
|
4287
|
+
>>> data = Image.open("./2.jpg")
|
|
4288
|
+
>>> output = vision.RandomGrayscale(1.0)(data)
|
|
4289
|
+
>>> print(np.array(output).shape, np.array(output).dtype)
|
|
4290
|
+
(300, 300, 3) uint8
|
|
4291
|
+
>>> os.remove("./2.jpg")
|
|
3145
4292
|
|
|
3146
4293
|
Tutorial Examples:
|
|
3147
4294
|
- `Illustration of vision transforms
|
|
3148
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4295
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3149
4296
|
"""
|
|
3150
4297
|
|
|
3151
4298
|
@check_prob
|
|
@@ -3193,17 +4340,29 @@ class RandomHorizontalFlip(ImageTensorOperation, PyTensorOperation):
|
|
|
3193
4340
|
``CPU``
|
|
3194
4341
|
|
|
3195
4342
|
Examples:
|
|
4343
|
+
>>> import numpy as np
|
|
3196
4344
|
>>> import mindspore.dataset as ds
|
|
3197
4345
|
>>> import mindspore.dataset.vision as vision
|
|
3198
4346
|
>>>
|
|
3199
|
-
>>>
|
|
3200
|
-
>>>
|
|
3201
|
-
>>>
|
|
3202
|
-
|
|
4347
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4348
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
4349
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4350
|
+
>>> transforms_list = [vision.RandomHorizontalFlip(0.75)]
|
|
4351
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
4352
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4353
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4354
|
+
... break
|
|
4355
|
+
(100, 100, 3) uint8
|
|
4356
|
+
>>>
|
|
4357
|
+
>>> # Use the transform in eager mode
|
|
4358
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
4359
|
+
>>> output = vision.RandomHorizontalFlip(1.0)(data)
|
|
4360
|
+
>>> print(output.shape, output.dtype)
|
|
4361
|
+
(100, 100, 3) uint8
|
|
3203
4362
|
|
|
3204
4363
|
Tutorial Examples:
|
|
3205
4364
|
- `Illustration of vision transforms
|
|
3206
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4365
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3207
4366
|
"""
|
|
3208
4367
|
|
|
3209
4368
|
@check_prob
|
|
@@ -3244,17 +4403,40 @@ class RandomHorizontalFlipWithBBox(ImageTensorOperation):
|
|
|
3244
4403
|
``CPU``
|
|
3245
4404
|
|
|
3246
4405
|
Examples:
|
|
4406
|
+
>>> import numpy as np
|
|
3247
4407
|
>>> import mindspore.dataset as ds
|
|
3248
4408
|
>>> import mindspore.dataset.vision as vision
|
|
3249
4409
|
>>>
|
|
3250
|
-
>>>
|
|
3251
|
-
>>>
|
|
3252
|
-
>>>
|
|
3253
|
-
|
|
4410
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4411
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
4412
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4413
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32))
|
|
4414
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func],
|
|
4415
|
+
... input_columns=["image"],
|
|
4416
|
+
... output_columns=["image", "bbox"])
|
|
4417
|
+
>>> transforms_list = [vision.RandomHorizontalFlipWithBBox(0.70)]
|
|
4418
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list,
|
|
4419
|
+
... input_columns=["image", "bbox"])
|
|
4420
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4421
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4422
|
+
... print(item["bbox"].shape, item["bbox"].dtype)
|
|
4423
|
+
... break
|
|
4424
|
+
(100, 100, 3) float32
|
|
4425
|
+
(1, 4) float32
|
|
4426
|
+
>>>
|
|
4427
|
+
>>> # Use the transform in eager mode
|
|
4428
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
4429
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(data.dtype))
|
|
4430
|
+
>>> func_data, func_bboxes = func(data)
|
|
4431
|
+
>>> output = vision.RandomHorizontalFlipWithBBox(1)(func_data, func_bboxes)
|
|
4432
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
4433
|
+
(100, 100, 3) float32
|
|
4434
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
4435
|
+
(1, 4) float32
|
|
3254
4436
|
|
|
3255
4437
|
Tutorial Examples:
|
|
3256
4438
|
- `Illustration of vision transforms
|
|
3257
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4439
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3258
4440
|
"""
|
|
3259
4441
|
|
|
3260
4442
|
@check_prob
|
|
@@ -3284,17 +4466,29 @@ class RandomInvert(ImageTensorOperation):
|
|
|
3284
4466
|
``CPU``
|
|
3285
4467
|
|
|
3286
4468
|
Examples:
|
|
4469
|
+
>>> import numpy as np
|
|
3287
4470
|
>>> import mindspore.dataset as ds
|
|
3288
4471
|
>>> import mindspore.dataset.vision as vision
|
|
3289
4472
|
>>>
|
|
3290
|
-
>>>
|
|
3291
|
-
>>>
|
|
3292
|
-
>>>
|
|
3293
|
-
|
|
4473
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4474
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
4475
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4476
|
+
>>> transforms_list = [vision.RandomInvert(0.5)]
|
|
4477
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
4478
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4479
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4480
|
+
... break
|
|
4481
|
+
(100, 100, 3) uint8
|
|
4482
|
+
>>>
|
|
4483
|
+
>>> # Use the transform in eager mode
|
|
4484
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
4485
|
+
>>> output = vision.RandomInvert(1.0)(data)
|
|
4486
|
+
>>> print(output.shape, output.dtype)
|
|
4487
|
+
(100, 100, 3) uint8
|
|
3294
4488
|
|
|
3295
4489
|
Tutorial Examples:
|
|
3296
4490
|
- `Illustration of vision transforms
|
|
3297
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4491
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3298
4492
|
"""
|
|
3299
4493
|
|
|
3300
4494
|
@check_prob
|
|
@@ -3324,17 +4518,29 @@ class RandomLighting(ImageTensorOperation, PyTensorOperation):
|
|
|
3324
4518
|
``CPU``
|
|
3325
4519
|
|
|
3326
4520
|
Examples:
|
|
4521
|
+
>>> import numpy as np
|
|
3327
4522
|
>>> import mindspore.dataset as ds
|
|
3328
4523
|
>>> import mindspore.dataset.vision as vision
|
|
3329
4524
|
>>>
|
|
3330
|
-
>>>
|
|
3331
|
-
>>>
|
|
3332
|
-
>>>
|
|
3333
|
-
|
|
4525
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4526
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
4527
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4528
|
+
>>> transforms_list = [vision.RandomLighting(0.1)]
|
|
4529
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
4530
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4531
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4532
|
+
... break
|
|
4533
|
+
(100, 100, 3) uint8
|
|
4534
|
+
>>>
|
|
4535
|
+
>>> # Use the transform in eager mode
|
|
4536
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
4537
|
+
>>> output = vision.RandomLighting(0.1)(data)
|
|
4538
|
+
>>> print(output.shape, output.dtype)
|
|
4539
|
+
(100, 100, 3) uint8
|
|
3334
4540
|
|
|
3335
4541
|
Tutorial Examples:
|
|
3336
4542
|
- `Illustration of vision transforms
|
|
3337
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4543
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3338
4544
|
"""
|
|
3339
4545
|
|
|
3340
4546
|
@check_alpha
|
|
@@ -3381,21 +4587,57 @@ class RandomPerspective(PyTensorOperation):
|
|
|
3381
4587
|
``CPU``
|
|
3382
4588
|
|
|
3383
4589
|
Examples:
|
|
4590
|
+
>>> import os
|
|
4591
|
+
>>> import numpy as np
|
|
4592
|
+
>>> from PIL import Image, ImageDraw
|
|
3384
4593
|
>>> import mindspore.dataset as ds
|
|
3385
4594
|
>>> import mindspore.dataset.vision as vision
|
|
3386
4595
|
>>> from mindspore.dataset.transforms import Compose
|
|
3387
4596
|
>>>
|
|
4597
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4598
|
+
>>> class MyDataset:
|
|
4599
|
+
... def __init__(self):
|
|
4600
|
+
... self.data = []
|
|
4601
|
+
... img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
4602
|
+
... draw = ImageDraw.Draw(img)
|
|
4603
|
+
... draw.ellipse(((0, 0), (100, 100)), fill=(255, 0, 0), outline=(255, 0, 0), width=5)
|
|
4604
|
+
... img.save("./1.jpg")
|
|
4605
|
+
... data = np.fromfile("./1.jpg", np.uint8)
|
|
4606
|
+
... self.data.append(data)
|
|
4607
|
+
...
|
|
4608
|
+
... def __getitem__(self, index):
|
|
4609
|
+
... return self.data[0]
|
|
4610
|
+
...
|
|
4611
|
+
... def __len__(self):
|
|
4612
|
+
... return 5
|
|
4613
|
+
>>>
|
|
4614
|
+
>>> my_dataset = MyDataset()
|
|
4615
|
+
>>> generator_dataset = ds.GeneratorDataset(my_dataset, column_names="image")
|
|
3388
4616
|
>>> transforms_list = Compose([vision.Decode(to_pil=True),
|
|
3389
4617
|
... vision.RandomPerspective(prob=0.1),
|
|
3390
4618
|
... vision.ToTensor()])
|
|
3391
4619
|
>>> # apply the transform to dataset through map function
|
|
3392
|
-
>>>
|
|
3393
|
-
>>>
|
|
3394
|
-
...
|
|
4620
|
+
>>> generator_dataset = generator_dataset.map(operations=transforms_list, input_columns="image")
|
|
4621
|
+
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4622
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4623
|
+
... break
|
|
4624
|
+
(3, 300, 300) float32
|
|
4625
|
+
>>> os.remove("./1.jpg")
|
|
4626
|
+
>>>
|
|
4627
|
+
>>> # Use the transform in eager mode
|
|
4628
|
+
>>> img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
4629
|
+
>>> draw = ImageDraw.Draw(img)
|
|
4630
|
+
>>> draw.polygon([(50, 50), (150, 50), (100, 150)], fill=(0, 255, 0), outline=(0, 255, 0))
|
|
4631
|
+
>>> img.save("./2.jpg")
|
|
4632
|
+
>>> data = Image.open("./2.jpg")
|
|
4633
|
+
>>> output = vision.RandomPerspective(prob=1.0)(data)
|
|
4634
|
+
>>> print(np.array(output).shape, np.array(output).dtype)
|
|
4635
|
+
(300, 300, 3) uint8
|
|
4636
|
+
>>> os.remove("./2.jpg")
|
|
3395
4637
|
|
|
3396
4638
|
Tutorial Examples:
|
|
3397
4639
|
- `Illustration of vision transforms
|
|
3398
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4640
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3399
4641
|
"""
|
|
3400
4642
|
|
|
3401
4643
|
@check_random_perspective
|
|
@@ -3448,17 +4690,29 @@ class RandomPosterize(ImageTensorOperation):
|
|
|
3448
4690
|
``CPU``
|
|
3449
4691
|
|
|
3450
4692
|
Examples:
|
|
4693
|
+
>>> import numpy as np
|
|
3451
4694
|
>>> import mindspore.dataset as ds
|
|
3452
4695
|
>>> import mindspore.dataset.vision as vision
|
|
3453
4696
|
>>>
|
|
3454
|
-
>>>
|
|
3455
|
-
>>>
|
|
3456
|
-
>>>
|
|
3457
|
-
|
|
4697
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4698
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
4699
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4700
|
+
>>> transforms_list = [vision.RandomPosterize((6, 8))]
|
|
4701
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
4702
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4703
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4704
|
+
... break
|
|
4705
|
+
(100, 100, 3) uint8
|
|
4706
|
+
>>>
|
|
4707
|
+
>>> # Use the transform in eager mode
|
|
4708
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
4709
|
+
>>> output = vision.RandomPosterize(1)(data)
|
|
4710
|
+
>>> print(output.shape, output.dtype)
|
|
4711
|
+
(100, 100, 3) uint8
|
|
3458
4712
|
|
|
3459
4713
|
Tutorial Examples:
|
|
3460
4714
|
- `Illustration of vision transforms
|
|
3461
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4715
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3462
4716
|
"""
|
|
3463
4717
|
|
|
3464
4718
|
@check_random_posterize
|
|
@@ -3510,21 +4764,32 @@ class RandomResizedCrop(ImageTensorOperation, PyTensorOperation):
|
|
|
3510
4764
|
``CPU``
|
|
3511
4765
|
|
|
3512
4766
|
Examples:
|
|
4767
|
+
>>> import numpy as np
|
|
3513
4768
|
>>> import mindspore.dataset as ds
|
|
3514
4769
|
>>> import mindspore.dataset.vision as vision
|
|
3515
4770
|
>>> from mindspore.dataset.vision import Inter
|
|
3516
4771
|
>>>
|
|
3517
|
-
>>>
|
|
4772
|
+
>>> # Use the transform in dataset pipeline mode
|
|
3518
4773
|
>>> resize_crop_op = vision.RandomResizedCrop(size=(50, 75), scale=(0.25, 0.5),
|
|
3519
4774
|
... interpolation=Inter.BILINEAR)
|
|
3520
|
-
>>> transforms_list = [
|
|
3521
|
-
>>>
|
|
3522
|
-
>>>
|
|
3523
|
-
|
|
4775
|
+
>>> transforms_list = [resize_crop_op]
|
|
4776
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
4777
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4778
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
4779
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4780
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4781
|
+
... break
|
|
4782
|
+
(50, 75, 3) uint8
|
|
4783
|
+
>>>
|
|
4784
|
+
>>> # Use the transform in eager mode
|
|
4785
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
4786
|
+
>>> output = vision.RandomResizedCrop(size=(50, 75), scale=(0.25, 0.5), interpolation=Inter.BILINEAR)(data)
|
|
4787
|
+
>>> print(output.shape, output.dtype)
|
|
4788
|
+
(50, 75, 3) uint8
|
|
3524
4789
|
|
|
3525
4790
|
Tutorial Examples:
|
|
3526
4791
|
- `Illustration of vision transforms
|
|
3527
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4792
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3528
4793
|
"""
|
|
3529
4794
|
|
|
3530
4795
|
@check_random_resize_crop
|
|
@@ -3598,20 +4863,42 @@ class RandomResizedCropWithBBox(ImageTensorOperation):
|
|
|
3598
4863
|
``CPU``
|
|
3599
4864
|
|
|
3600
4865
|
Examples:
|
|
4866
|
+
>>> import numpy as np
|
|
3601
4867
|
>>> import mindspore.dataset as ds
|
|
3602
4868
|
>>> import mindspore.dataset.vision as vision
|
|
3603
4869
|
>>> from mindspore.dataset.vision import Inter
|
|
3604
4870
|
>>>
|
|
3605
|
-
>>>
|
|
4871
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4872
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
4873
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4874
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32))
|
|
4875
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func],
|
|
4876
|
+
... input_columns=["image"],
|
|
4877
|
+
... output_columns=["image", "bbox"])
|
|
3606
4878
|
>>> bbox_op = vision.RandomResizedCropWithBBox(size=50, interpolation=Inter.NEAREST)
|
|
3607
|
-
>>> transforms_list = [
|
|
3608
|
-
>>>
|
|
3609
|
-
|
|
3610
|
-
|
|
4879
|
+
>>> transforms_list = [bbox_op]
|
|
4880
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list,
|
|
4881
|
+
... input_columns=["image", "bbox"])
|
|
4882
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4883
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4884
|
+
... print(item["bbox"].shape, item["bbox"].dtype)
|
|
4885
|
+
... break
|
|
4886
|
+
(50, 50, 3) float32
|
|
4887
|
+
(1, 4) float32
|
|
4888
|
+
>>>
|
|
4889
|
+
>>> # Use the transform in eager mode
|
|
4890
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
4891
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(data.dtype))
|
|
4892
|
+
>>> func_data, func_bboxes = func(data)
|
|
4893
|
+
>>> output = vision.RandomResizedCropWithBBox((16, 64), (0.5, 0.5), (0.5, 0.5))(func_data, func_bboxes)
|
|
4894
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
4895
|
+
(16, 64, 3) float32
|
|
4896
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
4897
|
+
(1, 4) float32
|
|
3611
4898
|
|
|
3612
4899
|
Tutorial Examples:
|
|
3613
4900
|
- `Illustration of vision transforms
|
|
3614
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4901
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3615
4902
|
"""
|
|
3616
4903
|
|
|
3617
4904
|
@check_random_resize_crop
|
|
@@ -3651,22 +4938,38 @@ class RandomResize(ImageTensorOperation):
|
|
|
3651
4938
|
``CPU``
|
|
3652
4939
|
|
|
3653
4940
|
Examples:
|
|
4941
|
+
>>> import numpy as np
|
|
3654
4942
|
>>> import mindspore.dataset as ds
|
|
3655
4943
|
>>> import mindspore.dataset.vision as vision
|
|
3656
4944
|
>>>
|
|
3657
|
-
>>>
|
|
4945
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4946
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
4947
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3658
4948
|
>>> # 1) randomly resize image, keeping aspect ratio
|
|
3659
|
-
>>> transforms_list1 = [vision.
|
|
3660
|
-
>>>
|
|
3661
|
-
|
|
4949
|
+
>>> transforms_list1 = [vision.RandomResize(50)]
|
|
4950
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list1, input_columns=["image"])
|
|
4951
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4952
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4953
|
+
... break
|
|
4954
|
+
(50, 50, 3) uint8
|
|
3662
4955
|
>>> # 2) randomly resize image to landscape style
|
|
3663
|
-
>>>
|
|
3664
|
-
>>>
|
|
3665
|
-
|
|
4956
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4957
|
+
>>> transforms_list2 = [vision.RandomResize((40, 60))]
|
|
4958
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list2, input_columns=["image"])
|
|
4959
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
4960
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
4961
|
+
... break
|
|
4962
|
+
(40, 60, 3) uint8
|
|
4963
|
+
>>>
|
|
4964
|
+
>>> # Use the transform in eager mode
|
|
4965
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
4966
|
+
>>> output = vision.RandomResize(10)(data)
|
|
4967
|
+
>>> print(output.shape, output.dtype)
|
|
4968
|
+
(10, 10, 3) uint8
|
|
3666
4969
|
|
|
3667
4970
|
Tutorial Examples:
|
|
3668
4971
|
- `Illustration of vision transforms
|
|
3669
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
4972
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3670
4973
|
"""
|
|
3671
4974
|
|
|
3672
4975
|
@check_resize
|
|
@@ -3703,24 +5006,55 @@ class RandomResizeWithBBox(ImageTensorOperation):
|
|
|
3703
5006
|
``CPU``
|
|
3704
5007
|
|
|
3705
5008
|
Examples:
|
|
5009
|
+
>>> import copy
|
|
5010
|
+
>>> import numpy as np
|
|
3706
5011
|
>>> import mindspore.dataset as ds
|
|
3707
5012
|
>>> import mindspore.dataset.vision as vision
|
|
3708
5013
|
>>>
|
|
3709
|
-
>>>
|
|
5014
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5015
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
5016
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5017
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32))
|
|
5018
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func],
|
|
5019
|
+
... input_columns=["image"],
|
|
5020
|
+
... output_columns=["image", "bbox"])
|
|
5021
|
+
>>> numpy_slices_dataset2 = copy.deepcopy(numpy_slices_dataset)
|
|
3710
5022
|
>>>
|
|
3711
5023
|
>>> # 1) randomly resize image with bounding boxes, keeping aspect ratio
|
|
3712
|
-
>>> transforms_list1 = [vision.
|
|
3713
|
-
>>>
|
|
3714
|
-
... input_columns=["image"])
|
|
5024
|
+
>>> transforms_list1 = [vision.RandomResizeWithBBox(60)]
|
|
5025
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list1,
|
|
5026
|
+
... input_columns=["image", "bbox"])
|
|
5027
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5028
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5029
|
+
... print(item["bbox"].shape, item["bbox"].dtype)
|
|
5030
|
+
... break
|
|
5031
|
+
(60, 60, 3) float32
|
|
5032
|
+
(1, 4) float32
|
|
3715
5033
|
>>>
|
|
3716
5034
|
>>> # 2) randomly resize image with bounding boxes to portrait style
|
|
3717
|
-
>>> transforms_list2 = [vision.
|
|
3718
|
-
>>>
|
|
3719
|
-
...
|
|
5035
|
+
>>> transforms_list2 = [vision.RandomResizeWithBBox((80, 60))]
|
|
5036
|
+
>>> numpy_slices_dataset2 = numpy_slices_dataset2.map(operations=transforms_list2,
|
|
5037
|
+
... input_columns=["image", "bbox"])
|
|
5038
|
+
>>> for item in numpy_slices_dataset2.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5039
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5040
|
+
... print(item["bbox"].shape, item["bbox"].dtype)
|
|
5041
|
+
... break
|
|
5042
|
+
(80, 60, 3) float32
|
|
5043
|
+
(1, 4) float32
|
|
5044
|
+
>>>
|
|
5045
|
+
>>> # Use the transform in eager mode
|
|
5046
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
5047
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(data.dtype))
|
|
5048
|
+
>>> func_data, func_bboxes = func(data)
|
|
5049
|
+
>>> output = vision.RandomResizeWithBBox(64)(func_data, func_bboxes)
|
|
5050
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
5051
|
+
(64, 64, 3) float32
|
|
5052
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
5053
|
+
(1, 4) float32
|
|
3720
5054
|
|
|
3721
5055
|
Tutorial Examples:
|
|
3722
5056
|
- `Illustration of vision transforms
|
|
3723
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5057
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3724
5058
|
"""
|
|
3725
5059
|
|
|
3726
5060
|
@check_resize
|
|
@@ -3770,21 +5104,33 @@ class RandomRotation(ImageTensorOperation, PyTensorOperation):
|
|
|
3770
5104
|
``CPU``
|
|
3771
5105
|
|
|
3772
5106
|
Examples:
|
|
5107
|
+
>>> import numpy as np
|
|
3773
5108
|
>>> import mindspore.dataset as ds
|
|
3774
5109
|
>>> import mindspore.dataset.vision as vision
|
|
3775
5110
|
>>> from mindspore.dataset.vision import Inter
|
|
3776
5111
|
>>>
|
|
3777
|
-
>>>
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
>>>
|
|
3782
|
-
>>>
|
|
3783
|
-
|
|
5112
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5113
|
+
>>> seed = ds.config.get_seed()
|
|
5114
|
+
>>> ds.config.set_seed(12345)
|
|
5115
|
+
>>> transforms_list = [vision.RandomRotation(degrees=5.0, resample=Inter.NEAREST, expand=True)]
|
|
5116
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5117
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5118
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5119
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5120
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5121
|
+
... break
|
|
5122
|
+
(107, 107, 3) uint8
|
|
5123
|
+
>>>
|
|
5124
|
+
>>> # Use the transform in eager mode
|
|
5125
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5126
|
+
>>> output = vision.RandomRotation(degrees=90, resample=Inter.NEAREST, expand=True)(data)
|
|
5127
|
+
>>> print(output.shape, output.dtype)
|
|
5128
|
+
(119, 119, 3) uint8
|
|
5129
|
+
>>> ds.config.set_seed(seed)
|
|
3784
5130
|
|
|
3785
5131
|
Tutorial Examples:
|
|
3786
5132
|
- `Illustration of vision transforms
|
|
3787
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5133
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3788
5134
|
"""
|
|
3789
5135
|
|
|
3790
5136
|
@check_random_rotation
|
|
@@ -3855,21 +5201,35 @@ class RandomSelectSubpolicy(ImageTensorOperation):
|
|
|
3855
5201
|
``CPU``
|
|
3856
5202
|
|
|
3857
5203
|
Examples:
|
|
5204
|
+
>>> import numpy as np
|
|
3858
5205
|
>>> import mindspore.dataset as ds
|
|
3859
5206
|
>>> import mindspore.dataset.vision as vision
|
|
3860
5207
|
>>>
|
|
3861
|
-
>>>
|
|
5208
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5209
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5210
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
3862
5211
|
>>> policy = [[(vision.RandomRotation((45, 45)), 0.5),
|
|
3863
5212
|
... (vision.RandomVerticalFlip(), 1),
|
|
3864
5213
|
... (vision.RandomColorAdjust(), 0.8)],
|
|
3865
5214
|
... [(vision.RandomRotation((90, 90)), 1),
|
|
3866
5215
|
... (vision.RandomColorAdjust(), 0.2)]]
|
|
3867
|
-
>>>
|
|
5216
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=vision.RandomSelectSubpolicy(policy),
|
|
3868
5217
|
... input_columns=["image"])
|
|
5218
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5219
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5220
|
+
... break
|
|
5221
|
+
(100, 100, 3) uint8
|
|
5222
|
+
>>>
|
|
5223
|
+
>>> # Use the transform in eager mode
|
|
5224
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5225
|
+
>>> policy = [[(vision.RandomRotation((90, 90)), 1), (vision.RandomColorAdjust(), 1)]]
|
|
5226
|
+
>>> output = vision.RandomSelectSubpolicy(policy)(data)
|
|
5227
|
+
>>> print(output.shape, output.dtype)
|
|
5228
|
+
(100, 100, 3) uint8
|
|
3869
5229
|
|
|
3870
5230
|
Tutorial Examples:
|
|
3871
5231
|
- `Illustration of vision transforms
|
|
3872
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5232
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3873
5233
|
"""
|
|
3874
5234
|
|
|
3875
5235
|
@check_random_select_subpolicy_op
|
|
@@ -3910,17 +5270,29 @@ class RandomSharpness(ImageTensorOperation, PyTensorOperation):
|
|
|
3910
5270
|
``CPU``
|
|
3911
5271
|
|
|
3912
5272
|
Examples:
|
|
5273
|
+
>>> import numpy as np
|
|
3913
5274
|
>>> import mindspore.dataset as ds
|
|
3914
5275
|
>>> import mindspore.dataset.vision as vision
|
|
3915
5276
|
>>>
|
|
3916
|
-
>>>
|
|
3917
|
-
>>>
|
|
3918
|
-
>>>
|
|
3919
|
-
|
|
5277
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5278
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5279
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5280
|
+
>>> transforms_list = [vision.RandomSharpness(degrees=(0.2, 1.9))]
|
|
5281
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5282
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5283
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5284
|
+
... break
|
|
5285
|
+
(100, 100, 3) uint8
|
|
5286
|
+
>>>
|
|
5287
|
+
>>> # Use the transform in eager mode
|
|
5288
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5289
|
+
>>> output = vision.RandomSharpness(degrees=(0, 0.6))(data)
|
|
5290
|
+
>>> print(output.shape, output.dtype)
|
|
5291
|
+
(100, 100, 3) uint8
|
|
3920
5292
|
|
|
3921
5293
|
Tutorial Examples:
|
|
3922
5294
|
- `Illustration of vision transforms
|
|
3923
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5295
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3924
5296
|
"""
|
|
3925
5297
|
|
|
3926
5298
|
@check_positive_degrees
|
|
@@ -3953,8 +5325,9 @@ class RandomSolarize(ImageTensorOperation):
|
|
|
3953
5325
|
Args:
|
|
3954
5326
|
threshold (tuple, optional): Range of random solarize threshold. Default: ``(0, 255)``.
|
|
3955
5327
|
Threshold values should always be in (min, max) format,
|
|
3956
|
-
where min and max are integers in the range [0, 255], and min <= max.
|
|
3957
|
-
|
|
5328
|
+
where min and max are integers in the range [0, 255], and min <= max. The pixel values
|
|
5329
|
+
belonging to the [min, max] range will be inverted.
|
|
5330
|
+
If min=max, then invert all pixel values greater than or equal min(max).
|
|
3958
5331
|
|
|
3959
5332
|
Raises:
|
|
3960
5333
|
TypeError : If `threshold` is not of type tuple.
|
|
@@ -3964,17 +5337,29 @@ class RandomSolarize(ImageTensorOperation):
|
|
|
3964
5337
|
``CPU``
|
|
3965
5338
|
|
|
3966
5339
|
Examples:
|
|
5340
|
+
>>> import numpy as np
|
|
3967
5341
|
>>> import mindspore.dataset as ds
|
|
3968
5342
|
>>> import mindspore.dataset.vision as vision
|
|
3969
5343
|
>>>
|
|
3970
|
-
>>>
|
|
3971
|
-
>>>
|
|
3972
|
-
>>>
|
|
3973
|
-
|
|
5344
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5345
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5346
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5347
|
+
>>> transforms_list = [vision.RandomSolarize(threshold=(10,100))]
|
|
5348
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5349
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5350
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5351
|
+
... break
|
|
5352
|
+
(100, 100, 3) uint8
|
|
5353
|
+
>>>
|
|
5354
|
+
>>> # Use the transform in eager mode
|
|
5355
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5356
|
+
>>> output = vision.RandomSolarize(threshold=(1, 10))(data)
|
|
5357
|
+
>>> print(output.shape, output.dtype)
|
|
5358
|
+
(100, 100, 3) uint8
|
|
3974
5359
|
|
|
3975
5360
|
Tutorial Examples:
|
|
3976
5361
|
- `Illustration of vision transforms
|
|
3977
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5362
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
3978
5363
|
"""
|
|
3979
5364
|
|
|
3980
5365
|
@check_random_solarize
|
|
@@ -4004,17 +5389,29 @@ class RandomVerticalFlip(ImageTensorOperation, PyTensorOperation):
|
|
|
4004
5389
|
``CPU``
|
|
4005
5390
|
|
|
4006
5391
|
Examples:
|
|
5392
|
+
>>> import numpy as np
|
|
4007
5393
|
>>> import mindspore.dataset as ds
|
|
4008
5394
|
>>> import mindspore.dataset.vision as vision
|
|
4009
5395
|
>>>
|
|
4010
|
-
>>>
|
|
4011
|
-
>>>
|
|
4012
|
-
>>>
|
|
4013
|
-
|
|
5396
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5397
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5398
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5399
|
+
>>> transforms_list = [vision.RandomVerticalFlip(0.25)]
|
|
5400
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5401
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5402
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5403
|
+
... break
|
|
5404
|
+
(100, 100, 3) uint8
|
|
5405
|
+
>>>
|
|
5406
|
+
>>> # Use the transform in eager mode
|
|
5407
|
+
>>> data = np.array([[0, 1, 2, 3, 4, 5]], dtype=np.uint8).reshape((2, 3))
|
|
5408
|
+
>>> output = vision.RandomVerticalFlip(1.0)(data)
|
|
5409
|
+
>>> print(output.shape, output.dtype)
|
|
5410
|
+
(2, 3) uint8
|
|
4014
5411
|
|
|
4015
5412
|
Tutorial Examples:
|
|
4016
5413
|
- `Illustration of vision transforms
|
|
4017
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5414
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4018
5415
|
"""
|
|
4019
5416
|
|
|
4020
5417
|
@check_prob
|
|
@@ -4055,17 +5452,39 @@ class RandomVerticalFlipWithBBox(ImageTensorOperation):
|
|
|
4055
5452
|
``CPU``
|
|
4056
5453
|
|
|
4057
5454
|
Examples:
|
|
5455
|
+
>>> import numpy as np
|
|
4058
5456
|
>>> import mindspore.dataset as ds
|
|
4059
5457
|
>>> import mindspore.dataset.vision as vision
|
|
4060
5458
|
>>>
|
|
4061
|
-
>>>
|
|
4062
|
-
>>>
|
|
4063
|
-
>>>
|
|
4064
|
-
|
|
5459
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5460
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
5461
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5462
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32))
|
|
5463
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func],
|
|
5464
|
+
... input_columns=["image"],
|
|
5465
|
+
... output_columns=["image", "bbox"])
|
|
5466
|
+
>>> transforms_list = [vision.RandomVerticalFlipWithBBox(0.20)]
|
|
5467
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image", "bbox"])
|
|
5468
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5469
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5470
|
+
... print(item["bbox"].shape, item["bbox"].dtype)
|
|
5471
|
+
... break
|
|
5472
|
+
(100, 100, 3) float32
|
|
5473
|
+
(1, 4) float32
|
|
5474
|
+
>>>
|
|
5475
|
+
>>> # Use the transform in eager mode
|
|
5476
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
5477
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(data.dtype))
|
|
5478
|
+
>>> func_data, func_bboxes = func(data)
|
|
5479
|
+
>>> output = vision.RandomVerticalFlipWithBBox(1)(func_data, func_bboxes)
|
|
5480
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
5481
|
+
(100, 100, 3) float32
|
|
5482
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
5483
|
+
(1, 4) float32
|
|
4065
5484
|
|
|
4066
5485
|
Tutorial Examples:
|
|
4067
5486
|
- `Illustration of vision transforms
|
|
4068
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5487
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4069
5488
|
"""
|
|
4070
5489
|
|
|
4071
5490
|
@check_prob
|
|
@@ -4099,17 +5518,29 @@ class Rescale(ImageTensorOperation):
|
|
|
4099
5518
|
``CPU`` ``GPU`` ``Ascend``
|
|
4100
5519
|
|
|
4101
5520
|
Examples:
|
|
5521
|
+
>>> import numpy as np
|
|
4102
5522
|
>>> import mindspore.dataset as ds
|
|
4103
5523
|
>>> import mindspore.dataset.vision as vision
|
|
4104
5524
|
>>>
|
|
4105
|
-
>>>
|
|
4106
|
-
>>>
|
|
4107
|
-
>>>
|
|
4108
|
-
|
|
5525
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5526
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5527
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5528
|
+
>>> transforms_list = [vision.Rescale(1.0 / 255.0, -1.0)]
|
|
5529
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5530
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5531
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5532
|
+
... break
|
|
5533
|
+
(100, 100, 3) float32
|
|
5534
|
+
>>>
|
|
5535
|
+
>>> # Use the transform in eager mode
|
|
5536
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5537
|
+
>>> output = vision.Rescale(1.0 / 255.0, -1.0)(data)
|
|
5538
|
+
>>> print(output.shape, output.dtype)
|
|
5539
|
+
(100, 100, 3) float32
|
|
4109
5540
|
|
|
4110
5541
|
Tutorial Examples:
|
|
4111
5542
|
- `Illustration of vision transforms
|
|
4112
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5543
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4113
5544
|
"""
|
|
4114
5545
|
|
|
4115
5546
|
@check_rescale
|
|
@@ -4127,6 +5558,8 @@ class Resize(ImageTensorOperation, PyTensorOperation):
|
|
|
4127
5558
|
"""
|
|
4128
5559
|
Resize the input image to the given size with a given interpolation mode :class:`~.vision.Inter` .
|
|
4129
5560
|
|
|
5561
|
+
Supports Ascend hardware acceleration and can be enabled through the `.device("Ascend")` method.
|
|
5562
|
+
|
|
4130
5563
|
Args:
|
|
4131
5564
|
size (Union[int, Sequence[int]]): The output size of the resized image. The size value(s) must be positive.
|
|
4132
5565
|
If size is an integer, the smaller edge of the image will be resized to this value with
|
|
@@ -4145,20 +5578,31 @@ class Resize(ImageTensorOperation, PyTensorOperation):
|
|
|
4145
5578
|
``CPU`` ``Ascend``
|
|
4146
5579
|
|
|
4147
5580
|
Examples:
|
|
5581
|
+
>>> import numpy as np
|
|
4148
5582
|
>>> import mindspore.dataset as ds
|
|
4149
5583
|
>>> import mindspore.dataset.vision as vision
|
|
4150
5584
|
>>> from mindspore.dataset.vision import Inter
|
|
4151
5585
|
>>>
|
|
4152
|
-
>>>
|
|
5586
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5587
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5588
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4153
5589
|
>>> resize_op = vision.Resize([100, 75], Inter.BICUBIC)
|
|
4154
|
-
>>> transforms_list = [
|
|
4155
|
-
>>>
|
|
4156
|
-
>>>
|
|
4157
|
-
...
|
|
5590
|
+
>>> transforms_list = [resize_op]
|
|
5591
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5592
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5593
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5594
|
+
... break
|
|
5595
|
+
(100, 75, 3) uint8
|
|
5596
|
+
>>>
|
|
5597
|
+
>>> # Use the transform in eager mode
|
|
5598
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5599
|
+
>>> output = vision.Resize([5, 5], Inter.BICUBIC)(data)
|
|
5600
|
+
>>> print(output.shape, output.dtype)
|
|
5601
|
+
(5, 5, 3) uint8
|
|
4158
5602
|
|
|
4159
5603
|
Tutorial Examples:
|
|
4160
5604
|
- `Illustration of vision transforms
|
|
4161
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5605
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4162
5606
|
"""
|
|
4163
5607
|
|
|
4164
5608
|
@check_resize_interpolation
|
|
@@ -4180,32 +5624,45 @@ class Resize(ImageTensorOperation, PyTensorOperation):
|
|
|
4180
5624
|
"""
|
|
4181
5625
|
Set the device for the current operator execution.
|
|
4182
5626
|
|
|
5627
|
+
- When the device is Ascend, input/output shape should be limited from [4, 6] to [32768, 32768].
|
|
5628
|
+
|
|
4183
5629
|
Args:
|
|
4184
5630
|
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
4185
|
-
``CPU`` . Default: ``CPU`` .
|
|
5631
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
4186
5632
|
|
|
4187
5633
|
Raises:
|
|
4188
5634
|
TypeError: If `device_target` is not of type str.
|
|
4189
|
-
ValueError: If `device_target` is not
|
|
5635
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
4190
5636
|
|
|
4191
5637
|
Supported Platforms:
|
|
4192
|
-
``CPU``
|
|
5638
|
+
``CPU`` ``Ascend``
|
|
4193
5639
|
|
|
4194
5640
|
Examples:
|
|
5641
|
+
>>> import numpy as np
|
|
4195
5642
|
>>> import mindspore.dataset as ds
|
|
4196
5643
|
>>> import mindspore.dataset.vision as vision
|
|
4197
5644
|
>>> from mindspore.dataset.vision import Inter
|
|
4198
5645
|
>>>
|
|
4199
|
-
>>>
|
|
5646
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4200
5647
|
>>> resize_op = vision.Resize([100, 75], Inter.BICUBIC).device("Ascend")
|
|
4201
|
-
>>> transforms_list = [
|
|
4202
|
-
>>>
|
|
4203
|
-
>>>
|
|
4204
|
-
|
|
5648
|
+
>>> transforms_list = [resize_op]
|
|
5649
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5650
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5651
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5652
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5653
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5654
|
+
... break
|
|
5655
|
+
(100, 75, 3) uint8
|
|
5656
|
+
>>>
|
|
5657
|
+
>>> # Use the transform in eager mode
|
|
5658
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5659
|
+
>>> output = vision.Resize([25, 25], Inter.BICUBIC).device("Ascend")(data)
|
|
5660
|
+
>>> print(output.shape, output.dtype)
|
|
5661
|
+
(25, 25, 3) uint8
|
|
4205
5662
|
|
|
4206
5663
|
Tutorial Examples:
|
|
4207
5664
|
- `Illustration of vision transforms
|
|
4208
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5665
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4209
5666
|
"""
|
|
4210
5667
|
self.device_target = device_target
|
|
4211
5668
|
if self.interpolation == Inter.ANTIALIAS and self.device_target == "Ascend":
|
|
@@ -4267,18 +5724,30 @@ class ResizedCrop(ImageTensorOperation):
|
|
|
4267
5724
|
``CPU``
|
|
4268
5725
|
|
|
4269
5726
|
Examples:
|
|
5727
|
+
>>> import numpy as np
|
|
4270
5728
|
>>> import mindspore.dataset as ds
|
|
4271
5729
|
>>> import mindspore.dataset.vision as vision
|
|
4272
5730
|
>>> from mindspore.dataset.vision import Inter
|
|
4273
5731
|
>>>
|
|
4274
|
-
>>>
|
|
4275
|
-
>>>
|
|
4276
|
-
>>>
|
|
4277
|
-
|
|
5732
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5733
|
+
>>> transforms_list = [vision.ResizedCrop(0, 0, 64, 64, (100, 75), Inter.BILINEAR)]
|
|
5734
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5735
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5736
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5737
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5738
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5739
|
+
... break
|
|
5740
|
+
(100, 75, 3) uint8
|
|
5741
|
+
>>>
|
|
5742
|
+
>>> # Use the transform in eager mode
|
|
5743
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5744
|
+
>>> output = vision.ResizedCrop(0, 0, 1, 1, (5, 5), Inter.BILINEAR)(data)
|
|
5745
|
+
>>> print(output.shape, output.dtype)
|
|
5746
|
+
(5, 5, 3) uint8
|
|
4278
5747
|
|
|
4279
5748
|
Tutorial Examples:
|
|
4280
5749
|
- `Illustration of vision transforms
|
|
4281
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5750
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4282
5751
|
"""
|
|
4283
5752
|
|
|
4284
5753
|
@check_resized_crop
|
|
@@ -4295,9 +5764,57 @@ class ResizedCrop(ImageTensorOperation):
|
|
|
4295
5764
|
self.interpolation = interpolation
|
|
4296
5765
|
self.implementation = Implementation.C
|
|
4297
5766
|
|
|
5767
|
+
@check_device_target
|
|
5768
|
+
def device(self, device_target="CPU"):
|
|
5769
|
+
"""
|
|
5770
|
+
Set the device for the current operator execution.
|
|
5771
|
+
|
|
5772
|
+
- When the device is Ascend, input/output shape should be limited from [4, 6] to [32768, 32768].
|
|
5773
|
+
|
|
5774
|
+
Args:
|
|
5775
|
+
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
5776
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
5777
|
+
|
|
5778
|
+
Raises:
|
|
5779
|
+
TypeError: If `device_target` is not of type str.
|
|
5780
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
5781
|
+
|
|
5782
|
+
Supported Platforms:
|
|
5783
|
+
``CPU`` ``Ascend``
|
|
5784
|
+
|
|
5785
|
+
Examples:
|
|
5786
|
+
>>> import numpy as np
|
|
5787
|
+
>>> import mindspore.dataset as ds
|
|
5788
|
+
>>> import mindspore.dataset.vision as vision
|
|
5789
|
+
>>> from mindspore.dataset.vision import Inter
|
|
5790
|
+
>>>
|
|
5791
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5792
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5793
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5794
|
+
>>> resize_crop_op = vision.ResizedCrop(0, 0, 64, 64, (100, 75)).device("Ascend")
|
|
5795
|
+
>>> transforms_list = [resize_crop_op]
|
|
5796
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5797
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5798
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5799
|
+
... break
|
|
5800
|
+
(100, 75, 3) uint8
|
|
5801
|
+
>>>
|
|
5802
|
+
>>> # Use the transform in eager mode
|
|
5803
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5804
|
+
>>> output = vision.ResizedCrop(0, 0, 64, 64, (32, 16), Inter.BILINEAR).device("Ascend")(data)
|
|
5805
|
+
>>> print(output.shape, output.dtype)
|
|
5806
|
+
(32, 16, 3) uint8
|
|
5807
|
+
|
|
5808
|
+
Tutorial Examples:
|
|
5809
|
+
- `Illustration of vision transforms
|
|
5810
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
5811
|
+
"""
|
|
5812
|
+
self.device_target = device_target
|
|
5813
|
+
return self
|
|
5814
|
+
|
|
4298
5815
|
def parse(self):
|
|
4299
5816
|
return cde.ResizedCropOperation(self.top, self.left, self.height,
|
|
4300
|
-
self.width, self.size, Inter.to_c_type(self.interpolation))
|
|
5817
|
+
self.width, self.size, Inter.to_c_type(self.interpolation), self.device_target)
|
|
4301
5818
|
|
|
4302
5819
|
|
|
4303
5820
|
class ResizeWithBBox(ImageTensorOperation):
|
|
@@ -4322,20 +5839,41 @@ class ResizeWithBBox(ImageTensorOperation):
|
|
|
4322
5839
|
``CPU``
|
|
4323
5840
|
|
|
4324
5841
|
Examples:
|
|
5842
|
+
>>> import numpy as np
|
|
4325
5843
|
>>> import mindspore.dataset as ds
|
|
4326
5844
|
>>> import mindspore.dataset.vision as vision
|
|
4327
5845
|
>>> from mindspore.dataset.vision import Inter
|
|
4328
5846
|
>>>
|
|
4329
|
-
>>>
|
|
5847
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5848
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
5849
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5850
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(np.float32))
|
|
5851
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=[func],
|
|
5852
|
+
... input_columns=["image"],
|
|
5853
|
+
... output_columns=["image", "bbox"])
|
|
4330
5854
|
>>> bbox_op = vision.ResizeWithBBox(50, Inter.NEAREST)
|
|
4331
|
-
>>> transforms_list = [
|
|
4332
|
-
>>>
|
|
4333
|
-
>>>
|
|
4334
|
-
...
|
|
5855
|
+
>>> transforms_list = [bbox_op]
|
|
5856
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image", "bbox"])
|
|
5857
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5858
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5859
|
+
... print(item["bbox"].shape, item["bbox"].dtype)
|
|
5860
|
+
... break
|
|
5861
|
+
(50, 50, 3) float32
|
|
5862
|
+
(1, 4) float32
|
|
5863
|
+
>>>
|
|
5864
|
+
>>> # Use the transform in eager mode
|
|
5865
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.float32)
|
|
5866
|
+
>>> func = lambda img: (data, np.array([[0, 0, data.shape[1], data.shape[0]]]).astype(data.dtype))
|
|
5867
|
+
>>> func_data, func_bboxes = func(data)
|
|
5868
|
+
>>> output = vision.ResizeWithBBox(100)(func_data, func_bboxes)
|
|
5869
|
+
>>> print(output[0].shape, output[0].dtype)
|
|
5870
|
+
(100, 100, 3) float32
|
|
5871
|
+
>>> print(output[1].shape, output[1].dtype)
|
|
5872
|
+
(1, 4) float32
|
|
4335
5873
|
|
|
4336
5874
|
Tutorial Examples:
|
|
4337
5875
|
- `Illustration of vision transforms
|
|
4338
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5876
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4339
5877
|
"""
|
|
4340
5878
|
|
|
4341
5879
|
@check_resize_interpolation
|
|
@@ -4367,22 +5905,33 @@ class RgbToHsv(PyTensorOperation):
|
|
|
4367
5905
|
``CPU``
|
|
4368
5906
|
|
|
4369
5907
|
Examples:
|
|
5908
|
+
>>> import numpy as np
|
|
4370
5909
|
>>> import mindspore.dataset as ds
|
|
4371
5910
|
>>> import mindspore.dataset.vision as vision
|
|
4372
5911
|
>>> from mindspore.dataset.transforms import Compose
|
|
4373
5912
|
>>>
|
|
4374
|
-
>>>
|
|
4375
|
-
|
|
5913
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5914
|
+
>>> transforms_list = Compose([vision.CenterCrop(20),
|
|
4376
5915
|
... vision.ToTensor(),
|
|
4377
5916
|
... vision.RgbToHsv()])
|
|
4378
5917
|
>>> # apply the transform to dataset through map function
|
|
4379
|
-
>>>
|
|
4380
|
-
>>>
|
|
4381
|
-
|
|
5918
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5919
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5920
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
5921
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
5922
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
5923
|
+
... break
|
|
5924
|
+
(3, 20, 20) float64
|
|
5925
|
+
>>>
|
|
5926
|
+
>>> # Use the transform in eager mode
|
|
5927
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
5928
|
+
>>> output = vision.RgbToHsv(is_hwc=True)(data)
|
|
5929
|
+
>>> print(output.shape, output.dtype)
|
|
5930
|
+
(100, 100, 3) float64
|
|
4382
5931
|
|
|
4383
5932
|
Tutorial Examples:
|
|
4384
5933
|
- `Illustration of vision transforms
|
|
4385
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
5934
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4386
5935
|
"""
|
|
4387
5936
|
|
|
4388
5937
|
@check_rgb_to_hsv
|
|
@@ -4437,21 +5986,30 @@ class Rotate(ImageTensorOperation):
|
|
|
4437
5986
|
``CPU``
|
|
4438
5987
|
|
|
4439
5988
|
Examples:
|
|
5989
|
+
>>> import numpy as np
|
|
4440
5990
|
>>> import mindspore.dataset as ds
|
|
4441
5991
|
>>> import mindspore.dataset.vision as vision
|
|
4442
5992
|
>>> from mindspore.dataset.vision import Inter
|
|
4443
5993
|
>>>
|
|
4444
|
-
>>>
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
>>>
|
|
4449
|
-
>>>
|
|
4450
|
-
...
|
|
5994
|
+
>>> # Use the transform in dataset pipeline mode
|
|
5995
|
+
>>> transforms_list = [vision.Rotate(degrees=30.0, resample=Inter.NEAREST, expand=True)]
|
|
5996
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
5997
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
5998
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
5999
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6000
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6001
|
+
... break
|
|
6002
|
+
(137, 137, 3) uint8
|
|
6003
|
+
>>>
|
|
6004
|
+
>>> # Use the transform in eager mode
|
|
6005
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6006
|
+
>>> output = vision.Rotate(degrees=30.0, resample=Inter.NEAREST, expand=True)(data)
|
|
6007
|
+
>>> print(output.shape, output.dtype)
|
|
6008
|
+
(137, 137, 3) uint8
|
|
4451
6009
|
|
|
4452
6010
|
Tutorial Examples:
|
|
4453
6011
|
- `Illustration of vision transforms
|
|
4454
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6012
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4455
6013
|
"""
|
|
4456
6014
|
|
|
4457
6015
|
@check_rotate
|
|
@@ -4476,12 +6034,12 @@ class Rotate(ImageTensorOperation):
|
|
|
4476
6034
|
|
|
4477
6035
|
|
|
4478
6036
|
class SlicePatches(ImageTensorOperation):
|
|
4479
|
-
"""
|
|
6037
|
+
r"""
|
|
4480
6038
|
Slice Tensor to multiple patches in horizontal and vertical directions.
|
|
4481
6039
|
|
|
4482
6040
|
The usage scenario is suitable to large height and width Tensor. The Tensor
|
|
4483
6041
|
will keep the same if set both num_height and num_width to 1. And the
|
|
4484
|
-
number of output tensors is equal to
|
|
6042
|
+
number of output tensors is equal to :math:`num\_height * num\_width`.
|
|
4485
6043
|
|
|
4486
6044
|
Args:
|
|
4487
6045
|
num_height (int, optional): The number of patches in vertical direction, which must be positive. Default: ``1``.
|
|
@@ -4507,24 +6065,36 @@ class SlicePatches(ImageTensorOperation):
|
|
|
4507
6065
|
``CPU``
|
|
4508
6066
|
|
|
4509
6067
|
Examples:
|
|
6068
|
+
>>> import numpy as np
|
|
4510
6069
|
>>> import mindspore.dataset as ds
|
|
4511
6070
|
>>> import mindspore.dataset.vision as vision
|
|
4512
6071
|
>>>
|
|
6072
|
+
>>> # Use the transform in dataset pipeline mode
|
|
4513
6073
|
>>> # default padding mode
|
|
4514
|
-
>>> decode_op = vision.Decode()
|
|
4515
6074
|
>>> num_h, num_w = (1, 4)
|
|
4516
6075
|
>>> slice_patches_op = vision.SlicePatches(num_h, num_w)
|
|
4517
|
-
>>> transforms_list = [
|
|
6076
|
+
>>> transforms_list = [slice_patches_op]
|
|
4518
6077
|
>>> cols = ['img' + str(x) for x in range(num_h*num_w)]
|
|
4519
6078
|
>>>
|
|
4520
|
-
>>>
|
|
4521
|
-
>>>
|
|
6079
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6080
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
6081
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list,
|
|
4522
6082
|
... input_columns=["image"],
|
|
4523
6083
|
... output_columns=cols)
|
|
6084
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6085
|
+
... print(len(item), item["img0"].shape, item["img0"].dtype)
|
|
6086
|
+
... break
|
|
6087
|
+
4 (100, 25, 3) uint8
|
|
6088
|
+
>>>
|
|
6089
|
+
>>> # Use the transform in eager mode
|
|
6090
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6091
|
+
>>> output = vision.SlicePatches(1, 2)(data)
|
|
6092
|
+
>>> print(np.array(output).shape, np.array(output).dtype)
|
|
6093
|
+
(2, 100, 50, 3) uint8
|
|
4524
6094
|
|
|
4525
6095
|
Tutorial Examples:
|
|
4526
6096
|
- `Illustration of vision transforms
|
|
4527
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6097
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4528
6098
|
"""
|
|
4529
6099
|
|
|
4530
6100
|
@check_slice_patches
|
|
@@ -4548,7 +6118,8 @@ class Solarize(ImageTensorOperation):
|
|
|
4548
6118
|
Args:
|
|
4549
6119
|
threshold (Union[float, Sequence[float, float]]): Range of solarize threshold, should always
|
|
4550
6120
|
be in (min, max) format, where min and max are integers in range of [0, 255], and min <= max.
|
|
4551
|
-
|
|
6121
|
+
The pixel values belonging to the [min, max] range will be inverted.
|
|
6122
|
+
If a single value is provided or min=max, then invert all pixel values greater than or equal min(max).
|
|
4552
6123
|
|
|
4553
6124
|
Raises:
|
|
4554
6125
|
TypeError: If `threshold` is not of type float or Sequence[float, float].
|
|
@@ -4558,17 +6129,29 @@ class Solarize(ImageTensorOperation):
|
|
|
4558
6129
|
``CPU``
|
|
4559
6130
|
|
|
4560
6131
|
Examples:
|
|
6132
|
+
>>> import numpy as np
|
|
4561
6133
|
>>> import mindspore.dataset as ds
|
|
4562
6134
|
>>> import mindspore.dataset.vision as vision
|
|
4563
6135
|
>>>
|
|
4564
|
-
>>>
|
|
4565
|
-
>>>
|
|
4566
|
-
>>>
|
|
4567
|
-
|
|
6136
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6137
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6138
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
6139
|
+
>>> transforms_list = [vision.Solarize(threshold=(10, 100))]
|
|
6140
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
6141
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6142
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6143
|
+
... break
|
|
6144
|
+
(100, 100, 3) uint8
|
|
6145
|
+
>>>
|
|
6146
|
+
>>> # Use the transform in eager mode
|
|
6147
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6148
|
+
>>> output = vision.Solarize(threshold=(1, 10))(data)
|
|
6149
|
+
>>> print(output.shape, output.dtype)
|
|
6150
|
+
(100, 100, 3) uint8
|
|
4568
6151
|
|
|
4569
6152
|
Tutorial Examples:
|
|
4570
6153
|
- `Illustration of vision transforms
|
|
4571
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6154
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4572
6155
|
"""
|
|
4573
6156
|
|
|
4574
6157
|
@check_solarize
|
|
@@ -4603,23 +6186,58 @@ class TenCrop(PyTensorOperation):
|
|
|
4603
6186
|
``CPU``
|
|
4604
6187
|
|
|
4605
6188
|
Examples:
|
|
6189
|
+
>>> import os
|
|
6190
|
+
>>> import numpy as np
|
|
6191
|
+
>>> from PIL import Image, ImageDraw
|
|
4606
6192
|
>>> import mindspore.dataset as ds
|
|
4607
6193
|
>>> import mindspore.dataset.vision as vision
|
|
4608
|
-
>>> import numpy
|
|
4609
6194
|
>>> from mindspore.dataset.transforms import Compose
|
|
4610
6195
|
>>>
|
|
6196
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6197
|
+
>>> class MyDataset:
|
|
6198
|
+
... def __init__(self):
|
|
6199
|
+
... self.data = []
|
|
6200
|
+
... img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
6201
|
+
... draw = ImageDraw.Draw(img)
|
|
6202
|
+
... draw.ellipse(((0, 0), (100, 100)), fill=(255, 0, 0), outline=(255, 0, 0), width=5)
|
|
6203
|
+
... img.save("./1.jpg")
|
|
6204
|
+
... data = np.fromfile("./1.jpg", np.uint8)
|
|
6205
|
+
... self.data.append(data)
|
|
6206
|
+
...
|
|
6207
|
+
... def __getitem__(self, index):
|
|
6208
|
+
... return self.data[0]
|
|
6209
|
+
...
|
|
6210
|
+
... def __len__(self):
|
|
6211
|
+
... return 5
|
|
6212
|
+
>>>
|
|
6213
|
+
>>> my_dataset = MyDataset()
|
|
6214
|
+
>>> generator_dataset = ds.GeneratorDataset(my_dataset, column_names="image")
|
|
4611
6215
|
>>> transforms_list = Compose([vision.Decode(to_pil=True),
|
|
4612
6216
|
... vision.TenCrop(size=200),
|
|
4613
6217
|
... # 4D stack of 10 images
|
|
4614
|
-
... lambda *images:
|
|
6218
|
+
... lambda *images: np.stack([vision.ToTensor()(image) for image in images])])
|
|
4615
6219
|
>>> # apply the transform to dataset through map function
|
|
4616
|
-
>>>
|
|
4617
|
-
>>>
|
|
4618
|
-
...
|
|
6220
|
+
>>> generator_dataset = generator_dataset.map(operations=transforms_list, input_columns="image")
|
|
6221
|
+
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6222
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6223
|
+
... break
|
|
6224
|
+
(10, 3, 200, 200) float32
|
|
6225
|
+
>>> os.remove("./1.jpg")
|
|
6226
|
+
>>>
|
|
6227
|
+
>>> # Use the transform in eager mode
|
|
6228
|
+
>>> img = Image.new("RGB", (300, 300), (255, 255, 255))
|
|
6229
|
+
>>> draw = ImageDraw.Draw(img)
|
|
6230
|
+
>>> draw.polygon([(50, 50), (150, 50), (100, 150)], fill=(0, 255, 0), outline=(0, 255, 0))
|
|
6231
|
+
>>> img.save("./2.jpg")
|
|
6232
|
+
>>> data = Image.open("./2.jpg")
|
|
6233
|
+
>>> output = vision.TenCrop(size=200)(data)
|
|
6234
|
+
>>> print(len(output), np.array(output[0]).shape, np.array(output[0]).dtype)
|
|
6235
|
+
10 (200, 200, 3) uint8
|
|
6236
|
+
>>> os.remove("./2.jpg")
|
|
4619
6237
|
|
|
4620
6238
|
Tutorial Examples:
|
|
4621
6239
|
- `Illustration of vision transforms
|
|
4622
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6240
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4623
6241
|
"""
|
|
4624
6242
|
|
|
4625
6243
|
@check_ten_crop
|
|
@@ -4654,23 +6272,34 @@ class ToNumpy(PyTensorOperation):
|
|
|
4654
6272
|
``CPU``
|
|
4655
6273
|
|
|
4656
6274
|
Examples:
|
|
6275
|
+
>>> import numpy as np
|
|
4657
6276
|
>>> import mindspore.dataset as ds
|
|
4658
6277
|
>>> import mindspore.dataset.vision as vision
|
|
4659
6278
|
>>> from mindspore.dataset.transforms import Compose
|
|
4660
6279
|
>>>
|
|
6280
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6281
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6282
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4661
6283
|
>>> # Use ToNumpy to explicitly select C++ implementation of subsequent op
|
|
4662
|
-
>>> transforms_list = Compose([vision.
|
|
4663
|
-
... vision.RandomHorizontalFlip(0.5),
|
|
6284
|
+
>>> transforms_list = Compose([vision.RandomHorizontalFlip(0.5),
|
|
4664
6285
|
... vision.ToNumpy(),
|
|
4665
|
-
... vision.Resize((
|
|
6286
|
+
... vision.Resize((50, 60))])
|
|
4666
6287
|
>>> # apply the transform to dataset through map function
|
|
4667
|
-
>>>
|
|
4668
|
-
>>>
|
|
4669
|
-
...
|
|
6288
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
6289
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6290
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6291
|
+
... break
|
|
6292
|
+
(50, 60, 3) uint8
|
|
6293
|
+
>>>
|
|
6294
|
+
>>> # Use the transform in eager mode
|
|
6295
|
+
>>> data = list(np.random.randint(0, 255, size=(32, 32, 3, 3)).astype(np.int32))
|
|
6296
|
+
>>> output = vision.ToNumpy()(data)
|
|
6297
|
+
>>> print(type(output), output.shape, output.dtype)
|
|
6298
|
+
<class 'numpy.ndarray'> (32, 32, 3, 3) int32
|
|
4670
6299
|
|
|
4671
6300
|
Tutorial Examples:
|
|
4672
6301
|
- `Illustration of vision transforms
|
|
4673
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6302
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4674
6303
|
"""
|
|
4675
6304
|
|
|
4676
6305
|
def __init__(self):
|
|
@@ -4703,22 +6332,34 @@ class ToPIL(PyTensorOperation):
|
|
|
4703
6332
|
``CPU``
|
|
4704
6333
|
|
|
4705
6334
|
Examples:
|
|
6335
|
+
>>> import numpy as np
|
|
4706
6336
|
>>> import mindspore.dataset as ds
|
|
4707
6337
|
>>> import mindspore.dataset.vision as vision
|
|
4708
6338
|
>>> from mindspore.dataset.transforms import Compose
|
|
4709
6339
|
>>>
|
|
6340
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6341
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6342
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4710
6343
|
>>> # data is already decoded, but not in PIL Image format
|
|
4711
6344
|
>>> transforms_list = Compose([vision.ToPIL(),
|
|
4712
6345
|
... vision.RandomHorizontalFlip(0.5),
|
|
4713
6346
|
... vision.ToTensor()])
|
|
4714
6347
|
>>> # apply the transform to dataset through map function
|
|
4715
|
-
>>>
|
|
4716
|
-
>>>
|
|
4717
|
-
...
|
|
6348
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
6349
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6350
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6351
|
+
... break
|
|
6352
|
+
(3, 100, 100) float32
|
|
6353
|
+
>>>
|
|
6354
|
+
>>> # Use the transform in eager mode
|
|
6355
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6356
|
+
>>> output = vision.ToPIL()(data)
|
|
6357
|
+
>>> print(type(output), np.array(output).shape, np.array(output).dtype)
|
|
6358
|
+
<class 'PIL.Image.Image'> (100, 100, 3) uint8
|
|
4718
6359
|
|
|
4719
6360
|
Tutorial Examples:
|
|
4720
6361
|
- `Illustration of vision transforms
|
|
4721
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6362
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4722
6363
|
"""
|
|
4723
6364
|
|
|
4724
6365
|
def __init__(self):
|
|
@@ -4756,22 +6397,33 @@ class ToTensor(ImageTensorOperation):
|
|
|
4756
6397
|
``CPU``
|
|
4757
6398
|
|
|
4758
6399
|
Examples:
|
|
6400
|
+
>>> import numpy as np
|
|
4759
6401
|
>>> import mindspore.dataset as ds
|
|
4760
6402
|
>>> import mindspore.dataset.vision as vision
|
|
4761
6403
|
>>> from mindspore.dataset.transforms import Compose
|
|
4762
6404
|
>>>
|
|
6405
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6406
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6407
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
4763
6408
|
>>> # create a list of transformations to be applied to the "image" column of each data row
|
|
4764
|
-
>>> transforms_list = Compose([vision.
|
|
4765
|
-
... vision.RandomHorizontalFlip(0.5),
|
|
6409
|
+
>>> transforms_list = Compose([vision.RandomHorizontalFlip(0.5),
|
|
4766
6410
|
... vision.ToTensor()])
|
|
4767
6411
|
>>> # apply the transform to dataset through map function
|
|
4768
|
-
>>>
|
|
4769
|
-
>>>
|
|
4770
|
-
...
|
|
6412
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
6413
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6414
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6415
|
+
... break
|
|
6416
|
+
(3, 100, 100) float32
|
|
6417
|
+
>>>
|
|
6418
|
+
>>> # Use the transform in eager mode
|
|
6419
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6420
|
+
>>> output = vision.ToTensor()(data)
|
|
6421
|
+
>>> print(output.shape, output.dtype)
|
|
6422
|
+
(3, 100, 100) float32
|
|
4771
6423
|
|
|
4772
6424
|
Tutorial Examples:
|
|
4773
6425
|
- `Illustration of vision transforms
|
|
4774
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6426
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4775
6427
|
"""
|
|
4776
6428
|
|
|
4777
6429
|
@check_to_tensor
|
|
@@ -4810,23 +6462,34 @@ class ToType(TypeCast):
|
|
|
4810
6462
|
``CPU`` ``GPU`` ``Ascend``
|
|
4811
6463
|
|
|
4812
6464
|
Examples:
|
|
6465
|
+
>>> import numpy as np
|
|
4813
6466
|
>>> import mindspore.dataset as ds
|
|
4814
6467
|
>>> import mindspore.dataset.vision as vision
|
|
4815
6468
|
>>> import numpy as np
|
|
4816
6469
|
>>> from mindspore.dataset.transforms import Compose
|
|
4817
6470
|
>>>
|
|
4818
|
-
>>>
|
|
4819
|
-
|
|
6471
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6472
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6473
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
6474
|
+
>>> transforms_list = Compose([vision.RandomHorizontalFlip(0.5),
|
|
4820
6475
|
... vision.ToTensor(),
|
|
4821
6476
|
... vision.ToType(np.float32)])
|
|
4822
6477
|
>>> # apply the transform to dataset through map function
|
|
4823
|
-
>>>
|
|
4824
|
-
>>>
|
|
4825
|
-
...
|
|
6478
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
6479
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6480
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6481
|
+
... break
|
|
6482
|
+
(3, 100, 100) float32
|
|
6483
|
+
>>>
|
|
6484
|
+
>>> # Use the transform in eager mode
|
|
6485
|
+
>>> data = np.array([2.71606445312564e-03, 6.3476562564e-03]).astype(np.float64)
|
|
6486
|
+
>>> output = vision.ToType(np.float32)(data)
|
|
6487
|
+
>>> print(output, output.dtype)
|
|
6488
|
+
[0.00271606 0.00634766] float32
|
|
4826
6489
|
|
|
4827
6490
|
Tutorial Examples:
|
|
4828
6491
|
- `Illustration of vision transforms
|
|
4829
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6492
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4830
6493
|
"""
|
|
4831
6494
|
|
|
4832
6495
|
|
|
@@ -4861,20 +6524,32 @@ class TrivialAugmentWide(ImageTensorOperation):
|
|
|
4861
6524
|
``CPU``
|
|
4862
6525
|
|
|
4863
6526
|
Examples:
|
|
6527
|
+
>>> import numpy as np
|
|
4864
6528
|
>>> import mindspore.dataset as ds
|
|
4865
6529
|
>>> import mindspore.dataset.vision as vision
|
|
4866
6530
|
>>> from mindspore.dataset.vision import Inter
|
|
4867
6531
|
>>>
|
|
4868
|
-
>>>
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
>>>
|
|
4872
|
-
|
|
4873
|
-
...
|
|
6532
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6533
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6534
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
6535
|
+
>>> transforms_list = [vision.TrivialAugmentWide(num_magnitude_bins=31,
|
|
6536
|
+
... interpolation=Inter.NEAREST,
|
|
6537
|
+
... fill_value=0)]
|
|
6538
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
6539
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6540
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6541
|
+
... break
|
|
6542
|
+
(100, 100, 3) uint8
|
|
6543
|
+
>>>
|
|
6544
|
+
>>> # Use the transform in eager mode
|
|
6545
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6546
|
+
>>> output = vision.TrivialAugmentWide()(data)
|
|
6547
|
+
>>> print(output.shape, output.dtype)
|
|
6548
|
+
(100, 100, 3) uint8
|
|
4874
6549
|
|
|
4875
6550
|
Tutorial Examples:
|
|
4876
6551
|
- `Illustration of vision transforms
|
|
4877
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6552
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4878
6553
|
"""
|
|
4879
6554
|
|
|
4880
6555
|
@check_trivial_augment_wide
|
|
@@ -4915,25 +6590,41 @@ class UniformAugment(CompoundOperation):
|
|
|
4915
6590
|
``CPU``
|
|
4916
6591
|
|
|
4917
6592
|
Examples:
|
|
6593
|
+
>>> import numpy as np
|
|
4918
6594
|
>>> import mindspore.dataset as ds
|
|
4919
6595
|
>>> import mindspore.dataset.vision as vision
|
|
4920
6596
|
>>> from mindspore.dataset.transforms import Compose
|
|
4921
6597
|
>>>
|
|
4922
|
-
>>>
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
>>>
|
|
4927
|
-
|
|
6598
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6599
|
+
>>> seed = ds.config.get_seed()
|
|
6600
|
+
>>> ds.config.set_seed(12345)
|
|
6601
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6602
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
6603
|
+
>>> transform = [vision.CenterCrop(64),
|
|
6604
|
+
... vision.RandomColor(),
|
|
6605
|
+
... vision.RandomSharpness(),
|
|
6606
|
+
... vision.RandomRotation(30)]
|
|
6607
|
+
>>> transforms_list = Compose([vision.UniformAugment(transform),
|
|
4928
6608
|
... vision.ToTensor()])
|
|
4929
6609
|
>>> # apply the transform to dataset through map function
|
|
4930
|
-
>>>
|
|
4931
|
-
>>>
|
|
4932
|
-
...
|
|
6610
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns="image")
|
|
6611
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6612
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6613
|
+
... break
|
|
6614
|
+
(3, 100, 100) float32
|
|
6615
|
+
>>>
|
|
6616
|
+
>>> # Use the transform in eager mode
|
|
6617
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6618
|
+
>>> transform = [vision.RandomCrop(size=[20, 40], padding=[32, 32, 32, 32]),
|
|
6619
|
+
... vision.RandomCrop(size=[20, 40], padding=[32, 32, 32, 32])]
|
|
6620
|
+
>>> output = vision.UniformAugment(transform)(data)
|
|
6621
|
+
>>> print(output.shape, output.dtype)
|
|
6622
|
+
(20, 40, 3) uint8
|
|
6623
|
+
>>> ds.config.set_seed(seed)
|
|
4933
6624
|
|
|
4934
6625
|
Tutorial Examples:
|
|
4935
6626
|
- `Illustration of vision transforms
|
|
4936
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6627
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4937
6628
|
"""
|
|
4938
6629
|
|
|
4939
6630
|
@check_uniform_augment
|
|
@@ -4970,25 +6661,84 @@ class VerticalFlip(ImageTensorOperation):
|
|
|
4970
6661
|
``CPU``
|
|
4971
6662
|
|
|
4972
6663
|
Examples:
|
|
6664
|
+
>>> import numpy as np
|
|
4973
6665
|
>>> import mindspore.dataset as ds
|
|
4974
6666
|
>>> import mindspore.dataset.vision as vision
|
|
4975
6667
|
>>>
|
|
4976
|
-
>>>
|
|
4977
|
-
>>>
|
|
4978
|
-
>>>
|
|
4979
|
-
|
|
6668
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6669
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6670
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
6671
|
+
>>> transforms_list = [vision.VerticalFlip()]
|
|
6672
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
6673
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6674
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6675
|
+
... break
|
|
6676
|
+
(100, 100, 3) uint8
|
|
6677
|
+
>>>
|
|
6678
|
+
>>> # Use the transform in eager mode
|
|
6679
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6680
|
+
>>> output = vision.VerticalFlip()(data)
|
|
6681
|
+
>>> print(output.shape, output.dtype)
|
|
6682
|
+
(100, 100, 3) uint8
|
|
4980
6683
|
|
|
4981
6684
|
Tutorial Examples:
|
|
4982
6685
|
- `Illustration of vision transforms
|
|
4983
|
-
<https://www.mindspore.cn/docs/en/r2.
|
|
6686
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
4984
6687
|
"""
|
|
4985
6688
|
|
|
4986
6689
|
def __init__(self):
|
|
4987
6690
|
super().__init__()
|
|
4988
6691
|
self.implementation = Implementation.C
|
|
4989
6692
|
|
|
6693
|
+
@check_device_target
|
|
6694
|
+
def device(self, device_target="CPU"):
|
|
6695
|
+
"""
|
|
6696
|
+
Set the device for the current operator execution.
|
|
6697
|
+
|
|
6698
|
+
- When the device is Ascend, input shape should be limited from [4, 6] to [8192, 4096].
|
|
6699
|
+
|
|
6700
|
+
Args:
|
|
6701
|
+
device_target (str, optional): The operator will be executed on this device. Currently supports
|
|
6702
|
+
``CPU`` and ``Ascend`` . Default: ``CPU`` .
|
|
6703
|
+
|
|
6704
|
+
Raises:
|
|
6705
|
+
TypeError: If `device_target` is not of type str.
|
|
6706
|
+
ValueError: If `device_target` is not within the valid set of ['CPU', 'Ascend'].
|
|
6707
|
+
|
|
6708
|
+
Supported Platforms:
|
|
6709
|
+
``CPU`` ``Ascend``
|
|
6710
|
+
|
|
6711
|
+
Examples:
|
|
6712
|
+
>>> import numpy as np
|
|
6713
|
+
>>> import mindspore.dataset as ds
|
|
6714
|
+
>>> import mindspore.dataset.vision as vision
|
|
6715
|
+
>>>
|
|
6716
|
+
>>> # Use the transform in dataset pipeline mode
|
|
6717
|
+
>>> data = np.random.randint(0, 255, size=(1, 100, 100, 3)).astype(np.uint8)
|
|
6718
|
+
>>> numpy_slices_dataset = ds.NumpySlicesDataset(data, ["image"])
|
|
6719
|
+
>>> vertical_flip_op = vision.VerticalFlip().device("Ascend")
|
|
6720
|
+
>>> transforms_list = [vertical_flip_op]
|
|
6721
|
+
>>> numpy_slices_dataset = numpy_slices_dataset.map(operations=transforms_list, input_columns=["image"])
|
|
6722
|
+
>>> for item in numpy_slices_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
|
|
6723
|
+
... print(item["image"].shape, item["image"].dtype)
|
|
6724
|
+
... break
|
|
6725
|
+
(100, 100, 3) uint8
|
|
6726
|
+
>>>
|
|
6727
|
+
>>> # Use the transform in eager mode
|
|
6728
|
+
>>> data = np.random.randint(0, 255, size=(100, 100, 3)).astype(np.uint8)
|
|
6729
|
+
>>> output = vision.VerticalFlip().device("Ascend")(data)
|
|
6730
|
+
>>> print(output.shape, output.dtype)
|
|
6731
|
+
(100, 100, 3) uint8
|
|
6732
|
+
|
|
6733
|
+
Tutorial Examples:
|
|
6734
|
+
- `Illustration of vision transforms
|
|
6735
|
+
<https://www.mindspore.cn/docs/en/r2.3.q1/api_python/samples/dataset/vision_gallery.html>`_
|
|
6736
|
+
"""
|
|
6737
|
+
self.device_target = device_target
|
|
6738
|
+
return self
|
|
6739
|
+
|
|
4990
6740
|
def parse(self):
|
|
4991
|
-
return cde.VerticalFlipOperation()
|
|
6741
|
+
return cde.VerticalFlipOperation(self.device_target)
|
|
4992
6742
|
|
|
4993
6743
|
|
|
4994
6744
|
def not_random(func):
|