Resolve review comments
This commit is contained in:
parent
c14a46a3f8
commit
c4d72f9ca4
@ -61,8 +61,7 @@ else()
|
||||
endif()
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime ${OFFLINE_TRANSFORMATIONS_LIB} openvino::frontend::common
|
||||
nlohmann_json)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime ${OFFLINE_TRANSFORMATIONS_LIB} openvino::frontend::common)
|
||||
|
||||
# perform copy
|
||||
if(OpenVINO_SOURCE_DIR)
|
||||
|
@ -20,7 +20,7 @@ source_group("include" FILES ${PUBLIC_HEADERS})
|
||||
add_library(${TARGET_NAME} STATIC EXCLUDE_FROM_ALL ${LIBRARY_SRC} ${PUBLIC_HEADERS})
|
||||
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC ngraph inference_engine_transformations ngraph::reference
|
||||
nlohmann_json_schema_validator
|
||||
nlohmann_json_schema_validator nlohmann_json
|
||||
PRIVATE openvino::itt pugixml::static openvino::frontend::common)
|
||||
|
||||
target_include_directories(${TARGET_NAME} PUBLIC ${PUBLIC_HEADERS_DIR}
|
||||
|
@ -10,20 +10,19 @@
|
||||
|
||||
#include "common/extensions/decoder_transformation_extension.hpp"
|
||||
#include "common/frontend_defs.hpp"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace frontend {
|
||||
|
||||
/// \brief JsonConfigExtension reads MO config file and delegate transformation functionality to specified
|
||||
/// transformation ID specified in the config.
|
||||
class FRONTEND_API JsonConfigExtension : public DecoderTransformationExtension {
|
||||
class JsonConfigExtension : public DecoderTransformationExtension {
|
||||
public:
|
||||
explicit JsonConfigExtension(const std::string& config_path);
|
||||
|
||||
protected:
|
||||
std::vector<Extension::Ptr> m_loaded_extensions;
|
||||
std::vector<std::pair<std::shared_ptr<DecoderTransformationExtension>, nlohmann::json>> m_target_extensions;
|
||||
std::vector<std::pair<std::shared_ptr<DecoderTransformationExtension>, std::string>> m_target_extensions;
|
||||
};
|
||||
} // namespace frontend
|
||||
} // namespace ov
|
||||
|
@ -4,131 +4,4 @@
|
||||
#pragma once
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
|
||||
static nlohmann::json json_schema = R"(
|
||||
{
|
||||
"definitions": {},
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Root",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$id": "#root/items",
|
||||
"title": "Items",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"match_kind"
|
||||
],
|
||||
"properties": {
|
||||
"custom_attributes": {
|
||||
"$id": "#root/items/custom_attributes",
|
||||
"title": "Custom_attributes",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"$id": "#root/items/id",
|
||||
"title": "Id",
|
||||
"type": "string",
|
||||
"pattern": "^.*$",
|
||||
"minLength": 1
|
||||
},
|
||||
"inputs": {
|
||||
"$id": "#root/items/inputs",
|
||||
"title": "Inputs",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$id": "#root/items/inputs/items",
|
||||
"title": "Items",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$id": "#root/items/inputs/items/items",
|
||||
"title": "Items",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$id": "#root/items/inputs/items/items/node",
|
||||
"title": "Node",
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"port": {
|
||||
"$id": "#root/items/inputs/items/items/port",
|
||||
"title": "Port",
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"required": ["node", "port"]
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
"instances": {
|
||||
"$id": "#root/items/instances",
|
||||
"title": "Instances",
|
||||
"type": ["array", "object"],
|
||||
"items": {
|
||||
"$id": "#root/items/instances/items",
|
||||
"title": "Items",
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"pattern": "^.*$"
|
||||
}
|
||||
},
|
||||
"match_kind": {
|
||||
"$id": "#root/items/match_kind",
|
||||
"title": "Match_kind",
|
||||
"type": "string",
|
||||
"enum": ["points", "scope", "general"],
|
||||
"default": "points",
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"outputs": {
|
||||
"$id": "#root/items/outputs",
|
||||
"title": "Outputs",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$id": "#root/items/outputs/items",
|
||||
"title": "Items",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$id": "#root/items/outputs/items/node",
|
||||
"title": "Node",
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"port": {
|
||||
"$id": "#root/items/outputs/items/port",
|
||||
"title": "Port",
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"required": ["node", "port"]
|
||||
}
|
||||
|
||||
},
|
||||
"include_inputs_to_sub_graph": {
|
||||
"$id": "#root/items/include_inputs_to_sub_graph",
|
||||
"title": "Include_inputs_to_sub_graph",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"include_outputs_to_sub_graph": {
|
||||
"$id": "#root/items/include_outputs_to_sub_graph",
|
||||
"title": "Include_outputs_to_sub_graph",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)"_json;
|
||||
extern const nlohmann::json json_schema;
|
||||
|
@ -33,7 +33,7 @@ namespace frontend {
|
||||
/// to derive new classes by regular users, this class is intended to be derived from and it doesn't have convenient
|
||||
/// ctos to be initialized. So it is intended for more advanced, internal users inside such components like Model
|
||||
/// Optimizer.
|
||||
class FRONTEND_API JsonTransformationExtension : public DecoderTransformationExtension {
|
||||
class JsonTransformationExtension : public DecoderTransformationExtension {
|
||||
public:
|
||||
explicit JsonTransformationExtension(const std::string& id) : m_id(id) {}
|
||||
|
||||
@ -43,7 +43,7 @@ public:
|
||||
}
|
||||
|
||||
virtual bool transform(std::shared_ptr<ov::Model>& function,
|
||||
const nlohmann::json& replacement_descriptions) const = 0;
|
||||
const std::string& replacement_descriptions) const = 0;
|
||||
|
||||
private:
|
||||
std::string m_id;
|
||||
|
@ -63,7 +63,7 @@ JsonConfigExtension::JsonConfigExtension(const std::string& config_path)
|
||||
if (auto json_ext = std::dynamic_pointer_cast<JsonTransformationExtension>(extension)) {
|
||||
for (const auto& section : sections) {
|
||||
if (section["id"] == json_ext->id()) {
|
||||
m_target_extensions.push_back({json_ext, section});
|
||||
m_target_extensions.push_back({json_ext, section.dump()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,133 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include "json_extension/json_schema.hpp"
|
||||
|
||||
const nlohmann::json json_schema = R"(
|
||||
{
|
||||
"definitions": {},
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Root",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$id": "#root/items",
|
||||
"title": "Items",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"match_kind"
|
||||
],
|
||||
"properties": {
|
||||
"custom_attributes": {
|
||||
"$id": "#root/items/custom_attributes",
|
||||
"title": "Custom_attributes",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"$id": "#root/items/id",
|
||||
"title": "Id",
|
||||
"type": "string",
|
||||
"pattern": "^.*$",
|
||||
"minLength": 1
|
||||
},
|
||||
"inputs": {
|
||||
"$id": "#root/items/inputs",
|
||||
"title": "Inputs",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$id": "#root/items/inputs/items",
|
||||
"title": "Items",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$id": "#root/items/inputs/items/items",
|
||||
"title": "Items",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$id": "#root/items/inputs/items/items/node",
|
||||
"title": "Node",
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"port": {
|
||||
"$id": "#root/items/inputs/items/items/port",
|
||||
"title": "Port",
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"required": ["node", "port"]
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
"instances": {
|
||||
"$id": "#root/items/instances",
|
||||
"title": "Instances",
|
||||
"type": ["array", "object"],
|
||||
"items": {
|
||||
"$id": "#root/items/instances/items",
|
||||
"title": "Items",
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"pattern": "^.*$"
|
||||
}
|
||||
},
|
||||
"match_kind": {
|
||||
"$id": "#root/items/match_kind",
|
||||
"title": "Match_kind",
|
||||
"type": "string",
|
||||
"enum": ["points", "scope", "general"],
|
||||
"default": "points",
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"outputs": {
|
||||
"$id": "#root/items/outputs",
|
||||
"title": "Outputs",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$id": "#root/items/outputs/items",
|
||||
"title": "Items",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"node": {
|
||||
"$id": "#root/items/outputs/items/node",
|
||||
"title": "Node",
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"pattern": "^.*$"
|
||||
},
|
||||
"port": {
|
||||
"$id": "#root/items/outputs/items/port",
|
||||
"title": "Port",
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"required": ["node", "port"]
|
||||
}
|
||||
|
||||
},
|
||||
"include_inputs_to_sub_graph": {
|
||||
"$id": "#root/items/include_inputs_to_sub_graph",
|
||||
"title": "Include_inputs_to_sub_graph",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"include_outputs_to_sub_graph": {
|
||||
"$id": "#root/items/include_outputs_to_sub_graph",
|
||||
"title": "Include_outputs_to_sub_graph",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)"_json;
|
@ -13,13 +13,13 @@ class JsonConfigExtensionWrapper : public ov::frontend::JsonConfigExtension {
|
||||
public:
|
||||
explicit JsonConfigExtensionWrapper(const std::string& config_path)
|
||||
: ov::frontend::JsonConfigExtension(config_path){};
|
||||
~JsonConfigExtensionWrapper() override{};
|
||||
~JsonConfigExtensionWrapper() override = default;;
|
||||
|
||||
std::vector<Extension::Ptr> get_loaded_extensions() {
|
||||
return m_loaded_extensions;
|
||||
};
|
||||
|
||||
std::vector<std::pair<std::shared_ptr<DecoderTransformationExtension>, nlohmann::json>> get_target_extensions() {
|
||||
std::vector<std::pair<std::shared_ptr<DecoderTransformationExtension>, std::string>> get_target_extensions() {
|
||||
return m_target_extensions;
|
||||
}
|
||||
};
|
||||
@ -32,13 +32,17 @@ struct JsonConfigFEParam {
|
||||
|
||||
class FrontEndJsonConfigTest : public ::testing::TestWithParam<JsonConfigFEParam> {
|
||||
public:
|
||||
std::string m_file_name = "test_json.json";
|
||||
std::ofstream m_output_json;
|
||||
JsonConfigFEParam m_param;
|
||||
ov::frontend::FrontEndManager m_fem;
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<JsonConfigFEParam>& obj);
|
||||
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
|
||||
protected:
|
||||
void generate_json_config();
|
||||
void initParamTest();
|
||||
};
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
#include <ostream>
|
||||
#include <util/graph_comparator.hpp>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace ov::frontend;
|
||||
@ -26,6 +25,11 @@ void FrontEndJsonConfigTest::SetUp() {
|
||||
initParamTest();
|
||||
}
|
||||
|
||||
void FrontEndJsonConfigTest::TearDown() {
|
||||
m_output_json.close();
|
||||
std::remove(m_file_name.c_str());
|
||||
}
|
||||
|
||||
void FrontEndJsonConfigTest::initParamTest() {
|
||||
m_param = GetParam();
|
||||
m_param.m_modelName = FrontEndTestUtils::make_model_path(m_param.m_modelsPath + m_param.m_modelName);
|
||||
@ -35,7 +39,7 @@ inline std::string get_lib_path(const std::string& lib_name) {
|
||||
return ov::util::make_plugin_library_name<char>(ov::util::get_ov_lib_path(), lib_name + IE_BUILD_POSTFIX);
|
||||
}
|
||||
|
||||
std::string generate_json_config() {
|
||||
void FrontEndJsonConfigTest::generate_json_config() {
|
||||
std::string json = R"(
|
||||
[
|
||||
{
|
||||
@ -71,13 +75,13 @@ std::string generate_json_config() {
|
||||
validator.set_root_schema(json_schema);
|
||||
validator.validate(config_json);
|
||||
|
||||
// update lib path
|
||||
for (auto& section : config_json) {
|
||||
section["library"] = get_lib_path(section["library"]);
|
||||
}
|
||||
std::string path = "/home/itikhonov/OpenVINO/openvino/src/core/tests/frontend/shared/include/json_files/test.json";
|
||||
std::ofstream output_json(path);
|
||||
output_json << std::setw(4) << config_json << std::endl;
|
||||
return path;
|
||||
|
||||
m_output_json.open(m_file_name);
|
||||
m_output_json << std::setw(4) << config_json << std::endl;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@ -87,7 +91,7 @@ TEST_P(FrontEndJsonConfigTest, testJsonConfig) {
|
||||
}
|
||||
|
||||
TEST_P(FrontEndJsonConfigTest, testAddJsonConfigExtension) {
|
||||
auto path_to_json = generate_json_config();
|
||||
EXPECT_NO_THROW(generate_json_config());
|
||||
std::map<std::string, nlohmann::json> reference_map = {
|
||||
{"buildin_extensions_1::TestExtension1",
|
||||
nlohmann::json::parse(
|
||||
@ -126,6 +130,7 @@ TEST_P(FrontEndJsonConfigTest, testAddJsonConfigExtension) {
|
||||
}
|
||||
)")},
|
||||
};
|
||||
|
||||
for (auto& ref_val : reference_map) {
|
||||
ref_val.second["library"] = get_lib_path(ref_val.second["library"]);
|
||||
}
|
||||
@ -136,7 +141,7 @@ TEST_P(FrontEndJsonConfigTest, testAddJsonConfigExtension) {
|
||||
ov::frontend::InputModel::Ptr m_inputModel;
|
||||
m_frontEnd = m_fem.load_by_framework(m_param.m_frontEndName);
|
||||
|
||||
auto json_config_ext = std::make_shared<JsonConfigExtensionWrapper>(path_to_json);
|
||||
auto json_config_ext = std::make_shared<JsonConfigExtensionWrapper>(m_file_name);
|
||||
m_frontEnd->add_extension(json_config_ext);
|
||||
|
||||
auto loaded_ext = json_config_ext->get_loaded_extensions();
|
||||
@ -148,7 +153,7 @@ TEST_P(FrontEndJsonConfigTest, testAddJsonConfigExtension) {
|
||||
for (const auto& target : target_ext) {
|
||||
auto transformation = std::dynamic_pointer_cast<JsonTransformationExtension>(target.first);
|
||||
EXPECT_NE(transformation, nullptr);
|
||||
EXPECT_EQ(reference_map.at(transformation->id()), target.second);
|
||||
EXPECT_EQ(reference_map.at(transformation->id()).dump(), target.second);
|
||||
}
|
||||
ASSERT_NO_THROW(m_inputModel = m_frontEnd->load(m_param.m_modelName));
|
||||
ASSERT_NE(m_inputModel, nullptr);
|
||||
@ -160,7 +165,7 @@ TEST_P(FrontEndJsonConfigTest, testAddJsonConfigExtension) {
|
||||
}
|
||||
|
||||
TEST_P(FrontEndJsonConfigTest, compareFunctions) {
|
||||
auto path_to_json = generate_json_config();
|
||||
EXPECT_NO_THROW(generate_json_config());
|
||||
|
||||
std::shared_ptr<ov::Model> function;
|
||||
{
|
||||
@ -168,7 +173,7 @@ TEST_P(FrontEndJsonConfigTest, compareFunctions) {
|
||||
ov::frontend::InputModel::Ptr m_inputModel;
|
||||
m_frontEnd = m_fem.load_by_framework(m_param.m_frontEndName);
|
||||
|
||||
auto json_config_ext = std::make_shared<JsonConfigExtensionWrapper>(path_to_json);
|
||||
auto json_config_ext = std::make_shared<JsonConfigExtensionWrapper>(m_file_name);
|
||||
m_frontEnd->add_extension(json_config_ext);
|
||||
|
||||
ASSERT_NO_THROW(m_inputModel = m_frontEnd->load(m_param.m_modelName));
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <openvino/core/core.hpp>
|
||||
|
||||
bool TestExtension1::transform(std::shared_ptr<ov::Model>& function, const nlohmann::json& config) const {
|
||||
bool TestExtension1::transform(std::shared_ptr<ov::Model>& function, const std::string& config) const {
|
||||
function->set_friendly_name("TestFunction");
|
||||
return true;
|
||||
}
|
||||
|
@ -11,5 +11,5 @@ class TestExtension1 : public ov::frontend::JsonTransformationExtension {
|
||||
public:
|
||||
TestExtension1();
|
||||
|
||||
bool transform(std::shared_ptr<ov::Model>& function, const nlohmann::json& config) const override;
|
||||
bool transform(std::shared_ptr<ov::Model>& function, const std::string& config) const override;
|
||||
};
|
||||
|
@ -6,14 +6,14 @@
|
||||
|
||||
#include <openvino/core/core.hpp>
|
||||
|
||||
bool TestExtension1::transform(std::shared_ptr<ov::Model>& function, const nlohmann::json& config) const {
|
||||
bool TestExtension1::transform(std::shared_ptr<ov::Model>& function, const std::string& config) const {
|
||||
function->set_friendly_name("TestFunction");
|
||||
return true;
|
||||
}
|
||||
|
||||
TestExtension1::TestExtension1() : ov::frontend::JsonTransformationExtension("buildin_extensions_2::TestExtension1") {}
|
||||
|
||||
bool TestExtension2::transform(std::shared_ptr<ov::Model>& function, const nlohmann::json& config) const {
|
||||
bool TestExtension2::transform(std::shared_ptr<ov::Model>& function, const std::string& config) const {
|
||||
function->set_friendly_name("TestFunction");
|
||||
return true;
|
||||
}
|
||||
|
@ -11,12 +11,12 @@ class TestExtension1 : public ov::frontend::JsonTransformationExtension {
|
||||
public:
|
||||
TestExtension1();
|
||||
|
||||
bool transform(std::shared_ptr<ov::Model>& function, const nlohmann::json& config) const override;
|
||||
bool transform(std::shared_ptr<ov::Model>& function, const std::string& config) const override;
|
||||
};
|
||||
|
||||
class TestExtension2 : public ov::frontend::JsonTransformationExtension {
|
||||
public:
|
||||
TestExtension2();
|
||||
|
||||
bool transform(std::shared_ptr<ov::Model>& function, const nlohmann::json& config) const override;
|
||||
bool transform(std::shared_ptr<ov::Model>& function, const std::string& config) const override;
|
||||
};
|
||||
|
@ -2,5 +2,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
telemetry_params = {
|
||||
'TID': "UA-17808594-29"
|
||||
'TID': "0"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user