Code Monkey home page Code Monkey logo

yolov5_deepsort_tensorrt's Introduction

yolov5_deepsort_tensorrt

Update!

Introduction

This repo uses YOLOv5 and DeepSORT to implement object tracking algorithm. Also using TensorRTX to convert model to engine, and deploying all code on the NVIDIA Xavier with TensorRT further.

NVIDIA Jetson Xavier NX and the X86 architecture works all be ok.

Environments

  1. the X86 architecture:
    • Ubuntu20.04 or 18.04 with CUDA 10.0 and cuDNN 7.6.5
    • TensorRT 7.0.0.1
    • PyTorch 1.7.1_cu11.0, TorchVision 0.8.2+cu110, TorchAudio 0.7.2
    • OpenCV-Python 4.2
    • pycuda 2021.1
  2. the NVIDIA embedded system:
    • Ubuntu18.04 with CUDA 10.2 and cuDNN 8.0.0
    • TensorRT 7.1.3.0
    • PyTorch 1.8.0 and TorchVision 0.9.0
    • OpenCV-Python 4.1.1
    • pycuda 2020.1

Speed

The following data are tested in the case of single target in the picture. the X86 architecture with GTX 2080Ti :

Networks Without TensorRT With TensorRT
YOLOV5 14ms / 71FPS / 1239M 10ms / 100FPS / 2801M
YOLOV5 + DeepSort 23ms / 43FPS / 1276M 12ms / 82FPS / 1712M

NVIDIA Jetson Xavier NX:

Networks Without TensorRT With TensorRT
YOLOV5 \ 43ms / 23FPS / 1397M
YOLOV5 + DeepSort \ 63ms / 15FPS / 2431M

Inference

  1. Clone this repo

    git clone https://github.com/cong/yolov5_deepsort_tensorrt.git
  2. Install the requirements

    pip install -r requirements.txt
  3. Run

    python demo_trt.py
    

    result.gif test.gif

Convert

Convert PyTorch yolov5 weights to TensorRT engine.

Notice: this repo uses YOLOv5 version 4.0 , so TensorRTX should uses version yolov5-v4.0 !

  1. generate ***.wts from PyTorch with ***.pt.

    git clone -b v4.0 https://github.com/ultralytics/yolov5.git
    git clone -b v4.0 https://github.com/wang-xinyu/tensorrtx.git
    # download https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
    cp {tensorrtx}/yolov5/gen_wts.py {ultralytics}/yolov5
    cd {ultralytics}/yolov5
    python gen_wts.py yolov5s.pt
    # a file 'yolov5s.wts' will be generated.
  2. build t{tensorrtx}/yolov5 and generate ***.engine

    cd {tensorrtx}/yolov5/
    # update CLASS_NUM in yololayer.h if your model is trained on custom dataset
    mkdir build
    cd build
    cp {ultralytics}/yolov5/yolov5s.wts {tensorrtx}/yolov5/build
    cmake ..
    make
    # serialize model to plan file
    sudo ./yolov5 -s [.wts] [.engine] [s/m/l/x/s6/m6/l6/x6 or c/c6 gd gw]
    # deserialize and run inference, the images in [image folder] will be processed.
    sudo ./yolov5 -d [.engine] [image folder]
    # For example yolov5s
    sudo ./yolov5 -s yolov5s.wts yolov5s.engine s
    sudo ./yolov5 -d yolov5s.engine ../samples
    # For example Custom model with depth_multiple=0.17, width_multiple=0.25 in yolov5.yaml
    sudo ./yolov5 -s yolov5_custom.wts yolov5.engine c 0.17 0.25
    sudo ./yolov5 -d yolov5.engine ../samples
  3. Once the images generated, as follows. _zidane.jpg and _bus.jpg, convert completed!

Convert PyTorch DeepSORT weights to TensorRT engine.

  1. generate ***.onnx from PyTorch with ***.pt.

    git clone https://github.com/ZQPei/deep_sort_pytorch
    git clone https://github.com/GesilaA/deepsort_tensorrt.git
    # 
    cp {GesilaA}/deepsort_tensorrt/exportOnnx.py {ZQPei}/deep_sort_pytorch
    cd {ZQPei}/deep_sort_pytorch
    python exportOnnx.py
    # a file 'deepsort.onnx' will be generated.
    cp {ZQPei}/deep_sort_pytorch/deepsort.onnx {GesilaA}/deepsort_tensorrt
  2. build {GesilaA}/deepsort_tensorrt and generate ***.engine

    cd {GesilaA}/deepsort_tensorrt
    # 
    mkdir build
    cd build
    cmake ..
    make
    # serialize model to plan file
    ./onnx2engine ../resources/deepsort.onnx ../resources/deepsort.engine
    # test
    ./demo ../resources/deepsort.engine ../resources/track.txt

Customize

  1. Training your own model.
  2. Convert your own model to engine(TensorRTX's version must same as YOLOV5's version).
  3. Replace the ***.engine and libmyplugins.so file.

Optional setting

  • Your likes are my motivation to update the project, if you feel that it is helpful to you, please give me a star. Thx! :)
  • For more information you can visit the Blog.

yolov5_deepsort_tensorrt's People

Contributors

mhammada avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yolov5_deepsort_tensorrt's Issues

Deep SORT error!

err
Hello guys, I am facing this error please help me solve it, it seems that this error is caused by deep sort because the yolov5 engine doesn't give any errors and I can detect with yolov5.engine but the tracker give this error.

Those are the versions of the packages installed on my ubuntu 18 device:
vers

libmyplugins.so在哪?

作者,您好,我就是单纯测试一下效果,libmyplugins.so这个文件从哪里找?

请问有人用pyinstaller 生成可执行程序吗?遇到pycuda问题

[TensorRT] ERROR: /home/jenkins/workspace/TensorRT/helpers/rel-7.1/L1_Nightly_Internal/build/source/rtSafe/resources.h (460) - Cuda Error in loadKernel: 3 (initialization error)
[TensorRT] ERROR: INVALID_STATE: std::exception
[TensorRT] ERROR: INVALID_CONFIG: Deserialize the cuda engine failed.
Traceback (most recent call last):
File "demo_trt.py", line 60, in
File "demo_trt.py", line 20, in detect
File "detector_trt.py", line 86, in init
AttributeError: 'NoneType' object has no attribute 'create_execution_context'
[16873] Failed to execute script 'demo_trt' due to unhandled exception!

PyCUDA ERROR: The context stack was not empty upon module cleanup.

A context was still active when the context stack was being
cleaned up. At this point in our execution, CUDA may already
have been deinitialized, so there is no way we can finish
cleanly. The program will be aborted now.
Use Context.pop() to avoid this problem.

已放弃 (核心已转储)

[TensorRT] ERROR: coreReadArchive.cpp (38) - Serialization Error in verifyHeader: 0 (Version tag does not match) [TensorRT] ERROR: INVALID_STATE: std::exception [TensorRT] ERROR: INVALID_CONFIG: Deserialize the cuda engine failed. Traceback (most recent call last): File "demo_trt.py", line 15, in <module> import tracker_trt AttributeError: 'NoneType' object has no attribute 'create_execution_context' ------------------------------------------------------------------- PyCUDA ERROR: The context stack was not empty upon module cleanup. ------------------------------------------------------------------- A context was still active when the context stack was being cleaned up. At this point in our execution, CUDA may already have been deinitialized, so there is no way we can finish cleanly. The program will be aborted now. Use Context.pop() to avoid this problem. ---------------------------------------------------

Im trying build the application in jetson TX2
Tried Jetpack - 4.4.1 and 4.4
Tensorrt- 7.3.1.0
torch- 1.8
torchvision- 0.9.0

Used v4.0 of yolov5 and tensorrtx git
and generated TRT engine
But still getting this error which says there is mismatch in Tenssorrt version

I don't understand, I have met all the environment requirements you have mentioned but still getting this error

Can you please help on this?

cannot open shared object file: No such file or directory

Traceback (most recent call last):
File "demo_trt.py", line 58, in
ctypes.CDLL(PLUGIN_LIBRARY)
File "/usr/lib/python3.6/ctypes/init.py", line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: weights/libmyplugins.so: cannot open shared object file: No such file or directory

pycuda._driver.LogicError: cuDeviceGet failed: initialization error

when i run demo_trt.py i got this error
detector = Detector(engine_file_path)
File "/home/radar/Desktop/yolotrt/yolov5_deepsort_tensorrt/detector_trt.py", line 43, in init
self.cfx = cuda.Device(0).make_context()
pycuda._driver.LogicError: cuDeviceGet failed: initialization error

deepsort.engine convert problem

不好意思,我在按照作者的指示轉換deepsort的時候發現他沒法直接轉換,一直回報modulenotfounderror: no module named 'fastreid'
請問有人遇到相同的問題嗎

deepsort加速问题

作者你好,您的代码部署到nx上了,但速度大概就是2~3FPS,请问您deepsort部分有加速吗?

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.