{"id":13643962,"url":"https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt","last_synced_at":"2025-04-21T06:32:17.664Z","repository":{"id":37707557,"uuid":"403797451","full_name":"RichardoMrMu/yolov5-deepsort-tensorrt","owner":"RichardoMrMu","description":"A c++ implementation of yolov5 and deepsort","archived":false,"fork":false,"pushed_at":"2024-05-09T02:28:25.000Z","size":3296,"stargazers_count":444,"open_issues_count":20,"forks_count":104,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-11-09T16:43:24.262Z","etag":null,"topics":["camera","class","deepsort","detection","head","jetson-nano","jetson-xavier","jetson-xavier-nx","nvidia","tensorrt","yolov5"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RichardoMrMu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-07T00:57:41.000Z","updated_at":"2024-11-05T15:29:16.000Z","dependencies_parsed_at":"2024-11-09T16:32:37.890Z","dependency_job_id":"22d08edf-4422-45e5-a9a0-69a26a0f0e5c","html_url":"https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichardoMrMu%2Fyolov5-deepsort-tensorrt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichardoMrMu%2Fyolov5-deepsort-tensorrt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichardoMrMu%2Fyolov5-deepsort-tensorrt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichardoMrMu%2Fyolov5-deepsort-tensorrt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RichardoMrMu","download_url":"https://codeload.github.com/RichardoMrMu/yolov5-deepsort-tensorrt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250008234,"owners_count":21359951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["camera","class","deepsort","detection","head","jetson-nano","jetson-xavier","jetson-xavier-nx","nvidia","tensorrt","yolov5"],"created_at":"2024-08-02T01:01:55.415Z","updated_at":"2025-04-21T06:32:17.657Z","avatar_url":"https://github.com/RichardoMrMu.png","language":"C++","funding_links":[],"categories":["Object Detection Applications"],"sub_categories":[],"readme":"# A C++ implementation of Yolov5 and Deepsort in Jetson Xavier nx and Jetson nano\n[![MIT License](https://img.shields.io/badge/license-MIT-green)](https://opensource.org/licenses/MIT)\n[![GitHub stars](https://img.shields.io/github/stars/RichardoMrMu/yolov5-deepsort-tensorrt.svg?style=flat-square\u0026logo=github\u0026label=Stars\u0026logoColor=white)](https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt)\n\nThis repository uses yolov5 and deepsort to follow human heads which can run in Jetson Xavier nx and Jetson nano. \nIn Jetson Xavier Nx, it can achieve 10 FPS when images contain heads about 70+(you can try python version, when you use python version, you can find it very slow in Jetson Xavier nx , and Deepsort can cost nearly 1s).\n\n\u003cimg src=\"assets/yolosort.gif\" \u003e\n\nThanks for [B.Q Long](https://github.com/lbq779660843), offer the windows cmakelists.txt. If you want run this rep in windows, you can use [CMakeLists_deepsort-tensorrt_win10.txt](https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt/blob/main/CMakeLists_deepsort-tensorrt_win10.txt) and [CMakeLists_yolov5-deepsort-tensorrt_win10.txt](https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt/blob/main/CMakeLists_yolov5-deepsort-tensorrt_win10.txt). \n\nYou can see video play in [BILIBILI](https://www.bilibili.com/video/BV1nR4y1H7sR/), or [YOUTUBE](https://www.youtube.com/watch?v=29vEi-7mEic) and [YOUTUBE](https://youtu.be/mVq3pWNjb3E).\n\n## Requirement\n1. Jetson nano or Jetson Xavier nx\n2. Jetpack 4.5.1\n3. python3 with default(jetson nano or jetson xavier nx has default python3 with tensorrt 7.1.3.0 )\n4. tensorrt 7.1.3.0\n5. torch 1.8.0\n6. torchvision 0.9.0\n7. torch2trt 0.3.0\n8. onnx 1.4.1\n9. opencv-python 4.5.3.56\n10. protobuf 3.17.3\n11. scipy 1.5.4\n\n\nif you have problem in this project, you can see this [artical](https://blog.csdn.net/weixin_42264234/article/details/120152117).\n\n## Comming soon\n- [ ] Int8 .\n- [ ] IOU Tracking.\n- [ ] Faster and use less memory.\n## Speed\n\nWhole process time from read image to finished deepsort (include every img preprocess and postprocess)\nand attention!!! the number of deepsort tracking is 70+, not single or 10-20 persons, is 70+. And all results can get in Jetson Xavier nx.\n| Backbone        | before TensorRT without tracking |before TensorRT with tracking |TensortRT(detection)| TensorRT(detection + tracking) | FPS(detection + tracking) |\n| :-------------- | --------------- | ------------------ |--------------|------------------------------ | ------------------------- |\n| Yolov5s_416      | 100ms           | 0.9s|10-15ms|100-150ms                          | 8 ~ 9                   |\n| Yolov5s-640 | 120ms             | 1s|18-20ms|100-150ms                      | 8 ~ 9                     |\n\n------\n\n## Build and Run\n\n```shell\ngit clone https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt.git\ncd yolov5-deepsort-tensorrt\n// before you cmake and make, please change ./src/main.cpp char* yolo_engine = \"\"; char* sort_engine = \"\"; to your own path\nmkdir build \ncmake ..\nmake \n```\nif you meet some errors in cmake and make, please see this [artical](https://blog.csdn.net/weixin_42264234/article/details/120152117) or see Attention.\n\n## DataSet\nIf you need to train your own model with head detection, you can use this [SCUT-HEAD](https://github.com/HCIILAB/SCUT-HEAD-Dataset-Release), this dataset has bbox with head and can download freely.\n\n## Model\nYou need two model, one is yolov5 model, for detection, generating from [tensorrtx](https://github.com/wang-xinyu/tensorrtx). And the other is deepsort model, for tracking. You should generate the model the same way.\n### Generate yolov5 model\nFor yolov5 detection model, I choose yolov5s, and choose `yolov5s.pt-\u003eyolov5s.wts-\u003eyolov5s.engine`\nNote that, used models can get from [yolov5](https://github.com/ultralytics/yolov5) and [deepsort](https://github.com/ZQPei/deep_sort_pytorch), and if you need to use your own model, you can follow the `Run Your Custom Model`.\nYou can also see [tensorrtx official readme](https://github.com/wang-xinyu/tensorrtx/tree/master/yolov5)\nThe following is deepsort.onnx and deesort.engine files, you can find in baiduyun and [https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt/releases/tag/yolosort](https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt/releases/tag/yolosort)\n| Model| Url |\n| :-------------- | --------------- |\n| 百度云 | [BaiduYun url](https://pan.baidu.com/s/1vpQFsD346lP64O1nhOilkw ) passwd:`z68e`| \n\n1. Get yolov5 repository\n\n\nNote that, here uses the official pertained model.And I use yolov5-5, v5.0. So if you train your own model, please be sure your yolov5 code is v5.0.\n\n```shell\ngit clone -b v5.0 https://github.com/ultralytics/yolov5.git\ncd yolov5\nmkdir weights\ncd weights\n// download https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt\nwget https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt\n\n```\n\n2. Get tensorrtx.\n\nFor yolov5 v5.0, download .pt from [yolov5 release v5.0](https://github.com/ultralytics/yolov5/releases/tag/v5.0), `git clone -b v5.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v5.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v5.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v5.0/yolov5).\n\n\n3. Get xxx.wst model\n\n```shell\ncp {tensorrtx}/yolov5/gen_wts.py {ultralytics}/yolov5/\ncd yolov5 \npython3 gen_wts.py -w ./weights/yolov5s.pt -o ./weights/yolov5s.wts\n// a file 'yolov5s.wts' will be generated.\n```\nYou can get yolov5s.wts model in `yolov5/weights/`\n\n4. Build tensorrtx/yolov5 and get tensorrt engine\n\n```shell \ncd tensorrtx/yolov5\n// update CLASS_NUM in yololayer.h if your model is trained on custom dataset\nmkdir build\ncd build\ncp {ultralytics}/yolov5/yolov5s.wts {tensorrtx}/yolov5/build\ncmake ..\nmake\n// yolov5s\nsudo ./yolov5 -s yolov5s.wts yolov5s.engine s\n// test your engine file\nsudo ./yolov5 -d yolov5s.engine ../samples\n```\nThen you get the yolov5s.engine, and you can put `yolov5s.engine` in My project. For example\n\n```shell\ncd {yolov5-deepsort-tensorrt}\nmkdir resources\ncp {tensorrtx}/yolov5/build/yolov5s.engine {yolov5-deepsort-tensorrt}/resources\n```\n\n5. Get deepsort engine file\nYou can get deepsort pretrained model in this [drive url](https://drive.google.com/drive/folders/1xhG0kRH1EX5B9_Iz8gQJb7UNnn_riXi6)\nand ckpt.t7 is ok.\n```shell\ngit clone https://github.com/RichardoMrMu/deepsort-tensorrt.git\n// 根据github的说明\ncp {deepsort-tensorrt}/exportOnnx.py {deep_sort_pytorch}/\npython3 exportOnnx.py\nmv {deep_sort_pytorch}/deepsort.onnx {deepsort-tensorrt}/resources\ncd {deepsort-tensorrt}\nmkdir build\ncd build\ncmake ..\nmake \n./onnx2engine ../resources/deepsort.onnx ../resources/deepsort.engine\n// test\n./demo ../resource/deepsort.engine ../resources/track.txt\n```\nAfter all 5 step, you can get the yolov5s.engine and deepsort.engine.\n\nYou may face some problems in getting yolov5s.engine and deepsort.engine, you can upload your issue in github or [csdn artical](https://blog.csdn.net/weixin_42264234/article/details/120152117).\n\u003cdetails\u003e\n\u003csummary\u003eDifferent versions of yolov5\u003c/summary\u003e\n\nCurrently, tensorrt support yolov5 v1.0(yolov5s only), v2.0, v3.0, v3.1, v4.0 and v5.0.\n\n- For yolov5 v5.0, download .pt from [yolov5 release v5.0](https://github.com/ultralytics/yolov5/releases/tag/v5.0), `git clone -b v5.0 https://github.com/ultralytics/yolov5.git` and `git clone https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in current page.\n- For yolov5 v4.0, download .pt from [yolov5 release v4.0](https://github.com/ultralytics/yolov5/releases/tag/v4.0), `git clone -b v4.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v4.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v4.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v4.0/yolov5).\n- For yolov5 v3.1, download .pt from [yolov5 release v3.1](https://github.com/ultralytics/yolov5/releases/tag/v3.1), `git clone -b v3.1 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v3.1 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v3.1](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v3.1/yolov5).\n- For yolov5 v3.0, download .pt from [yolov5 release v3.0](https://github.com/ultralytics/yolov5/releases/tag/v3.0), `git clone -b v3.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v3.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v3.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v3.0/yolov5).\n- For yolov5 v2.0, download .pt from [yolov5 release v2.0](https://github.com/ultralytics/yolov5/releases/tag/v2.0), `git clone -b v2.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v2.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v2.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v2.0/yolov5).\n- For yolov5 v1.0, download .pt from [yolov5 release v1.0](https://github.com/ultralytics/yolov5/releases/tag/v1.0), `git clone -b v1.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v1.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v1.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v1.0/yolov5).\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eConfig\u003c/summary\u003e\n\n- Choose the model s/m/l/x/s6/m6/l6/x6 from command line arguments.\n- Input shape defined in yololayer.h\n- Number of classes defined in yololayer.h, **DO NOT FORGET TO ADAPT THIS, If using your own model**\n- INT8/FP16/FP32 can be selected by the macro in yolov5.cpp, **INT8 need more steps, pls follow `How to Run` first and then go the `INT8 Quantization` below**\n- GPU id can be selected by the macro in yolov5.cpp\n- NMS thresh in yolov5.cpp\n- BBox confidence thresh in yolov5.cpp\n- Batch size in yolov5.cpp\n\u003c/details\u003e\n\n## Run Your Custom Model\nYou may need train your own model and transfer your trained-model to tensorRT. So you can follow the following steps.\n1. Train Custom Model\nYou can follow the [official wiki](https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data\n) to train your own model on your dataset. For example, I choose yolov5-s to train my model.\n2. Transfer Custom Model\nJust like [tensorRT official guideline](https://github.com/wang-xinyu/tensorrtx/edit/master/yolov5/).When your follow ` Generate yolov5 model` to get yolov5 and tensorrt rep, next step is to transfer your pytorch model to tensorrt.\nBefore this, you need to change yololayer.h file 20,21 and 22 line(CLASS_NUM，INPUT_H,INPUT_W) to your own parameters.\n\n```shell\n// before \nstatic constexpr int CLASS_NUM = 80; // 20\nstatic constexpr int INPUT_H = 640;  // 21  yolov5's input height and width must be divisible by 32.\nstatic constexpr int INPUT_W = 640; // 22\n\n// after \n// if your model is 2 classfication and image size is 416*416\nstatic constexpr int CLASS_NUM = 2; // 20\nstatic constexpr int INPUT_H = 416;  // 21  yolov5's input height and width must be divisible by 32.\nstatic constexpr int INPUT_W = 416; // 22\n```\n\n```shell\ncd {tensorrtx}/yolov5/\n// update CLASS_NUM in yololayer.h if your model is trained on custom dataset\n\nmkdir build\ncd build\ncp {ultralytics}/yolov5/yolov5s.wts {tensorrtx}/yolov5/build\ncmake ..\nmake\nsudo ./yolov5 -s [.wts] [.engine] [s/m/l/x/s6/m6/l6/x6 or c/c6 gd gw]  // serialize model to plan file\nsudo ./yolov5 -d [.engine] [image folder]  // deserialize and run inference, the images in [image folder] will be processed.\n// For example yolov5s\nsudo ./yolov5 -s yolov5s.wts yolov5s.engine s\nsudo ./yolov5 -d yolov5s.engine ../samples\n// For example Custom model with depth_multiple=0.17, width_multiple=0.25 in yolov5.yaml\nsudo ./yolov5 -s yolov5_custom.wts yolov5.engine c 0.17 0.25\nsudo ./yolov5 -d yolov5.engine ../samples\n```\n\nIn this way, you can get your own tensorrt yolov5 model. Enjoy it!\n\n# Other Project\n- [yolov5-deepsort-tensorrt](https://github.com/RichardoMrMu/yolov5-deepsort-tensorrt)\n- [facial-emotion-recognition](https://github.com/RichardoMrMu/facial-emotion-recognition)\n- [yolov5-fire-smoke-detect-python](https://github.com/RichardoMrMu/yolov5-fire-smoke-detect-python)\n- [yolov5-helmet-detection](https://github.com/RichardoMrMu/yolov5-helmet-detection)\n- [yolov5-fire-smoke-detect](https://github.com/RichardoMrMu/yolov5-fire-smoke-detect)\n- [gazecapture-web gaze estimation](https://github.com/RichardoMrMu/gazecapture-web)\n- [yolov5-helmet-detection-python](https://github.com/RichardoMrMu/yolov5-helmet-detection-python)\n- [yolov5-reflective-clothes-detect-python](https://github.com/RichardoMrMu/yolov5-reflective-clothes-detect-python)\n- [yolov5-reflective-clothes-detect](https://github.com/RichardoMrMu/yolov5-reflective-clothes-detect)\n- [yolov5-smoking-detect](https://github.com/RichardoMrMu/yolov5-smoking-detect)\n- [yolov5-mask-detect](https://github.com/RichardoMrMu/yolov5-mask-detect)\n- [yolov5-mask-detection-python](https://github.com/RichardoMrMu/yolov5-mask-detection-python)\n- [yolov5-smoke-detection-python](https://github.com/RichardoMrMu/yolov5-smoke-detection-python)\n- [deepsort-tensorrt](https://github.com/RichardoMrMu/deepsort-tensorrt)\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRichardoMrMu%2Fyolov5-deepsort-tensorrt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRichardoMrMu%2Fyolov5-deepsort-tensorrt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRichardoMrMu%2Fyolov5-deepsort-tensorrt/lists"}