Skip to content

Commit

Permalink
Added the remaining test cases, covering mean with weights (ignoring …
Browse files Browse the repository at this point in the history
…index), higher dimension, and no reduction
  • Loading branch information
AJThePro99 committed Feb 20, 2025
1 parent 2257722 commit 9b11313
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
38 changes: 37 additions & 1 deletion src/frontends/onnx/tests/onnx_import.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>({0.5f, 1.5f, 2.5f, 3.5f, 4.5f, 5.5f});
test_case.add_input<int64_t>({1, 2});
test_case.add_expected_output<float>(Shape{}, {1.81521f});

test_case.add_expected_output<float>(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<float>({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<int64_t>({0, -1, 2, 1});
test_case.add_input<float>({0.5f, 1.0f, 2.0f});

test_case.add_expected_output<float>(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<float>({1.f, 2.f, 3.f, 4.f, 5.f, 6.f});
test_case.add_input<int64_t>({2, 1});

test_case.add_expected_output<float>(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<float>(std::vector<float>(24, 1.0f));
test_case.add_input<int64_t>({1, 0, 2, 1, 0, 2, 1, 1});

test_case.add_expected_output<float>(Shape{}, {1.0986123f});
test_case.run_with_tolerance_as_fp(0.001f);
}

0 comments on commit 9b11313

Please sign in to comment.