Skip to content

Commit

Permalink
Merge branch 'master' into transformation_tests_poc
Browse files Browse the repository at this point in the history
  • Loading branch information
iefode authored May 13, 2024
2 parents a1aae5f + fb838f2 commit 4fe34b1
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 73 deletions.
8 changes: 8 additions & 0 deletions src/bindings/js/node/include/model_wrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class ModelWrap : public Napi::ObjectWrap<ModelWrap> {
*/
Napi::Value is_dynamic(const Napi::CallbackInfo& info);

/**
* @brief Returns the number of outputs for this model
* @param info Contains information about the environment and passed arguments
* This method does not accept any arguments. If arguments are provided it throws Napi::Error
* @return number indicating the quantity of outputs for the model
*/
Napi::Value get_output_size(const Napi::CallbackInfo& info);

/**
* @brief Sets a friendly name for a model.
* @param info Contains information about the environment and passed arguments
Expand Down
1 change: 1 addition & 0 deletions src/bindings/js/node/lib/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ interface Model {
input(nameOrId?: string | number): Output;
getName(): string;
isDynamic(): boolean;
getOutputSize(): number;
setFriendlyName(name: string): void;
getFriendlyName(): string;
}
Expand Down
11 changes: 11 additions & 0 deletions src/bindings/js/node/src/model_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Napi::Function ModelWrap::get_class(Napi::Env env) {
InstanceMethod("output", &ModelWrap::get_output),
InstanceMethod("input", &ModelWrap::get_input),
InstanceMethod("isDynamic", &ModelWrap::is_dynamic),
InstanceMethod("getOutputSize", &ModelWrap::get_output_size),
InstanceMethod("setFriendlyName", &ModelWrap::set_friendly_name),
InstanceMethod("getFriendlyName", &ModelWrap::get_friendly_name),
InstanceAccessor<&ModelWrap::get_inputs>("inputs"),
Expand Down Expand Up @@ -131,6 +132,16 @@ Napi::Value ModelWrap::is_dynamic(const Napi::CallbackInfo& info) {
return Napi::Boolean::New(env, result);
}

Napi::Value ModelWrap::get_output_size(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
if (info.Length() > 0) {
reportError(env, "getOutputSize() does not accept any arguments.");
return env.Undefined();
}
const auto size = static_cast<double>(_model->get_output_size());
return Napi::Number::New(env, size);
}

Napi::Value ModelWrap::set_friendly_name(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
try {
Expand Down
18 changes: 18 additions & 0 deletions src/bindings/js/node/tests/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,21 @@ describe('Node.js getFriendlyName() / setFriendlyName()', () => {
});
});
});

describe('Model.getOutputSize()', () => {

it('should return a number indicating number of outputs for the model', () => {
const result = model.getOutputSize();
assert.strictEqual(typeof result, 'number', 'getOutputSize() should return a number');
});

it('should not accept any arguments', () => {
assert.throws(() => {
model.getOutputSize('unexpected argument');
}, /^Error: getOutputSize\(\) does not accept any arguments\.$/, 'Expected getOutputSize to throw an error when called with arguments');
});

it('should return 1 for the default model', () => {
assert.strictEqual(model.getOutputSize(), 1, 'Expected getOutputSize to return 1 for the default model');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "op/org.openvinotoolkit/deformable_conv_2d.hpp"

#include "openvino/frontend/exception.hpp"
#include "openvino/op/deformable_convolution.hpp"
#include "utils/convpool.hpp"

Expand All @@ -36,16 +37,32 @@ ov::OutputVector deformable_conv_2d(const ov::frontend::onnx::Node& node) {
const auto deformable_groups = node.get_attribute_value<int64_t>("deformable_groups", 1);
const auto auto_pad_type = convpool::get_auto_pad(node);

return {std::make_shared<v8::DeformableConvolution>(inputs.at(0),
inputs.at(1),
inputs.at(2),
strides,
paddings.first,
paddings.second,
dilations,
auto_pad_type,
group,
deformable_groups)};
if (inputs.size() == 3) {
return {std::make_shared<v8::DeformableConvolution>(inputs.at(0),
inputs.at(1),
inputs.at(2),
strides,
paddings.first,
paddings.second,
dilations,
auto_pad_type,
group,
deformable_groups)};
} else if (inputs.size() == 4) {
return {std::make_shared<v8::DeformableConvolution>(inputs.at(0),
inputs.at(1),
inputs.at(2),
inputs.at(3),
strides,
paddings.first,
paddings.second,
dilations,
auto_pad_type,
group,
deformable_groups)};
} else {
FRONT_END_GENERAL_CHECK(false, "Invalid number of inputs");
}
}
} // namespace set_1
} // namespace op
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
ir_version: 7
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "data"
input: "deformation"
input: "filters"
input: "mask"
output: "out"
op_type: "DeformableConv2D"
}
name: "test_graph"
input {
name: "data"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "deformation"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 8
}
dim {
dim_value: 3
}
dim {
dim_value: 3
}
}
}
}
}
input {
name: "filters"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 2
}
dim {
dim_value: 2
}
}
}
}
}
input {
name: "mask"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 4
}
dim {
dim_value: 3
}
dim {
dim_value: 3
}
}
}
}
}
initializer {
name: "filters"
dims: 1
dims: 1
dims: 2
dims: 2
data_type: 1
float_data: 0.1
float_data: 0.2
float_data: 0.3
float_data: 0.4
}
output {
name: "out"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 3
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 7
}
35 changes: 35 additions & 0 deletions src/frontends/onnx/tests/onnx_import_org_openvino.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,41 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deformable_conv_2d) {
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_deformable_conv_2d_with_mask) {
auto model = convert_model("org.openvinotoolkit/deformable_conv_2d_with_mask.onnx");

auto test_case = ov::test::TestCase(model, s_device);

// data
test_case.add_input<float>(
{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f});

// deformations
test_case.add_input<float>({0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f,
1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f,
0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f,
0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f,
1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f,
0.0f, 1.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f});

// mask
test_case.add_input<float>({0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f,
1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f, 2.3f, 2.4f,
2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f, 3.1f, 3.2f, 3.3f, 3.4f, 3.5f, 3.6f});

test_case.add_expected_output<float>(Shape{1, 1, 3, 3},
{14.7299995f,
7.3200006f,
15.0600004f,
31.1000004f,
28.9899998f,
20.5800018f,
32.6200027f,
6.6400003f,
1.4399999f});
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_generate_proposals) {
auto model = convert_model("org.openvinotoolkit/generate_proposals.onnx");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ onnx_controlflow_loop_power

# No evaluator for DeformableConv2D
onnx_model_deformable_conv_2d
onnx_model_deformable_conv_2d_with_mask

# New fails
onnx_model_quant_conv_linear_3d
Expand Down
14 changes: 12 additions & 2 deletions src/frontends/tensorflow/src/input_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,12 @@ std::vector<std::shared_ptr<OpPlace>> InputModel::InputModelTFImpl::topologicall
ops_to_do.push(output_operation_place);
}

// walk through all NextIteration nodes and put their producers into ops_to_do
// this is needed to avoid missed nodes in the body graph of TF1 While operation
for (const auto& op_place : m_op_places) {
auto op_decoder = op_place->get_decoder();
auto op_name = op_decoder->get_op_name();
if (op_decoder->get_op_type() == "NextIteration") {
// walk through all NextIteration nodes and put their producers into ops_to_do
// this is needed to avoid missed nodes in the body graph of TF1 While operation
std::string producer_name;
std::string producer_output_port_name;
size_t producer_output_port_idx;
Expand All @@ -390,6 +391,15 @@ std::vector<std::shared_ptr<OpPlace>> InputModel::InputModelTFImpl::topologicall
"NextIteration is not found among operation places " +
producer_name);
ops_to_do.push(m_op_places_map.at(producer_name));
} else if (op_decoder->get_op_type() == "LookupTableImport" ||
op_decoder->get_op_type() == "LookupTableImportV2") {
// all LookupTableImport nodes must be preserved in a graph for conversion because
// they can be terminating nodes and contain input values for HashTable initialization
FRONT_END_GENERAL_CHECK(m_op_places_map.count(op_name),
"[TensorFlow Frontend] internal error or inconsistent model: LookupTableImport "
"operation is not found among operation places " +
op_name);
ops_to_do.push(m_op_places_map.at(op_name));
}
}

Expand Down
Loading

0 comments on commit 4fe34b1

Please sign in to comment.