Skip to content

Commit

Permalink
Merge pull request opencv#21159 from rogday:ceil_mode
Browse files Browse the repository at this point in the history
fix ceil_mode for Average/MaxPooling

* fix ceil_mode

* add a comment
  • Loading branch information
rogday authored Dec 2, 2021
1 parent b6df9de commit 1613d30
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions modules/dnn/src/onnx/onnx_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,19 +612,32 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto)
}
}

void setCeilMode(LayerParams& layerParams)
{
// auto_pad attribute is deprecated and uses ceil
if (layerParams.has("pad_mode"))
{
layerParams.set("ceil_mode", true);
}
else if (!layerParams.has("ceil_mode"))
{
layerParams.set("ceil_mode", false);
}
}

void ONNXImporter::parseMaxPool(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
layerParams.type = "Pooling";
layerParams.set("pool", "MAX");
layerParams.set("ceil_mode", layerParams.has("pad_mode"));
setCeilMode(layerParams);
addLayer(layerParams, node_proto);
}

void ONNXImporter::parseAveragePool(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto)
{
layerParams.type = "Pooling";
layerParams.set("pool", "AVE");
layerParams.set("ceil_mode", layerParams.has("pad_mode"));
setCeilMode(layerParams);
layerParams.set("ave_pool_padded_area", framework_name == "pytorch");
addLayer(layerParams, node_proto);
}
Expand Down

0 comments on commit 1613d30

Please sign in to comment.