Commit 559d5890 authored by Michał Karzyński's avatar Michał Karzyński Committed by Robert Kimball

[ONNX] Move Convolution and Pooling helpers to utils/convpool (#1486)

parent e81d30f1
......@@ -34,6 +34,15 @@ add_library(onnx_import_interface OBJECT
add_library(onnx_import STATIC
onnx.pb.cc
core/attribute.cpp
core/attribute.hpp
core/graph.cpp
core/graph.hpp
core/model.hpp
core/node.cpp
core/node.hpp
core/tensor.hpp
core/value_info.hpp
exceptions.hpp
op/add.hpp
op/batch_norm.cpp
......@@ -48,16 +57,7 @@ add_library(onnx_import STATIC
utils/broadcasting.cpp
utils/broadcasting.hpp
utils/convpool.cpp
utils/convpool.hpp
core/attribute.cpp
core/attribute.hpp
core/graph.cpp
core/graph.hpp
core/model.hpp
core/node.cpp
core/node.hpp
core/tensor.hpp
core/value_info.hpp)
utils/convpool.hpp)
add_dependencies(onnx_import onnx_import_interface)
......
......@@ -117,65 +117,6 @@ namespace ngraph
return (outs << "<Node(" << node.op_type() << "): " << node.get_name() << ">");
}
namespace attribute
{
/**
* @brief Get shape of kernel (filter) in pixels.
*
* @param node The Node ptr representing Conv or Pool operation.
* @return The kernel Shape object representing its dimensions (height, width, depth).
*/
inline Shape get_kernel_shape(const Node& node)
{
return node.get_attribute_value<std::vector<std::size_t>>("kernel_shape", {1, 1});
}
namespace detail
{
inline Strides get_strides_helper(const Node& node,
const std::string& name,
const Shape& kernel_shape)
{
return node.get_attribute_value<std::vector<std::size_t>>(
name, std::vector<std::size_t>(kernel_shape.size(), 1UL));
}
} // namespace detail
/**
* @brief Get number of pixels to stride operation by in each direction.
*
* @param node The Node ptr representing Conv or Pool operation.
* @param kernel_shape The shape of the kernel which we retrieve strides for.
* @return The kernel Shape object representing its dimensions (height, width, depth).
*/
inline Strides get_strides(const Node& node, const Shape& kernel_shape)
{
return detail::get_strides_helper(node, "strides", kernel_shape);
}
/**
* @brief Get number of pixels to stride operation by in each direction.
*
* @param node The Node ptr representing Conv or Pool operation.
* @return The kernel Shape object representing its dimensions (height, width, depth).
*/
inline Strides get_strides(const Node& node)
{
return get_strides(node, get_kernel_shape(node));
}
/**
* @brief Get number of pixels for filter dilation in each direction.
*
* @param node The Node ptr representing ONNX operation.
* @return The Strides object containing number of pixels for filter dilation
* (height, width, depth).
*/
inline Strides get_dilations(const Node& node)
{
return detail::get_strides_helper(node, "dilations", get_kernel_shape(node));
}
} // namespace attribute
} // namespace onnx_import
} // namespace ngraph
......@@ -17,12 +17,49 @@
#include "convpool.hpp"
#include <cmath>
#include "ngraph/coordinate_diff.hpp"
#include "ngraph/shape.hpp"
#include "core/attribute.hpp"
#include "core/node.hpp"
namespace ngraph
{
namespace onnx_import
{
namespace attribute
{
Shape get_kernel_shape(const Node& node)
{
return node.get_attribute_value<std::vector<std::size_t>>("kernel_shape", {1, 1});
}
namespace detail
{
Strides get_strides_helper(const Node& node,
const std::string& name,
const Shape& kernel_shape)
{
return node.get_attribute_value<std::vector<std::size_t>>(
name, std::vector<std::size_t>(kernel_shape.size(), 1UL));
}
} // namespace detail
Strides get_strides(const Node& node, const Shape& kernel_shape)
{
return detail::get_strides_helper(node, "strides", kernel_shape);
}
Strides get_strides(const Node& node)
{
return get_strides(node, get_kernel_shape(node));
}
Strides get_dilations(const Node& node)
{
return detail::get_strides_helper(node, "dilations", get_kernel_shape(node));
}
namespace
{
CoordinateDiff get_auto_pads(const Shape& kernel_shape, const std::string& auto_pad)
......
......@@ -28,6 +28,40 @@ namespace ngraph
{
namespace attribute
{
/**
* @brief Get shape of kernel (filter) in pixels.
*
* @param node The Node ptr representing Conv or Pool operation.
* @return The kernel Shape object representing its dimensions (height, width, depth).
*/
Shape get_kernel_shape(const Node& node);
/**
* @brief Get number of pixels to stride operation by in each direction.
*
* @param node The Node ptr representing Conv or Pool operation.
* @param kernel_shape The shape of the kernel which we retrieve strides for.
* @return The kernel Shape object representing its dimensions (height, width, depth).
*/
Strides get_strides(const Node& node, const Shape& kernel_shape);
/**
* @brief Get number of pixels to stride operation by in each direction.
*
* @param node The Node ptr representing Conv or Pool operation.
* @return The kernel Shape object representing its dimensions (height, width, depth).
*/
Strides get_strides(const Node& node);
/**
* @brief Get number of pixels for filter dilation in each direction.
*
* @param node The Node ptr representing ONNX operation.
* @return The Strides object containing number of pixels for filter dilation
* (height, width, depth).
*/
Strides get_dilations(const Node& node);
/**
* @brief Get padding values for the operation described by an ONNX node.
* @details If `auto_pad` attribute is specified as SAME_UPPER or SAME_LOWER, or VALID
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment