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

Add TensorRT export and inference notebooks #253

Merged
merged 2 commits into from
Dec 24, 2021
Merged

Conversation

zhiqwang
Copy link
Owner

@zhiqwang zhiqwang commented Dec 24, 2021

Here is a small demo to surgeon the YOLOv5 ONNX model and then export to TensorRT engine.

Super parameters

model_path = "https://github.com/ultralytics/yolov5/releases/download/v6.0/yolov5n6.pt"
checkpoint_path = attempt_download(model_path)
onnx_path = "yolov5n6.onnx"
engine_path = "yolov5n6.engine"

score_thresh = 0.35
iou_thresh = 0.45
detections_per_img = 100

Surgeon the yolov5 ONNX models

from yolort.runtime.yolo_graphsurgeon import YOLOGraphSurgeon

yolo_gs = YOLOGraphSurgeon(
    model_path,
    version="r6.0",
    enable_dynamic=False,
)

yolo_gs.register_nms(
    score_thresh=score_thresh,
    nms_thresh=iou_thresh,
    detections_per_img=detections_per_img,
)

# Export the ONNX model
yolo_gs.save(onnx_path)

Build the TensorRT engine

from yolort.runtime.trt_helper import EngineBuilder

engine_builder = EngineBuilder()
engine_builder.create_network(onnx_path)
engine_builder.create_engine(engine_path, precision="fp32")

@zhiqwang zhiqwang added the enhancement New feature or request label Dec 24, 2021
@codecov
Copy link

codecov bot commented Dec 24, 2021

Codecov Report

Merging #253 (e8af511) into main (1d86967) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #253   +/-   ##
=======================================
  Coverage   93.62%   93.62%           
=======================================
  Files          11       11           
  Lines         675      675           
=======================================
  Hits          632      632           
  Misses         43       43           
Flag Coverage Δ
unittests 93.62% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1d86967...e8af511. Read the comment docs.

@zhiqwang zhiqwang merged commit 02c74a0 into main Dec 24, 2021
@zhiqwang zhiqwang deleted the add-trt-notebooks branch December 24, 2021 19:44
@zhiqwang zhiqwang added the API Library use interface label Dec 24, 2021
@zhiqwang zhiqwang added the documentation Improvements or additions to documentation label Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Library use interface documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant