Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init from yolov5_quant_sample #11441

Closed
wants to merge 1 commit into from
Closed

Conversation

wjx052333
Copy link

@wjx052333 wjx052333 commented Apr 26, 2023

πŸ€– Generated by Copilot at 7a1a558

Summary

πŸŽ›οΈπŸ³πŸ”’

This pull request adds quantization-aware training (QAT) and ONNX export capabilities to the yolov5 model, and provides tools and scripts for converting the ONNX model to a TensorRT engine with int8 quantization and dynamic shape support. It also includes docker files, hyperparameters, and a demo for QAT. It modifies the models package to use pytorch_quantization modules, and disables layer fusion when loading a checkpoint. It adds new files in the trt and trt/trt_dynamic folders for processing, calibrating, evaluating, and visualizing the TensorRT engine.

To make yolov5 more efficient
We added QAT and made it persistent
We used pytorch_quantization
And ONNX export for conversion
To TensorRT engines with int8 inference

Walkthrough

  • Add QAT support for yolov5 models and export them to ONNX and TorchScript formats (link, link, link, link, link, link, link, link, link)
  • Build and launch docker images for QAT experiments with docker/build.sh and docker/launch.sh (link, link)
  • Convert ONNX models with QAT to TensorRT engines with int8 quantization using trt/onnx_to_trt.py and trt/onnx_to_trt_partialquant.py, optionally with a calibrator (link, link, link)
  • Process and visualize images using TensorRT engines with trt/Processor.py, trt/Visualizer.py, and trt/demo.py (link, link, link)
  • Support dynamic shape for TensorRT engines with trt/trt_dynamic/Processor_dynamic.py and trt/trt_dynamic/eval_yolo_trt_dynamic.py (link, link)
  • Add a comment to data/hyps/hyp.qat.yaml to describe its content and usage (link)

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Provide a comprehensive Quantization-Aware Training (QAT) workflow for YOLOv5 in a command-line script.

πŸ“Š Key Changes

  • Introduce yolo_quant_flow.py with functions for QAT, calibration, and fine-tuning.
  • Export trained YOLOv5 models to ONNX format with dynamic axis support.
  • Implement data loaders and model preparation for QAT and fine-tuning.
  • Evaluate model accuracy throughout the quantization process.

🎯 Purpose & Impact

  • Enhances the YOLOv5 workflow to support quantization-aware training (QAT), potentially leading to smaller model sizes and faster inference without significant loss in accuracy.
  • The ONNX export capability with dynamic shape support allows for more flexibility and compatibility with different deployment backends.
  • The script automates the evaluation of model accuracy pre- and post-quantization, ensuring that the model maintains its performance throughout the process.

@wjx052333 wjx052333 closed this Apr 26, 2023
@wjx052333 wjx052333 deleted the quant branch April 26, 2023 06:28
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘‹ Hello @wjx052333, thank you for submitting a YOLOv5 πŸš€ PR! To allow your work to be integrated as seamlessly as possible, we advise you to:

  • βœ… Verify your PR is up-to-date with ultralytics/yolov5 master branch. If your PR is behind you can update your code by clicking the 'Update branch' button or by running git pull and git merge master locally.
  • βœ… Verify all YOLOv5 Continuous Integration (CI) checks are passing.
  • βœ… Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." β€” Bruce Lee

@wjx052333 wjx052333 restored the quant branch April 26, 2023 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant