2.0.4
v2.0.4
Background
- Running
onnx2tf.py -i densenet-12.onnx -cotoffailed atMul(sng_Mul_1) with a broadcast shape mismatch. - Actual TF shapes at failure:
x:(1, 112, 112, 64)y:(1, 64, 1, 1)(channel-first style)
Root Cause
- In
shape_unmatched_special_avoidance_workaround, some transpose paths converted constantnp.ndarrayinputs intotf.Tensor. - After this conversion, downstream
explicit_broadcastbehavior changed and the constant was no longer normalized to NHWC-compatible shape. - As a result, the constant remained
(1, 64, 1, 1)instead of(1, 1, 1, 64), causingtf.math.multiplyto fail.
Implemented Fix
- File:
onnx2tf/utils/common_functions.py - Function:
shape_unmatched_special_avoidance_workaround - Added helper:
_transpose_preserve_array(tensor, perm)- Uses
np.transposewhentensorisnp.ndarray - Uses existing
transpose_with_flexing_deterrencefor tensor-like inputs
- Replaced internal transpose call sites in this function with
_transpose_preserve_arrayso constants keepnp.ndarraytype through alignment.
Effect
- Constant layout alignment now preserves array semantics and allows
explicit_broadcastto correctly reshape constants to channel-last form when needed. - For the failing case,
yis now normalized to(1, 1, 1, 64), andMulexecutes successfully.
Validation
- Reproduced and re-ran:
python onnx2tf/onnx2tf.py -i densenet-12.onnx -cotof
- Result:
- Conversion completed successfully (
exit code 0) - Validation logs reported matching outputs for the model conversion path.
- Conversion completed successfully (
What's Changed
- fix-shape_unmatched_special_avoidance_workaround by @PINTO0309 in #836
Full Changelog: 2.0.3...2.0.4