Skip to content
Snippets Groups Projects
Commit 39e21343 authored by Houssem ROUIS's avatar Houssem ROUIS Committed by Olivier BICHLER
Browse files

update Pooling metaOps headers

parent 0782ece3
No related branches found
No related tags found
2 merge requests!341Error,!311fix failed onnx tests
......@@ -173,7 +173,8 @@ extern std::shared_ptr<Node> PaddedAvgPooling(const std::array<DimSize_t, DIM> &
const std::string& name = "",
const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1),
const std::array<DimSize_t, DIM> &dilations = create_array<DimSize_t,DIM>(1),
const std::array<DimSize_t, 2*DIM> &padding_dims = create_array<DimSize_t,2*DIM>(0));
const std::array<DimSize_t, 2*DIM> &padding_dims = create_array<DimSize_t,2*DIM>(0),
bool ceil_mode = false);
/**
* @brief Creates a padded average pooling operation as a MetaOperator.
......@@ -190,7 +191,8 @@ template <std::array<DimSize_t, 1>::size_type DIM>
extern std::shared_ptr<MetaOperator_Op> PaddedAvgPooling_Op(const std::array<DimSize_t, DIM> &kernel_dims,
const std::array<DimSize_t, DIM> &stride_dims = create_array<DimSize_t,DIM>(1),
const std::array<DimSize_t, DIM> &dilations = create_array<DimSize_t,DIM>(1),
const std::array<DimSize_t, 2*DIM> &padding_dims = create_array<DimSize_t,2*DIM>(0));
const std::array<DimSize_t, 2*DIM> &padding_dims = create_array<DimSize_t,2*DIM>(0),
bool ceil_mode = false);
// Helper function for average pooling with C-style array for kernel_dims, enabling automatic DIM deduction.
template <DimSize_t DIM>
......@@ -202,7 +204,8 @@ PaddedAvgPooling(DimSize_t const (&kernel_dims)[DIM],
const std::array<DimSize_t, DIM> &dilations =
create_array<DimSize_t, DIM>(1),
const std::array<DimSize_t, 2 * DIM> &padding_dims =
create_array<DimSize_t, 2 * DIM>(0));
create_array<DimSize_t, 2 * DIM>(0),
bool ceil_mode = false);
////////////////////////////////////////////////////////////////////////////////
......@@ -268,7 +271,7 @@ inline std::shared_ptr<Node> PaddedMaxPooling(
const std::array<DimSize_t, DIM> &dilations = create_array<DimSize_t,DIM>(1),
const std::array<DimSize_t, 2*DIM> &padding_dims = create_array<DimSize_t,2*DIM>(0),
bool ceil_mode= false) {
return PaddedMaxPooling(to_array(kernel_dims), name, stride_dims, padding_dims, dilations, ceil_mode);
return PaddedMaxPooling(to_array(kernel_dims), name, stride_dims, dilations, padding_dims, ceil_mode);
}
/**
......
......@@ -58,7 +58,7 @@ template <DimIdx_t DIM> void declare_AvgPoolingOp(py::module &m) {
bool>(),
py::arg("kernel_dims"),
py::arg("stride_dims") = create_array<DimSize_t, DIM>(1),
py::arg("stride_dims") = create_array<DimSize_t, DIM>(1),
py::arg("dilations") = create_array<DimSize_t, DIM>(1),
py::arg("ceil_mode") = false)
.def("get_inputs_name", &AvgPooling_Op<DIM>::getInputsName)
.def("get_outputs_name", &AvgPooling_Op<DIM>::getOutputsName)
......
......@@ -110,60 +110,76 @@ template <DimIdx_t DIM> void declare_PaddedAvgPoolingOp(py::module &m) {
m.def(("PaddedAvgPooling" + std::to_string(DIM) + "D").c_str(), [](const std::vector<DimSize_t>& kernel_dims,
const std::string& name,
const std::vector<DimSize_t> &stride_dims,
const std::vector<DimSize_t> &padding_dims)
const std::vector<DimSize_t> &dilations,
const std::vector<DimSize_t> &padding_dims,
bool ceil_mode)
{
AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [{}] does not match DIM [{}]", kernel_dims.size(), DIM);
AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [{}] does not match DIM [{}]", stride_dims.size(), DIM);
AIDGE_ASSERT(dilations.size() == DIM, "dilations size [{}] does not match DIM [{}]", dilations.size(), DIM);
AIDGE_ASSERT(padding_dims.size() == 2*DIM, "padding_dims size [{}] does not match DIM [{}]", padding_dims.size(), 2*DIM);
return PaddedAvgPooling<DIM>(to_array<DIM>(kernel_dims.begin()), name, to_array<DIM>(stride_dims.begin()), to_array<2*DIM>(padding_dims.begin()));
return PaddedAvgPooling<DIM>(to_array<DIM>(kernel_dims.begin()), name, to_array<DIM>(stride_dims.begin()), to_array<DIM>(dilations.begin()), to_array<2*DIM>(padding_dims.begin()), ceil_mode);
}, py::arg("kernel_dims"),
py::arg("name") = "",
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0));
py::arg("dilations") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("ceil_mode") = false);
m.def(("PaddedAvgPooling" + std::to_string(DIM) + "DOp").c_str(), [](const std::vector<DimSize_t>& kernel_dims,
const std::vector<DimSize_t> &stride_dims,
const std::vector<DimSize_t> &padding_dims)
const std::vector<DimSize_t> &dilations,
const std::vector<DimSize_t> &padding_dims,
bool ceil_mode)
{
AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [{}] does not match DIM [{}]", kernel_dims.size(), DIM);
AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [{}] does not match DIM [{}]", stride_dims.size(), DIM);
AIDGE_ASSERT(dilations.size() == DIM, "dilations size [{}] does not match DIM [{}]", dilations.size(), DIM);
AIDGE_ASSERT(padding_dims.size() == 2*DIM, "padding_dims size [{}] does not match DIM [{}]", padding_dims.size(), 2*DIM);
return PaddedAvgPooling_Op<DIM>(to_array<DIM>(kernel_dims.begin()), to_array<DIM>(stride_dims.begin()), to_array<2*DIM>(padding_dims.begin()));
return PaddedAvgPooling_Op<DIM>(to_array<DIM>(kernel_dims.begin()), to_array<DIM>(stride_dims.begin()), to_array<DIM>(dilations.begin()), to_array<2*DIM>(padding_dims.begin()), ceil_mode);
}, py::arg("kernel_dims"),
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0));
py::arg("dilations") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("ceil_mode") = false);
}
template <DimIdx_t DIM> void declare_PaddedMaxPoolingOp(py::module &m) {
m.def(("PaddedMaxPooling" + std::to_string(DIM) + "D").c_str(), [](const std::vector<DimSize_t>& kernel_dims,
const std::string& name,
const std::vector<DimSize_t> &stride_dims,
const std::vector<DimSize_t> &dilations,
const std::vector<DimSize_t> &padding_dims,
bool ceil_mode)
{
AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [{}] does not match DIM [{}]", kernel_dims.size(), DIM);
AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [{}] does not match DIM [{}]", stride_dims.size(), DIM);
AIDGE_ASSERT(dilations.size() == DIM, "dilations size [{}] does not match DIM [{}]", dilations.size(), DIM);
AIDGE_ASSERT(padding_dims.size() == 2*DIM, "padding_dims size [{}] does not match DIM [{}]", padding_dims.size(), 2*DIM);
return PaddedMaxPooling<DIM>(to_array<DIM>(kernel_dims.begin()), name, to_array<DIM>(stride_dims.begin()), to_array<2*DIM>(padding_dims.begin()), ceil_mode);
return PaddedMaxPooling<DIM>(to_array<DIM>(kernel_dims.begin()), name, to_array<DIM>(stride_dims.begin()), to_array<DIM>(dilations.begin()), to_array<2*DIM>(padding_dims.begin()), ceil_mode);
}, py::arg("kernel_dims"),
py::arg("name") = "",
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("dilations") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("ceil_mode") = false);
m.def(("PaddedMaxPooling" + std::to_string(DIM) + "DOp").c_str(), [](const std::vector<DimSize_t>& kernel_dims,
const std::vector<DimSize_t> &stride_dims,
const std::vector<DimSize_t> &dilations,
const std::vector<DimSize_t> &padding_dims,
bool ceil_mode)
{
AIDGE_ASSERT(kernel_dims.size() == DIM, "kernel_dims size [{}] does not match DIM [{}]", kernel_dims.size(), DIM);
AIDGE_ASSERT(stride_dims.size() == DIM, "stride_dims size [{}] does not match DIM [{}]", stride_dims.size(), DIM);
AIDGE_ASSERT(dilations.size() == DIM, "dilations size [{}] does not match DIM [{}]", dilations.size(), DIM);
AIDGE_ASSERT(padding_dims.size() == 2*DIM, "padding_dims size [{}] does not match DIM [{}]", padding_dims.size(), 2*DIM);
return PaddedMaxPooling_Op<DIM>(to_array<DIM>(kernel_dims.begin()), to_array<DIM>(stride_dims.begin()), to_array<2*DIM>(padding_dims.begin()), ceil_mode);
return PaddedMaxPooling_Op<DIM>(to_array<DIM>(kernel_dims.begin()), to_array<DIM>(stride_dims.begin()), to_array<DIM>(dilations.begin()), to_array<2*DIM>(padding_dims.begin()), ceil_mode);
}, py::arg("kernel_dims"),
py::arg("stride_dims") = std::vector<DimSize_t>(DIM,1),
py::arg("dilations") = std::vector<DimSize_t>(DIM,1),
py::arg("padding_dims") = std::vector<DimSize_t>(2*DIM,0),
py::arg("ceil_mode") = false);
......
......@@ -34,31 +34,35 @@ template <std::array<DimSize_t, 1>::size_type DIM>
std::shared_ptr<Node> PaddedAvgPooling(const std::array<DimSize_t, DIM> &kernel_dims,
const std::string& name,
const std::array<DimSize_t, DIM> &stride_dims,
const std::array<DimSize_t, 2*DIM> &padding_dims)
const std::array<DimSize_t, DIM> &dilations,
const std::array<DimSize_t, 2*DIM> &padding_dims,
bool ceil_mode)
{
auto graph = Sequential({
Pad<DIM>(padding_dims, (!name.empty()) ? name + "_pad" : ""),
AvgPooling(kernel_dims, (!name.empty()) ? name + "_avgpooling" : "", stride_dims)
AvgPooling(kernel_dims, (!name.empty()) ? name + "_avgpooling" : "", stride_dims, dilations, ceil_mode)
});
return MetaOperator(("PaddedAvgPooling" + std::to_string(DIM) + "D").c_str(), graph, {}, name);
}
template std::shared_ptr<Node> PaddedAvgPooling<1>(const std::array<DimSize_t,1>&, const std::string&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,2>&);
template std::shared_ptr<Node> PaddedAvgPooling<2>(const std::array<DimSize_t,2>&, const std::string&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,4>&);
template std::shared_ptr<Node> PaddedAvgPooling<1>(const std::array<DimSize_t,1>&, const std::string&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,2>&, bool);
template std::shared_ptr<Node> PaddedAvgPooling<2>(const std::array<DimSize_t,2>&, const std::string&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,4>&, bool);
// helper with C-style array instead of std::array for kernel_dims to allow automatic template DIM deduction
template <DimSize_t DIM>
std::shared_ptr<Node> PaddedAvgPooling(const DimSize_t (&kernel_dims)[DIM],
const std::string& name,
const std::array<DimSize_t, DIM> &stride_dims,
const std::array<DimSize_t, 2*DIM> &padding_dims)
const std::array<DimSize_t, DIM> &dilations,
const std::array<DimSize_t, 2*DIM> &padding_dims,
bool ceil_mode)
{
return PaddedAvgPooling(to_array(kernel_dims), name, stride_dims, padding_dims);
return PaddedAvgPooling(to_array(kernel_dims), name, stride_dims, dilations, padding_dims, ceil_mode);
}
template std::shared_ptr<Node> PaddedAvgPooling<1>(const DimSize_t (&kernel_dims)[1], const std::string&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,2>&);
template std::shared_ptr<Node> PaddedAvgPooling<2>(const DimSize_t (&kernel_dims)[2], const std::string&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,4>&);
template std::shared_ptr<Node> PaddedAvgPooling<1>(const DimSize_t (&kernel_dims)[1], const std::string&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,2>&, bool);
template std::shared_ptr<Node> PaddedAvgPooling<2>(const DimSize_t (&kernel_dims)[2], const std::string&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,4>&, bool);
//////////////////////////////////
......@@ -68,17 +72,19 @@ template std::shared_ptr<Node> PaddedAvgPooling<2>(const DimSize_t (&kernel_dims
template <std::array<DimSize_t, 1>::size_type DIM>
inline std::shared_ptr<MetaOperator_Op> PaddedAvgPooling_Op(const std::array<DimSize_t, DIM> &kernel_dims,
const std::array<DimSize_t, DIM> &stride_dims,
const std::array<DimSize_t, 2*DIM> &padding_dims)
const std::array<DimSize_t, DIM> &dilations,
const std::array<DimSize_t, 2*DIM> &padding_dims,
bool ceil_mode)
{
auto graph = Sequential({
Pad<DIM>(padding_dims, ""),
AvgPooling(kernel_dims, "", stride_dims)
AvgPooling(kernel_dims, "", stride_dims, dilations, ceil_mode)
});
return std::make_shared<MetaOperator_Op>(("PaddedAvgPooling" + std::to_string(DIM) + "D").c_str(), graph);
}
template std::shared_ptr<MetaOperator_Op> PaddedAvgPooling_Op<1>(const std::array<DimSize_t,1>&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,2>&);
template std::shared_ptr<MetaOperator_Op> PaddedAvgPooling_Op<2>(const std::array<DimSize_t,2>&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,4>&);
template std::shared_ptr<MetaOperator_Op> PaddedAvgPooling_Op<1>(const std::array<DimSize_t,1>&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,1>&, const std::array<DimSize_t,2>&, bool);
template std::shared_ptr<MetaOperator_Op> PaddedAvgPooling_Op<2>(const std::array<DimSize_t,2>&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,2>&, const std::array<DimSize_t,4>&, bool);
} // namespace Aidge
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment