[tmva][sofie] Account for dilation in Conv2D same padding calculation#21685
[tmva][sofie] Account for dilation in Conv2D same padding calculation#21685harz05 wants to merge 3 commits intoroot-project:masterfrom
Conversation
sanjibansg
left a comment
There was a problem hiding this comment.
Hi @harz05,
Thanks for this PR. Can you add a test so that we can verify this patch?
Test Results 21 files 21 suites 2d 21h 12m 42s ⏱️ Results for commit 22e2914. ♻️ This comment has been updated with latest results. |
|
Hello @sanjibansg, I tried adding a numerical test with Conv2D(kernel=3, padding='same', dilation_rate=2) on 8×8 input and on testing locally I found that the output shape was correct (8x8x4=256 vs 144 before the fix), confirming the padding calculation works. |
Hi @harz05, |
|
hello @sanjibansg |
|
There was a clang and ruff formatting issue during the run, I fixed that. CI was also getting Windows x86 failure but i'm not really sure what's the issue in that. |
Changes
The
padding='same'calculation in the Keras Conv2D parser was using the raw kernel size instead of the effective kernel size, which for dilated convolutions isdilation * (kernel - 1) + 1.fAttrDilationswas extracted from the layer attributes but never factored into the padding formula.For
dilation=2, kernel=3, input=8, stride=1the old formula produced padding=2 while the correct value is 4, causing the generated inference code to operate on tensors with wrong spatial dimensions. Withdilation=1the effective kernel size reduces to the raw kernel size, so existing models are unaffected.Checklist
This PR fixes #21684