This guide explains how to export a trained YOLOv5 and YOLOv7 models from PyTorch to tflite and quantized tflite format. We assume that the models are trained and stored by the YOLOv5 repository or the YOLOv7 repository.
export.py
from YOLOv5-DG repository is used to export pytorch .pt and .pth to tflite format.
python export.py --include tflite --weights PATH_TO_PT_FILE
In order to export to quantized tflite, add --int8 and --data with the path to representative dataset for quantization. --max-int8-img-cnt is used for limiting the number of images used for quantization.
python export.py --include tflite --weights PATH_TO_PT_FILE --int8 --data PATH_TO_REP_DATASET --max-int8-img-cnt NUM_IMG_USED_FOR_QUANT
export_v7.py
from YOLOv7-DG repository is used to export pytorch .pt and .pth to tflite format.
python export_v7.py --tflite --weights PATH_TO_PT_FILE
In order to export to quantized tflite, add --int8 and --data with the path to representative dataset for quantization. --max-int8-img-cnt is used for limiting the number of images used for quantization.
python export_v7.py --tflite --weights PATH_TO_PT_FILE --int8 --data PATH_TO_REP_DATASET --max-int8-img-cnt NUM_IMG_USED_FOR_QUANT