Remove onnx_custom_op doc (#10638)
* Remove onnx_custom_op doc * Remove test * Fixed tests
This commit is contained in:
parent
f2bbd5bbb8
commit
806ce96899
|
|
@ -86,11 +86,6 @@ ov_model_convert("${OpenVINO_SOURCE_DIR}/${rel_path}"
|
|||
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_model_zoo/onnx_import"
|
||||
ie_onnx_import_out_files)
|
||||
|
||||
set(rel_path "docs/onnx_custom_op")
|
||||
ov_model_convert("${OpenVINO_SOURCE_DIR}/${rel_path}"
|
||||
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_model_zoo/docs/models"
|
||||
docs_onnx_out_files)
|
||||
|
||||
if(ENABLE_TESTS)
|
||||
if(ENABLE_OV_ONNX_FRONTEND AND ENABLE_REQUIREMENTS_INSTALL)
|
||||
find_package(PythonInterp 3 REQUIRED)
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@ if(NOT ENABLE_DOCKER)
|
|||
set(OpenVINO_DIR ${CMAKE_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
if(ENABLE_OV_ONNX_FRONTEND)
|
||||
add_subdirectory(onnx_custom_op)
|
||||
endif()
|
||||
add_subdirectory(template_extension)
|
||||
|
||||
set(all_docs_targets
|
||||
|
|
|
|||
|
|
@ -1045,7 +1045,6 @@ EXCLUDE_SYMBOLS = InferenceEngine::details \
|
|||
EXAMPLE_PATH = "@OpenVINO_SOURCE_DIR@" \
|
||||
"@OpenVINO_SOURCE_DIR@/docs/HOWTO/" \
|
||||
"@OpenVINO_SOURCE_DIR@/docs/" \
|
||||
"@OpenVINO_SOURCE_DIR@/docs/onnx_custom_op/" \
|
||||
"@OpenVINO_SOURCE_DIR@/docs/template_extension/" \
|
||||
"@OpenVINO_SOURCE_DIR@/docs/template_extension/old/" \
|
||||
"@OpenVINO_SOURCE_DIR@/docs/template_extension/new/" \
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
# Copyright (C) 2018-2022 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# [cmake:onnx_custom_op]
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
set(TARGET_NAME "onnx_custom_op")
|
||||
|
||||
find_package(OpenVINO REQUIRED COMPONENTS ONNX)
|
||||
|
||||
add_library(${TARGET_NAME} STATIC onnx_custom_op.cpp onnx_custom_op.hpp)
|
||||
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC openvino::core openvino::frontend::onnx)
|
||||
# [cmake:onnx_custom_op]
|
||||
|
||||
# Enable code style check
|
||||
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME})
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
ir_version: 3
|
||||
producer_name: "nGraph ONNX Importer"
|
||||
graph {
|
||||
node {
|
||||
input: "in"
|
||||
output: "out"
|
||||
name: "customrelu"
|
||||
op_type: "CustomRelu"
|
||||
domain: "com.example"
|
||||
attribute {
|
||||
name: "alpha"
|
||||
type: FLOAT
|
||||
f: 2
|
||||
}
|
||||
attribute {
|
||||
name: "beta"
|
||||
type: FLOAT
|
||||
f: 3
|
||||
}
|
||||
}
|
||||
name: "custom relu graph"
|
||||
input {
|
||||
name: "in"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 1
|
||||
shape {
|
||||
dim {
|
||||
dim_value: 8
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "out"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 1
|
||||
shape {
|
||||
dim {
|
||||
dim_value: 8
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opset_import {
|
||||
domain: "com.example"
|
||||
version: 1
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
//! [onnx_custom_op:headers]
|
||||
// onnx_import/onnx_utils.hpp provides ngraph::onnx_import::register_operator function, that registers operator in ONNX importer's set.
|
||||
#include <onnx_import/onnx_utils.hpp>
|
||||
// ngraph/opsets/opset5.hpp provides the declaration of predefined nGraph operator set
|
||||
#include <ngraph/opsets/opset5.hpp>
|
||||
//! [onnx_custom_op:headers]
|
||||
|
||||
void register_custom_relu_operator() {
|
||||
// CustomRelu is defined as follows:
|
||||
// x >= 0 => f(x) = x * alpha
|
||||
// x < 0 => f(x) = x * beta
|
||||
|
||||
//! [onnx_custom_op:register_operator]
|
||||
ngraph::onnx_import::register_operator(
|
||||
"CustomRelu", 1, "com.example", [](const ngraph::onnx_import::Node& onnx_node) -> ngraph::OutputVector {
|
||||
namespace opset = ngraph::opset5;
|
||||
|
||||
ngraph::OutputVector ng_inputs{onnx_node.get_ng_inputs()};
|
||||
const ngraph::Output<ngraph::Node>& data = ng_inputs.at(0);
|
||||
// create constant node with a single element that's equal to zero
|
||||
std::shared_ptr<ngraph::Node> zero_node = opset::Constant::create(data.get_element_type(), ngraph::Shape{}, {0});
|
||||
// create a negative map for 'data' node, 1 for negative values , 0 for positive values or zero
|
||||
// then convert it from boolean type to `data.get_element_type()`
|
||||
std::shared_ptr<ngraph::Node> negative_map = std::make_shared<opset::Convert>(
|
||||
std::make_shared<opset::Less>(data, zero_node), data.get_element_type());
|
||||
// create a positive map for 'data' node, 0 for negative values , 1 for positive values or zero
|
||||
// then convert it from boolean type to `data.get_element_type()`
|
||||
std::shared_ptr<ngraph::Node> positive_map = std::make_shared<opset::Convert>(
|
||||
std::make_shared<opset::GreaterEqual>(data, zero_node), data.get_element_type());
|
||||
|
||||
// fetch alpha and beta attributes from ONNX node
|
||||
float alpha = onnx_node.get_attribute_value<float>("alpha", 1); // if 'alpha' attribute is not provided in the model, then the default value is 1
|
||||
float beta = onnx_node.get_attribute_value<float>("beta");
|
||||
// create constant node with a single element 'alpha' with type f32
|
||||
std::shared_ptr<ngraph::Node> alpha_node = opset::Constant::create(ngraph::element::f32, ngraph::Shape{}, {alpha});
|
||||
// create constant node with a single element 'beta' with type f32
|
||||
std::shared_ptr<ngraph::Node> beta_node = opset::Constant::create(ngraph::element::f32, ngraph::Shape{}, {beta});
|
||||
|
||||
return {
|
||||
std::make_shared<opset::Add>(
|
||||
std::make_shared<opset::Multiply>(alpha_node, std::make_shared<opset::Multiply>(data, positive_map)),
|
||||
std::make_shared<opset::Multiply>(beta_node, std::make_shared<opset::Multiply>(data, negative_map))
|
||||
)
|
||||
};
|
||||
});
|
||||
//! [onnx_custom_op:register_operator]
|
||||
}
|
||||
|
||||
void unregister_custom_relu_operator() {
|
||||
//! [onnx_custom_op:unregister_operator]
|
||||
ngraph::onnx_import::unregister_operator("CustomRelu", 1, "com.example");
|
||||
//! [onnx_custom_op:unregister_operator]
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
void register_custom_relu_operator();
|
||||
void unregister_custom_relu_operator();
|
||||
|
|
@ -12,12 +12,9 @@ set(INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} $<TARGET_PROPERTY:openvino_intel_cpu_pl
|
|||
set(DEPENDENCIES openvino_intel_cpu_plugin)
|
||||
set(LINK_LIBRARIES funcSharedTests cpuSpecificRtInfo)
|
||||
if (ENABLE_OV_ONNX_FRONTEND)
|
||||
list(APPEND INCLUDES "${OpenVINO_SOURCE_DIR}/docs/onnx_custom_op")
|
||||
list(APPEND LINK_LIBRARIES onnx_custom_op)
|
||||
list(APPEND DEPENDENCIES template_extension onnx_custom_op)
|
||||
list(APPEND DEFINES TEST_MODELS="${TEST_MODEL_ZOO}")
|
||||
else()
|
||||
set(EXCLUDED_SOURCE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/extension ${CMAKE_CURRENT_SOURCE_DIR}/onnx)
|
||||
set(EXCLUDED_SOURCE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/onnx)
|
||||
endif()
|
||||
|
||||
addIeTargetTest(
|
||||
|
|
|
|||
|
|
@ -5,11 +5,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <ie_core.hpp>
|
||||
#include <ngraph/ngraph.hpp>
|
||||
#include <onnx_import/onnx_utils.hpp>
|
||||
#include <file_utils.h>
|
||||
#include <common_test_utils/test_assertions.hpp>
|
||||
#include <onnx_custom_op.hpp>
|
||||
|
||||
|
||||
class CustomAbsKernel : public InferenceEngine::ILayerExecImpl {
|
||||
public:
|
||||
|
|
@ -152,23 +149,6 @@ static std::string model_full_path(const char* path) {
|
|||
return FileUtils::makePath<char>(TEST_MODELS, path);
|
||||
}
|
||||
|
||||
TEST(Extension, OnnxModelWithCustomAbs) {
|
||||
std::vector<float> input_values{1, -2, 3, -4, 5, -6, 7, -8, 9, -10};
|
||||
std::vector<float> expected{1, 4, 3, 8, 5, 12, 7, 16, 9, 20};
|
||||
InferenceEngine::Core ie;
|
||||
ie.AddExtension(std::make_shared<CustomAbsExtension>());
|
||||
ngraph::onnx_import::register_operator(
|
||||
CustomAbs::get_type_info_static().name, 1, "custom_domain", [](const ngraph::onnx_import::Node& node) -> ngraph::OutputVector {
|
||||
ngraph::OutputVector ng_inputs{node.get_ng_inputs()};
|
||||
return {std::make_shared<CustomAbs>(ng_inputs.at(0))};
|
||||
});
|
||||
|
||||
auto network = ie.ReadNetwork(model_full_path("func_tests/models/custom_abs_op.onnx"));
|
||||
infer_model(ie, network, input_values, expected);
|
||||
ngraph::onnx_import::unregister_operator(CustomAbs::get_type_info_static().name, 1, "custom_domain");
|
||||
}
|
||||
|
||||
|
||||
TEST(Extension, XmlModelWithCustomAbs) {
|
||||
std::string model = R"V0G0N(
|
||||
<net name="Network" version="10">
|
||||
|
|
@ -293,15 +273,3 @@ TEST(Extension, OnnxModelWithExtensionFromDSO) {
|
|||
auto network = ie.ReadNetwork(model_full_path("func_tests/models/custom_template_op.onnx"));
|
||||
infer_model(ie, network, input_values, expected);
|
||||
}
|
||||
|
||||
|
||||
TEST(Extension, OnnxModelWithCustomReluDocsExample) {
|
||||
std::vector<float> input_values{0, -1, 2, -3, 4, -5, 6, -7};
|
||||
std::vector<float> expected{0, -3, 4, -9, 8, -15, 12, -21};
|
||||
|
||||
register_custom_relu_operator();
|
||||
InferenceEngine::Core ie;
|
||||
auto network = ie.ReadNetwork(model_full_path("docs/models/custom_relu_model.onnx"));
|
||||
infer_model(ie, network, input_values, expected);
|
||||
unregister_custom_relu_operator();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue