diff --git a/src/frontends/onnx/tests/models/softmax_crossentropy_loss_higher_dim.prototxt b/src/frontends/onnx/tests/models/softmax_crossentropy_loss_higher_dim.prototxt new file mode 100644 index 00000000000000..52cda8520df3b1 --- /dev/null +++ b/src/frontends/onnx/tests/models/softmax_crossentropy_loss_higher_dim.prototxt @@ -0,0 +1,55 @@ +ir_version: 7 +producer_name: "OpenVINO ONNX Frontend" +graph { + node { + input: "x" + input: "y" + output: "z" + op_type: "SoftmaxCrossEntropyLoss" + attribute { + name: "reduction" + s: "mean" + type: STRING + } + } + name: "test_sce_higher_dim" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { dim_value: 2 } + dim { dim_value: 3 } + dim { dim_value: 2 } + dim { dim_value: 2 } + } + } + } + } + input { + name: "y" + type { + tensor_type { + elem_type: 7 + shape { + dim { dim_value: 2 } + dim { dim_value: 2 } + dim { dim_value: 2 } + } + } + } + } + output { + name: "z" + type { + tensor_type { + elem_type: 1 + shape {} + } + } + } +} +opset_import { + version: 13 +} \ No newline at end of file diff --git a/src/frontends/onnx/tests/models/softmax_crossentropy_loss_mean_weight_ii.prototxt b/src/frontends/onnx/tests/models/softmax_crossentropy_loss_mean_weight_ii.prototxt new file mode 100644 index 00000000000000..c0e2d1e893d0f3 --- /dev/null +++ b/src/frontends/onnx/tests/models/softmax_crossentropy_loss_mean_weight_ii.prototxt @@ -0,0 +1,70 @@ +ir_version: 7 +producer_name: "OpenVINO ONNX Frontend" +graph { + node { + input: "x" + input: "y" + input: "w" + output: "z" + op_type: "SoftmaxCrossEntropyLoss" + attribute { + name: "reduction" + s: "mean" + type: STRING + } + attribute { + name: "ignore_index" + i: -1 + type: INT + } + } + name: "test_sce_mean_weight_ii" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { dim_value: 2 } + dim { dim_value: 3 } + dim { dim_value: 2 } + } + } + } + } + input { + name: "y" + type { + tensor_type { + elem_type: 7 + shape { + dim { dim_value: 2 } + dim { dim_value: 2 } + } + } + } + } + input { + name: "w" + type { + tensor_type { + elem_type: 1 + shape { + dim { dim_value: 3 } + } + } + } + } + output { + name: "z" + type { + tensor_type { + elem_type: 1 + shape {} + } + } + } +} +opset_import { + version: 13 +} \ No newline at end of file diff --git a/src/frontends/onnx/tests/models/softmax_crossentropy_loss_none.prototxt b/src/frontends/onnx/tests/models/softmax_crossentropy_loss_none.prototxt new file mode 100644 index 00000000000000..6b81cf2cf41d97 --- /dev/null +++ b/src/frontends/onnx/tests/models/softmax_crossentropy_loss_none.prototxt @@ -0,0 +1,53 @@ +ir_version: 7 +producer_name: "OpenVINO ONNX Frontend" +graph { + node { + input: "x" + input: "y" + output: "z" + op_type: "SoftmaxCrossEntropyLoss" + attribute { + name: "reduction" + s: "none" + type: STRING + } + } + name: "test_sce_none" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { dim_value: 2 } + dim { dim_value: 3 } + } + } + } + } + input { + name: "y" + type { + tensor_type { + elem_type: 7 + shape { + dim { dim_value: 2 } + } + } + } + } + output { + name: "z" + type { + tensor_type { + elem_type: 1 + shape { + dim { dim_value: 2 } + } + } + } + } +} +opset_import { + version: 13 +} \ No newline at end of file diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp index 36155f43ed9d6a..0253fc3989e0e2 100644 --- a/src/frontends/onnx/tests/onnx_import.in.cpp +++ b/src/frontends/onnx/tests/onnx_import.in.cpp @@ -6949,9 +6949,45 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_float8e4m3fn_constant) { OPENVINO_TEST(${BACKEND_NAME}, onnx_model_softmax_crossentropy_loss_sum) { auto model = convert_model("softmax_crossentropy_loss_sum.onnx"); auto test_case = ov::test::TestCase(model, s_device); + test_case.add_input({0.5f, 1.5f, 2.5f, 3.5f, 4.5f, 5.5f}); test_case.add_input({1, 2}); - test_case.add_expected_output(Shape{}, {1.81521f}); + test_case.add_expected_output(Shape{}, {1.81521f}); test_case.run_with_tolerance_as_fp(0.0015f); } + +OPENVINO_TEST(${BACKEND_NAME}, onnx_model_softmax_crossentropy_loss_mean_weight_ii) { + auto model = convert_model("softmax_crossentropy_loss_mean_weight_ii.onnx"); + auto test_case = ov::test::TestCase(model, s_device); + + test_case.add_input({1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f}); + test_case.add_input({0, -1, 2, 1}); + test_case.add_input({0.5f, 1.0f, 2.0f}); + + test_case.add_expected_output(Shape{}, {1.2857887f}); + test_case.run_with_tolerance_as_fp(0.001f); +} + + +OPENVINO_TEST(${BACKEND_NAME}, onnx_model_softmax_crossentropy_loss_none) { + auto model = convert_model("softmax_crossentropy_loss_none.onnx"); + auto test_case = ov::test::TestCase(model, s_device); + + test_case.add_input({1.f, 2.f, 3.f, 4.f, 5.f, 6.f}); + test_case.add_input({2, 1}); + + test_case.add_expected_output(Shape{2}, {0.40760595f, 1.4076059f}); + test_case.run_with_tolerance_as_fp(0.001f); +} + +OPENVINO_TEST(${BACKEND_NAME}, onnx_model_softmax_crossentropy_loss_higher_dim) { + auto model = convert_model("softmax_crossentropy_loss_higher_dim.onnx"); + auto test_case = ov::test::TestCase(model, s_device); + + test_case.add_input(std::vector(24, 1.0f)); + test_case.add_input({1, 0, 2, 1, 0, 2, 1, 1}); + + test_case.add_expected_output(Shape{}, {1.0986123f}); + test_case.run_with_tolerance_as_fp(0.001f); +}