rmccorm4 / tensorrt-utils

⚡ Useful scripts when using TensorRT
Apache License 2.0
240 stars 55 forks source link

infer_tensorrt_imagenet.py: Not Predicting The Correct Classes #22

Open Hassan313 opened 4 years ago

Hassan313 commented 4 years ago

Hi @rmccorm4 ,

I am using the infer_tensorrt_imagenet.py file to infer the images of imagenet with the int8 engine created by TensorRT.

Here is the way that I am using the code:

python3 infer_tensorrt_imagenet.py --engine resnet18.int8.engine \ -d /home/hassan/Datasets/ImageNet/ -b 1 -n 5

Here are the results:

[TensorRT] WARNING: Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles [TensorRT] WARNING: Explicit batch network detected and batch size specified, use execute without batch size instead. Allocating buffers ... Input image: /home/hassan/Datasets/ImageNet/ILSVRC2012_val_00000025.JPEG Prediction: wall clock Probability: 0.09 Prediction: matchstick Probability: 0.06 Prediction: switch Probability: 0.03 Prediction: screw Probability: 0.03 Prediction: envelope Probability: 0.02

[TensorRT] WARNING: Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles [TensorRT] WARNING: Explicit batch network detected and batch size specified, use execute without batch size instead. Allocating buffers ... Input image: /home/hassan/Datasets/ImageNet/ILSVRC2012_val_00000073.JPEG Prediction: wall clock Probability: 0.06 Prediction: matchstick Probability: 0.06 Prediction: switch Probability: 0.04 Prediction: screw Probability: 0.03 Prediction: envelope Probability: 0.02

[TensorRT] WARNING: Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles [TensorRT] WARNING: Explicit batch network detected and batch size specified, use execute without batch size instead. Allocating buffers ... Input image: /home/hassan/Datasets/ImageNet/ILSVRC2012_val_00000117.JPEG Prediction: wing Probability: 0.07 Prediction: spotlight Probability: 0.02 Prediction: lampshade Probability: 0.02 Prediction: matchstick Probability: 0.02 Prediction: wall clock Probability: 0.02

[TensorRT] WARNING: Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles [TensorRT] WARNING: Explicit batch network detected and batch size specified, use execute without batch size instead. Allocating buffers ... Input image: /home/hassan/Datasets/ImageNet/ILSVRC2012_val_00000113.JPEG Prediction: wall clock Probability: 0.06 Prediction: envelope Probability: 0.06 Prediction: matchstick Probability: 0.04 Prediction: lampshade Probability: 0.03 Prediction: refrigerator Probability: 0.03

There are certain classes popping up (like wall clock). Can you kindly help?

Thank you.

rmccorm4 commented 4 years ago

Hi @Hassan313 ,

Sorry for the delay.

Few questions come to mind:

  1. Are the inference results correct on fp32/fp16 engines? If yes, then probably an int8 calibration issue. If not, then probably an issue with the model/conversion.

  2. Was your int8 calibration data similar/representative of the data you're testing with inference?

  3. Are the images already pre-processed?

  4. Does using a different pre-processing function give better results?