Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONNX] Extend ONNX Frontend with BlackmanWindow, HammingWindow and HannWindow operators #19428

Merged
merged 29 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3626da4
ONNX BlackManWindow enabled
siddhant-0707 Aug 10, 2023
799a68e
added a test periodic
siddhant-0707 Aug 10, 2023
48ddce8
Add the license statement
siddhant-0707 Aug 10, 2023
eb607ae
ONNX HammingWindow, HannWindow enabled
siddhant-0707 Aug 25, 2023
70c5d92
minor tests added
siddhant-0707 Aug 26, 2023
98ac0c6
Merge branch 'master' into onnx-new-windows
siddhant-0707 Aug 26, 2023
57925e1
Merge branch 'master' into onnx-new-windows
p-wysocki Aug 30, 2023
d1f763a
made reviewed changes
siddhant-0707 Sep 3, 2023
93f3092
Merge branch 'master' into onnx-new-windows
siddhant-0707 Sep 3, 2023
10b0a8c
made reviewed changes
siddhant-0707 Sep 6, 2023
997d07a
fixed clang-format
siddhant-0707 Sep 6, 2023
c084d3e
Merge branch 'master' into onnx-new-windows
siddhant-0707 Sep 6, 2023
228636f
Merge branch 'master' into onnx-new-windows
siddhant-0707 Sep 7, 2023
5d468a8
Merge branch 'openvinotoolkit:master' into onnx-new-windows
siddhant-0707 Sep 21, 2023
372d931
add OPENVINO_SUPPRESS_DEPRECATED_START
siddhant-0707 Sep 21, 2023
e5237a6
include math.h
siddhant-0707 Sep 22, 2023
80bf2fc
float fix
siddhant-0707 Sep 25, 2023
6d2801a
Merge branch 'openvinotoolkit:master' into onnx-new-windows
siddhant-0707 Sep 30, 2023
bf359ec
fix
siddhant-0707 Oct 2, 2023
8349725
fix namespace to set_1
siddhant-0707 Oct 3, 2023
e2287c1
test fixes
siddhant-0707 Oct 4, 2023
cf486ce
fix cast to output_datatype
siddhant-0707 Oct 6, 2023
898d691
fix, replace cast with ov::convert
siddhant-0707 Oct 11, 2023
081cc1c
fix, use element::f32
siddhant-0707 Oct 11, 2023
342ceb2
major fixes
siddhant-0707 Oct 18, 2023
cfbf2a5
Merge branch 'master' into onnx-new-windows
siddhant-0707 Oct 18, 2023
986629b
fixes
siddhant-0707 Oct 19, 2023
b63907e
Update onnx_import.in.cpp
siddhant-0707 Oct 20, 2023
898c94a
Update onnx_import.in.cpp
siddhant-0707 Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions src/frontends/onnx/frontend/src/op/blackmanwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "op/blackmanwindow.hpp"

#include <memory>

#include "default_opset.hpp"
#include "utils/common.hpp"

namespace ngraph {
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
namespace onnx_import {
namespace op {
namespace set_17 {
OutputVector blackmanwindow(const Node& node) {
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
const auto size = node.get_ng_inputs().at(0);
const auto output_datatype = common::get_ngraph_element_type(node.get_attribute_value("output_datatype", 1));
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
const bool periodic = node.get_attribute_value<int64_t>("periodic", 1);

const ov::PartialShape shape = size.get_partial_shape();
const std::vector<size_t> axis_lengths = shape.to_shape();

element::Type tensor_type;
switch (output_datatype) {
case element::Type_t::f32:
tensor_type = element::f32;
break;
case element::Type_t::u8:
tensor_type = element::u8;
break;
case element::Type_t::i8:
tensor_type = element::i8;
break;
case element::Type_t::u16:
tensor_type = element::u16;
break;
case element::Type_t::i16:
tensor_type = element::i16;
break;
case element::Type_t::i32:
tensor_type = element::i32;
break;
case element::Type_t::i64:
tensor_type = element::i64;
break;
case element::Type_t::f16:
tensor_type = element::f16;
break;
case element::Type_t::f64:
tensor_type = element::f64;
break;
case element::Type_t::u32:
tensor_type = element::u32;
break;
case element::Type_t::u64:
tensor_type = element::u64;
break;
case element::Type_t::bf16:
tensor_type = element::bf16;
break;
default:
throw std::runtime_error("Unsupported output data type.");
}

// Weights as described in ONNX BlackManWindow docs
// https://github.com/onnx/onnx/blob/main/docs/Operators.md#blackmanwindow
const auto a_0 = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{0.42});
const auto a_1 = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{-0.50});
const auto a_2 = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{0.08});

const auto start = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{0.0});
const auto step = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{1.0});
const auto range = std::make_shared<default_opset::Range>(start, size, step, tensor_type);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor_1 = std::make_shared<default_opset::Multiply>(
range,
std::make_shared<default_opset::Divide>(
std::make_shared<default_opset::Multiply>(
pi,
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<int>{2})),
periodic ? size
: std::make_shared<default_opset::Subtract>(
size,
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<int>{1}))));
const auto factor_2 = std::make_shared<default_opset::Multiply>(
range,
std::make_shared<default_opset::Divide>(
std::make_shared<default_opset::Multiply>(
pi,
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<int>{4})),
periodic ? size
: std::make_shared<default_opset::Subtract>(
size,
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<int>{1}))));
const auto cos_1 = std::make_shared<default_opset::Cos>(factor_1);
const auto cos_2 = std::make_shared<default_opset::Cos>(factor_2);
const auto scaled_cos_1 = std::make_shared<default_opset::Multiply>(cos_1, a_1);
const auto scaled_cos_2 = std::make_shared<default_opset::Multiply>(cos_2, a_2);
const auto y_values =
std::make_shared<default_opset::Add>(std::make_shared<default_opset::Add>(a_0, scaled_cos_1), scaled_cos_2);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);
gkrivor marked this conversation as resolved.
Show resolved Hide resolved

return {output};
}
} // namespace set_17
} // namespace op
} // namespace onnx_import
} // namespace ngraph
siddhant-0707 marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions src/frontends/onnx/frontend/src/op/blackmanwindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_17 {
gkrivor marked this conversation as resolved.
Show resolved Hide resolved

OutputVector blackmanwindow(const Node& node);

} // namespace set_17
} // namespace op
} // namespace onnx_import
} // namespace ngraph
99 changes: 99 additions & 0 deletions src/frontends/onnx/frontend/src/op/hammingwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "op/hammingwindow.hpp"

#include <memory>

#include "default_opset.hpp"
#include "utils/common.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_17 {
OutputVector hammingwindow(const Node& node) {
const auto size = node.get_ng_inputs().at(0);
const auto output_datatype = common::get_ngraph_element_type(node.get_attribute_value("output_datatype", 1));
const bool periodic = node.get_attribute_value<int64_t>("periodic", 1);

const ov::PartialShape shape = size.get_partial_shape();
const std::vector<size_t> axis_lengths = shape.to_shape();

element::Type tensor_type;
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
switch (output_datatype) {
case element::Type_t::f32:
tensor_type = element::f32;
break;
case element::Type_t::u8:
tensor_type = element::u8;
break;
case element::Type_t::i8:
tensor_type = element::i8;
break;
case element::Type_t::u16:
tensor_type = element::u16;
break;
case element::Type_t::i16:
tensor_type = element::i16;
break;
case element::Type_t::i32:
tensor_type = element::i32;
break;
case element::Type_t::i64:
tensor_type = element::i64;
break;
case element::Type_t::f16:
tensor_type = element::f16;
break;
case element::Type_t::f64:
tensor_type = element::f64;
break;
case element::Type_t::u32:
tensor_type = element::u32;
break;
case element::Type_t::u64:
tensor_type = element::u64;
break;
case element::Type_t::bf16:
tensor_type = element::bf16;
break;
default:
throw std::runtime_error("Unsupported output data type.");
}

// Weights as described in ONNX BlackManWindow docs
// https://github.com/onnx/onnx/blob/main/docs/Operators.md#hammingwindow
const auto a_0 = std::make_shared<default_opset::Divide>(
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{25}),
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{46}));
const auto a_1 = std::make_shared<default_opset::Subtract>(
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{1}),
a_0);

const auto start = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{0.0});
const auto step = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{1.0});
const auto range = std::make_shared<default_opset::Range>(start, size, step, tensor_type);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor = std::make_shared<default_opset::Multiply>(
range,
std::make_shared<default_opset::Divide>(
std::make_shared<default_opset::Multiply>(
pi,
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<int>{2})),
periodic ? size
: std::make_shared<default_opset::Subtract>(
size,
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<int>{1}))));

const auto cos = std::make_shared<default_opset::Cos>(factor);
const auto scaled_cos = std::make_shared<default_opset::Multiply>(cos, a_1);
const auto y_values = std::make_shared<default_opset::Subtract>(a_0, scaled_cos);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);
gkrivor marked this conversation as resolved.
Show resolved Hide resolved

return {output};
}
} // namespace set_17
} // namespace op
} // namespace onnx_import
} // namespace ngraph
19 changes: 19 additions & 0 deletions src/frontends/onnx/frontend/src/op/hammingwindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_17 {

OutputVector hammingwindow(const Node& node);

} // namespace set_17
} // namespace op
} // namespace onnx_import
} // namespace ngraph
95 changes: 95 additions & 0 deletions src/frontends/onnx/frontend/src/op/hannwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "op/hannwindow.hpp"

#include <memory>

#include "default_opset.hpp"
#include "utils/common.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_17 {
OutputVector hannwindow(const Node& node) {
const auto size = node.get_ng_inputs().at(0);
const auto output_datatype = common::get_ngraph_element_type(node.get_attribute_value("output_datatype", 1));
const bool periodic = node.get_attribute_value<int64_t>("periodic", 1);

const ov::PartialShape shape = size.get_partial_shape();
const std::vector<size_t> axis_lengths = shape.to_shape();

element::Type tensor_type;
gkrivor marked this conversation as resolved.
Show resolved Hide resolved
switch (output_datatype) {
case element::Type_t::f32:
tensor_type = element::f32;
break;
case element::Type_t::u8:
tensor_type = element::u8;
break;
case element::Type_t::i8:
tensor_type = element::i8;
break;
case element::Type_t::u16:
tensor_type = element::u16;
break;
case element::Type_t::i16:
tensor_type = element::i16;
break;
case element::Type_t::i32:
tensor_type = element::i32;
break;
case element::Type_t::i64:
tensor_type = element::i64;
break;
case element::Type_t::f16:
tensor_type = element::f16;
break;
case element::Type_t::f64:
tensor_type = element::f64;
break;
case element::Type_t::u32:
tensor_type = element::u32;
break;
case element::Type_t::u64:
tensor_type = element::u64;
break;
case element::Type_t::bf16:
tensor_type = element::bf16;
break;
default:
throw std::runtime_error("Unsupported output data type.");
}

// Weights as described in ONNX BlackManWindow docs
// https://github.com/onnx/onnx/blob/main/docs/Operators.md#hannwindow
const auto a_0 = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{0.5});
const auto a_1 = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{0.5});

const auto start = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{0.0});
const auto step = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<float>{1.0});
const auto range = std::make_shared<default_opset::Range>(start, size, step, tensor_type);
const auto pi = default_opset::Constant::create(tensor_type, ov::Shape(), {static_cast<float>(M_PI)});
const auto factor = std::make_shared<default_opset::Multiply>(
range,
std::make_shared<default_opset::Divide>(
std::make_shared<default_opset::Multiply>(
pi,
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<int>{2})),
periodic ? size
: std::make_shared<default_opset::Subtract>(
size,
std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(), std::vector<int>{1}))));

const auto cos = std::make_shared<default_opset::Cos>(factor);
const auto scaled_cos = std::make_shared<default_opset::Multiply>(cos, a_1);
const auto y_values = std::make_shared<default_opset::Subtract>(a_0, scaled_cos);
const auto output = std::make_shared<default_opset::Constant>(tensor_type, ov::Shape(axis_lengths), y_values);

return {output};
}
} // namespace set_17
} // namespace op
} // namespace onnx_import
} // namespace ngraph
19 changes: 19 additions & 0 deletions src/frontends/onnx/frontend/src/op/hannwindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ngraph/node.hpp"
#include "onnx_import/core/node.hpp"

namespace ngraph {
namespace onnx_import {
namespace op {
namespace set_17 {

OutputVector hannwindow(const Node& node);

} // namespace set_17
} // namespace op
} // namespace onnx_import
} // namespace ngraph
Loading
Loading