diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index b4dc3e1573..75b2d2a928 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1135,7 +1135,10 @@ void ONNXImporter::parseAveragePool(LayerParams& layerParams, const opencv_onnx: layerParams.type = "Pooling"; layerParams.set("pool", "AVE"); setCeilMode(layerParams); - layerParams.set("ave_pool_padded_area", framework_name == "pytorch"); + // count_include_pad says whether padded values count towards the kernel area. + // Keep the previous producer-based default when the attribute is missing. + const bool countIncludePad = layerParams.get("count_include_pad", framework_name == "pytorch") != 0; + layerParams.set("ave_pool_padded_area", countIncludePad); addLayer(layerParams, node_proto); } diff --git a/modules/dnn/test/test_onnx_conformance_layer_filter_opencv_all_denylist.inl.hpp b/modules/dnn/test/test_onnx_conformance_layer_filter_opencv_all_denylist.inl.hpp index 0370b22764..48d0037d84 100644 --- a/modules/dnn/test/test_onnx_conformance_layer_filter_opencv_all_denylist.inl.hpp +++ b/modules/dnn/test/test_onnx_conformance_layer_filter_opencv_all_denylist.inl.hpp @@ -34,8 +34,6 @@ "test_argmin_no_keepdims_random", "test_argmin_no_keepdims_random_select_last_index", #endif -"test_averagepool_2d_pads_count_include_pad", -"test_averagepool_2d_precomputed_pads_count_include_pad", "test_averagepool_2d_same_lower", "test_cast_FLOAT_to_STRING", "test_cast_STRING_to_FLOAT", diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index 66889e097b..8954df1519 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -829,6 +829,12 @@ TEST_P(Test_ONNX_layers, AveragePooling) testONNXModels("average_pooling"); } +// PyTorch model with count_include_pad=0: the attribute must override the producer-based default +TEST_P(Test_ONNX_layers, AveragePooling_exclude_pad) +{ + testONNXModels("average_pooling_exclude_pad"); +} + TEST_P(Test_ONNX_layers, MaxPooling3D) { #if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)