tensorflow / tensorflow/model-optimization

Convert model to full int after quantization aware training

Open
#765 1 comment 0 reactions 1 assignee View on GitHub

@Xhark is already working on this.

Since Jul 23, 2021.

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

Description

The Quantization aware training in Keras example mentions the following after performing quantization aware training (here):

After this, you have an actually quantized model with int8 weights and uint8 activations.

However, when the model is converted to TF Lite using the snippet of code from the example the resulting model is not a full integer model. For instance, these are what interpreter.get_input_details() and interpreter.get_output_details() return, respectively.

[{'name': 'input_1',
  'index': 0,
  'shape': array([ 1, 28, 28], dtype=int32),
  'shape_signature': array([-1, 28, 28], dtype=int32),
  'dtype': numpy.float32,
  'quantization': (0.0, 0),
  'quantization_parameters': {'scales': array([], dtype=float32),
   'zero_points': array([], dtype=int32),
   'quantized_dimension': 0},
  'sparsity_parameters': {}}]


[{'name': 'Identity',
  'index': 19,
  'shape': array([ 1, 10], dtype=int32),
  'shape_signature': array([-1, 10], dtype=int32),
  'dtype': numpy.float32,
  'quantization': (0.0, 0),
  'quantization_parameters': {'scales': array([], dtype=float32),
   'zero_points': array([], dtype=int32),
   'quantized_dimension': 0},
  'sparsity_parameters': {}}]

I've tried to convert that model to a full integer model using the standard TF Lite procedure (setting converter.target_spec.supported_ops, converter.inference_input_type, converter.inference_output_type, and converter.representative_dataset), however, the following error is raised RuntimeError: Quantization not yet supported for op: 'DEQUANTIZE'.

Is it possible to convert a model trained with quantization aware training to a full integer model?

Thanks,
Gustavo

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.