tensorflow / tensorflow/model-optimization

Custom_Layer Quantization with custom training (QAT)

Open
#1,084 2 comments 0 reactions 1 assignee View on GitHub

@Xhark is already working on this.

Since Aug 15, 2023.

bug
Dominant language
Python
Stars
1.6k
Forks
349
Avg merge
3d 2h
Merged PRs (30d)
1

Description

Describe the bug
Unable to quantize the custom layer to Int8 even after quantization.

System information

TensorFlow version (installed from source or binary): 2.15.0-dev20230814

TensorFlow Model Optimization version (installed from source or binary): 0.7.5

Python version: 3.10.12

Describe the expected behavior
Train a model which contains custom layer and export a quantise only the layer to int8 version for later to implement on an FPGA
accelerator.

Describe the current behavior
The custom layer which is supposed to be quantized always exports the un-quantized weights. If I change the tf.lite.OpsSet.TFLITE_BUILTINS to tf.lite.OpsSet.TFLITE_BUILTINS_INT8, the layer is getting quantized but the accuracy of the model is dropping from 99% to 9%. But I followed the QAT guid from as mentioned in the official website and the link to the colab notebook is provided below along with the custom layer code.

Code to reproduce the issue
Code

Additional context
I have used quantize_config while applying the quantization and passed the necessary elements through the scope. I have used tf.lite.OpsSet.SELECT_TF_OPS to enable tf.Extract_images through quantization.
Adder_Layer.txt

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.