Description
Hi,
I successfully converted a Mobilenet model (the original model) to both TRT fp32 model and int8 model.
For my case, the mobilenet model is trained with normalized images, (I mean the image is first normalized, (x-127.5)/128, outside the model and then feed into the model.
I did following test:
Case 1. for the original model, I used an image, imgA, did inference like:
(imgA-127.5)/128 → Original model → get embedding embO
Case 2. for the TRT fp32 model, I used the same image, imgA, did inference like:
(imgA-127.5)/128 → TRT fp32 model → get embedding embFP32
Case 3. For the TRT int8 model, I used a set of images to do the calibration. Before sending the image to the calibration, I normalized the image first, like:
(image-127.5)/128 → input to calibration function;
In inference, I used the same imgA,
(imgA-127.5)/128 → TRT int8 model → get embedding embINT8
Results:
The similarity between embO and embFP32 is 99.9%, which means the two results are almost the same.
The similarity between embO and embINT8 is 55%, means they are different;
Later on, I create another TRT int8 model. The same as 3, but in calibration, I feed the testing images directly to calibration without normalization as following:
Case 4. For the TRT int8 model, I used a set of images to do the calibration. Before sending the image to the calibration, I normalized the image first, like:
images → input to calibration function;
In inference, I used the same imgA,
(imgA-127.5)/128 → TRT int8 model → get embedding embINT8_2
The similarity between embO and embINT8_2 is 89.5%, means the two are similar but not very close;
Above results are really confusing. Maybe I didn’t understand the calibration correctly. My questions:
a). Since my model is trained with already normalized images, means before input to the model, the images have been normalized. So naturally, in int8 calibration, I need to normalized the images first before sending them to do calibration; like I did in Case 3. But from the results, the embINT8 is quite different from embO.
Instead, if I send the images to calibration without normalization, like Case 4, the result, embINT8_2, is much similar with embO.
How could that be?? Or my understanding about calibration is not right?
b) Even the case 4 is wright, the similarity is still not very high. Although the int8 model has performance loss, but I still expect it can be much higher, like >95%.
Environment
TensorRT Version: v5.1
GPU Type: GTX 1050
Nvidia Driver Version: 418.39
CUDA Version: 10.1
CUDNN Version: 7.5.0 (updated)
Operating System + Version: ubuntu 16.04
Python Version (if applicable): p2.7
TensorFlow Version (if applicable):
PyTorch Version (if applicable):
Baremetal or Container (if container which image + tag):
Relevant Files
Please attach or include links to any models, data, files, or scripts necessary to reproduce your issue. (Github repo, Google Drive, Dropbox, etc.)
Steps To Reproduce
Please include:
- Exact steps/commands to build your repro
- Exact steps/commands to run your repro
- Full traceback of errors encountered