dnn: accept 4-value pads in ONNX MaxUnpool and read them as [H, W]

This commit is contained in:
Shiven Solanki
2026-11-26 14:37:36 +08:00
parent 2d579693d8
commit dbaf062c67
2 changed files with 11 additions and 3 deletions

View File

@@ -1382,9 +1382,11 @@ void ONNXImporter2::parseMaxUnpool(LayerParams& layerParams, const opencv_onnx::
if (layerParams.has("pad"))
{
DictValue pads = layerParams.get("pad");
CV_CheckEQ(pads.size(), 2, "");
pool_pad_w = pads.get<int>(0);
pool_pad_h = pads.get<int>(1);
CV_CheckEQ(pads.size(), 4, "DNN/ONNX: MaxUnpool expects 4 pads values for 2D input");
pool_pad_h = pads.get<int>(0);
pool_pad_w = pads.get<int>(1);
CV_CheckEQ(pads.get<int>(2), pool_pad_h, "DNN/ONNX: MaxUnpool supports only symmetric pads");
CV_CheckEQ(pads.get<int>(3), pool_pad_w, "DNN/ONNX: MaxUnpool supports only symmetric pads");
}
layerParams.set("pool_pad_w", pool_pad_w);
layerParams.set("pool_pad_h", pool_pad_h);

View File

@@ -325,6 +325,12 @@ TEST_P(Test_ONNX_layers, MaxUnpool_non_square)
testONNXModels("maxunpool_non_square", npy, 0, 0, false, false, 2);
}
// pads are [top, left, bottom, right]; unequal H and W pads catch swapped axes.
TEST_P(Test_ONNX_layers, MaxUnpool_pads)
{
testONNXModels("maxunpool_pads", npy, 0, 0, false, false, 2);
}
// Opset 20 removed DFT's axis attribute; with no axis input, the axis defaults to -2.
TEST_P(Test_ONNX_layers, DFT_opset20_default_axis)
{