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

tensorrt .engine file validation #5626

Closed
wants to merge 4 commits into from
Closed

Conversation

shihanyu
Copy link

@shihanyu shihanyu commented Nov 12, 2021

"add the tensorrt .engine file validate ability by modifying the val.py file and adding the yolov5_trt.py in utils/. (pycuda should be installed by command pip3 install pycuda)
val command:
python path/to/val.py --data aaaaa.yaml --img 640 --engine_library bbbbb.so --engine_path cccc.engine
(The way to generate the .so file and the .engine file can be refered to https://github.com/wangxinyu/tensorrtx/tree/master/yolov5 )
and the file can only be used on the same type GPU as where it was generated .that's why I did not upload my .so and .engine file.
Hope it helps, and if there is any problem,let me know.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Integration of TensorRT inference within YOLOv5 validation script for boosted performance and speed.

📊 Key Changes

  • 🔧 Added pycuda to requirements for CUDA operations and TensorRT compatibility.
  • 🐍 Added new Python file utils/yolov5_trt.py for handling TensorRT operations.
    • This module wraps the TensorRT API and provides methods for image pre-processing, post-processing, and running inferences.
  • 🏎️ Updated val.py to support TensorRT engine validation:
    • Included ability to load TensorRT engine and run inferences directly from the validation script.
    • Validation can now be performed with .engine files by utilizing the new --engine-library and --engine-path arguments.

🎯 Purpose & Impact

  • Increased Inference Speed: TensorRT's optimized engine accelerates inference, which can be highly beneficial for deployment on edge devices or scenarios where latency is critical.
  • 🔄 Flexibility: Users can choose between standard PyTorch validation or high-performance TensorRT validation based on their needs.
  • 🌐 Broader Usage: This change appeals to users who prefer or require using TensorRT for inference due to its performance benefits on NVIDIA GPUs.

hanyu.shi and others added 2 commits November 12, 2021 17:27
…y file and adding the yolov5_trt.py in utils/. (pycuda should be installed by command pip3 install pycuda) val command:python path/to/val.py --data coco128.yaml --img 640 --engine_library xxxx.so --engine_path xxxx.engine
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 @shihanyu, thank you for submitting a 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:

  • ✅ Verify your PR is up-to-date with upstream/master. If your PR is behind upstream/master an automatic GitHub actions rebase may be attempted by including the /rebase command in a comment body, or by running the following code, replacing 'feature' with the name of your local branch:
git remote add upstream https://github.com/ultralytics/yolov5.git
git fetch upstream
git checkout feature  # <----- replace 'feature' with local branch name
git merge upstream/master
git push -u origin -f
  • ✅ Verify all 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

@glenn-jocher
Copy link
Member

glenn-jocher commented Nov 16, 2021

@shihanyu thanks for the PR! I think I may have not explained the DetectMultiBackend() module correctly to you. This module is responsible for ALL inference on any backend (i.e. ONNX, PyTorch, TensorFlow, CoreML). This is where ALL TorchScript specific logic must be placed, with the output from DetectMultiBackend() matching across all backends.

yolov5/models/common.py

Lines 276 to 287 in e80a09b

class DetectMultiBackend(nn.Module):
# YOLOv5 MultiBackend class for python inference on various backends
def __init__(self, weights='yolov5s.pt', device=None, dnn=True):
# Usage:
# PyTorch: weights = *.pt
# TorchScript: *.torchscript.pt
# CoreML: *.mlmodel
# TensorFlow: *_saved_model
# TensorFlow: *.pb
# TensorFlow Lite: *.tflite
# ONNX Runtime: *.onnx
# OpenCV DNN: *.onnx with dnn=True

Also please check CI failures: https://github.com/ultralytics/yolov5/runs/4220927192?check_suite_focus=true

@shihanyu
Copy link
Author

shihanyu commented Nov 16, 2021 via email

@glenn-jocher
Copy link
Member

@shihanyu closing this PR to focus on #5699. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐

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.

2 participants