6
6
#include " exceptions.hpp"
7
7
#include " openvino/frontend/exception.hpp"
8
8
#include " openvino/op/add.hpp"
9
+ #include " openvino/op/avg_pool.hpp"
9
10
#include " openvino/op/constant.hpp"
10
11
#include " openvino/op/convert.hpp"
11
12
#include " openvino/op/divide.hpp"
@@ -57,21 +58,12 @@ ov::OutputVector qlinear_activation(const ov::frontend::onnx::Node& node, const
57
58
}
58
59
59
60
ov::OutputVector qlinear_sigmoid (const ov::frontend::onnx::Node& node) {
60
- // Original documentation:
61
- // https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#commicrosoftqlinearsigmoid
62
- // f(x) = quantize(Sigmoid(dequantize(x)))
63
-
64
61
return qlinear_activation (node, [](const std::shared_ptr<ov::Node>& input_dequantized) {
65
62
return std::make_shared<v0::Sigmoid>(input_dequantized);
66
63
});
67
64
}
68
65
69
66
ov::OutputVector qlinear_leaky_relu (const ov::frontend::onnx::Node& node) {
70
- // Original documentation:
71
- // https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#commicrosoftqlinearleakyrelu
72
- // f(x) = quantize(alpha * dequantize(x)) for x < 0,
73
- // quantize(dequantize(x)) for x >= 0
74
-
75
67
return qlinear_activation (node, [&](const std::shared_ptr<ov::Node>& input_dequantized) {
76
68
auto alpha =
77
69
v0::Constant::create (input_dequantized->get_element_type (), {}, {node.get_attribute_value <float >(" alpha" )});
@@ -80,10 +72,44 @@ ov::OutputVector qlinear_leaky_relu(const ov::frontend::onnx::Node& node) {
80
72
});
81
73
}
82
74
83
- namespace {
84
- ONNX_OP (" QLinearSigmoid" , OPSET_SINCE(1 ), com_microsoft::opset_1::qlinear_sigmoid, MICROSOFT_DOMAIN);
75
+ ov::OutputVector qlinear_avg_pool (const ov::frontend::onnx::Node& node) {
76
+ return qlinear_activation (node, [&](const std::shared_ptr<ov::Node>& input_dequantized) {
77
+ const auto kernel_shape = node.get_attribute_value <std::vector<int64_t >>(" kernel_shape" );
78
+ auto strides = node.get_attribute_value <std::vector<int64_t >>(" strides" , std::vector<int64_t >{1 });
79
+ auto pads = node.get_attribute_value <std::vector<int64_t >>(" pads" , std::vector<int64_t >{0 });
80
+ const auto ceil_mode = node.get_attribute_value <int64_t >(" ceil_mode" , 0 );
81
+ const auto count_include_pad = node.get_attribute_value <int64_t >(" count_include_pad" , 0 );
82
+ const auto auto_pad = node.get_attribute_value <std::string>(" auto_pad" , " NOTSET" );
83
+
84
+ const auto input_rank = input_dequantized->get_shape ().size ();
85
+ const size_t num_spatial_dims = input_rank - 2 ;
86
+
87
+ pads.resize (num_spatial_dims * 2 , pads.size () == 1 ? pads[0 ] : 0 );
88
+ strides.resize (num_spatial_dims, strides.size () == 1 ? strides[0 ] : 1 );
89
+
90
+ auto avg_pool = std::make_shared<v1::AvgPool>(input_dequantized,
91
+ Strides (strides.begin (), strides.end ()),
92
+ Shape (pads.begin (), pads.begin () + num_spatial_dims),
93
+ Shape (pads.begin () + num_spatial_dims, pads.end ()),
94
+ Shape (kernel_shape.begin (), kernel_shape.end ()),
95
+ count_include_pad == 0 ,
96
+ ceil_mode != 0 ? RoundingType::CEIL : RoundingType::FLOOR,
97
+ auto_pad == " SAME_UPPER" ? PadType::SAME_UPPER
98
+ : auto_pad == " SAME_LOWER" ? PadType::SAME_LOWER
99
+ : PadType::EXPLICIT);
100
+
101
+ return avg_pool;
102
+ });
85
103
}
86
- ONNX_OP (" QLinearLeakyRelu" , OPSET_SINCE(1 ), com_microsoft::opset_1::qlinear_leaky_relu, MICROSOFT_DOMAIN);
104
+
105
+ bool register_multiple_operators (void ) {
106
+ ONNX_OP_M (" QLinearSigmoid" , OPSET_SINCE (1 ), com_microsoft::opset_1::qlinear_sigmoid, MICROSOFT_DOMAIN);
107
+ ONNX_OP_M (" QLinearLeakyRelu" , OPSET_SINCE (1 ), com_microsoft::opset_1::qlinear_leaky_relu, MICROSOFT_DOMAIN);
108
+ ONNX_OP_M (" QLinearAveragePool" , OPSET_SINCE (1 ), com_microsoft::opset_1::qlinear_avg_pool, MICROSOFT_DOMAIN);
109
+ return true ;
110
+ }
111
+
112
+ static bool registered = register_multiple_operators();
87
113
88
114
} // namespace opset_1
89
115
} // namespace com_microsoft
0 commit comments