tensorflow / models

Models and examples built with TensorFlow
Other
76.95k stars 45.79k forks source link

Incorrect quantized SSD mobiledet DSP model after quantization aware training #8726

Open k8280627 opened 4 years ago

k8280627 commented 4 years ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

1. The entire URL of the file you are using

https://github.com/tensorflow/models/tree/master/research/object_detection

2. Describe the bug

I trained SSD+Mobiledet DSP model on a custom dataset, and did quantization aware training for 17K steps. However, when I exported the model to frozen graph using export_tflite_ssd_graph.py, the FakeQuantWithMinMaxVars that comes from ReLU6 have min and max range larger than 0-6.

https://github.com/tensorflow/models/issues/6112 this issue describes the similar issue, but it's not answered.

3. Steps to reproduce

  1. train SSD+mobiledet DSP, with pretrained weights stored in this link as fine-tune checkpoint:http://download.tensorflow.org/models/object_detection/ssdlite_mobiledet_dsp_320x320_coco_2020_05_19.tar.gz.
  2. perform quantization aware training with the trained SSD+mobiledet DSP model as fine-tune checkpoint.
  3. export the tflite graph using export_tflite_ssd_graph.py.

4. Expected behavior

The tflite graph would contain FakeQuantWithMinMaxVars that comes from ReLU6 that have min and max range larger than 0-6.

5. Additional context

6. System information

k8280627 commented 4 years ago

Hi @tombstone @jch1 @pkulzc,

I noticed that the uint8 mobile.tflite in this link is properly quantized, as in the FakeQuantWithMinMaxVars that comes from ReLU6 have the min and max range within 0-6.

I was wondering, is this model.tflite quantized by quantization aware training (QAT) or post training quantization? If it's QAT, then could you let me know if there is any specific setting that I'd have to set or if there's anything that I might miss out?

Another question is, for the quantization of the convolutional layer, is it per-tensor or per-axis quantization? Is there any option that I can force it to do per-tensor quantization, either with QAT of post training quantization?

Thank you very much for your help!! Really appreciate it very much! If you need additional information, please let me know as I'd love to solve this issue as soon as possible 😄

k8280627 commented 4 years ago

Hi @tombstone @jch1 @pkulzc,

just wanted to bump this up and see if there's any update on this issue. Please let me know if you need additional information.