[ONNX] Use kernel shape in MaxPool to create default strides/dilations/paddings (#3522)
This commit is contained in:
parent
312db9a713
commit
3db6b54815
@ -41,13 +41,12 @@ namespace ngraph
|
||||
/// - AveragePool
|
||||
/// - MaxPool
|
||||
///
|
||||
/// This base class holds all common attributes like srides, dilations,
|
||||
/// This class holds all common attributes like srides, dilations,
|
||||
/// paddings, kernel shape and auto_pad type.
|
||||
///
|
||||
/// \see GlobalPoolingFactory
|
||||
class PoolingFactory
|
||||
{
|
||||
public:
|
||||
explicit PoolingFactory(const Node& node);
|
||||
virtual ~PoolingFactory() = default;
|
||||
|
||||
///
|
||||
@ -63,8 +62,6 @@ namespace ngraph
|
||||
OutputVector make_max_pool() const;
|
||||
|
||||
protected:
|
||||
explicit PoolingFactory(const Node& node);
|
||||
|
||||
Node m_onnx_node;
|
||||
const OutputVector m_inputs;
|
||||
Shape m_kernel_shape;
|
||||
@ -75,18 +72,6 @@ namespace ngraph
|
||||
ngraph::op::PadType m_auto_pad;
|
||||
ngraph::op::RoundingType m_rounding_type;
|
||||
};
|
||||
|
||||
///
|
||||
/// \brief Factory class which generates sub-graphs for ONNX 'local' pooling
|
||||
/// operators.
|
||||
/// \note For a 'local' pooling operation, the kernel shape attribute is required
|
||||
class LocalPoolingFactory : public PoolingFactory
|
||||
{
|
||||
public:
|
||||
explicit LocalPoolingFactory(const Node& node);
|
||||
virtual ~LocalPoolingFactory() = default;
|
||||
};
|
||||
|
||||
} // namespace pooling
|
||||
} // namespace onnx_import
|
||||
} // namespace ngraph
|
||||
|
@ -28,7 +28,7 @@ namespace ngraph
|
||||
{
|
||||
OutputVector average_pool(const Node& node)
|
||||
{
|
||||
return pooling::LocalPoolingFactory(node).make_avg_pool();
|
||||
return pooling::PoolingFactory(node).make_avg_pool();
|
||||
}
|
||||
|
||||
} // namespace set_1
|
||||
|
@ -31,7 +31,7 @@ namespace ngraph
|
||||
{
|
||||
OutputVector max_pool(const Node& node)
|
||||
{
|
||||
auto max_pool = pooling::LocalPoolingFactory(node).make_max_pool();
|
||||
auto max_pool = pooling::PoolingFactory(node).make_max_pool();
|
||||
max_pool.emplace_back(std::make_shared<NullNode>()); // Indices (optional)
|
||||
return max_pool;
|
||||
}
|
||||
|
@ -31,12 +31,13 @@ namespace ngraph
|
||||
PoolingFactory::PoolingFactory(const Node& node)
|
||||
: m_onnx_node{node}
|
||||
, m_inputs{node.get_ng_inputs()}
|
||||
, m_strides{convpool::get_strides(node)}
|
||||
, m_dilations{convpool::get_dilations(node)}
|
||||
, m_kernel_shape(node.get_attribute_value<std::vector<std::size_t>>("kernel_shape"))
|
||||
, m_strides{convpool::get_strides(node, m_kernel_shape.size())}
|
||||
, m_dilations{convpool::get_dilations(node, m_kernel_shape.size())}
|
||||
, m_auto_pad{convpool::get_auto_pad(node)}
|
||||
, m_rounding_type{convpool::get_rounding_type(node)}
|
||||
{
|
||||
const auto paddings = convpool::get_pads(node);
|
||||
const auto paddings = convpool::get_pads(node, m_kernel_shape.size());
|
||||
const CoordinateDiff& padding_above{paddings.second};
|
||||
const CoordinateDiff& padding_below{paddings.first};
|
||||
m_padding_below = Shape{std::begin(padding_below), std::end(padding_below)};
|
||||
@ -67,13 +68,6 @@ namespace ngraph
|
||||
m_rounding_type,
|
||||
m_auto_pad)};
|
||||
}
|
||||
|
||||
LocalPoolingFactory::LocalPoolingFactory(const Node& node)
|
||||
: PoolingFactory(node)
|
||||
{
|
||||
// Kernel shape is required
|
||||
m_kernel_shape = node.get_attribute_value<std::vector<std::size_t>>("kernel_shape");
|
||||
}
|
||||
} // namespace pooling
|
||||
} // namespace onnx_import
|
||||
} // namespace ngraph
|
||||
|
@ -0,0 +1,35 @@
|
||||
ir_version: 3
|
||||
producer_name: "nGraph ONNX Importer"
|
||||
graph {
|
||||
node {
|
||||
input: "x"
|
||||
output: "y"
|
||||
op_type: "MaxPool"
|
||||
attribute {
|
||||
name: "kernel_shape"
|
||||
ints: 2
|
||||
ints: 2
|
||||
type: INTS
|
||||
}
|
||||
}
|
||||
name: "compute_graph"
|
||||
input {
|
||||
name: "x"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
output {
|
||||
name: "y"
|
||||
type {
|
||||
tensor_type {
|
||||
elem_type: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
opset_import {
|
||||
version: 7
|
||||
}
|
@ -1285,3 +1285,18 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_dyn_shapes_reduce_max_dynamic_input_rank_negat
|
||||
test_case.add_expected_output<float>(Shape{2, 1}, {4, 8});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, onnx_model_max_pool_dyn_rank_without_default_attrs)
|
||||
{
|
||||
auto function = onnx_import::import_onnx_model(file_util::path_join(
|
||||
SERIALIZED_ZOO, "onnx/dynamic_shapes/max_pool_dyn_rank_without_default_attrs.prototxt"));
|
||||
|
||||
auto test_case = test::TestCase<TestEngine, TestCaseType::DYNAMIC>(function);
|
||||
|
||||
Shape input_shape{1, 1, 4, 4};
|
||||
std::vector<float> input(shape_size(input_shape));
|
||||
std::iota(input.begin(), input.end(), 0);
|
||||
test_case.add_input<float>(input_shape, input);
|
||||
test_case.add_expected_output<float>(Shape{1, 1, 3, 3}, {5, 6, 7, 9, 10, 11, 13, 14, 15});
|
||||
test_case.run();
|
||||
}
|
||||
|
@ -205,6 +205,7 @@ onnx_dyn_shapes_flatten_neg_axis
|
||||
onnx_model_range_positive_step
|
||||
onnx_model_range_negative_step
|
||||
onnx_dyn_shapes_slice_1_3d_input_21_axes_ends_max
|
||||
onnx_model_max_pool_dyn_rank_without_default_attrs
|
||||
|
||||
# LSTMSequence Layer is not instance of RNNLayer class
|
||||
# (Constant W, B, R inputs are required)
|
||||
|
Loading…
Reference in New Issue
Block a user