Giter Club home page Giter Club logo

yolov8_tensorrt's Introduction

B站教学视频

https://www.bilibili.com/video/BV1Pa4y1N7HS

Introduction

  • 基于Tensorrt加速Yolov8,本项目采用ONNX转Tensorrt方案
  • 支持Windows10Linux
  • 支持Python/C++

YOLOv8

Environment

  • Tensorrt 8.4.3.
  • Cuda 11.6 Cudnn 8.4.1
  • onnx 1.12.0

Quick Start

安装yolov8仓库,并下载官方模型。

pip install ultralytics==8.0.5
pip install onnx==1.12.0
# download offical weights(".pt" file)
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt

使用官方命令导出ONNX模型

yolo mode=export model=yolov8n.pt format=onnx dynamic=False

使用本仓库v8_transform.py转换官方的ONNX模型,会自动生成yolov8n.transd.onnx。

python v8_transform.py yolov8n.onnx

将生成的onnx模型复制到tensorrt/bin文件夹下,使用官方trtexec转化onnx模型。FP32预测删除--fp16参数即可

trtexec --onnx=yolov8n.transd.onnx --saveEngine=yolov8n_fp16.trt --fp16

C++

配置OpencvTensorrt环境,具体可参考https://github.com/Monday-Leo/Yolov5_Tensorrt_Win10

打开本仓库的CMakeLists.txt,修改OpencvTensorrt路径,之后cmake。

#change to your own path
##################################################
set(OpenCV_DIR "E:/opencv/build")  
set(TRT_DIR "E:/TensorRT-8.4.3.1")  
##################################################

预测图片zidane.jpg和模型yolov8n_fp16.trt放入exe文件夹,直接运行程序,没有做warmup预测,首次预测时间不准,想要精确计时请自行修改代码做warmup。想要修改模型路径和图片路径请修改主程序。

int main() {
	std::string img_path = "zidane.jpg";
	std::string model_path = "yolov8n_fp16.trt";
	single_inference(img_path,model_path);
	return 0;
}

Python

在刚才的C++工程中右键yolov8,点击属性,修改为动态链接库

将本仓库的python_trt.py复制到dll文件夹下。

设置模型路径,dll路径和想要预测的图片路径,特别注意模型路径需要加b''

det = Detector(model_path=b"./yolov8n_fp16.trt",dll_path="./yolov8.dll")  # b'' is needed
img = cv2.imread("./zidane.jpg")

Reference

https://github.com/ultralytics/ultralytics

https://github.com/shouxieai/infer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.