mirror of
https://github.com/opencv/opencv.git
synced 2026-12-03 05:33:03 -06:00
* dnn: fix masked Attention ONNX import and commutative mask-Add fusion ONNXImporter2::parseAttention required every input after X to be constant before populating params.blobs, leaving blobs empty for dynamic masks, pushing constant masks into blobs[2], and failing on omitted or trailing empty optional inputs. AttentionLayerImpl also read bias from blobs.back() instead of blobs[1], and ModelFusionAttention::isMaskAdd hardcoded inputs[1] so Add(mask, scores) bound Attention's mask to the removed score node. Fold constant weight and bias into blobs[0..1], keep any 4th mask input on layer->inputs[1], and match score_arg in isMaskAdd. * dnn(onnx): lower the Attention int32 mask_index with addKeyPaddingMaskBias mask_index is an int32 0/1 padding mask, not an additive bias. Turn it into the additive mask the layer applies, the same way parseMultiHeadAttention does, saving and restoring node_inputs and node_outputs around the helper. The test loads its models from opencv_extra (same branch name) with testONNXModels() instead of building them and the reference in code; the first three cases now use the spec's int32 [B, S] mask. * dnn: keep AttentionLayerImpl's blob access as on 5.x parseAttention now always gives the layer exactly two blobs, the weight and the bias, and the fusion passes do the same, so blobs.front() and blobs.back() already pick them. The blobs[0]/blobs[1] change is not needed.