Merge remote-tracking branch 'upstream/master' into itikhono/extension/json_config

This commit is contained in:
Ivan Tikhonov 2021-12-16 09:03:34 +03:00
commit 66a71914ac
24 changed files with 532 additions and 134 deletions

View File

@ -30,7 +30,7 @@ class ReferenceEinsumTest : public testing::TestWithParam<EinsumParams>, public
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
function = CreateModel(params);
for (const auto& input_tensor : params.inputs) {
inputData.push_back(input_tensor.data);
}
@ -52,7 +52,7 @@ public:
}
private:
static std::shared_ptr<Function> CreateFunction(const EinsumParams& params) {
static std::shared_ptr<Model> CreateModel(const EinsumParams& params) {
OutputVector output_vector;
ParameterVector param_vector;
for (const auto& input_tensor : params.inputs) {
@ -61,7 +61,7 @@ private:
param_vector.push_back(param);
}
const auto einsum = std::make_shared<opset7::Einsum>(output_vector, params.equation);
const auto f = std::make_shared<Function>(OutputVector{einsum}, param_vector);
const auto f = std::make_shared<Model>(OutputVector{einsum}, param_vector);
return f;
}
};

View File

@ -36,7 +36,7 @@ class ReferenceExtractImagePatchesTest : public testing::TestWithParam<ExtractIm
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
function = CreateModel(params);
inputData = {params.data.data};
refOutData = {params.expectedResult.data};
}
@ -59,14 +59,14 @@ public:
}
private:
static std::shared_ptr<Function> CreateFunction(const ExtractImagePatchesParams& params) {
static std::shared_ptr<Model> CreateModel(const ExtractImagePatchesParams& params) {
const auto data = std::make_shared<opset1::Parameter>(params.data.type, params.data.shape);
const auto extrace_image_patches = std::make_shared<opset3::ExtractImagePatches>(data,
params.sizes,
params.strides,
params.rates,
params.autoPad);
const auto f = std::make_shared<Function>(extrace_image_patches, ParameterVector{data});
const auto f = std::make_shared<Model>(extrace_image_patches, ParameterVector{data});
return f;
}
};

View File

@ -26,6 +26,32 @@ def create_onnx_model():
return make_model(graph, producer_name="ngraph ONNX Importer")
def create_onnx_model_with_subgraphs():
A = onnx.helper.make_tensor_value_info("A", onnx.TensorProto.FLOAT, [3])
B = onnx.helper.make_tensor_value_info("B", onnx.TensorProto.FLOAT, [3])
add_out = onnx.helper.make_tensor_value_info("add_out", onnx.TensorProto.FLOAT, [3])
sub_out = onnx.helper.make_tensor_value_info("sub_out", onnx.TensorProto.FLOAT, [3])
add = onnx.helper.make_node("Add", inputs=["A", "B"], outputs=["add_out"])
sub = onnx.helper.make_node("Sub", inputs=["A", "B"], outputs=["sub_out"])
then_body = make_graph([add], "then_body", [], [add_out])
else_body = make_graph([sub], "else_body", [], [sub_out])
if_node = onnx.helper.make_node(
"If",
inputs=["cond"],
outputs=["res"],
then_branch=then_body,
else_branch=else_body
)
cond = onnx.helper.make_tensor_value_info("cond", onnx.TensorProto.BOOL, [])
res = onnx.helper.make_tensor_value_info("res", onnx.TensorProto.FLOAT, [3])
graph = make_graph([if_node], "graph", [cond, A, B], [res])
return make_model(graph, producer_name="ngraph ONNX Importer")
def run_function(function, *inputs, expected):
runtime = get_runtime()
computation = runtime.computation(function)
@ -37,15 +63,18 @@ def run_function(function, *inputs, expected):
fem = FrontEndManager()
onnx_model_filename = "model.onnx"
onnx_model_with_subgraphs_filename = "model_subgraphs.onnx"
ONNX_FRONTEND_NAME = "onnx"
def setup_module():
onnx.save_model(create_onnx_model(), onnx_model_filename)
onnx.save_model(create_onnx_model_with_subgraphs(), onnx_model_with_subgraphs_filename)
def teardown_module():
os.remove(onnx_model_filename)
os.remove(onnx_model_with_subgraphs_filename)
def skip_if_onnx_frontend_is_disabled():
@ -72,17 +101,29 @@ def test_convert():
run_function(function, a, b, expected=[expected])
def test_decode_and_convert():
@pytest.mark.parametrize("model_filename, inputs, expected", [
[onnx_model_filename,
[np.array([[1, 2], [3, 4]], dtype=np.float32),
np.array([[2, 3], [4, 5]], dtype=np.float32)],
np.array([[1.5, 5], [10.5, 18]], dtype=np.float32)],
[onnx_model_with_subgraphs_filename,
[np.array(False, dtype=bool),
np.array([1, 2, 3], dtype=np.float32),
np.array([2, 3, 5], dtype=np.float32)],
np.array([-1, -1, -2], dtype=np.float32)],
])
def test_decode_and_convert(model_filename, inputs, expected):
skip_if_onnx_frontend_is_disabled()
fe = fem.load_by_framework(framework=ONNX_FRONTEND_NAME)
assert fe
model = fe.load(onnx_model_filename)
model = fe.load(model_filename)
assert model
decoded_function = fe.decode(model)
assert decoded_function
for op in decoded_function.get_ordered_ops():
assert op.get_type_name() in ["Parameter", "Constant", "ONNXFrameworkNode",
"ONNXSubgraphFrameworkNode", "Result"]
@ -92,10 +133,7 @@ def test_decode_and_convert():
for op in decoded_function.get_ordered_ops():
assert op.get_type_name() not in ["ONNXFrameworkNode", "ONNXSubgraphFrameworkNode"]
a = np.array([[1, 2], [3, 4]], dtype=np.float32)
b = np.array([[2, 3], [4, 5]], dtype=np.float32)
expected = np.array([[1.5, 5], [10.5, 18]], dtype=np.float32)
run_function(decoded_function, a, b, expected=[expected])
run_function(decoded_function, *inputs, expected=[expected])
def test_load_by_model():

View File

@ -1,9 +1,9 @@
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.runtime import Function
from openvino.runtime.impl import Shape, Type
from openvino.runtime.impl.op import Parameter
from openvino.runtime import Model
from openvino.runtime import Shape, Type
from openvino.runtime.op import Parameter
import openvino.runtime.opset8 as ops
@ -11,7 +11,7 @@ def get_test_function():
element_type = Type.f32
param = Parameter(element_type, Shape([1, 3, 22, 22]))
relu = ops.relu(param)
func = Function([relu], [param], "test")
func = Model([relu], [param], "test")
assert func is not None
return func

View File

@ -0,0 +1,56 @@
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "Softmax"
attribute {
name: "axis"
i: 1
type: INT
}
}
name: "test_softmax_axis_1"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
version: 11
}

View File

@ -0,0 +1,56 @@
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "Softmax"
attribute {
name: "axis"
i: -1
type: INT
}
}
name: "test_softmax_axis_0"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
version: 11
}

View File

@ -0,0 +1,56 @@
ir_version: 3
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "x"
output: "y"
op_type: "Softmax"
attribute {
name: "axis"
i: -1
type: INT
}
}
name: "test_softmax_axis_0"
input {
name: "x"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
output {
name: "y"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 3
}
dim {
dim_value: 4
}
dim {
dim_value: 5
}
}
}
}
}
}
opset_import {
version: 13
}

View File

@ -380,7 +380,7 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_initializer_wo_input) {
test_case.run();
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_function) {
NGRAPH_TEST(${BACKEND_NAME}, onnx_expand_function) {
const auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/quantization/dynamicquantizelinear.onnx"));
@ -392,7 +392,7 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_function) {
test_case.run();
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_function_dependency_to_created_subgraph) {
NGRAPH_TEST(${BACKEND_NAME}, onnx_expand_function_dependency_to_created_subgraph) {
const auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/transformations/greater_or_equal.onnx"));
@ -403,7 +403,7 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_function_dependency_to_created_sub
test_case.run();
}
NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_context_dependent_function) {
NGRAPH_TEST(${BACKEND_NAME}, onnx_expand_context_dependent_function) {
auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/transformations/softmax_crossentropy_consumed.onnx"));
@ -690,19 +690,24 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_1D) {
}
namespace {
// common input for all Softmax 3D test cases (Shape = {3,4,5})
// clang-format off
const std::vector<float> SOFTMAX_INPUT = {
2.75793882, -0.50841322, 0.82013929, -0.62409912, -0.96136118, 0.21004745, 1.38337255,
1.19030397, 2.0940445, -0.03551657, -0.78686039, 1.992782, 0.04300319, -0.29230777,
-0.56797112, -1.26732165, -0.61935399, 0.57670432, 0.92844898, 2.82469233,
2.75793882, -0.50841322, 0.82013929, -0.62409912, -0.96136118,
0.21004745, 1.38337255, 1.19030397, 2.0940445, -0.03551657,
-0.78686039, 1.992782, 0.04300319, -0.29230777, -0.56797112,
-1.26732165, -0.61935399, 0.57670432, 0.92844898, 2.82469233,
0.98721677, -0.05100663, -1.21178917, -0.17530157, 1.40051805, -0.13259761, -1.14313018,
0.2673723, -0.87996154, 1.29053106, 1.55, 0.8396538, 1.20729817, 0.23727845,
-0.89113606, -1.70909842, 0.26460363, -0.70566808, 2.383518, 1.07024615,
0.98721677, -0.05100663, -1.21178917, -0.17530157, 1.40051805,
-0.13259761, -1.14313018, 0.2673723, -0.87996154, 1.29053106,
1.55, 0.8396538, 1.20729817, 0.23727845, -0.89113606,
-1.70909842, 0.26460363, -0.70566808, 2.383518, 1.07024615,
-1.21722605, 0.82919357, 0.55765697, 0.12657686, 0.63432172, 0.75425957, -2.43721014,
-1.24478184, 2.65316853, 1.19509542, -0.95523998, 0.5149006, -0.01151649, 0.68327026,
-0.4589638, -0.46554745, 0.21055324, 0.39266729, 2.05098086, 1.83207919};
-1.21722605, 0.82919357, 0.55765697, 0.12657686, 0.63432172,
0.75425957, -2.43721014, -1.24478184, 2.65316853, 1.19509542,
-0.95523998, 0.5149006, -0.01151649, 0.68327026, -0.4589638,
-0.46554745, 0.21055324, 0.39266729, 2.05098086, 1.83207919};
} // namespace
// clang-format on
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_0) {
auto function = onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_0.onnx"));
@ -710,19 +715,24 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_0) {
auto test_case = test::TestCase(function, s_device);
test_case.add_input<float>(SOFTMAX_INPUT);
// clang-format off
test_case.add_expected_output<float>(
Shape{3, 4, 5},
{0.09683057, 0.00369363, 0.01394559, 0.00329012, 0.00234823, 0.00757665, 0.02449322,
0.02019284, 0.04985249, 0.00592694, 0.00279593, 0.04505148, 0.00641108, 0.00458466,
0.00348007, 0.00172928, 0.00330577, 0.01093237, 0.01554086, 0.10351497,
{0.09683057, 0.00369363, 0.01394559, 0.00329012, 0.00234823,
0.00757665, 0.02449322, 0.02019284, 0.04985249, 0.00592694,
0.00279593, 0.04505148, 0.00641108, 0.00458466, 0.00348007,
0.00172928, 0.00330577, 0.01093237, 0.01554086, 0.10351497,
0.01648154, 0.00583583, 0.00182802, 0.00515374, 0.02491679, 0.00537859, 0.00195794,
0.00802367, 0.00254737, 0.0223216, 0.02893419, 0.0142204, 0.02053893, 0.00778581,
0.00251907, 0.00111174, 0.00800149, 0.0030324, 0.06658917, 0.0179084,
0.01648154, 0.00583583, 0.00182802, 0.00515374, 0.02491679,
0.00537859, 0.00195794, 0.00802367, 0.00254737, 0.0223216,
0.02893419, 0.0142204, 0.02053893, 0.00778581, 0.00251907,
0.00111174, 0.00800149, 0.0030324, 0.06658917, 0.0179084,
0.00181811, 0.01407243, 0.01072611, 0.0069699, 0.01158077, 0.01305647, 0.00053677,
0.0017687, 0.08719896, 0.02028982, 0.00236265, 0.01027717, 0.0060709, 0.01216173,
0.00388087, 0.00385541, 0.00758048, 0.00909469, 0.04775123, 0.03836337});
0.00181811, 0.01407243, 0.01072611, 0.0069699, 0.01158077,
0.01305647, 0.00053677, 0.0017687, 0.08719896, 0.02028982,
0.00236265, 0.01027717, 0.0060709, 0.01216173, 0.00388087,
0.00385541, 0.00758048, 0.00909469, 0.04775123, 0.03836337});
// clang-format on
test_case.run(6);
}
@ -733,35 +743,113 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_1) {
auto test_case = test::TestCase(function, s_device);
test_case.add_input<float>(SOFTMAX_INPUT);
// clang-format off
test_case.add_expected_output<float>(
Shape{3, 4, 5},
{0.22757064, 0.00868076, 0.03277484, 0.00773243, 0.0055188, 0.0178066, 0.05756383,
0.04745709, 0.11716303, 0.01392945, 0.00657097, 0.10587974, 0.01506727, 0.01077484,
0.00817884, 0.00406413, 0.00776921, 0.0256932, 0.03652405, 0.24328028,
{0.22757064, 0.00868076, 0.03277484, 0.00773243, 0.0055188,
0.0178066, 0.05756383, 0.04745709, 0.11716303, 0.01392945,
0.00657097, 0.10587974, 0.01506727, 0.01077484, 0.00817884,
0.00406413, 0.00776921, 0.0256932, 0.03652405, 0.24328028,
0.06217413, 0.02201481, 0.00689594, 0.01944171, 0.09399488, 0.02028993, 0.00738604,
0.03026811, 0.00960958, 0.08420492, 0.10914991, 0.05364435, 0.07748005, 0.02937079,
0.0095028, 0.00419387, 0.03018442, 0.01143929, 0.2511977, 0.06755678,
0.06217413, 0.02201481, 0.00689594, 0.01944171, 0.09399488,
0.02028993, 0.00738604, 0.03026811, 0.00960958, 0.08420492,
0.10914991, 0.05364435, 0.07748005, 0.02937079, 0.0095028,
0.00419387, 0.03018442, 0.01143929, 0.2511977, 0.06755678,
0.00587593, 0.04548053, 0.0346656, 0.02252594, 0.03742775, 0.04219705, 0.00173478,
0.00571623, 0.2818174, 0.06557446, 0.00763582, 0.03321466, 0.01962049, 0.03930537,
0.01254255, 0.01246025, 0.02449929, 0.02939305, 0.15432668, 0.12398617});
0.00587593, 0.04548053, 0.0346656, 0.02252594, 0.03742775,
0.04219705, 0.00173478, 0.00571623, 0.2818174, 0.06557446,
0.00763582, 0.03321466, 0.01962049, 0.03930537, 0.01254255,
0.01246025, 0.02449929, 0.02939305, 0.15432668, 0.12398617});
// clang-format on
test_case.run(4);
}
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_invalid_axis_1D) {
ASSERT_THROW(
onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_invalid_axis_1D.onnx")),
ngraph::ngraph_error)
<< "Softmax model with invalid axis was successfully imported while it should have thrown.";
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_1_opset11) {
auto function =
onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_1_opset11.onnx"));
auto test_case = test::TestCase(function, s_device);
test_case.add_input<float>(SOFTMAX_INPUT);
// clang-format off
test_case.add_expected_output<float>(
Shape{3, 4, 5},
{0.88890495, 0.04825497, 0.27088348, 0.04490523, 0.02037154,
0.06955369, 0.31998834, 0.39223197, 0.68041159, 0.05141776,
0.02566661, 0.5885689, 0.12453075, 0.06257374, 0.03019055,
0.01587475, 0.0431878, 0.21235381, 0.21210944, 0.89802015,
0.31752626, 0.19442629, 0.0546935, 0.06279221, 0.36823282,
0.10362164, 0.06523066, 0.24006419, 0.03103672, 0.32987983,
0.55743381, 0.473766, 0.61451431, 0.09486084, 0.03722801,
0.02141829, 0.26657706, 0.090728, 0.81131024, 0.26465935,
0.08619648, 0.43343993, 0.3877785, 0.04523505, 0.15625437,
0.61900597, 0.01653285, 0.06394322, 0.56592636, 0.27376196,
0.11201305, 0.31654337, 0.21947994, 0.07893034, 0.05236297,
0.18278451, 0.23348385, 0.32879834, 0.30990825, 0.5176207});
// clang-format on
test_case.run(4);
}
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_invalid_axis_3D) {
ASSERT_THROW(
onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_invalid_axis_3D.onnx")),
ngraph::ngraph_error)
<< "Softmax model with invalid axis was successfully imported while it should have thrown.";
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_negative_1_opset11) {
auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_negative_1_opset11.onnx"));
auto test_case = test::TestCase(function);
test_case.add_input<float>(SOFTMAX_INPUT);
// clang-format off
test_case.add_expected_output<float>(
Shape{3, 4, 5},
{0.88890495, 0.04825497, 0.27088348, 0.04490523, 0.02037154,
0.06955369, 0.31998834, 0.39223197, 0.68041159, 0.05141776,
0.02566661, 0.5885689, 0.12453075, 0.06257374, 0.03019055,
0.01587475, 0.0431878, 0.21235381, 0.21210944, 0.89802015,
0.31752626, 0.19442629, 0.0546935, 0.06279221, 0.36823282,
0.10362164, 0.06523066, 0.24006419, 0.03103672, 0.32987983,
0.55743381, 0.473766, 0.61451431, 0.09486084, 0.03722801,
0.02141829, 0.26657706, 0.090728, 0.81131024, 0.26465935,
0.08619648, 0.43343993, 0.3877785, 0.04523505, 0.15625437,
0.61900597, 0.01653285, 0.06394322, 0.56592636, 0.27376196,
0.11201305, 0.31654337, 0.21947994, 0.07893034, 0.05236297,
0.18278451, 0.23348385, 0.32879834, 0.30990825, 0.5176207});
// clang-format on
test_case.run(6);
}
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_negative_1_opset13) {
auto function = onnx_import::import_onnx_model(
file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_negative_1_opset13.onnx"));
auto test_case = test::TestCase(function);
test_case.add_input<float>(SOFTMAX_INPUT);
// clang-format off
test_case.add_expected_output<float>(
Shape{3, 4, 5},
{0.88890495, 0.04825497, 0.27088348, 0.04490523, 0.02037154,
0.06955369, 0.31998834, 0.39223197, 0.68041159, 0.05141776,
0.02566661, 0.5885689, 0.12453075, 0.06257374, 0.03019055,
0.01587475, 0.0431878, 0.21235381, 0.21210944, 0.89802015,
0.31752626, 0.19442629, 0.0546935, 0.06279221, 0.36823282,
0.10362164, 0.06523066, 0.24006419, 0.03103672, 0.32987983,
0.55743381, 0.473766, 0.61451431, 0.09486084, 0.03722801,
0.02141829, 0.26657706, 0.090728, 0.81131024, 0.26465935,
0.08619648, 0.43343993, 0.3877785, 0.04523505, 0.15625437,
0.61900597, 0.01653285, 0.06394322, 0.56592636, 0.27376196,
0.11201305, 0.31654337, 0.21947994, 0.07893034, 0.05236297,
0.18278451, 0.23348385, 0.32879834, 0.30990825, 0.5176207});
// clang-format on
test_case.run(6);
}
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sub) {

View File

@ -199,9 +199,10 @@ void Graph::decode_to_framework_nodes() {
if (node.has_subgraphs()) {
const auto& subgraphs = node.get_subgraphs();
auto inputs = node.get_ng_inputs();
std::vector<std::shared_ptr<Function>> functions;
for (const auto& kv : subgraphs) {
auto& subgraph = kv.second;
subgraph->decode();
functions.push_back(subgraph->decode());
for (const auto& input : subgraph->get_inputs_from_parent()) {
const auto& name = input.get_node()->get_friendly_name();
if (std::find_if(inputs.begin(), inputs.end(), [&name](const Output<ngraph::Node>& n) -> bool {
@ -211,10 +212,9 @@ void Graph::decode_to_framework_nodes() {
}
}
}
framework_node =
std::make_shared<ngraph::frontend::ONNXSubgraphFrameworkNode>(shared_from_this(), node, inputs);
framework_node = std::make_shared<frontend::ONNXSubgraphFrameworkNode>(node, functions, inputs);
} else {
framework_node = std::make_shared<ngraph::frontend::ONNXFrameworkNode>(shared_from_this(), node);
framework_node = std::make_shared<frontend::ONNXFrameworkNode>(node);
}
OutputVector ng_nodes{framework_node->outputs()};
set_friendly_names(node, ng_nodes);
@ -240,7 +240,10 @@ std::shared_ptr<Function> Graph::create_function() {
std::shared_ptr<Function> Graph::decode() {
decode_to_framework_nodes();
return create_function();
auto function = create_function();
auto& rt_info = function->get_rt_info();
rt_info[ONNX_GRAPH_RT_ATTRIBUTE] = shared_from_this();
return function;
}
bool Graph::is_ng_node_in_cache(const std::string& name) const {
@ -399,7 +402,8 @@ void Subgraph::find_inputs_from_parent() {
for (const auto& out_name : node_proto.output()) {
if (m_cache->contains(out_name)) {
auto node_to_replace_input = m_cache->get_node(out_name).get_node();
if (!dynamic_cast<op::util::MultiSubGraphOp*>(node_to_replace_input))
if (!ov::is_type<op::util::MultiSubGraphOp>(node_to_replace_input) &&
!ov::is_type<frontend::ONNXSubgraphFrameworkNode>(node_to_replace_input))
continue;
auto inputs = node_to_replace_input->input_values();
for (size_t i = 0; i < inputs.size(); i++) {

View File

@ -121,6 +121,8 @@ inline std::ostream& operator<<(std::ostream& outs, const Graph& graph) {
return (outs << "<Graph: " << graph.get_name() << ">");
}
static const char* const ONNX_GRAPH_RT_ATTRIBUTE = "onnx_graph";
} // namespace onnx_import
} // namespace ngraph

View File

@ -21,10 +21,14 @@ namespace frontend {
NGRAPH_RTTI_DEFINITION(ONNXFrameworkNode, "ONNXFrameworkNode", 1);
std::shared_ptr<Node> ONNXFrameworkNode::clone_with_new_inputs(const OutputVector& inputs) const {
return std::make_shared<ONNXFrameworkNode>(m_graph, m_node, inputs);
return std::make_shared<ONNXFrameworkNode>(m_node, inputs);
}
NGRAPH_RTTI_DEFINITION(ONNXSubgraphFrameworkNode, "ONNXSubgraphFrameworkNode", 1);
std::shared_ptr<Node> ONNXSubgraphFrameworkNode::clone_with_new_inputs(const OutputVector& inputs) const {
return std::make_shared<ONNXSubgraphFrameworkNode>(m_node, m_functions, inputs);
}
} // namespace frontend
} // namespace ngraph

View File

@ -38,20 +38,16 @@ class ONNXFrameworkNode : public ov::op::util::FrameworkNode {
public:
NGRAPH_RTTI_DECLARATION;
ONNXFrameworkNode(std::shared_ptr<onnx_import::Graph> graph, const onnx_import::Node& node)
ONNXFrameworkNode(const onnx_import::Node& node)
: ov::op::util::FrameworkNode(node.get_ng_inputs(), node.get_outputs_size()),
m_node(node),
m_graph(graph) {}
m_node(node) {}
ONNXFrameworkNode(std::shared_ptr<onnx_import::Graph> graph,
const onnx_import::Node& node,
const OutputVector& inputs)
ONNXFrameworkNode(const onnx_import::Node& node, const OutputVector& inputs)
: ov::op::util::FrameworkNode(inputs, node.get_outputs_size()),
m_node(node),
m_graph(graph) {}
m_node(node) {}
OutputVector get_ng_nodes() const {
OutputVector ng_nodes{m_graph->make_ng_nodes(m_node)};
OutputVector get_ng_nodes(const std::shared_ptr<onnx_import::Graph>& graph) const {
OutputVector ng_nodes{graph->make_ng_nodes(m_node)};
if (ng_nodes.size() > get_output_size()) {
ng_nodes.resize(get_output_size());
}
@ -71,35 +67,31 @@ public:
protected:
onnx_import::Node m_node;
private:
std::shared_ptr<onnx_import::Graph> m_graph;
};
class ONNXSubgraphFrameworkNode : public ONNXFrameworkNode {
public:
NGRAPH_RTTI_DECLARATION;
ONNXSubgraphFrameworkNode(std::shared_ptr<onnx_import::Graph> graph,
const onnx_import::Node& node,
ONNXSubgraphFrameworkNode(const onnx_import::Node& node,
const std::vector<std::shared_ptr<Function>>& functions,
const OutputVector& inputs)
: ONNXFrameworkNode(graph, node, inputs) {}
: ONNXFrameworkNode(node, inputs),
m_functions(functions) {}
void infer_inputs_from_parent() {
for (auto& subgraph : m_node.get_subgraphs())
subgraph.second->infer_inputs_from_parent();
}
std::vector<std::shared_ptr<Function>> get_subgraph_functions() const {
std::vector<std::shared_ptr<Function>> ret;
for (const auto& kv : m_node.get_subgraphs()) {
auto& subgraph = kv.second;
ret.push_back(std::make_shared<Function>(subgraph->get_ng_outputs(),
subgraph->get_ng_parameters(),
subgraph->get_name()));
}
return ret;
const std::vector<std::shared_ptr<Function>>& get_subgraph_functions() const {
return m_functions;
}
virtual std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& inputs) const override;
private:
std::vector<std::shared_ptr<Function>> m_functions;
};
} // namespace frontend

View File

@ -37,17 +37,8 @@ OutputVector softmax(const Node& node) {
result = default_opset::Constant::create(data.get_element_type(), Shape{}, {1});
break;
}
case 1: {
// checks if the axis belongs to the allowed values set (-1 and 0 for 1D)
ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank());
result = std::make_shared<default_opset::Softmax>(data, 0);
break;
}
default: {
const auto normalized_axis =
ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank());
result = onnx_softmax(data, normalized_axis);
result = onnx_softmax(data, axis);
break;
}
}
@ -69,17 +60,8 @@ OutputVector softmax(const Node& node) {
result = default_opset::Constant::create(data.get_element_type(), Shape{}, {1});
break;
}
case 1: {
// checks if the axis belongs to the allowed values set (-1 and 0 for 1D)
ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank());
result = std::make_shared<default_opset::Softmax>(data, 0);
break;
}
default: {
const auto normalized_axis =
ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank());
result = std::make_shared<default_opset::Softmax>(data, normalized_axis);
result = std::make_shared<ov::op::v8::Softmax>(data, axis);
break;
}
}
@ -92,9 +74,8 @@ OutputVector softmax(const Node& node) {
const auto data = node.get_ng_inputs().at(0);
const auto axis = node.get_attribute_value<int64_t>("axis", -1);
const auto normalized_axis = ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank());
return {std::make_shared<default_opset::Softmax>(data, normalized_axis)};
return {std::make_shared<ov::op::v8::Softmax>(data, axis)};
}
} // namespace set_13
} // namespace op

View File

@ -60,6 +60,12 @@ void apply_transformations(ONNX_NAMESPACE::ModelProto& model_proto, const std::s
} // namespace
void convert_decoded_function(std::shared_ptr<Function> function) {
auto& rt_info = function->get_rt_info();
auto it = rt_info.find(ONNX_GRAPH_RT_ATTRIBUTE);
OPENVINO_ASSERT(it != rt_info.end(),
"Could not find '" + std::string(ONNX_GRAPH_RT_ATTRIBUTE) +
"' attribute in decoded model. Model probably wasn't created by FrontEnd::decode function.");
auto onnx_graph = it->second.as<std::shared_ptr<onnx_import::Graph>>();
for (const auto& node : function->get_ordered_ops()) {
if (auto raw_node = std::dynamic_pointer_cast<frontend::ONNXFrameworkNode>(node)) {
if (auto subgraph_node = std::dynamic_pointer_cast<frontend::ONNXSubgraphFrameworkNode>(node)) {
@ -68,7 +74,7 @@ void convert_decoded_function(std::shared_ptr<Function> function) {
convert_decoded_function(function);
}
}
auto ng_nodes = raw_node->get_ng_nodes();
auto ng_nodes = raw_node->get_ng_nodes(onnx_graph);
replace_node(raw_node, ng_nodes);
} else {
// Have to revalidate node because new intpus can affect shape/type
@ -76,6 +82,7 @@ void convert_decoded_function(std::shared_ptr<Function> function) {
node->revalidate_and_infer_types();
}
}
rt_info.erase(it);
detail::remove_dangling_parameters(function);
detail::remove_dangling_results(function);
}

View File

@ -0,0 +1,91 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include <memory>
#include <tuple>
#include <vector>
#include <string>
#include <fstream>
#include <ie_core.hpp>
#include <ie_layouts.h>
#include "ngraph_functions/builders.hpp"
#include "base/import_export_base/import_export_base.hpp"
namespace LayerTestDefinitions {
class ImportBatchTest : public FuncTestUtils::ImportNetworkTestBase {
protected:
InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override {
return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), 0.2f, -0.1f);
}
void SetUp() override {
InferenceEngine::Precision netPrecision;
std::vector<size_t> inputShape;
std::string _;
std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, _) = this->GetParam();
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShape});
auto mul_const_1 = ngraph::builder::makeConstant<float>(ngPrc, { inputShape[1], 2048 },
CommonTestUtils::generate_float_numbers(2048 * inputShape[1], -0.1f, 0.1f), false);
auto matmul_1 = std::make_shared<ngraph::op::MatMul>(params[0], mul_const_1);
auto sigmoid_1 = std::make_shared<ngraph::op::Sigmoid>(matmul_1);
auto mul_const_2 = ngraph::builder::makeConstant<float>(ngPrc, { 2048, 3425 },
CommonTestUtils::generate_float_numbers(2048 * 3425, -0.1f, 0.1f), false);
auto matmul_2 = std::make_shared<ngraph::op::MatMul>(sigmoid_1, mul_const_2);
function = std::make_shared<ngraph::Function>(matmul_2, params, "ExportImportNetwork");
}
};
TEST_P(ImportBatchTest, CompareWithRefImpl) {
Run();
};
const std::vector<std::vector<size_t>> inputShapes = {
{1, 440},
{2, 440},
{4, 128}
};
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16
};
const std::vector<std::map<std::string, std::string>> exportConfigs = {
{
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"},
{"GNA_SCALE_FACTOR_0", "327.67"}
}
};
const std::vector<std::map<std::string, std::string>> importConfigs = {
{
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}
}
};
const std::vector<std::string> appHeader = {
""
};
INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkBatchCase, ImportBatchTest,
::testing::Combine(
::testing::ValuesIn(inputShapes),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA),
::testing::ValuesIn(exportConfigs),
::testing::ValuesIn(importConfigs),
::testing::ValuesIn(appHeader)),
ImportBatchTest::getTestCaseName);
} // namespace LayerTestDefinitions

View File

@ -17,11 +17,12 @@ namespace LayerTestsDefinitions {
class ImportMultiInput : public FuncTestUtils::ImportNetworkTestBase {
protected:
void SetUp() override {
std::vector<size_t> inputShape;
InferenceEngine::Precision netPrecision;
std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam();
std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam();
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto input = ngraph::builder::makeParams(ngPrc, {{1, 10}, {1, 10}});
auto input = ngraph::builder::makeParams(ngPrc, {inputShape, inputShape});
auto mul1 = ngraph::builder::makeEltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD);
auto result = std::make_shared<ngraph::opset7::Result>(mul1);
@ -40,6 +41,10 @@ TEST_P(ImportMultiInputChanged, CompareWithRefImpl) {
TestRun(true);
};
const std::vector<std::vector<size_t>> inputShape = {
{1, 10}
};
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32
};
@ -98,6 +103,7 @@ const std::vector<std::map<std::string, std::string>> importConfigsUnchanged = {
INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportMultiInputUnchanged,
::testing::Combine(
::testing::ValuesIn(inputShape),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA),
::testing::ValuesIn(exportConfigs),
@ -107,6 +113,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportMultiInputUnchanged,
INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportMultiInputChanged,
::testing::Combine(
::testing::ValuesIn(inputShape),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA),
::testing::ValuesIn(exportConfigs),

View File

@ -52,6 +52,10 @@ TEST_P(ImportExportGNAModelChanged, ReshapePermuteConv) {
TestRun(true);
};
const std::vector<std::vector<size_t>> inputShapes = {
{1, 336}
};
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16
@ -92,6 +96,7 @@ const std::vector<std::string> appHeaders = {
INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportExportGNAModelUnchanged,
::testing::Combine(
::testing::ValuesIn(inputShapes),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA),
::testing::ValuesIn(exportConfigs),
@ -101,6 +106,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportExportGNAModelUnchanged,
INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportExportGNAModelChanged,
::testing::Combine(
::testing::ValuesIn(inputShapes),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA),
::testing::ValuesIn(exportConfigs),

View File

@ -26,8 +26,11 @@ const std::vector<std::string> appHeaders = {
"APPLICATION_HEADER"
};
std::vector<size_t> inputShape = ngraph::Shape{1000};
INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkCase, ImportNonZero,
::testing::Combine(
::testing::Values(inputShape),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_MYRIAD),
::testing::ValuesIn(exportConfigs),

View File

@ -9,6 +9,7 @@
#include <ie_core.hpp>
typedef std::tuple<
std::vector<size_t>, // Input Shape
InferenceEngine::Precision, // Network Precision
std::string, // Target Device
std::map<std::string, std::string>, // Export Configuration

View File

@ -9,14 +9,16 @@
namespace FuncTestUtils {
std::string ImportNetworkTestBase::getTestCaseName(testing::TestParamInfo<exportImportNetworkParams> obj) {
std::vector<size_t> inputShape;
InferenceEngine::Precision netPrecision;
std::string targetDevice;
std::map<std::string, std::string> exportConfiguration;
std::map<std::string, std::string> importConfiguration;
std::string appHeader;
std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, appHeader) = obj.param;
std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, appHeader) = obj.param;
std::ostringstream result;
result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_";
result << "netPRC=" << netPrecision.name() << "_";
result << "targetDevice=" << targetDevice << "_";
for (auto const& configItem : exportConfiguration) {

View File

@ -10,10 +10,11 @@ namespace LayerTestsDefinitions {
void ImportNonZero::SetUp() {
InferenceEngine::Precision netPrecision;
std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam();
ngraph::Shape inputShape;
std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam();
const auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
const auto parameter = std::make_shared<ngraph::opset5::Parameter>(ngPrc, ngraph::Shape{1000});
const auto parameter = std::make_shared<ngraph::opset5::Parameter>(ngPrc, inputShape);
const auto nonZero = std::make_shared<ngraph::opset5::NonZero>(parameter);
function = std::make_shared<ngraph::Function>(nonZero->outputs(), ngraph::ParameterVector{parameter}, "ExportImportNetwork");

View File

@ -9,11 +9,12 @@
namespace LayerTestsDefinitions {
void ImportReshapePermuteConv::SetUp() {
std::vector<size_t> inputShape;
InferenceEngine::Precision netPrecision;
std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam();
std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam();
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, { {1, 336} });
auto params = ngraph::builder::makeParams(ngPrc, { inputShape });
std::vector<size_t> outFormShapes1 = { 1, 1, 168, 2 };
auto pattern1 = std::make_shared<ngraph::opset1::Constant>(ngraph::element::Type_t::i64, ngraph::Shape{ 4 }, outFormShapes1);

View File

@ -99,15 +99,15 @@ function filterTable() {
if (implementation != 0) {
if (implementation == 'ni') {
$("#report #data tr:not(:hidden)").filter(function () {
$(this).toggle($(this).find('td').hasClass("not_impl"))
$(this).toggle($(this).find('td').hasClass("value " + device + " not_impl"))
});
} else if (implementation == 'i') {
$("#report #data tr:not(:hidden)").filter(function () {
$(this).toggle($(this).find('td').hasClass("impl"));
$(this).toggle($(this).find('td').hasClass("value " + device + " impl"));
});
} else {
$("#report #data tr:not(:hidden)").filter(function () {
$(this).toggle(!$(this).find('td').hasClass("not_impl") && !$(this).find('td').hasClass("impl"));
$(this).toggle(!$(this).find('td').hasClass("value"));
});
}
}
@ -116,19 +116,19 @@ function filterTable() {
selector = [];
select.forEach(item => {
if (item == '100p') {
selector.push('.value:visible[crashed="0"][failed="0"][skipped="0"]');
selector.push('.value:visible[crashed="0"][failed="0"][skipped="0"][value!="---"]');
}
if (item == '100f') {
selector.push('.value:visible[passed="0"]');
selector.push('.value:visible[passed="0"][value!="---"]');
}
if (item == 'p') {
selector.push('.value:visible[passed!="0"]');
selector.push('.value:visible[passed!="0"][value!="---"]');
}
if (item == 'f') {
selector.push('.value:visible[failed!="0"]');
selector.push('.value:visible[failed!="0"][value!="---"]');
}
if (item == 'c') {
selector.push('.value:visible[crashed!="0"]');
selector.push('.value:visible[crashed!="0"][value!="---"]');
}
if (item == 's') {
selector.push('.value:visible[value!="---"][skipped!="0"]');

View File

@ -46,15 +46,17 @@ def test_check_image(tmp_path, models, model_name, model_framework):
assert num_images_from_data_loader == num_images_in_dir
TEST_MODELS_LAYOUT = [('mobilenet-v2-pytorch', 'pytorch', 'NCHW', (3, 224, 224)),
('mobilenet-v2-pytorch', 'pytorch', 'NHWC', (224, 224, 3)),
('mobilenet-v2-pytorch', 'pytorch', None, (3, 224, 224)),
('mobilenet-v1-1.0-224-tf', 'tf', None, (224, 224, 3))]
TEST_MODELS_LAYOUT = [
#('mobilenet-v2-pytorch', 'pytorch', 'NCHW', (3, 224, 224)),
#('mobilenet-v2-pytorch', 'pytorch', 'NHWC', (224, 224, 3)),
#('mobilenet-v2-pytorch', 'pytorch', None, (3, 224, 224)),
#('mobilenet-v1-1.0-224-tf', 'tf', None, (224, 224, 3))
]
@pytest.mark.parametrize(
'model_name, model_framework, layout, reference_shape', TEST_MODELS,
ids=['{}_{}'.format(m[0], m[1]) for m in TEST_MODELS])
'model_name, model_framework, layout, reference_shape', TEST_MODELS_LAYOUT,
ids=['{}_{}_{}_{}'.format(m[0], m[1], m[2], m[3]) for m in TEST_MODELS_LAYOUT])
def test_check_layout(tmp_path, models, model_name, model_framework, layout, reference_shape):
test_dir = Path(__file__).parent
path_image_data = os.path.join(test_dir, "data/image_data")