Model Creation in OpenVINO™ Runtime

OpenVINO™ Runtime with API 2.0 includes the nGraph engine as a common part. The ngraph namespace has been changed to ov, but all other parts of the ngraph API have been preserved.

The code snippets below show how to change the application code for migration to API 2.0.

nGraph API

// _____________    _____________
// | Parameter |    | Parameter |
// |   data1   |    |   data2   |
// |___________|    |___________|
//         |            |
// data1_t |            | data2_t
//          \          /
//           \        /
//            \      /
//         ____\____/____
//         |   Concat   |
//         |   concat   |
//         |____________|
//               |
//               | concat_t
//               |
//        _______|_______
//        |    Result   |
//        |    result   |
//        |_____________|
auto data1 = std::make_shared<ngraph::opset8::Parameter>(ngraph::element::i64, ngraph::Shape{1, 3, 2, 2});
data1->set_friendly_name("data1");        // operation name
data1->output(0).set_names({"data1_t"});  // tensor names
auto data2 = std::make_shared<ngraph::opset8::Parameter>(ngraph::element::i64, ngraph::Shape{1, 2, 2, 2});
data2->set_friendly_name("data2");        // operation name
data2->output(0).set_names({"data2_t"});  // tensor names

auto concat = std::make_shared<ngraph::opset8::Concat>(ngraph::OutputVector{data1, data2}, 1);
concat->set_friendly_name("concat");        // operation name
concat->output(0).set_names({"concat_t"});  // tensor name

auto result = std::make_shared<ngraph::opset8::Result>(concat);
result->set_friendly_name("result");  // operation name

auto f = std::make_shared<ngraph::Function>(ngraph::ResultVector{result},
                                            ngraph::ParameterVector{data1, data2},
                                            "function_name");
# _____________    _____________
# | Parameter |    | Parameter |
# |   data1   |    |   data2   |
# |___________|    |___________|
#         |            |
#         |            |
#          \          /
#           \        /
#            \      /
#         ____\____/____
#         |   Concat   |
#         |   concat   |
#         |____________|
#               |
#               |
#               |
#        _______|_______
#        |    Result   |
#        |    result   |
#        |_____________|

import ngraph as ng
import numpy as np


data1 = ng.opset8.parameter([1, 3, 2, 2], np.int64)
data1.friendly_name = "data1" # operation name
data2 = ng.opset8.parameter([1, 2, 2, 2], np.int64)
data2.friendly_name = "data2" # operation name

concat = ng.opset8.concat([data1, data2], 1)
concat.friendly_name = "concat" # operation name

result = ng.opset8.result(concat)
result.friendly_name = "result" # operation name

f = ng.Function(result, [data1, data2], "function_name")

API 2.0

// _____________    _____________
// | Parameter |    | Parameter |
// |   data1   |    |   data2   |
// |___________|    |___________|
//         |            |
// data1_t |            | data2_t
//          \          /
//           \        /
//            \      /
//         ____\____/____
//         |   Concat   |
//         |   concat   |
//         |____________|
//               |
//               | concat_t
//               |
//        _______|_______
//        |    Result   |
//        |    result   |
//        |_____________|
auto data1 = std::make_shared<ov::opset8::Parameter>(ov::element::i64, ov::Shape{1, 3, 2, 2});
data1->set_friendly_name("data1");        // operation name
data1->output(0).set_names({"data1_t"});  // tensor names
auto data2 = std::make_shared<ov::opset8::Parameter>(ov::element::i64, ov::Shape{1, 2, 2, 2});
data2->set_friendly_name("data2");        // operation name
data2->output(0).set_names({"data2_t"});  // tensor names

auto concat = std::make_shared<ov::opset8::Concat>(ov::OutputVector{data1, data2}, 1);
concat->set_friendly_name("concat");        // operation name
concat->output(0).set_names({"concat_t"});  // tensor name

auto result = std::make_shared<ov::opset8::Result>(concat);
result->set_friendly_name("result");  // operation name

auto f = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{data1, data2}, "function_name");
# _____________    _____________
# | Parameter |    | Parameter |
# |   data1   |    |   data2   |
# |___________|    |___________|
#         |            |
# data1_t |            | data2_t
#          \          /
#           \        /
#            \      /
#         ____\____/____
#         |   Concat   |
#         |   concat   |
#         |____________|
#               |
#               | concat_t
#               |
#        _______|_______
#        |    Result   |
#        |    result   |
#        |_____________|

import openvino.runtime as ov


data1 = ov.opset8.parameter([1, 3, 2, 2], ov.Type.i64)
data1.friendly_name = "data1"      # operation name
data1.output(0).name = "data1_t" # tensor name
data2 = ov.opset8.parameter([1, 2, 2, 2], ov.Type.i64)
data2.friendly_name = "data2"      # operation name
data2.output(0).name = "data2_t"   # tensor name

concat = ov.opset8.concat([data1, data2], 1)
concat.friendly_name = "concat"    # operation name
concat.output(0).name = "concat_t" # tensor name

result = ov.opset8.result(concat)
result.friendly_name = "result"    # operation name

model = ov.Model(result, [data1, data2], "model_name")