mindspore 2.1.0__cp37-cp37m-win_amd64.whl → 2.2.11__cp37-cp37m-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mindspore might be problematic. Click here for more details.
- mindspore/.commit_id +1 -1
- mindspore/Microsoft.VisualStudio.Telemetry.dll +0 -0
- mindspore/Newtonsoft.Json.dll +0 -0
- mindspore/__init__.py +4 -1
- mindspore/_c_dataengine.cp37-win_amd64.pyd +0 -0
- mindspore/_c_expression.cp37-win_amd64.pyd +0 -0
- mindspore/_c_mindrecord.cp37-win_amd64.pyd +0 -0
- mindspore/_check_jit_forbidden_api.py +3 -1
- mindspore/_checkparam.py +23 -29
- mindspore/_extends/graph_kernel/__init__.py +0 -1
- mindspore/_extends/graph_kernel/model/graph_split.py +84 -76
- mindspore/_extends/graph_kernel/model/model_builder.py +9 -50
- mindspore/_extends/graph_kernel/splitter.py +4 -11
- mindspore/_extends/parallel_compile/akg_compiler/akg_process.py +122 -15
- mindspore/_extends/parallel_compile/akg_compiler/build_tbe_kernel.py +84 -67
- mindspore/_extends/parallel_compile/akg_compiler/tbe_topi.py +4 -2
- mindspore/_extends/parallel_compile/akg_compiler/util.py +10 -7
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_adapter.py +2 -2
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_helper.py +6 -5
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job.py +1 -1
- mindspore/_extends/parallel_compile/tbe_compiler/tbe_job_manager.py +1 -1
- mindspore/_extends/parse/__init__.py +13 -15
- mindspore/_extends/parse/namespace.py +7 -33
- mindspore/_extends/parse/parser.py +67 -72
- mindspore/_extends/parse/resources.py +1 -1
- mindspore/_extends/parse/standard_method.py +86 -106
- mindspore/_extends/parse/trope.py +1 -1
- mindspore/_extends/remote/kernel_build_server.py +25 -7
- mindspore/_extends/remote/kernel_build_server_akg_v2.py +55 -0
- mindspore/_install_custom.py +43 -0
- mindspore/amp.py +47 -11
- mindspore/atlprov.dll +0 -0
- mindspore/boost/boost.py +1 -8
- mindspore/boost/boost_cell_wrapper.py +3 -2
- mindspore/boost/grad_accumulation.py +1 -1
- mindspore/boost/group_loss_scale_manager.py +8 -7
- mindspore/c1.dll +0 -0
- mindspore/c1xx.dll +0 -0
- mindspore/c2.dll +0 -0
- mindspore/common/__init__.py +5 -3
- mindspore/common/_jit_fallback_utils.py +6 -0
- mindspore/common/_register_for_adapter.py +2 -0
- mindspore/common/_register_for_tensor.py +2 -2
- mindspore/common/_stub_tensor.py +13 -0
- mindspore/common/_utils.py +29 -0
- mindspore/common/api.py +174 -259
- mindspore/common/auto_dynamic_shape.py +494 -0
- mindspore/common/dtype.py +18 -11
- mindspore/common/dump.py +6 -4
- mindspore/common/initializer.py +14 -14
- mindspore/common/jit_config.py +33 -15
- mindspore/common/lazy_inline.py +126 -7
- mindspore/common/mindir_util.py +101 -0
- mindspore/common/parameter.py +51 -41
- mindspore/common/seed.py +4 -4
- mindspore/common/sparse_tensor.py +13 -14
- mindspore/common/tensor.py +243 -165
- mindspore/communication/__init__.py +7 -4
- mindspore/communication/_comm_helper.py +83 -4
- mindspore/communication/management.py +152 -84
- mindspore/config/op_info.config +14 -3
- mindspore/context.py +152 -61
- mindspore/dataset/__init__.py +5 -5
- mindspore/dataset/audio/__init__.py +2 -2
- mindspore/dataset/audio/transforms.py +52 -52
- mindspore/dataset/callback/ds_callback.py +16 -2
- mindspore/dataset/core/config.py +68 -51
- mindspore/dataset/engine/cache_client.py +33 -7
- mindspore/dataset/engine/datasets.py +250 -112
- mindspore/dataset/engine/datasets_audio.py +43 -211
- mindspore/dataset/engine/datasets_standard_format.py +16 -35
- mindspore/dataset/engine/datasets_text.py +43 -67
- mindspore/dataset/engine/datasets_user_defined.py +86 -100
- mindspore/dataset/engine/datasets_vision.py +219 -1029
- mindspore/dataset/engine/iterators.py +11 -4
- mindspore/dataset/engine/obs/obs_mindrecord_dataset.py +4 -0
- mindspore/dataset/engine/obs/util.py +3 -0
- mindspore/dataset/engine/samplers.py +1 -1
- mindspore/dataset/engine/validators.py +19 -5
- mindspore/dataset/text/__init__.py +3 -3
- mindspore/dataset/text/transforms.py +101 -127
- mindspore/dataset/text/utils.py +205 -138
- mindspore/dataset/transforms/__init__.py +1 -1
- mindspore/dataset/transforms/py_transforms_util.py +40 -12
- mindspore/dataset/transforms/transforms.py +95 -40
- mindspore/dataset/utils/browse_dataset.py +8 -2
- mindspore/dataset/utils/line_reader.py +17 -19
- mindspore/dataset/vision/__init__.py +3 -3
- mindspore/dataset/vision/c_transforms.py +6 -3
- mindspore/dataset/vision/transforms.py +409 -287
- mindspore/dataset/vision/utils.py +13 -14
- mindspore/dataset/vision/validators.py +11 -1
- mindspore/dnnl.dll +0 -0
- mindspore/dpcmi.dll +0 -0
- mindspore/experimental/map_parameter.py +14 -0
- mindspore/{nn/optim_ex → experimental/optim}/__init__.py +30 -29
- mindspore/{nn/optim_ex → experimental/optim}/adam.py +60 -67
- mindspore/{nn/optim_ex → experimental/optim}/adamw.py +181 -203
- mindspore/experimental/optim/lr_scheduler.py +1427 -0
- mindspore/{nn/optim_ex → experimental/optim}/optimizer.py +252 -259
- mindspore/{nn/optim_ex → experimental/optim}/sgd.py +147 -152
- mindspore/gen_ops.py +273 -0
- mindspore/include/OWNERS +0 -1
- mindspore/include/api/data_type.h +2 -1
- mindspore/include/api/graph.h +0 -15
- mindspore/include/api/kernel.h +2 -0
- mindspore/include/api/kernel_api.h +37 -12
- mindspore/include/api/model.h +17 -14
- mindspore/include/api/status.h +8 -3
- mindspore/include/api/types.h +37 -4
- mindspore/include/c_api/ms/abstract.h +67 -0
- mindspore/include/c_api/ms/attribute.h +197 -0
- mindspore/include/c_api/ms/base/handle_types.h +43 -0
- mindspore/include/c_api/ms/base/macros.h +32 -0
- mindspore/include/c_api/ms/base/status.h +33 -0
- mindspore/include/c_api/ms/base/types.h +282 -0
- mindspore/include/c_api/ms/context.h +102 -0
- mindspore/include/c_api/ms/graph.h +160 -0
- mindspore/include/c_api/ms/node.h +606 -0
- mindspore/include/c_api/ms/tensor.h +161 -0
- mindspore/include/c_api/ms/value.h +84 -0
- mindspore/include/dataset/constants.h +6 -5
- mindspore/include/dataset/execute.h +23 -13
- mindspore/include/dataset/text.h +26 -26
- mindspore/include/dataset/transforms.h +13 -13
- mindspore/include/dataset/vision.h +60 -60
- mindspore/include/dataset/vision_ascend.h +5 -6
- mindspore/include/dataset/vision_lite.h +17 -17
- mindspore/jpeg62.dll +0 -0
- mindspore/mindrecord/tools/imagenet_to_mr.py +1 -1
- mindspore/mindrecord/tools/mnist_to_mr.py +2 -2
- mindspore/mindspore_backend.dll +0 -0
- mindspore/mindspore_common.dll +0 -0
- mindspore/mindspore_core.dll +0 -0
- mindspore/mindspore_glog.dll +0 -0
- mindspore/mindspore_shared_lib.dll +0 -0
- mindspore/msobj140.dll +0 -0
- mindspore/mspdb140.dll +0 -0
- mindspore/mspdbcore.dll +0 -0
- mindspore/mspdbst.dll +0 -0
- mindspore/mspft140.dll +0 -0
- mindspore/msvcdis140.dll +0 -0
- mindspore/msvcp140_1.dll +0 -0
- mindspore/msvcp140_2.dll +0 -0
- mindspore/msvcp140_atomic_wait.dll +0 -0
- mindspore/msvcp140_codecvt_ids.dll +0 -0
- mindspore/nn/__init__.py +0 -2
- mindspore/nn/cell.py +313 -74
- mindspore/nn/dynamic_lr.py +21 -21
- mindspore/nn/layer/activation.py +22 -30
- mindspore/nn/layer/basic.py +15 -13
- mindspore/nn/layer/channel_shuffle.py +1 -1
- mindspore/nn/layer/container.py +271 -9
- mindspore/nn/layer/conv.py +323 -204
- mindspore/nn/layer/dense.py +8 -5
- mindspore/nn/layer/embedding.py +33 -27
- mindspore/nn/layer/flash_attention.py +61 -95
- mindspore/nn/layer/image.py +8 -6
- mindspore/nn/layer/math.py +16 -25
- mindspore/nn/layer/normalization.py +107 -66
- mindspore/nn/layer/padding.py +1 -1
- mindspore/nn/layer/pooling.py +131 -109
- mindspore/nn/layer/rnn_cells.py +27 -22
- mindspore/nn/layer/rnns.py +13 -16
- mindspore/nn/layer/thor_layer.py +1 -1
- mindspore/nn/layer/transformer.py +221 -154
- mindspore/nn/learning_rate_schedule.py +9 -1
- mindspore/nn/loss/loss.py +235 -174
- mindspore/nn/optim/ada_grad.py +2 -1
- mindspore/nn/optim/adadelta.py +1 -0
- mindspore/nn/optim/adafactor.py +2 -1
- mindspore/nn/optim/adam.py +7 -4
- mindspore/nn/optim/adamax.py +3 -2
- mindspore/nn/optim/adasum.py +2 -2
- mindspore/nn/optim/asgd.py +2 -3
- mindspore/nn/optim/ftrl.py +6 -5
- mindspore/nn/optim/lamb.py +7 -4
- mindspore/nn/optim/lars.py +1 -1
- mindspore/nn/optim/lazyadam.py +5 -3
- mindspore/nn/optim/momentum.py +2 -1
- mindspore/nn/optim/optimizer.py +53 -4
- mindspore/nn/optim/proximal_ada_grad.py +3 -4
- mindspore/nn/optim/rmsprop.py +4 -3
- mindspore/nn/optim/rprop.py +23 -12
- mindspore/nn/optim/sgd.py +26 -11
- mindspore/nn/optim/thor.py +9 -7
- mindspore/nn/probability/bijector/bijector.py +5 -5
- mindspore/nn/probability/bijector/power_transform.py +27 -27
- mindspore/nn/probability/bijector/softplus.py +3 -3
- mindspore/nn/probability/distribution/_utils/custom_ops.py +3 -3
- mindspore/nn/probability/distribution/bernoulli.py +5 -5
- mindspore/nn/probability/distribution/beta.py +3 -3
- mindspore/nn/probability/distribution/categorical.py +7 -7
- mindspore/nn/probability/distribution/cauchy.py +0 -1
- mindspore/nn/probability/distribution/distribution.py +3 -3
- mindspore/nn/probability/distribution/gamma.py +3 -3
- mindspore/nn/probability/distribution/geometric.py +4 -4
- mindspore/nn/probability/distribution/gumbel.py +4 -4
- mindspore/nn/probability/distribution/log_normal.py +2 -2
- mindspore/nn/probability/distribution/logistic.py +2 -2
- mindspore/nn/probability/distribution/poisson.py +4 -4
- mindspore/nn/probability/distribution/transformed_distribution.py +3 -3
- mindspore/nn/probability/distribution/uniform.py +6 -6
- mindspore/nn/wrap/__init__.py +4 -2
- mindspore/nn/wrap/cell_wrapper.py +87 -34
- mindspore/nn/wrap/grad_reducer.py +8 -5
- mindspore/nn/wrap/loss_scale.py +105 -42
- mindspore/numpy/array_creations.py +1 -2
- mindspore/numpy/array_ops.py +3 -2
- mindspore/numpy/utils_const.py +5 -5
- mindspore/opencv_core452.dll +0 -0
- mindspore/opencv_imgcodecs452.dll +0 -0
- mindspore/opencv_imgproc452.dll +0 -0
- mindspore/ops/_grad_experimental/__init__.py +0 -5
- mindspore/ops/_grad_experimental/grad_array_ops.py +2 -3
- mindspore/ops/_grad_experimental/grad_comm_ops.py +15 -2
- mindspore/ops/_grad_experimental/grad_debug_ops.py +0 -37
- mindspore/ops/_grad_experimental/grad_implementations.py +11 -1
- mindspore/ops/_grad_experimental/grad_inner_ops.py +2 -216
- mindspore/ops/_grad_experimental/grad_math_ops.py +19 -199
- mindspore/ops/_grad_experimental/grad_sparse.py +15 -0
- mindspore/ops/_grad_experimental/grad_sparse_ops.py +3 -3
- mindspore/ops/_op_impl/_custom_op/dsd_back_impl.py +1 -1
- mindspore/ops/_op_impl/aicpu/__init__.py +14 -2
- mindspore/ops/_op_impl/aicpu/add.py +3 -3
- mindspore/ops/_op_impl/aicpu/bias_add_grad.py +0 -1
- mindspore/ops/_op_impl/aicpu/count_nonzero.py +43 -0
- mindspore/ops/_op_impl/{_custom_op/flash_attention/constants.py → aicpu/eps.py} +18 -27
- mindspore/ops/_op_impl/aicpu/gamma.py +2 -2
- mindspore/ops/_op_impl/aicpu/linear_sum_assignment.py +21 -2
- mindspore/ops/_op_impl/aicpu/log_uniform_candidate_sampler.py +6 -3
- mindspore/ops/_op_impl/aicpu/lu_unpack_grad.py +0 -1
- mindspore/ops/_op_impl/aicpu/multinomial.py +3 -3
- mindspore/ops/_op_impl/aicpu/parameterized_truncated_normal.py +15 -7
- mindspore/ops/_op_impl/aicpu/random_categorical.py +39 -19
- mindspore/ops/_op_impl/aicpu/random_choice_with_mask.py +5 -2
- mindspore/ops/_op_impl/aicpu/random_poisson.py +103 -52
- mindspore/ops/_op_impl/aicpu/random_shuffle.py +17 -15
- mindspore/ops/_op_impl/aicpu/{sparseaddmm.py → sparse_addmm.py} +2 -2
- mindspore/ops/_op_impl/aicpu/{sparsesparsemaximum.py → sparse_sparse_maximum.py} +4 -4
- mindspore/ops/_op_impl/aicpu/standard_laplace.py +5 -5
- mindspore/ops/_op_impl/aicpu/standard_normal.py +5 -5
- mindspore/ops/_op_impl/aicpu/truncated_normal.py +9 -7
- mindspore/ops/_op_impl/aicpu/uniform.py +5 -3
- mindspore/ops/_op_impl/aicpu/uniform_candidate_sampler.py +8 -4
- mindspore/ops/_op_impl/aicpu/uniform_int.py +5 -5
- mindspore/ops/_op_impl/aicpu/uniform_real.py +4 -4
- mindspore/ops/_op_impl/tbe/__init__.py +4 -4
- mindspore/ops/_op_impl/tbe/inplace_index_add.py +7 -3
- mindspore/ops/_op_impl/tbe/trans_data_ds.py +2 -0
- mindspore/ops/_primitive_cache.py +1 -1
- mindspore/ops/_tracefunc.py +45 -13
- mindspore/ops/_utils/utils.py +6 -1
- mindspore/ops/_vmap/vmap_array_ops.py +3 -3
- mindspore/ops/_vmap/vmap_base.py +3 -3
- mindspore/ops/_vmap/vmap_convolution_ops.py +1 -1
- mindspore/ops/_vmap/vmap_grad_math_ops.py +6 -4
- mindspore/ops/_vmap/vmap_math_ops.py +5 -2
- mindspore/ops/_vmap/vmap_nn_ops.py +61 -7
- mindspore/ops/arg_dtype_cast.py +54 -0
- mindspore/ops/composite/base.py +37 -10
- mindspore/ops/composite/math_ops.py +5 -4
- mindspore/ops/composite/multitype_ops/_compile_utils.py +275 -73
- mindspore/ops/composite/multitype_ops/_constexpr_utils.py +16 -9
- mindspore/ops/composite/multitype_ops/add_impl.py +43 -4
- mindspore/ops/composite/multitype_ops/getitem_impl.py +42 -4
- mindspore/ops/composite/multitype_ops/ones_like_impl.py +6 -0
- mindspore/ops/composite/multitype_ops/setitem_impl.py +2 -1
- mindspore/ops/composite/multitype_ops/zeros_like_impl.py +9 -0
- mindspore/ops/deprecated.py +304 -0
- mindspore/ops/function/__init__.py +4 -1
- mindspore/ops/function/array_func.py +174 -193
- mindspore/ops/function/clip_func.py +81 -13
- mindspore/ops/function/debug_func.py +1 -1
- mindspore/ops/function/grad/grad_func.py +18 -9
- mindspore/ops/function/image_func.py +10 -4
- mindspore/ops/function/linalg_func.py +5 -5
- mindspore/ops/function/math_func.py +575 -386
- mindspore/ops/function/nn_func.py +568 -260
- mindspore/ops/function/random_func.py +88 -57
- mindspore/ops/function/sparse_func.py +1 -1
- mindspore/ops/function/sparse_unary_func.py +14 -12
- mindspore/ops/function/vmap_func.py +6 -5
- mindspore/ops/functional.py +15 -10
- mindspore/ops/op_info_register.py +244 -25
- mindspore/ops/operations/__init__.py +31 -19
- mindspore/ops/operations/_grad_ops.py +71 -7
- mindspore/ops/operations/_inner_ops.py +350 -17
- mindspore/ops/operations/_quant_ops.py +4 -8
- mindspore/ops/operations/_sequence_ops.py +42 -0
- mindspore/ops/operations/array_ops.py +68 -282
- mindspore/ops/operations/comm_ops.py +107 -59
- mindspore/ops/operations/custom_ops.py +94 -70
- mindspore/ops/operations/debug_ops.py +8 -4
- mindspore/ops/operations/image_ops.py +18 -12
- mindspore/ops/operations/inner_ops.py +26 -3
- mindspore/ops/operations/math_ops.py +192 -144
- mindspore/ops/operations/nn_ops.py +857 -489
- mindspore/ops/operations/other_ops.py +0 -22
- mindspore/ops/operations/random_ops.py +53 -111
- mindspore/ops/operations/sparse_ops.py +3 -1
- mindspore/ops/primitive.py +24 -18
- mindspore/parallel/_auto_parallel_context.py +68 -8
- mindspore/parallel/_cost_model_context.py +2 -2
- mindspore/parallel/_offload_context.py +17 -3
- mindspore/parallel/_parallel_serialization.py +12 -5
- mindspore/parallel/_ps_context.py +12 -0
- mindspore/parallel/_tensor.py +18 -13
- mindspore/parallel/_transformer/layers.py +5 -3
- mindspore/parallel/_transformer/loss.py +1 -0
- mindspore/parallel/_transformer/moe.py +2 -2
- mindspore/parallel/_transformer/op_parallel_config.py +12 -1
- mindspore/parallel/_transformer/transformer.py +23 -3
- mindspore/parallel/_utils.py +11 -7
- mindspore/parallel/algo_parameter_config.py +85 -5
- mindspore/parallel/checkpoint_transform.py +19 -12
- mindspore/parallel/shard.py +21 -14
- mindspore/pgodb140.dll +0 -0
- mindspore/pgort140.dll +0 -0
- mindspore/profiler/common/struct_type.py +3 -3
- mindspore/profiler/common/util.py +4 -2
- mindspore/profiler/envprofiling.py +1 -1
- mindspore/profiler/parser/aicpu_data_parser.py +5 -3
- mindspore/profiler/parser/ascend_flops_generator.py +2 -2
- mindspore/profiler/parser/ascend_fpbp_generator.py +1 -1
- mindspore/profiler/parser/ascend_hccl_generator.py +249 -12
- mindspore/profiler/parser/ascend_msprof_exporter.py +150 -255
- mindspore/profiler/parser/ascend_msprof_generator.py +204 -17
- mindspore/profiler/parser/ascend_op_generator.py +6 -6
- mindspore/profiler/parser/ascend_steptrace_generator.py +6 -4
- mindspore/profiler/parser/ascend_timeline_generator.py +14 -187
- mindspore/profiler/parser/base_timeline_generator.py +10 -8
- mindspore/profiler/parser/cpu_gpu_timeline_generator.py +16 -12
- mindspore/profiler/parser/flops_parser.py +15 -11
- mindspore/profiler/parser/framework_parser.py +38 -22
- mindspore/profiler/parser/hccl_parser.py +16 -12
- mindspore/profiler/parser/integrator.py +22 -11
- mindspore/profiler/parser/memory_usage_parser.py +2 -2
- mindspore/profiler/parser/minddata_analyzer.py +12 -14
- mindspore/profiler/parser/minddata_pipeline_parser.py +1 -1
- mindspore/profiler/parser/msadvisor_parser.py +8 -4
- mindspore/profiler/parser/op_intermediate_parser.py +5 -2
- mindspore/profiler/parser/optime_parser.py +1 -1
- mindspore/profiler/parser/profiler_info.py +21 -2
- mindspore/profiler/parser/step_trace_parser.py +11 -14
- mindspore/profiler/profiling.py +179 -89
- mindspore/rewrite/api/node.py +102 -19
- mindspore/rewrite/api/node_type.py +5 -1
- mindspore/rewrite/api/pattern_engine.py +1 -1
- mindspore/rewrite/api/scoped_value.py +9 -17
- mindspore/rewrite/api/symbol_tree.py +131 -47
- mindspore/rewrite/ast_helpers/__init__.py +2 -1
- mindspore/rewrite/ast_helpers/ast_finder.py +129 -0
- mindspore/rewrite/ast_helpers/ast_modifier.py +116 -104
- mindspore/rewrite/ast_transformers/flatten_recursive_stmt.py +93 -46
- mindspore/rewrite/common/rewrite_elog.py +5 -1
- mindspore/rewrite/namer.py +33 -24
- mindspore/rewrite/namespace.py +14 -5
- mindspore/{_extends/graph_kernel/expanders/complex → rewrite/node}/__init__.py +9 -9
- mindspore/rewrite/node/call_function.py +79 -0
- mindspore/rewrite/node/cell_container.py +135 -0
- mindspore/rewrite/node/control_flow.py +88 -0
- mindspore/rewrite/{node.py → node/node.py} +273 -234
- mindspore/rewrite/node/node_manager.py +254 -0
- mindspore/rewrite/{topological_manager.py → node/node_topological_manager.py} +13 -46
- mindspore/rewrite/parsers/arguments_parser.py +22 -21
- mindspore/rewrite/parsers/assign_parser.py +216 -221
- mindspore/rewrite/parsers/attribute_parser.py +9 -7
- mindspore/rewrite/parsers/class_def_parser.py +174 -113
- mindspore/rewrite/parsers/constant_parser.py +9 -6
- mindspore/rewrite/parsers/container_parser.py +9 -7
- mindspore/rewrite/parsers/for_parser.py +42 -21
- mindspore/rewrite/parsers/function_def_parser.py +24 -16
- mindspore/rewrite/parsers/if_parser.py +28 -24
- mindspore/rewrite/parsers/module_parser.py +196 -25
- mindspore/rewrite/{parser.py → parsers/parser.py} +4 -2
- mindspore/rewrite/{parser_register.py → parsers/parser_register.py} +1 -1
- mindspore/rewrite/parsers/return_parser.py +6 -6
- mindspore/rewrite/sparsify/sparse_transformer.py +12 -3
- mindspore/rewrite/sparsify/utils.py +1 -1
- mindspore/rewrite/symbol_tree.py +523 -578
- mindspore/rewrite/symbol_tree_builder.py +9 -193
- mindspore/rewrite/symbol_tree_dumper.py +2 -2
- mindspore/run_check/_check_version.py +6 -4
- mindspore/{ops/bprop_mindir → safeguard}/__init__.py +4 -3
- mindspore/safeguard/rewrite_obfuscation.py +541 -0
- mindspore/tbbmalloc.dll +0 -0
- mindspore/tinyxml2.dll +0 -0
- mindspore/train/_utils.py +7 -3
- mindspore/train/amp.py +323 -123
- mindspore/train/anf_ir_pb2.py +14 -2
- mindspore/train/callback/_backup_and_restore.py +2 -12
- mindspore/train/callback/_callback.py +29 -4
- mindspore/train/callback/_checkpoint.py +23 -8
- mindspore/train/callback/_early_stop.py +2 -2
- mindspore/train/callback/_landscape.py +4 -4
- 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 +3 -4
- mindspore/train/callback/_summary_collector.py +15 -8
- mindspore/train/callback/_time_monitor.py +58 -5
- mindspore/train/data_sink.py +5 -11
- mindspore/train/dataset_helper.py +84 -57
- mindspore/train/loss_scale_manager.py +2 -2
- mindspore/train/metrics/__init__.py +3 -3
- mindspore/train/metrics/cosine_similarity.py +1 -1
- mindspore/train/metrics/hausdorff_distance.py +3 -2
- mindspore/train/metrics/mean_surface_distance.py +3 -2
- mindspore/train/metrics/metric.py +39 -19
- mindspore/train/metrics/roc.py +2 -2
- mindspore/train/metrics/root_mean_square_surface_distance.py +4 -3
- mindspore/train/mind_ir_pb2.py +85 -36
- mindspore/train/model.py +187 -47
- mindspore/train/serialization.py +487 -161
- mindspore/train/summary/_summary_adapter.py +1 -1
- mindspore/train/summary/_writer_pool.py +3 -2
- mindspore/train/summary/summary_record.py +37 -17
- mindspore/train/train_thor/convert_utils.py +3 -3
- mindspore/train/train_thor/dataset_helper.py +1 -1
- mindspore/turbojpeg.dll +0 -0
- mindspore/vcmeta.dll +0 -0
- mindspore/vcruntime140.dll +0 -0
- mindspore/vcruntime140_1.dll +0 -0
- mindspore/version.py +1 -1
- {mindspore-2.1.0.dist-info → mindspore-2.2.11.dist-info}/METADATA +7 -4
- {mindspore-2.1.0.dist-info → mindspore-2.2.11.dist-info}/RECORD +429 -486
- mindspore/_extends/graph_kernel/expander.py +0 -80
- mindspore/_extends/graph_kernel/expanders/__init__.py +0 -54
- mindspore/_extends/graph_kernel/expanders/_utils.py +0 -269
- mindspore/_extends/graph_kernel/expanders/addn.py +0 -33
- mindspore/_extends/graph_kernel/expanders/batchnorm.py +0 -152
- mindspore/_extends/graph_kernel/expanders/batchnorm_grad.py +0 -105
- mindspore/_extends/graph_kernel/expanders/clip_by_norm_no_div_sum.py +0 -33
- mindspore/_extends/graph_kernel/expanders/complex/abs.py +0 -30
- mindspore/_extends/graph_kernel/expanders/complex/add.py +0 -44
- mindspore/_extends/graph_kernel/expanders/complex/div.py +0 -62
- mindspore/_extends/graph_kernel/expanders/complex/mul.py +0 -52
- mindspore/_extends/graph_kernel/expanders/complex/real_div.py +0 -62
- mindspore/_extends/graph_kernel/expanders/complex/sub.py +0 -45
- mindspore/_extends/graph_kernel/expanders/conv2d.py +0 -200
- mindspore/_extends/graph_kernel/expanders/dropout_grad.py +0 -30
- mindspore/_extends/graph_kernel/expanders/equal_count.py +0 -50
- mindspore/_extends/graph_kernel/expanders/erfc.py +0 -35
- mindspore/_extends/graph_kernel/expanders/expand_dims.py +0 -50
- mindspore/_extends/graph_kernel/expanders/fused_adam.py +0 -44
- mindspore/_extends/graph_kernel/expanders/fused_adam_weight_decay.py +0 -47
- mindspore/_extends/graph_kernel/expanders/fused_mul_add.py +0 -28
- mindspore/_extends/graph_kernel/expanders/gelu_grad.py +0 -70
- mindspore/_extends/graph_kernel/expanders/gkdropout.py +0 -40
- mindspore/_extends/graph_kernel/expanders/identity.py +0 -25
- mindspore/_extends/graph_kernel/expanders/layernorm.py +0 -93
- mindspore/_extends/graph_kernel/expanders/layernorm_grad.py +0 -113
- mindspore/_extends/graph_kernel/expanders/logsoftmax.py +0 -46
- mindspore/_extends/graph_kernel/expanders/logsoftmax_grad.py +0 -36
- mindspore/_extends/graph_kernel/expanders/matmul.py +0 -80
- mindspore/_extends/graph_kernel/expanders/maximum_grad.py +0 -59
- mindspore/_extends/graph_kernel/expanders/minimum_grad.py +0 -80
- mindspore/_extends/graph_kernel/expanders/oneslike.py +0 -26
- mindspore/_extends/graph_kernel/expanders/reduce_mean.py +0 -43
- mindspore/_extends/graph_kernel/expanders/relu_grad.py +0 -32
- mindspore/_extends/graph_kernel/expanders/sigmoid_cross_entropy_with_logits.py +0 -41
- mindspore/_extends/graph_kernel/expanders/sigmoid_cross_entropy_with_logits_grad.py +0 -35
- mindspore/_extends/graph_kernel/expanders/sigmoid_grad.py +0 -31
- mindspore/_extends/graph_kernel/expanders/slice.py +0 -35
- mindspore/_extends/graph_kernel/expanders/softmax_cross_entropy_with_logits.py +0 -42
- mindspore/_extends/graph_kernel/expanders/softmax_grad_ext.py +0 -41
- mindspore/_extends/graph_kernel/expanders/softsign.py +0 -28
- mindspore/_extends/graph_kernel/expanders/sqrt_grad.py +0 -29
- mindspore/_extends/graph_kernel/expanders/square_sum_all.py +0 -44
- mindspore/_extends/graph_kernel/expanders/square_sum_v1.py +0 -37
- mindspore/_extends/graph_kernel/expanders/squared_difference.py +0 -43
- mindspore/_extends/graph_kernel/expanders/tanh_grad.py +0 -31
- mindspore/_extends/graph_kernel/model/op_infer.py +0 -506
- mindspore/dataset/datapreprocess/__init__.py +0 -20
- mindspore/dataset/datapreprocess/preprocess_imagenet_validate_dataset.py +0 -54
- mindspore/include/api/net.h +0 -142
- mindspore/nn/lr_scheduler.py +0 -262
- mindspore/ops/_grad_experimental/grad_image_ops.py +0 -248
- mindspore/ops/_grad_experimental/grad_linalg_ops.py +0 -181
- mindspore/ops/_grad_experimental/grad_other_ops.py +0 -72
- mindspore/ops/_grad_experimental/grad_scalar_ops.py +0 -112
- mindspore/ops/_grad_experimental/grad_sequence_ops.py +0 -351
- mindspore/ops/_op_impl/_custom_op/flash_attention/__init__.py +0 -0
- mindspore/ops/_op_impl/_custom_op/flash_attention/attention.py +0 -350
- mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_bwd.py +0 -409
- mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_fwd.py +0 -578
- mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_impl.py +0 -199
- mindspore/ops/_op_impl/_custom_op/flash_attention/tik_ops_utils.py +0 -446
- mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/__init__.py +0 -0
- mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/sparse_tiling.py +0 -45
- mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/strategy.py +0 -67
- mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/wukong_tiling.py +0 -62
- mindspore/ops/bprop_mindir/BNTrainingReduce_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Broadcast_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Depend_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/DepthwiseConv2dNative_bprop.mindir +0 -138
- mindspore/ops/bprop_mindir/EmbeddingLookup_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Load_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/ScatterNonAliasingAdd_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/SparseGatherV2_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/SparseSoftmaxCrossEntropyWithLogits_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Switch_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TransShape_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/TupleGetItem_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Unique_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/Unstack_bprop.mindir +0 -0
- mindspore/ops/bprop_mindir/generate_mindir.py +0 -114
- mindspore/rewrite/node_visitor.py +0 -44
- {mindspore-2.1.0.dist-info → mindspore-2.2.11.dist-info}/WHEEL +0 -0
- {mindspore-2.1.0.dist-info → mindspore-2.2.11.dist-info}/entry_points.txt +0 -0
- {mindspore-2.1.0.dist-info → mindspore-2.2.11.dist-info}/top_level.txt +0 -0
mindspore/nn/loss/loss.py
CHANGED
|
@@ -43,14 +43,51 @@ class LossBase(Cell):
|
|
|
43
43
|
to apply reduction to loss values.
|
|
44
44
|
|
|
45
45
|
Args:
|
|
46
|
-
reduction (str):
|
|
47
|
-
``
|
|
46
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
47
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
48
|
+
|
|
49
|
+
- ``'none'``: no reduction will be applied.
|
|
50
|
+
- ``'mean'``: compute and return the (weighted) mean of elements in the output.
|
|
51
|
+
- ``'sum'``: the output elements will be summed.
|
|
48
52
|
|
|
49
53
|
Raises:
|
|
50
|
-
ValueError: If `reduction` is not one of 'none'
|
|
54
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
51
55
|
|
|
52
56
|
Supported Platforms:
|
|
53
57
|
``Ascend`` ``GPU`` ``CPU``
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
>>> import mindspore
|
|
61
|
+
>>> from mindspore import ops, Tensor, nn
|
|
62
|
+
>>> import numpy as np
|
|
63
|
+
>>>
|
|
64
|
+
>>> class Net(nn.LossBase):
|
|
65
|
+
... def __init__(self, reduction='mean'):
|
|
66
|
+
... super(Net, self).__init__(reduction)
|
|
67
|
+
... self.abs = ops.Abs()
|
|
68
|
+
...
|
|
69
|
+
... def construct(self, logits, labels):
|
|
70
|
+
... x = self.abs(logits - labels)
|
|
71
|
+
... output = self.get_loss(x)
|
|
72
|
+
... axis = self.get_axis(x)
|
|
73
|
+
... return output, axis
|
|
74
|
+
>>> net = Net()
|
|
75
|
+
>>> # Case 1: logits.shape = labels.shape = (3,)
|
|
76
|
+
>>> logits = Tensor(np.array([1, 2, 3]), mindspore.float32)
|
|
77
|
+
>>> labels = Tensor(np.array([1, 2, 2]), mindspore.float32)
|
|
78
|
+
>>> output, axis = net(logits, labels)
|
|
79
|
+
>>> print(output)
|
|
80
|
+
0.33333334
|
|
81
|
+
>>> print(axis)
|
|
82
|
+
(0,)
|
|
83
|
+
>>> # Case 2: logits.shape = labels.shape = (3, 3)
|
|
84
|
+
>>> logits = Tensor(np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]]), mindspore.float32)
|
|
85
|
+
>>> labels = Tensor(np.array([[1, 2, 2],[1, 2, 3],[1, 2, 3]]), mindspore.float32)
|
|
86
|
+
>>> output, axis = net(logits, labels)
|
|
87
|
+
>>> print(output)
|
|
88
|
+
0.11111111
|
|
89
|
+
>>> print(axis)
|
|
90
|
+
(0, 1)
|
|
54
91
|
"""
|
|
55
92
|
|
|
56
93
|
def __init__(self, reduction='mean'):
|
|
@@ -79,34 +116,6 @@ class LossBase(Cell):
|
|
|
79
116
|
|
|
80
117
|
Args:
|
|
81
118
|
x (Tensor): Tensor of any shape.
|
|
82
|
-
|
|
83
|
-
Examples:
|
|
84
|
-
>>> import mindspore
|
|
85
|
-
>>> from mindspore import ops, Tensor, nn
|
|
86
|
-
>>> import numpy as np
|
|
87
|
-
>>>
|
|
88
|
-
>>> class Net(nn.LossBase):
|
|
89
|
-
... def __init__(self, reduction='mean'):
|
|
90
|
-
... super(Net, self).__init__(reduction)
|
|
91
|
-
... self.abs = ops.Abs()
|
|
92
|
-
...
|
|
93
|
-
... def construct(self, logits, labels):
|
|
94
|
-
... x = self.abs(logits - labels)
|
|
95
|
-
... axis = self.get_axis(x)
|
|
96
|
-
... return axis
|
|
97
|
-
>>> net = Net()
|
|
98
|
-
>>> # Case 1: logits.shape = labels.shape = (3,)
|
|
99
|
-
>>> logits = Tensor(np.array([1, 2, 3]), mindspore.float32)
|
|
100
|
-
>>> labels = Tensor(np.array([1, 2, 3]), mindspore.float32)
|
|
101
|
-
>>> output = net(logits, labels)
|
|
102
|
-
>>> print(output)
|
|
103
|
-
(0,)
|
|
104
|
-
>>> # Case 2: logits.shape = labels.shape = (3, 3)
|
|
105
|
-
>>> logits = Tensor(np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]]), mindspore.float32)
|
|
106
|
-
>>> labels = Tensor(np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]]), mindspore.float32)
|
|
107
|
-
>>> output = net(logits, labels)
|
|
108
|
-
>>> print(output)
|
|
109
|
-
(0, 1)
|
|
110
119
|
"""
|
|
111
120
|
shape = F.shape(x)
|
|
112
121
|
length = F.tuple_len(shape)
|
|
@@ -126,34 +135,6 @@ class LossBase(Cell):
|
|
|
126
135
|
|
|
127
136
|
Returns:
|
|
128
137
|
Return the weighted loss.
|
|
129
|
-
|
|
130
|
-
Examples:
|
|
131
|
-
>>> import mindspore
|
|
132
|
-
>>> from mindspore import ops, Tensor, nn
|
|
133
|
-
>>> import numpy as np
|
|
134
|
-
>>>
|
|
135
|
-
>>> class Net(nn.LossBase):
|
|
136
|
-
... def __init__(self, reduction='mean'):
|
|
137
|
-
... super(Net, self).__init__(reduction)
|
|
138
|
-
... self.abs = ops.Abs()
|
|
139
|
-
...
|
|
140
|
-
... def construct(self, logits, labels):
|
|
141
|
-
... x = self.abs(logits - labels)
|
|
142
|
-
... output = self.get_loss(x)
|
|
143
|
-
... return output
|
|
144
|
-
>>> net = Net()
|
|
145
|
-
>>> # Case 1: logits.shape = labels.shape = (3,)
|
|
146
|
-
>>> logits = Tensor(np.array([1, 2, 3]), mindspore.float32)
|
|
147
|
-
>>> labels = Tensor(np.array([1, 2, 2]), mindspore.float32)
|
|
148
|
-
>>> output = net(logits, labels)
|
|
149
|
-
>>> print(output)
|
|
150
|
-
0.33333334
|
|
151
|
-
>>> # Case 2: logits.shape = labels.shape = (3, 3)
|
|
152
|
-
>>> logits = Tensor(np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]]), mindspore.float32)
|
|
153
|
-
>>> labels = Tensor(np.array([[1, 2, 2],[1, 2, 3],[1, 2, 3]]), mindspore.float32)
|
|
154
|
-
>>> output = net(logits, labels)
|
|
155
|
-
>>> print(output)
|
|
156
|
-
0.11111111
|
|
157
138
|
"""
|
|
158
139
|
input_dtype = x.dtype
|
|
159
140
|
x = self.cast(x, mstype.float32)
|
|
@@ -203,7 +184,7 @@ class L1Loss(LossBase):
|
|
|
203
184
|
.. math::
|
|
204
185
|
\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad \text{with } l_n = \left| x_n - y_n \right|,
|
|
205
186
|
|
|
206
|
-
where :math:`N` is the batch size. If `reduction` is not 'none'
|
|
187
|
+
where :math:`N` is the batch size. If `reduction` is not ``'none'``, then:
|
|
207
188
|
|
|
208
189
|
.. math::
|
|
209
190
|
\ell(x, y) =
|
|
@@ -213,9 +194,12 @@ class L1Loss(LossBase):
|
|
|
213
194
|
\end{cases}
|
|
214
195
|
|
|
215
196
|
Args:
|
|
216
|
-
reduction (str):
|
|
217
|
-
``
|
|
218
|
-
|
|
197
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
198
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
199
|
+
|
|
200
|
+
- ``'none'``: no reduction will be applied.
|
|
201
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
202
|
+
- ``'sum'``: the output elements will be summed.
|
|
219
203
|
|
|
220
204
|
Inputs:
|
|
221
205
|
- **logits** (Tensor) - Predicted value, Tensor of any dimension.
|
|
@@ -227,7 +211,7 @@ class L1Loss(LossBase):
|
|
|
227
211
|
Tensor, data type is float.
|
|
228
212
|
|
|
229
213
|
Raises:
|
|
230
|
-
ValueError: If `reduction` is not one of 'none'
|
|
214
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
231
215
|
ValueError: If `logits` and `labels` have different shapes and cannot be broadcasted to each other.
|
|
232
216
|
|
|
233
217
|
Supported Platforms:
|
|
@@ -273,7 +257,7 @@ class MSELoss(LossBase):
|
|
|
273
257
|
.. math::
|
|
274
258
|
\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad \text{with} \quad l_n = (x_n - y_n)^2.
|
|
275
259
|
|
|
276
|
-
where :math:`N` is the batch size. If `reduction` is not 'none'
|
|
260
|
+
where :math:`N` is the batch size. If `reduction` is not ``'none'``, then:
|
|
277
261
|
|
|
278
262
|
.. math::
|
|
279
263
|
\ell(x, y) =
|
|
@@ -283,8 +267,12 @@ class MSELoss(LossBase):
|
|
|
283
267
|
\end{cases}
|
|
284
268
|
|
|
285
269
|
Args:
|
|
286
|
-
reduction (str):
|
|
287
|
-
``
|
|
270
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
271
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
272
|
+
|
|
273
|
+
- ``'none'``: no reduction will be applied.
|
|
274
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
275
|
+
- ``'sum'``: the output elements will be summed.
|
|
288
276
|
|
|
289
277
|
Inputs:
|
|
290
278
|
- **logits** (Tensor) - The predicted value of the input. Tensor of any dimension.
|
|
@@ -293,11 +281,11 @@ class MSELoss(LossBase):
|
|
|
293
281
|
and they should be broadcasted to each other.
|
|
294
282
|
|
|
295
283
|
Outputs:
|
|
296
|
-
Tensor, loss of type float, the shape is zero if `reduction` is 'mean' or 'sum'
|
|
284
|
+
Tensor, loss of type float, the shape is zero if `reduction` is ``'mean'`` or ``'sum'`` .,
|
|
297
285
|
while the shape of output is the broadcasted shape if `reduction` is 'none'.
|
|
298
286
|
|
|
299
287
|
Raises:
|
|
300
|
-
ValueError: If `reduction` is not one of 'none'
|
|
288
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` or ``'sum'``.
|
|
301
289
|
ValueError: If `logits` and `labels` have different shapes and cannot be broadcasted.
|
|
302
290
|
|
|
303
291
|
Supported Platforms:
|
|
@@ -412,7 +400,7 @@ class MAELoss(LossBase):
|
|
|
412
400
|
.. math::
|
|
413
401
|
\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad \text{with } l_n = \left| x_n - y_n \right|,
|
|
414
402
|
|
|
415
|
-
where :math:`N` is the batch size. If `reduction` is not 'none'
|
|
403
|
+
where :math:`N` is the batch size. If `reduction` is not ``'none'``, then:
|
|
416
404
|
|
|
417
405
|
.. math::
|
|
418
406
|
\ell(x, y) =
|
|
@@ -422,8 +410,12 @@ class MAELoss(LossBase):
|
|
|
422
410
|
\end{cases}
|
|
423
411
|
|
|
424
412
|
Args:
|
|
425
|
-
reduction (str):
|
|
426
|
-
|
|
413
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
414
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
415
|
+
|
|
416
|
+
- ``'none'``: no reduction will be applied.
|
|
417
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
418
|
+
- ``'sum'``: the output elements will be summed.
|
|
427
419
|
|
|
428
420
|
Inputs:
|
|
429
421
|
- **logits** (Tensor) - Tensor of shape :math:`(M, *)` where :math:`*` means, any number of
|
|
@@ -433,11 +425,11 @@ class MAELoss(LossBase):
|
|
|
433
425
|
and they should be broadcasted to each other.
|
|
434
426
|
|
|
435
427
|
Outputs:
|
|
436
|
-
Tensor, weighted loss float tensor, the shape is zero if `reduction` is 'mean' or 'sum'
|
|
428
|
+
Tensor, weighted loss float tensor, the shape is zero if `reduction` is ``'mean'`` or ``'sum'`` .,
|
|
437
429
|
while the shape of output is the broadcasted shape if `reduction` is 'none'.
|
|
438
430
|
|
|
439
431
|
Raises:
|
|
440
|
-
ValueError: If `reduction` is not one of 'none'
|
|
432
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
441
433
|
|
|
442
434
|
Supported Platforms:
|
|
443
435
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -487,9 +479,12 @@ class MarginRankingLoss(LossBase):
|
|
|
487
479
|
|
|
488
480
|
Args:
|
|
489
481
|
margin (float, optional): Specify the adjustment factor of the operation. Default: ``0.0`` .
|
|
490
|
-
reduction (str, optional):
|
|
491
|
-
``
|
|
492
|
-
|
|
482
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
483
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
484
|
+
|
|
485
|
+
- ``'none'``: no reduction will be applied.
|
|
486
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
487
|
+
- ``'sum'``: the output elements will be summed.
|
|
493
488
|
|
|
494
489
|
Inputs:
|
|
495
490
|
- **input1** (Tensor) - Tensor of shape :math:`(N, *)` where :math:`*` means, any number
|
|
@@ -499,7 +494,7 @@ class MarginRankingLoss(LossBase):
|
|
|
499
494
|
:math:`(x_1, x_2, x_3, ..., x_R)`, then the shape of `target` must be :math:`(x_1, x_2, x_3, ..., x_R)`.
|
|
500
495
|
|
|
501
496
|
Outputs:
|
|
502
|
-
Tensor or Scalar. if `reduction` is "none"
|
|
497
|
+
Tensor or Scalar. if `reduction` is ``"none"``, its shape is the same as `labels`.
|
|
503
498
|
Otherwise, a scalar value will be returned.
|
|
504
499
|
|
|
505
500
|
Raises:
|
|
@@ -509,7 +504,7 @@ class MarginRankingLoss(LossBase):
|
|
|
509
504
|
TypeError: If the types of `input1` and `target` are inconsistent.
|
|
510
505
|
ValueError: If the shape of `input1` and `input2` are inconsistent.
|
|
511
506
|
ValueError: If the shape of `input1` and `target` are inconsistent.
|
|
512
|
-
ValueError: If `reduction` is not one of 'none'
|
|
507
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'`` , ``'sum'``.
|
|
513
508
|
|
|
514
509
|
Supported Platforms:
|
|
515
510
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -582,8 +577,12 @@ class SmoothL1Loss(LossBase):
|
|
|
582
577
|
Args:
|
|
583
578
|
beta (float): The loss function calculates the threshold of the transformation between L1Loss and L2Loss.
|
|
584
579
|
Default: ``1.0`` .
|
|
585
|
-
reduction (str):
|
|
586
|
-
|
|
580
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
581
|
+
``'sum'`` . Default: ``'none'`` .
|
|
582
|
+
|
|
583
|
+
- ``'none'``: no reduction will be applied.
|
|
584
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
585
|
+
- ``'sum'``: the output elements will be summed.
|
|
587
586
|
|
|
588
587
|
Inputs:
|
|
589
588
|
- **logits** (Tensor) - Predictive value. Tensor of any dimension. Data type must be one of float16,
|
|
@@ -591,12 +590,12 @@ class SmoothL1Loss(LossBase):
|
|
|
591
590
|
- **labels** (Tensor) - Ground truth data, same shape and dtype as the `logits`.
|
|
592
591
|
|
|
593
592
|
Outputs:
|
|
594
|
-
Tensor, if `reduction` is 'none'
|
|
593
|
+
Tensor, if `reduction` is ``'none'``, then output is a tensor with the same shape as `logits`.
|
|
595
594
|
Otherwise the shape of output tensor is :math:`()`.
|
|
596
595
|
|
|
597
596
|
Raises:
|
|
598
597
|
TypeError: If `beta` is not a float.
|
|
599
|
-
ValueError: If `reduction` is not one of 'none'
|
|
598
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
600
599
|
TypeError: If `logits` or `labels` are not Tensor.
|
|
601
600
|
TypeError: If dtype of `logits` or `labels` is neither float16 not float32.
|
|
602
601
|
TypeError: If dtype of `logits` is not the same as `labels`.
|
|
@@ -638,27 +637,31 @@ class SoftMarginLoss(LossBase):
|
|
|
638
637
|
(containing 1 or -1).
|
|
639
638
|
|
|
640
639
|
.. math::
|
|
641
|
-
\text{loss}(x, y) = \sum_i \frac{\log(1 + \exp(-y[i]*x[i]))}{
|
|
640
|
+
\text{loss}(x, y) = \sum_i \frac{\log(1 + \exp(-y[i]*x[i]))}{x.nelement()}
|
|
642
641
|
|
|
643
642
|
:math:`x.nelement()` represents the number of element of `x` .
|
|
644
643
|
|
|
645
644
|
Args:
|
|
646
|
-
reduction (str): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
647
|
-
Default: ``
|
|
645
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
646
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
647
|
+
|
|
648
|
+
- ``'none'``: no reduction will be applied.
|
|
649
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
650
|
+
- ``'sum'``: the output elements will be summed.
|
|
648
651
|
|
|
649
652
|
Inputs:
|
|
650
653
|
- **logits** (Tensor) - Predict data. Data type must be float16 or float32.
|
|
651
654
|
- **labels** (Tensor) - Ground truth data, with the same type and shape as `logits`.
|
|
652
655
|
|
|
653
656
|
Outputs:
|
|
654
|
-
Tensor or Scalar, if `reduction` is "none"
|
|
657
|
+
Tensor or Scalar, if `reduction` is ``"none"``, its shape is the same as `logits`.
|
|
655
658
|
Otherwise, a scalar value will be returned.
|
|
656
659
|
|
|
657
660
|
Raises:
|
|
658
661
|
TypeError: If `logits` or `labels` is not a Tensor.
|
|
659
662
|
TypeError: If dtype of `logits` or `labels` is neither float16 nor float32.
|
|
660
663
|
ValueError: If shape of `logits` is not the same as `labels`.
|
|
661
|
-
ValueError: If `reduction` is not one of 'none'
|
|
664
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
662
665
|
|
|
663
666
|
Supported Platforms:
|
|
664
667
|
``Ascend`` ``GPU``
|
|
@@ -710,9 +713,13 @@ class SoftmaxCrossEntropyWithLogits(LossBase):
|
|
|
710
713
|
of entry is a valid one.
|
|
711
714
|
|
|
712
715
|
Args:
|
|
713
|
-
sparse (bool): Specifies whether labels use sparse format or not. Default: ``False`` .
|
|
714
|
-
reduction (str):
|
|
715
|
-
``
|
|
716
|
+
sparse (bool, optional): Specifies whether labels use sparse format or not. Default: ``False`` .
|
|
717
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
718
|
+
``'sum'`` . Default: ``'none'`` .
|
|
719
|
+
|
|
720
|
+
- ``'none'``: no reduction will be applied.
|
|
721
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
722
|
+
- ``'sum'``: the output elements will be summed.
|
|
716
723
|
|
|
717
724
|
Inputs:
|
|
718
725
|
- **logits** (Tensor) - Tensor of shape :math:`(N, C)` . Data type must be float16 or float32.
|
|
@@ -726,7 +733,7 @@ class SoftmaxCrossEntropyWithLogits(LossBase):
|
|
|
726
733
|
TypeError: If `sparse` is not a bool.
|
|
727
734
|
TypeError: If `sparse` is True and dtype of `labels` is neither int32 not int64.
|
|
728
735
|
TypeError: If `sparse` is False and dtype of `labels` is neither float16 not float32.
|
|
729
|
-
ValueError: If `reduction` is not one of 'none'
|
|
736
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
730
737
|
|
|
731
738
|
Supported Platforms:
|
|
732
739
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -984,8 +991,12 @@ class SampledSoftmaxLoss(LossBase):
|
|
|
984
991
|
remove_accidental_hits (bool): Whether to remove "accidental hits"
|
|
985
992
|
where a sampled class equals to one of the labels classes. Default: ``True`` .
|
|
986
993
|
seed (int): Random seed for candidate sampling. Default: 0
|
|
987
|
-
reduction (str):
|
|
988
|
-
``
|
|
994
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
995
|
+
``'sum'`` . Default: ``'none'`` .
|
|
996
|
+
|
|
997
|
+
- ``'none'``: no reduction will be applied.
|
|
998
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
999
|
+
- ``'sum'``: the output elements will be summed.
|
|
989
1000
|
|
|
990
1001
|
Inputs:
|
|
991
1002
|
- **weights** (Tensor) - Tensor of shape :math:`(C, dim)`.
|
|
@@ -994,13 +1005,13 @@ class SampledSoftmaxLoss(LossBase):
|
|
|
994
1005
|
- **logits** (Tensor) - Tensor of shape :math:`(N, dim)`. The forward activations of the input network.
|
|
995
1006
|
|
|
996
1007
|
Outputs:
|
|
997
|
-
Tensor or Scalar, if `reduction` is 'none'
|
|
1008
|
+
Tensor or Scalar, if `reduction` is ``'none'``, then output is a tensor with shape :math:`(N,)`.
|
|
998
1009
|
Otherwise, the output is a scalar.
|
|
999
1010
|
|
|
1000
1011
|
Raises:
|
|
1001
1012
|
TypeError: If `sampled_values` is not a list or tuple.
|
|
1002
1013
|
TypeError: If dtype of `labels` is neither int32 not int64.
|
|
1003
|
-
ValueError: If `reduction` is not one of 'none'
|
|
1014
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
1004
1015
|
ValueError: If `num_sampled` or `num_true` is greater than `num_classes`.
|
|
1005
1016
|
ValueError: If length of `sampled_values` is not equal to 3.
|
|
1006
1017
|
|
|
@@ -1228,8 +1239,13 @@ class TripletMarginWithDistanceLoss(LossBase):
|
|
|
1228
1239
|
swap (bool): The distance swap is described in detail in the paper
|
|
1229
1240
|
`Learning shallow convolutional feature descriptors with triplet losses` by
|
|
1230
1241
|
V. Balntas, E. Riba et al. Default: ``False`` .
|
|
1231
|
-
reduction (str): Apply specific reduction method to the output:
|
|
1232
|
-
``'
|
|
1242
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1243
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
1244
|
+
|
|
1245
|
+
- ``'none'``: no reduction will be applied.
|
|
1246
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
1247
|
+
- ``'sum'``: the output elements will be summed.
|
|
1248
|
+
|
|
1233
1249
|
margin (float): Make a margin between the positive pair and the negative pair. Default: ``1.0`` .
|
|
1234
1250
|
|
|
1235
1251
|
Inputs:
|
|
@@ -1241,7 +1257,7 @@ class TripletMarginWithDistanceLoss(LossBase):
|
|
|
1241
1257
|
with the same type and shape as `x`.
|
|
1242
1258
|
|
|
1243
1259
|
Outputs:
|
|
1244
|
-
Union[Tensor, Scalar], if `reduction` is 'none'
|
|
1260
|
+
Union[Tensor, Scalar], if `reduction` is ``'none'``, its shape is :math:`(N)`.
|
|
1245
1261
|
Otherwise, a scalar value will be returned.
|
|
1246
1262
|
|
|
1247
1263
|
Raises:
|
|
@@ -1250,7 +1266,7 @@ class TripletMarginWithDistanceLoss(LossBase):
|
|
|
1250
1266
|
ValueError: If dimensions of input `x`, `positive` and `negative` are less than or equal to 1 at the same time.
|
|
1251
1267
|
ValueError: If length of shape of `margin` is not 0.
|
|
1252
1268
|
ValueError: If shape of `x`, `positive` and `negative` cannot broadcast.
|
|
1253
|
-
ValueError: If `reduction` is not one of 'none'
|
|
1269
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
1254
1270
|
|
|
1255
1271
|
Supported Platforms:
|
|
1256
1272
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -1333,15 +1349,19 @@ class PoissonNLLLoss(LossBase):
|
|
|
1333
1349
|
full (bool, optional): Whether include the Stirling approximation term in the loss calculation.
|
|
1334
1350
|
Default: ``False`` .
|
|
1335
1351
|
eps (float, optional): Lower bound of `input` when calculating logarithms. Default: ``1e-08`` .
|
|
1336
|
-
reduction (str, optional): Apply specific reduction method to the output:
|
|
1337
|
-
``'
|
|
1352
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1353
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
1354
|
+
|
|
1355
|
+
- ``'none'``: no reduction will be applied.
|
|
1356
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
1357
|
+
- ``'sum'``: the output elements will be summed.
|
|
1338
1358
|
|
|
1339
1359
|
Inputs:
|
|
1340
1360
|
- **input** (Tensor) - The input Tensor. The shape can be any number of dimensions.
|
|
1341
1361
|
- **target** (Tensor) - The label Tensor which has the same shape as `input`.
|
|
1342
1362
|
|
|
1343
1363
|
Outputs:
|
|
1344
|
-
Tensor or Scalar, if `reduction` is 'none'
|
|
1364
|
+
Tensor or Scalar, if `reduction` is ``'none'``, then output is a tensor and has the same shape as `input`.
|
|
1345
1365
|
Otherwise it is a scalar.
|
|
1346
1366
|
|
|
1347
1367
|
Raises:
|
|
@@ -1411,25 +1431,28 @@ class MultiLabelSoftMarginLoss(LossBase):
|
|
|
1411
1431
|
\sum_{j = 1}^{C}\left(y_{ij}\log\frac{1}{1 + e^{- x_{ij}}} + \left( 1 - y_{ij}
|
|
1412
1432
|
\right)\log\frac{e^{-x_{ij}}}{1 + e^{-x_{ij}}} \right)
|
|
1413
1433
|
|
|
1414
|
-
where :math:`
|
|
1434
|
+
where :math:`x_{ij}` represents the predicted score of sample :math:`i` for class :math:`j`. :math:`y_{ij}`
|
|
1415
1435
|
represents the binary label of sample :math:`i` for class :math:`j`, where sample :math:`i` belongs to
|
|
1416
|
-
class :math:`j` if :math:`
|
|
1436
|
+
class :math:`j` if :math:`y_{ij}=1` , and sample :math:`i` does not belong to class :math:`j` if :math:`y_{ij}=0`.
|
|
1417
1437
|
For a multi-label classification task, each sample may have multiple labels with a value of 1 in the binary
|
|
1418
1438
|
label :math:`y`. `weight` will multiply to the loss of each class if given.
|
|
1419
1439
|
|
|
1420
1440
|
Args:
|
|
1421
1441
|
weight (Union[Tensor, int, float]): The manual rescaling weight given to each class. Default: ``None`` .
|
|
1422
|
-
reduction (str):
|
|
1423
|
-
``'
|
|
1424
|
-
|
|
1442
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1443
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
1444
|
+
|
|
1445
|
+
- ``'none'``: no reduction will be applied.
|
|
1446
|
+
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
1447
|
+
- ``'sum'``: the output elements will be summed.
|
|
1425
1448
|
|
|
1426
1449
|
Inputs:
|
|
1427
|
-
- **x** (Tensor) - A tensor of shape (N, C)
|
|
1450
|
+
- **x** (Tensor) - A tensor of shape :math:`(N, C)`, where N is batch size and C is number
|
|
1428
1451
|
of classes.
|
|
1429
1452
|
- **target** (Tensor) - The label target Tensor which has the same shape as `x`.
|
|
1430
1453
|
|
|
1431
1454
|
Outputs:
|
|
1432
|
-
Tensor, the data type is the same as x, if the reduction is 'none'
|
|
1455
|
+
Tensor, the data type is the same as x, if the reduction is ``'none'``, its shape is (N), otherwise it is zero.
|
|
1433
1456
|
|
|
1434
1457
|
Raises:
|
|
1435
1458
|
ValueError: If the rank of `x` or `target` is not 2.
|
|
@@ -1481,8 +1504,8 @@ class MultiMarginLoss(LossBase):
|
|
|
1481
1504
|
``'sum'`` . Default: ``'mean'`` .
|
|
1482
1505
|
|
|
1483
1506
|
- ``'none'``: no reduction will be applied.
|
|
1484
|
-
- ``'mean'``:
|
|
1485
|
-
- ``'sum'``: the output will be summed.
|
|
1507
|
+
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
1508
|
+
- ``'sum'``: the output elements will be summed.
|
|
1486
1509
|
|
|
1487
1510
|
weight (Tensor, optional): The rescaling weight to each class with shape :math:`(C,)`. Data type only
|
|
1488
1511
|
support float32, float16 or float64. Default: ``None`` , all classes are weighted equally.
|
|
@@ -1494,7 +1517,7 @@ class MultiMarginLoss(LossBase):
|
|
|
1494
1517
|
value of target should be non-negative, less than C. `target` is :math:`y` in the above formula.
|
|
1495
1518
|
|
|
1496
1519
|
Outputs:
|
|
1497
|
-
Tensor, When `reduction` is 'none'
|
|
1520
|
+
Tensor, When `reduction` is ``'none'``, the shape is :math:`(N,)`.
|
|
1498
1521
|
Otherwise, it is a scalar. Has the same data type with `x`.
|
|
1499
1522
|
|
|
1500
1523
|
Raises:
|
|
@@ -1504,7 +1527,7 @@ class MultiMarginLoss(LossBase):
|
|
|
1504
1527
|
TypeError: If dtype of `x` is not float16, float or float64.
|
|
1505
1528
|
TypeError: If dtype of `weight` and `x` is not the same.
|
|
1506
1529
|
ValueError: If 'p' is not 1 or 2.
|
|
1507
|
-
ValueError: If 'reduction' is not one of {'none','sum','mean'}.
|
|
1530
|
+
ValueError: If 'reduction' is not one of { ``'none'`` , ``'sum'`` , ``'mean'`` }.
|
|
1508
1531
|
ValueError: If shape[0] of `x` is not equal to shape[0] of `target`.
|
|
1509
1532
|
ValueError: If shape[1] of `x` is not equal to shape[0] of `weight`.
|
|
1510
1533
|
ValueError: IF rank of `weight` is not 1.
|
|
@@ -1529,7 +1552,6 @@ class MultiMarginLoss(LossBase):
|
|
|
1529
1552
|
"""Initialize MultiMarginLoss."""
|
|
1530
1553
|
super(MultiMarginLoss, self).__init__()
|
|
1531
1554
|
self.multi_margin_loss = MultiMarginLossOp(p=p, margin=margin, reduction=reduction)
|
|
1532
|
-
self.generate_ones = ops.Fill()
|
|
1533
1555
|
self.weight = weight
|
|
1534
1556
|
|
|
1535
1557
|
def construct(self, x, target, weight=None):
|
|
@@ -1541,7 +1563,7 @@ class MultiMarginLoss(LossBase):
|
|
|
1541
1563
|
if not weight_one:
|
|
1542
1564
|
_check_is_tensor('weight', weight, self.cls_name)
|
|
1543
1565
|
else:
|
|
1544
|
-
weight =
|
|
1566
|
+
weight = F.fill(x.dtype, x.astype('float32')[0].shape, 1)
|
|
1545
1567
|
loss = self.multi_margin_loss(x, target, weight)
|
|
1546
1568
|
return loss
|
|
1547
1569
|
|
|
@@ -1575,8 +1597,12 @@ class BCELoss(LossBase):
|
|
|
1575
1597
|
Args:
|
|
1576
1598
|
weight (Tensor, optional): A rescaling weight applied to the loss of each batch element.
|
|
1577
1599
|
And it must have the same shape and data type as `inputs`. Default: ``None`` .
|
|
1578
|
-
reduction (str):
|
|
1579
|
-
|
|
1600
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1601
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
1602
|
+
|
|
1603
|
+
- ``'none'``: no reduction will be applied.
|
|
1604
|
+
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
1605
|
+
- ``'sum'``: the output elements will be summed.
|
|
1580
1606
|
|
|
1581
1607
|
Inputs:
|
|
1582
1608
|
- **logits** (Tensor) - The input tensor with shape :math:`(N, *)` where :math:`*` means, any number
|
|
@@ -1585,12 +1611,12 @@ class BCELoss(LossBase):
|
|
|
1585
1611
|
of additional dimensions. The same shape and data type as `logits`.
|
|
1586
1612
|
|
|
1587
1613
|
Outputs:
|
|
1588
|
-
Tensor, has the same dtype as `logits`. if `reduction` is 'none'
|
|
1614
|
+
Tensor, has the same dtype as `logits`. if `reduction` is ``'none'``, then it has the same shape as `logits`.
|
|
1589
1615
|
Otherwise, it is a scalar Tensor.
|
|
1590
1616
|
|
|
1591
1617
|
Raises:
|
|
1592
1618
|
TypeError: If dtype of `logits`, `labels` or `weight` (if given) is neither float16 not float32.
|
|
1593
|
-
ValueError: If `reduction` is not one of 'none'
|
|
1619
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
1594
1620
|
ValueError: If shape of `logits` is not the same as `labels` or `weight` (if given).
|
|
1595
1621
|
|
|
1596
1622
|
Supported Platforms:
|
|
@@ -1650,9 +1676,12 @@ class CosineEmbeddingLoss(LossBase):
|
|
|
1650
1676
|
|
|
1651
1677
|
Args:
|
|
1652
1678
|
margin (float): Should be in [-1.0, 1.0]. Default: ``0.0`` .
|
|
1653
|
-
reduction (str):
|
|
1654
|
-
``
|
|
1655
|
-
|
|
1679
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1680
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
1681
|
+
|
|
1682
|
+
- ``'none'``: no reduction will be applied.
|
|
1683
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
1684
|
+
- ``'sum'``: the output elements will be summed.
|
|
1656
1685
|
|
|
1657
1686
|
Inputs:
|
|
1658
1687
|
- **logits_x1** (Tensor) - Tensor of shape :math:`(N, *)` where :math:`*` means, any number
|
|
@@ -1662,12 +1691,12 @@ class CosineEmbeddingLoss(LossBase):
|
|
|
1662
1691
|
:math:`(x_1, x_2, x_3, ..., x_R)`, then the shape of `labels` must be :math:`(x_1, x_3, x_4, ..., x_R)`.
|
|
1663
1692
|
|
|
1664
1693
|
Outputs:
|
|
1665
|
-
Tensor or Scalar, if `reduction` is "none"
|
|
1694
|
+
Tensor or Scalar, if `reduction` is ``"none"``, its shape is the same as `labels`.
|
|
1666
1695
|
Otherwise, a scalar value will be returned.
|
|
1667
1696
|
|
|
1668
1697
|
Raises:
|
|
1669
1698
|
TypeError: If `margin` is not a float.
|
|
1670
|
-
ValueError: If `reduction` is not one of 'none'
|
|
1699
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
1671
1700
|
ValueError: If `margin` is not in range [-1, 1].
|
|
1672
1701
|
|
|
1673
1702
|
Supported Platforms:
|
|
@@ -1744,7 +1773,11 @@ class MultilabelMarginLoss(LossBase):
|
|
|
1744
1773
|
|
|
1745
1774
|
Args:
|
|
1746
1775
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1747
|
-
``'sum'`` . Default: ``
|
|
1776
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
1777
|
+
|
|
1778
|
+
- ``'none'``: no reduction will be applied.
|
|
1779
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
1780
|
+
- ``'sum'``: the output elements will be summed.
|
|
1748
1781
|
|
|
1749
1782
|
Inputs:
|
|
1750
1783
|
- **x** (Tensor) - Predict data. Tensor of shape :math:`(C)` or :math:`(N, C)`, where :math:`N`
|
|
@@ -1753,7 +1786,7 @@ class MultilabelMarginLoss(LossBase):
|
|
|
1753
1786
|
label targets padded by -1.
|
|
1754
1787
|
|
|
1755
1788
|
Outputs:
|
|
1756
|
-
- **y** (Union[Tensor, Scalar]) - The loss of MultilabelMarginLoss. If `reduction` is "none"
|
|
1789
|
+
- **y** (Union[Tensor, Scalar]) - The loss of MultilabelMarginLoss. If `reduction` is ``"none"``, its shape
|
|
1757
1790
|
is :math:`(N)`. Otherwise, a scalar value will be returned.
|
|
1758
1791
|
|
|
1759
1792
|
Raises:
|
|
@@ -1762,7 +1795,7 @@ class MultilabelMarginLoss(LossBase):
|
|
|
1762
1795
|
TypeError: If dtype of `target` is not int32.
|
|
1763
1796
|
ValueError: If length of shape of `x` is neither 1 nor 2.
|
|
1764
1797
|
ValueError: If shape of `x` is not the same as `target`.
|
|
1765
|
-
ValueError: If `reduction` is not one of 'none'
|
|
1798
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
1766
1799
|
|
|
1767
1800
|
Supported Platforms:
|
|
1768
1801
|
``Ascend`` ``GPU``
|
|
@@ -1811,8 +1844,13 @@ class BCEWithLogitsLoss(LossBase):
|
|
|
1811
1844
|
\end{cases}
|
|
1812
1845
|
|
|
1813
1846
|
Args:
|
|
1814
|
-
reduction (str):
|
|
1815
|
-
``'
|
|
1847
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1848
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
1849
|
+
|
|
1850
|
+
- ``'none'``: no reduction will be applied.
|
|
1851
|
+
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
1852
|
+
- ``'sum'``: the output elements will be summed.
|
|
1853
|
+
|
|
1816
1854
|
weight (Tensor, optional): A rescaling weight applied to the loss of each batch element.
|
|
1817
1855
|
If not None, it can be broadcast to a tensor with shape of `logits`,
|
|
1818
1856
|
data type must be float16 or float32. Default: ``None`` .
|
|
@@ -1827,7 +1865,7 @@ class BCEWithLogitsLoss(LossBase):
|
|
|
1827
1865
|
of additional dimensions. The same shape and data type as `logits`.
|
|
1828
1866
|
|
|
1829
1867
|
Outputs:
|
|
1830
|
-
Tensor or Scalar, if `reduction` is 'none'
|
|
1868
|
+
Tensor or Scalar, if `reduction` is ``'none'``, its shape is the same as `logits`.
|
|
1831
1869
|
Otherwise, a scalar value will be returned.
|
|
1832
1870
|
|
|
1833
1871
|
Raises:
|
|
@@ -1837,7 +1875,7 @@ class BCEWithLogitsLoss(LossBase):
|
|
|
1837
1875
|
TypeError: If data type of `weight` or `pos_weight` is neither float16 nor float32.
|
|
1838
1876
|
TypeError: If data type of `reduction` is not string.
|
|
1839
1877
|
ValueError: If `weight` or `pos_weight` can not be broadcast to a tensor with shape of `logits`.
|
|
1840
|
-
ValueError: If `reduction` is not one of 'none'
|
|
1878
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
1841
1879
|
|
|
1842
1880
|
Supported Platforms:
|
|
1843
1881
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -1858,28 +1896,17 @@ class BCEWithLogitsLoss(LossBase):
|
|
|
1858
1896
|
"""Initialize BCEWithLogitsLoss."""
|
|
1859
1897
|
super(BCEWithLogitsLoss, self).__init__()
|
|
1860
1898
|
self.reduction = reduction
|
|
1861
|
-
self.bce_with_logits_loss = P.BCEWithLogitsLoss(reduction=reduction)
|
|
1862
1899
|
if isinstance(weight, Parameter):
|
|
1863
1900
|
raise TypeError(f"For '{self.cls_name}', the 'weight' can not be a Parameter.")
|
|
1864
1901
|
if isinstance(pos_weight, Parameter):
|
|
1865
1902
|
raise TypeError(f"For '{self.cls_name}', the 'pos_weight' can not be a Parameter.")
|
|
1866
1903
|
self.weight = weight
|
|
1867
1904
|
self.pos_weight = pos_weight
|
|
1868
|
-
self.ones = P.OnesLike()
|
|
1869
1905
|
|
|
1870
1906
|
def construct(self, logits, labels):
|
|
1871
1907
|
_check_is_tensor('logits', logits, self.cls_name)
|
|
1872
1908
|
_check_is_tensor('labels', labels, self.cls_name)
|
|
1873
|
-
|
|
1874
|
-
if self.weight is not None:
|
|
1875
|
-
weight = self.weight
|
|
1876
|
-
else:
|
|
1877
|
-
weight = ones_input
|
|
1878
|
-
if self.pos_weight is not None:
|
|
1879
|
-
pos_weight = self.pos_weight
|
|
1880
|
-
else:
|
|
1881
|
-
pos_weight = ones_input
|
|
1882
|
-
loss = self.bce_with_logits_loss(logits, labels, weight, pos_weight)
|
|
1909
|
+
loss = ops.binary_cross_entropy_with_logits(logits, labels, self.weight, self.pos_weight, self.reduction)
|
|
1883
1910
|
return loss
|
|
1884
1911
|
|
|
1885
1912
|
|
|
@@ -1932,9 +1959,12 @@ class FocalLoss(LossBase):
|
|
|
1932
1959
|
gamma (float): Gamma is used to adjust the steepness of weight curve in focal loss. Default: ``2.0`` .
|
|
1933
1960
|
weight (Union[Tensor, None]): A rescaling weight applied to the loss of each batch element. The dimension of
|
|
1934
1961
|
weight should be 1. If None, no weight is applied. Default: ``None`` .
|
|
1935
|
-
reduction (str):
|
|
1936
|
-
|
|
1937
|
-
|
|
1962
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
1963
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
1964
|
+
|
|
1965
|
+
- ``'none'``: no reduction will be applied.
|
|
1966
|
+
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
1967
|
+
- ``'sum'``: the output elements will be summed.
|
|
1938
1968
|
|
|
1939
1969
|
Inputs:
|
|
1940
1970
|
- **logits** (Tensor) - Tensor of shape should be :math:`(N, C)` or :math:`(N, C, H)` or :math:`(N, C, H, W)`.
|
|
@@ -1948,7 +1978,7 @@ class FocalLoss(LossBase):
|
|
|
1948
1978
|
range [-:math:`C`, :math:`C`). Where :math:`C` is the number of classes in logits.
|
|
1949
1979
|
|
|
1950
1980
|
Outputs:
|
|
1951
|
-
Tensor or Scalar, if `reduction` is "none"
|
|
1981
|
+
Tensor or Scalar, if `reduction` is ``"none"``, its shape is the same as `logits`.
|
|
1952
1982
|
Otherwise, a scalar value will be returned.
|
|
1953
1983
|
|
|
1954
1984
|
Raises:
|
|
@@ -1956,7 +1986,7 @@ class FocalLoss(LossBase):
|
|
|
1956
1986
|
TypeError: If `weight` is not a Tensor.
|
|
1957
1987
|
ValueError: If `labels` dim is different from `logits`.
|
|
1958
1988
|
ValueError: If `labels` channel is not 1 and `labels` shape is different from `logits`.
|
|
1959
|
-
ValueError: If `reduction` is not one of 'none'
|
|
1989
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
1960
1990
|
|
|
1961
1991
|
Supported Platforms:
|
|
1962
1992
|
``Ascend``
|
|
@@ -2050,7 +2080,7 @@ class HuberLoss(LossBase):
|
|
|
2050
2080
|
delta * (|x_n - y_n| - 0.5 * delta), & \text{otherwise. }
|
|
2051
2081
|
\end{cases}
|
|
2052
2082
|
|
|
2053
|
-
where :math:`N` is the batch size. If `reduction` is not "none"
|
|
2083
|
+
where :math:`N` is the batch size. If `reduction` is not ``"none"``, then:
|
|
2054
2084
|
|
|
2055
2085
|
.. math::
|
|
2056
2086
|
\ell(x, y) =
|
|
@@ -2060,9 +2090,13 @@ class HuberLoss(LossBase):
|
|
|
2060
2090
|
\end{cases}
|
|
2061
2091
|
|
|
2062
2092
|
Args:
|
|
2063
|
-
reduction (str):
|
|
2064
|
-
``
|
|
2065
|
-
|
|
2093
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2094
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
2095
|
+
|
|
2096
|
+
- ``'none'``: no reduction will be applied.
|
|
2097
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
2098
|
+
- ``'sum'``: the output elements will be summed.
|
|
2099
|
+
|
|
2066
2100
|
delta (Union[int, float]): The threshold to change between two type of loss.
|
|
2067
2101
|
The value must be positive. Default: ``1.0`` .
|
|
2068
2102
|
|
|
@@ -2073,7 +2107,7 @@ class HuberLoss(LossBase):
|
|
|
2073
2107
|
and they should be broadcasted to each other.
|
|
2074
2108
|
|
|
2075
2109
|
Outputs:
|
|
2076
|
-
Tensor or Scalar, if `reduction` is "none"
|
|
2110
|
+
Tensor or Scalar, if `reduction` is ``"none"``, return a Tensor with same shape and dtype as `logits`.
|
|
2077
2111
|
Otherwise, a scalar value will be returned.
|
|
2078
2112
|
|
|
2079
2113
|
Raises:
|
|
@@ -2081,7 +2115,7 @@ class HuberLoss(LossBase):
|
|
|
2081
2115
|
TypeError: If data type of `logits` or `labels` are not the same.
|
|
2082
2116
|
TypeError: If dtype of `delta` is neither float nor int.
|
|
2083
2117
|
ValueError: If `delta` is less than or equal to 0.
|
|
2084
|
-
ValueError: If `reduction` is not one of "none"
|
|
2118
|
+
ValueError: If `reduction` is not one of ``"none"``, ``"mean"``, ``"sum"``.
|
|
2085
2119
|
ValueError: If `logits` and `labels` have different shapes and cannot be broadcasted to each other.
|
|
2086
2120
|
|
|
2087
2121
|
Supported Platforms:
|
|
@@ -2150,7 +2184,12 @@ class TripletMarginLoss(LossBase):
|
|
|
2150
2184
|
swap (bool, optional): The distance swap change the negative distance to the distance between positive
|
|
2151
2185
|
sample and negative sample. Default: ``False`` .
|
|
2152
2186
|
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2153
|
-
``'sum'`` . Default: ``
|
|
2187
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
2188
|
+
|
|
2189
|
+
- ``'none'``: no reduction will be applied.
|
|
2190
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
2191
|
+
- ``'sum'``: the output elements will be summed.
|
|
2192
|
+
|
|
2154
2193
|
margin (Union[Tensor, float]) - Make a margin between the positive pair and the negative pair.
|
|
2155
2194
|
Default: ``1.0`` .
|
|
2156
2195
|
|
|
@@ -2165,7 +2204,7 @@ class TripletMarginLoss(LossBase):
|
|
|
2165
2204
|
Default: ``1.0`` .
|
|
2166
2205
|
|
|
2167
2206
|
Outputs:
|
|
2168
|
-
Tensor. If `reduction` is "none"
|
|
2207
|
+
Tensor. If `reduction` is ``"none"``, its shape is :math:`(N)`. Otherwise, a scalar value will be returned.
|
|
2169
2208
|
|
|
2170
2209
|
Raises:
|
|
2171
2210
|
TypeError: If `x` or `positive` or 'negative' is not a Tensor.
|
|
@@ -2177,7 +2216,7 @@ class TripletMarginLoss(LossBase):
|
|
|
2177
2216
|
ValueError: If the dimension of input `x` or `positive` or `negative` is bigger than or equal to 8.
|
|
2178
2217
|
ValueError: If length of shape of `margin` is not 0.
|
|
2179
2218
|
ValueError: If shape of `x`, `positive` and `negative` cannot broadcast.
|
|
2180
|
-
ValueError: If `reduction` is not one of 'none'
|
|
2219
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
2181
2220
|
|
|
2182
2221
|
Supported Platforms:
|
|
2183
2222
|
``GPU``
|
|
@@ -2239,7 +2278,7 @@ class NLLLoss(LossBase):
|
|
|
2239
2278
|
:math:`N` is the batch size, :math:`c` belonging to :math:`[0, C-1]` is class index,
|
|
2240
2279
|
where :math:`C` is the number of classes.
|
|
2241
2280
|
|
|
2242
|
-
If `reduction` is not 'none' (default 'mean'), then
|
|
2281
|
+
If `reduction` is not ``'none'`` (default 'mean'), then
|
|
2243
2282
|
|
|
2244
2283
|
.. math::
|
|
2245
2284
|
|
|
@@ -2253,8 +2292,12 @@ class NLLLoss(LossBase):
|
|
|
2253
2292
|
The data type only supports float32 or float16. Default: ``None`` .
|
|
2254
2293
|
ignore_index (int): Specifies a target value that is ignored (typically for padding value)
|
|
2255
2294
|
and does not contribute to the gradient. Default: ``-100`` .
|
|
2256
|
-
reduction (str):
|
|
2257
|
-
Default: ``'mean'`` .
|
|
2295
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2296
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
2297
|
+
|
|
2298
|
+
- ``'none'``: no reduction will be applied.
|
|
2299
|
+
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
2300
|
+
- ``'sum'``: the output elements will be summed.
|
|
2258
2301
|
|
|
2259
2302
|
Inputs:
|
|
2260
2303
|
- **logits** (Tensor) - Tensor of shape :math:`(N, C)`
|
|
@@ -2270,7 +2313,7 @@ class NLLLoss(LossBase):
|
|
|
2270
2313
|
TypeError: If `weight` is not a Tensor.
|
|
2271
2314
|
TypeError: If `ignore_index` is not an int.
|
|
2272
2315
|
TypeError: If the data type of `weight` is not float16 or float32.
|
|
2273
|
-
ValueError: If `reduction` is not one of 'none'
|
|
2316
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
2274
2317
|
TypeError: If `logits` is not a Tensor.
|
|
2275
2318
|
TypeError: If `labels` is not a Tensor.
|
|
2276
2319
|
|
|
@@ -2356,7 +2399,7 @@ class CrossEntropyLoss(LossBase):
|
|
|
2356
2399
|
where :math:`x` is the inputs, :math:`t` is the target, :math:`w` is the weight,
|
|
2357
2400
|
N is the batch size, :math:`c` belonging to [0, C-1] is class index, where :math:`C` is the number of classes.
|
|
2358
2401
|
|
|
2359
|
-
If reduction is not 'none' (default 'mean'), then
|
|
2402
|
+
If reduction is not ``'none'`` (default 'mean'), then
|
|
2360
2403
|
|
|
2361
2404
|
.. math::
|
|
2362
2405
|
|
|
@@ -2378,7 +2421,7 @@ class CrossEntropyLoss(LossBase):
|
|
|
2378
2421
|
where :math:`x` is the inputs, :math:`t` is the target, :math:`w` is the weight,
|
|
2379
2422
|
N is the batch size, :math:`c` belonging to [0, C-1] is class index, where :math:`C` is the number of classes.
|
|
2380
2423
|
|
|
2381
|
-
If reduction is not 'none' (default 'mean'), then
|
|
2424
|
+
If reduction is not ``'none'`` (default 'mean'), then
|
|
2382
2425
|
|
|
2383
2426
|
.. math::
|
|
2384
2427
|
|
|
@@ -2394,8 +2437,13 @@ class CrossEntropyLoss(LossBase):
|
|
|
2394
2437
|
The data type only supports float32 or float16. Default: ``None`` .
|
|
2395
2438
|
ignore_index (int): Specifies a target value that is ignored (typically for padding value)
|
|
2396
2439
|
and does not contribute to the gradient. Default: ``-100`` .
|
|
2397
|
-
reduction (str):
|
|
2398
|
-
Default: ``'mean'`` .
|
|
2440
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2441
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
2442
|
+
|
|
2443
|
+
- ``'none'``: no reduction will be applied.
|
|
2444
|
+
- ``'mean'``: compute and return the weighted mean of elements in the output.
|
|
2445
|
+
- ``'sum'``: the output elements will be summed.
|
|
2446
|
+
|
|
2399
2447
|
label_smoothing (float): Label smoothing values, a regularization tool used to prevent the model
|
|
2400
2448
|
from overfitting when calculating Loss. The value range is [0.0, 1.0]. Default value: ``0.0`` .
|
|
2401
2449
|
|
|
@@ -2414,7 +2462,7 @@ class CrossEntropyLoss(LossBase):
|
|
|
2414
2462
|
TypeError: If `weight` is not a Tensor.
|
|
2415
2463
|
TypeError: If `ignore_index` is not an int.
|
|
2416
2464
|
TypeError: If the data type of `weight` is not float16 or float32.
|
|
2417
|
-
ValueError: If `reduction` is not one of 'none'
|
|
2465
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
2418
2466
|
TypeError: If `label_smoothing` is not a float.
|
|
2419
2467
|
TypeError: If `logits` is not a Tensor.
|
|
2420
2468
|
TypeError: If `labels` is not a Tensor.
|
|
@@ -2562,8 +2610,13 @@ class CTCLoss(LossBase):
|
|
|
2562
2610
|
|
|
2563
2611
|
Args:
|
|
2564
2612
|
blank (int, optional): The blank label. Default: ``0`` .
|
|
2565
|
-
reduction (str, optional):
|
|
2566
|
-
``'
|
|
2613
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2614
|
+
``'sum'`` . Default: ``'mean'`` .
|
|
2615
|
+
|
|
2616
|
+
- ``'none'``: no reduction will be applied.
|
|
2617
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
2618
|
+
- ``'sum'``: the output elements will be summed.
|
|
2619
|
+
|
|
2567
2620
|
zero_infinity (bool, optional): If loss is infinite, this parameter determines whether to set that loss
|
|
2568
2621
|
and its correlated gradient to zero. Default: ``False`` .
|
|
2569
2622
|
|
|
@@ -2583,7 +2636,7 @@ class CTCLoss(LossBase):
|
|
|
2583
2636
|
TypeError: If `zero_infinity` is not a bool, `reduction` is not string.
|
|
2584
2637
|
TypeError: If the dtype of `log_probs` is not float or double.
|
|
2585
2638
|
TypeError: If the dtype of `targets`, `input_lengths` or `target_lengths` is not int32 or int64.
|
|
2586
|
-
ValueError: If `reduction` is not "none"
|
|
2639
|
+
ValueError: If `reduction` is not ``"none"``, ``"mean"`` or ``"sum"``.
|
|
2587
2640
|
ValueError: If the value of `blank` is not in range [0, C). C is number of classes of `log_probs` .
|
|
2588
2641
|
ValueError: If the shape of `log_probs` is :math:`(T, C)`, the dimension of `targets` is not 1 or 2.
|
|
2589
2642
|
ValueError: If the shape of `log_probs` is :math:`(T, C)`, the first dimension of 2-D `target` is not 1.
|
|
@@ -2669,9 +2722,13 @@ class GaussianNLLLoss(LossBase):
|
|
|
2669
2722
|
full (bool, optional): Whether include the constant term in the loss calculation. When :math:`full=True`,
|
|
2670
2723
|
the constant term `const.` will be :math:`0.5 * log(2\pi)`. Default: ``False`` .
|
|
2671
2724
|
eps (float, optional): Used to improve the stability of log function. Default: ``1e-6`` .
|
|
2672
|
-
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2725
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2673
2726
|
``'sum'`` . Default: ``'mean'`` .
|
|
2674
2727
|
|
|
2728
|
+
- ``'none'``: no reduction will be applied.
|
|
2729
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
2730
|
+
- ``'sum'``: the output elements will be summed.
|
|
2731
|
+
|
|
2675
2732
|
Inputs:
|
|
2676
2733
|
- **logits** (Tensor) - Tensor of shape :math:`(N, *)` or :math:`(*)` where :math:`*` means any number of
|
|
2677
2734
|
additional dimensions.
|
|
@@ -2690,7 +2747,7 @@ class GaussianNLLLoss(LossBase):
|
|
|
2690
2747
|
TypeError: If `full` is not a bool.
|
|
2691
2748
|
TypeError: If `eps` is not a float.
|
|
2692
2749
|
ValueError: If `eps` is not a float within (0, inf).
|
|
2693
|
-
ValueError: If `reduction` is not one of 'none'
|
|
2750
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
2694
2751
|
|
|
2695
2752
|
Supported Platforms:
|
|
2696
2753
|
``Ascend`` ``GPU`` ``CPU``
|
|
@@ -2758,9 +2815,13 @@ class HingeEmbeddingLoss(LossBase):
|
|
|
2758
2815
|
Args:
|
|
2759
2816
|
margin (float, int): Threshold defined by Hinge Embedding Loss :math:`margin`.
|
|
2760
2817
|
Represented as :math:`\Delta` in the formula. Default: ``1.0`` .
|
|
2761
|
-
reduction (str):
|
|
2818
|
+
reduction (str, optional): Apply specific reduction method to the output: ``'none'`` , ``'mean'`` ,
|
|
2762
2819
|
``'sum'`` . Default: ``'mean'`` .
|
|
2763
2820
|
|
|
2821
|
+
- ``'none'``: no reduction will be applied.
|
|
2822
|
+
- ``'mean'``: compute and return the mean of elements in the output.
|
|
2823
|
+
- ``'sum'``: the output elements will be summed.
|
|
2824
|
+
|
|
2764
2825
|
Inputs:
|
|
2765
2826
|
- **logits** (Tensor) - The predicted value, expressed as :math:`x` in the equation.
|
|
2766
2827
|
Tensor of shape :math:`(*)` where :math:`*` means any number of dimensions.
|
|
@@ -2775,7 +2836,7 @@ class HingeEmbeddingLoss(LossBase):
|
|
|
2775
2836
|
TypeError: If `labels` is not a Tensor.
|
|
2776
2837
|
TypeError: If `margin` is not a float or int.
|
|
2777
2838
|
ValueError: If `labels` does not have the same shape as `logits` or they could not broadcast to each other.
|
|
2778
|
-
ValueError: If `reduction` is not one of 'none'
|
|
2839
|
+
ValueError: If `reduction` is not one of ``'none'``, ``'mean'``, ``'sum'``.
|
|
2779
2840
|
|
|
2780
2841
|
Supported Platforms:
|
|
2781
2842
|
``Ascend`` ``GPU`` ``CPU``
|