qonnx icon indicating copy to clipboard operation
qonnx copied to clipboard

Keras3 and Qkeras3 Conversion to QONNX

Open nfirle opened this issue 2 months ago • 2 comments

This PR adds support for converting QKeras models built with Keras 3. The internal naming scheme in Keras 3 has changed (e.g. added numerical suffixes to layer names), which previously caused quantizer name resolution to fail.

Main changes:

Extended quantizer name matching to handle Keras 3 naming patterns (using regex to match suffixes like _).

Added dynamic import for BaseQuantizer to support both old and new QKeras versions.

Updated Keras conversion tests to work with QKeras V3.

⚠️ Note: This functionality depends on the updated from_keras implementation in tf2onnx (PR #2398 ).

nfirle avatar Oct 18 '25 16:10 nfirle

Thanks @nfirle . Couple of questions from me:

  • Will this break compatibility with the older versions? (Keras2/QKeras2) or will those still work?
  • There are some print statements in qkeras/onnx.py - if those are for debugging please remove/comment them out:
        match_keras3 = r"/" + re.escape(keras_name) + r"_\d+/"
        print("onnx:",onnx_name)
        print("keras:",keras_name)
        print("keras3:",match_keras3)

maltanar avatar Oct 21 '25 09:10 maltanar

I have removed the print statements; I accidentally uploaded the wrong version. It remains compatible with the old version of keras2/qkeras2. However, it will only work once my pull request has been accepted by tf2onnx.

nfirle avatar Oct 25 '25 16:10 nfirle