Skip to content

2.0.4

Choose a tag to compare

@PINTO0309 PINTO0309 released this 07 Feb 00:19
· 2250 commits to main since this release
586229f

v2.0.4

Background

  • Running onnx2tf.py -i densenet-12.onnx -cotof failed at Mul (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 constant np.ndarray inputs into tf.Tensor.
  • After this conversion, downstream explicit_broadcast behavior 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), causing tf.math.multiply to fail.

Implemented Fix

  • File: onnx2tf/utils/common_functions.py
  • Function: shape_unmatched_special_avoidance_workaround
  • Added helper:
    • _transpose_preserve_array(tensor, perm)
    • Uses np.transpose when tensor is np.ndarray
    • Uses existing transpose_with_flexing_deterrence for tensor-like inputs
  • Replaced internal transpose call sites in this function with _transpose_preserve_array so constants keep np.ndarray type through alignment.

Effect

  • Constant layout alignment now preserves array semantics and allows explicit_broadcast to correctly reshape constants to channel-last form when needed.
  • For the failing case, y is now normalized to (1, 1, 1, 64), and Mul executes 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.

What's Changed

  • fix-shape_unmatched_special_avoidance_workaround by @PINTO0309 in #836

Full Changelog: 2.0.3...2.0.4