{"id":28418863,"url":"https://github.com/engcang/tensorrt_yolov9_ros","last_synced_at":"2025-06-25T21:31:47.112Z","repository":{"id":225372012,"uuid":"765803037","full_name":"engcang/TensorRT_YOLOv9_ROS","owner":"engcang","description":"(ROS, C++) YOLOv9 detection using TensorRT, now supporting TensorRT 10","archived":false,"fork":false,"pushed_at":"2024-05-11T18:59:10.000Z","size":59,"stargazers_count":45,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T19:30:43.031Z","etag":null,"topics":["computer-vision","cpp","object-detection","ros","yolo","yolov9"],"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/engcang.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":"2024-03-01T16:40:30.000Z","updated_at":"2025-05-22T08:23:18.000Z","dependencies_parsed_at":"2024-03-13T18:42:47.945Z","dependency_job_id":null,"html_url":"https://github.com/engcang/TensorRT_YOLOv9_ROS","commit_stats":null,"previous_names":["engcang/tensorrt_yolov9_ros"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/engcang/TensorRT_YOLOv9_ROS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engcang%2FTensorRT_YOLOv9_ROS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engcang%2FTensorRT_YOLOv9_ROS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engcang%2FTensorRT_YOLOv9_ROS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engcang%2FTensorRT_YOLOv9_ROS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/engcang","download_url":"https://codeload.github.com/engcang/TensorRT_YOLOv9_ROS/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engcang%2FTensorRT_YOLOv9_ROS/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261956076,"owners_count":23236008,"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":["computer-vision","cpp","object-detection","ros","yolo","yolov9"],"created_at":"2025-06-04T13:20:33.074Z","updated_at":"2025-06-25T21:31:47.100Z","avatar_url":"https://github.com/engcang.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003ch1 align=\"center\"\u003e\u003cspan\u003eTensorRT-YOLOv9-ROS\u003c/span\u003e\u003c/h1\u003e\n\n+ ROS version of [YOLOv9](https://github.com/WongKinYiu/yolov9) accelerated with [TensorRT](https://github.com/NVIDIA/TensorRT) API\n+ This repository is a merely re-implementation with `ROS` of the:\n  + 👏 [TensorRT-YOLOv9-C++](https://github.com/spacewalk01/TensorRT-YOLOv9), which is based on\n    + [YOLOv9](https://github.com/WongKinYiu/yolov9) - `YOLOv9`: Learning What You Want to Learn Using Programmable Gradient Information.\n    + [TensorRT](https://github.com/NVIDIA/TensorRT/tree/release/8.6/samples) - `TensorRT` samples and api documentation.\n    + [TensorRTx](https://github.com/wang-xinyu/tensorrtx) - Implementation of popular deep learning networks with TensorRT network definition API.\n\nhttps://github.com/engcang/TensorRT_YOLOv9_ROS/assets/34734707/0dff22cc-ec12-45fb-a931-fb0c90181fd7\n\n\u003cbr\u003e\n\n### Known issues / notes\n+ The resolution of image to be trained should be multiplication of 64\n+ [2024-05-12] - **Now supporting `TensorRT` \u003e= 10**\n+ **Check the paths of TensorRT in CMakeLists.txt's line 25, 26**\n\n\u003cbr\u003e\n\n## Dependencies\n+ `ROS` (currently supporting only `ROS1`)\n+ `C++` \u003e= 17\n+ `cmake` \u003e= 3.14\n+ `OpenCV` \u003e= 4.2\n+ `TensorRT`, `CUDA`, `cuDNN`\n  + `.engine` file generated with `TensorRT`\n+ Tested versions:\n  + Desktop with i9-10900k, RTX 3080 - `CUDA` 11.5, `cuDNN` 8.3.2.44, `TensorRT` 8.4.0.6\n\n\u003c/details\u003e\n\u003cbr\u003e\n\n## You may want to:\n\n\u003cdetails\u003e\u003csummary\u003e ■ Unfold here to see how to install CUDA, cuDNN and TensorRT \u003c/summary\u003e\n\n### ● **Note that apt install with deb is preferred to run file and source file build for both of `CUDA` and `cuDNN`**\n+ Download and install `CUDA` following instructions at here - https://developer.nvidia.com/cuda-downloads\n+ Download and install `cuDNN` following instructions at here - https://developer.nvidia.com/cudnn-downloads\n  + If you want, also refer to here - https://docs.nvidia.com/deeplearning/cudnn/installation/linux.html#\n+ Set up environmental paths\n```bash\ngedit ~/.bashrc\n*** Type and save below, CUDA_PATH should be like /usr/local/cuda-11.5, depending on your version ***\nexport PATH=CUDA_PATH/bin:$PATH \nexport LD_LIBRARY_PATH=CUDA_PATH/lib64:$LD_LIBRARY_PATH\n\n. ~/.bashrc\n\ngedit ~/.profile\n*** Type and save below, CUDA_PATH should be like /usr/local/cuda-11.5, depending on your version ***\nexport PATH=CUDA_PATH/bin:$PATH \nexport LD_LIBRARY_PATH=CUDA_PATH/lib64:$LD_LIBRARY_PATH\n\n. ~/.profile\n```\n+ Verify, if installed properly\n```bash\n# Verify\ndpkg -l | grep cuda\ndpkg -l | grep cudnn\nnvcc --version\n```\n\n\u003cbr\u003e\n\n### ● **Note that apt install with deb is preferred to other methods for `TensorRT`**\n+ Download `TensorRT` at here - https://developer.nvidia.com/tensorrt-download\n+ Follow the instructions at here - https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-debian\n  + Installing full packages is recommended, which means:\n  ```bash\n  sudo apt install tensorrt\n  sudo apt install python3-libnvinfer-dev\n  sudo apt install onnx-graphsurgeon\n  ```\n\n\u003cbr\u003e\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e ■ Unfold here to see how to train custom data / generate TensorRT engine file with safe Python3 virtual environment \u003c/summary\u003e\n\n\u003cbr\u003e\n\n### ● Common step for training / engine file\n0. Make sure that you have installed all dependencies properly.\n  + Particularly, you should install full packages of `TensorRT`: `tensorrt`, `python3-libnvinfer-dev`, `onnx-graphsurgeon`\n1. Install and make `Python3` virtual env\n```bash\npython3 -m pip install virtualenv virtualenvwrapper\ncd \u003cPATH YOU WANT TO SAVE VIRTUAL ENVIRONMENT\u003e\nvirtualenv -p python3 \u003cNAME YOU WANT\u003e\n\n*** Now you can activate with\nsource \u003cPATH YOU SAVED\u003e/\u003cNAME YOU WANT\u003e/bin/activate\n\n*** Deactivate with\ndeactivate\n```\n2. (While virtual env being activated), clone `YOLOv9` repo and install requirements\n```bash\ngit clone https://github.com/WongKinYiu/yolov9\ncd yolov9\npip install -r requirements.txt\n```\n\n\u003cbr\u003e\n\n### ● Converting .pt to .onnx, and then .engine\n0. (While virtual env being activated)\n1. Get trained `YOLOv9` weight file as `.pt` by training your own data or downloading the pre-trained model at here - https://github.com/WongKinYiu/yolov9/releases\n2. Reparameterize the `.pt` file (saving computation, memory, and size by trimming unnecessary parts for inference but necessary only for training)\n```bash\ncd yolov9 # cloned at above step\nwget https://raw.githubusercontent.com/engcang/TensorRT_YOLOv9_ROS/main/reparameterize.py\n\n*** Change the number of classes in the reparameterize.py in line 8 (nc=80)\npython reparameterize.py yolov9-c.pt yolov9-c-reparameterized.pt # input.pt output.put\n```\n3. Export `.pt` file as `.onnx`\n```bash\npython export.py --weights yolov9-c-reparameterized.pt --include onnx\n```\n4. Then `.onnx` to `.engine`\n```bash\n/usr/src/tensorrt/bin/trtexec --onnx=yolov9-c-reparameterized.onnx --saveEngine=yolov9-c.engine\n#for faster, less accurate\n/usr/src/tensorrt/bin/trtexec --onnx=yolov9-c-reparameterized.onnx --saveEngine=yolov9-c-fp16.engine --fp16\n#not recommended - much faster, much less accurate\n/usr/src/tensorrt/bin/trtexec --onnx=yolov9-c-reparameterized.onnx --saveEngine=yolov9-c-int8.engine --int8\n```\n\n\u003cbr\u003e\n\n### ● Training your own data\n0. (While virtual env being activated) + `YOLOv9` is cloned already, requirements are installed already\n1. Prepare data and labels in `YOLO format`.\n  + You may want to use this - https://github.com/AlexeyAB/Yolo_mark\n  + Or `roboflow` - https://docs.ultralytics.com/yolov5/tutorials/roboflow_datasets_integration/\n2. Make proper `data.yaml` file by copying and editing `yolov9/data/coco.yaml` as follows:\n```yaml\npath: training  # dataset root dir (relative from train.py file)\ntrain: train    # train images folder (relative to 'path')\nval: val        # val images folder (relative to 'path')\ntest: test      # test images folder (relative to 'path')\n\n# Classes\nnames:\n  0: Transmission tower\n  1: Insulator\n```\n3. Make proper `yolov9.yaml` file by copying and editing `yolov9/models/detect/yolov9.yaml or yolov9-c, yolov9-e, etc.`\n```yaml\n# parameters\nnc: 2  # number of classes\ndepth_multiple: 1.0  # model depth multiple\nwidth_multiple: 1.0  # layer channel multiple\n#activation: nn.LeakyReLU(0.1)\n#activation: nn.ReLU()\n\n# anchors\nanchors: 3\n\n# YOLOv9 backbone\nbackbone:\n  [\n   [-1, 1, Silence, []],  \n   \n   # conv down\n   [-1, 1, Conv, [64, 3, 2]],  # 1-P1/2\n   \n   ...\n  ]\n```\n4. Edit learning parameters by editing `yolov9/data/hyps/hyp.scratch-high.yaml`\n5. **Put all of files properly in the `yolov9` folder. If outside the `yolov9` folder, error occurs!**\n```\nyolov9\n│  ...\n├─ data # Reference folder\n│  ├─ coco.yaml\n│  └─ hyps\n│     └─ hyp.scratch-high.yaml\n├─ models # Reference folder\n│  ...\n│  ├─ detect\n│  ...\n│  │  ├─ yolov9-c.yaml\n│  │  ├─ yolov9-e.yaml\n│  │  └─ yolov9.yaml\n├─ runs # Output saved folder\n│  ...\n├─ train.py # Using this file for GELAN\n├─ train_dual.py # Using this file for YOLOv9\n├─ training # Using this folder\n│  ├─ yolov9-c.pt\n│  ├─ data.yaml\n│  ├─ yolov9.yaml\n│  ├─ test\n│  │  ├─ 02001.jpg\n│  │  ├─ 02001.txt\n│  │  └─ ...\n│  ├─ train\n│  │  ├─ 00001.jpg\n│  │  ├─ 00001.txt\n│  │  └─ ...\n│  ├─ val\n│  │  ├─ 04000.jpg\n│  │  ├─ 04000.txt\n│  │  └─ ...\n└─ └─ ...\n```\n6. Train\n```bash\ncd yolov9\n\n*** Using pretrained model (yolov9-c.pt here), fine-tuning:\npython train_dual.py --batch-size 4 --epochs 100 --img 640 --device 0 --close-mosaic 15 \\\n--data training/data.yaml --weights training/yolov9-c.pt --cfg training/yolov9.yaml --hyp data/hyps/hyp.scratch-high.yaml\n\n*** From the scratch:\npython train_dual.py --batch-size 4 --epochs 100 --img 640 --device 0 --close-mosaic 15 \\\n--data training/data.yaml --weights '' --cfg training/yolov9.yaml --hyp data/hyps/hyp.scratch-high.yaml\n```\n\n\u003cbr\u003e\n\n### ● Trouble shooting for training\n0. (While virtual env being activated)\n1. `AttributeError: 'FreeTypeFont' object has no attribute 'getsize'`\n  + This is because installed Pillow version is too recent.\n  + Solve with `pip install Pillow==9.5.0`\n2. Getting `Killed` and does not train\n  + Lack of memory, reduce `batch-size` a lot\n3. `AssertionError: Invalid CUDA '--device 0' requested, use '--device cpu' or pass valid CUDA device(s)`\n  + This is because installed `torch` and `torchvision` are not `CUDA` versions.\n  + Solve as:\n  ```bash\n  *** Check the version at https://download.pytorch.org/whl/torch_stable.html\n  *** torch \u003e= 1.7.0, torchvision\u003e=0.8.1\n\n  pip install torch==1.11.0+cu115 torchvision==0.12.0+cu115 -f https://download.pytorch.org/whl/torch_stable.html\n  ```\n4. `RuntimeError: CUDA out of memory. Tried to allocate 50.00 MiB (GPU 0; 9.76 GiB total capacity; 6.68 GiB already allocated; 45.00 MiB free; 6.82 GiB reserved in total by PyTorch) If reserved memory is \u003e\u003e allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF`\n  + Lack of memory, reduce `batch-size` a lot\n\n\u003c/details\u003e\n\n\u003cbr\u003e\n\n## How to install\n+ Make sure you have installed all of dependencies properly\n+ Clone this repository (**Check the paths of TensorRT in CMakeLists.txt**) and build\n\n```bash\ncd ~/\u003cyour_workspace\u003e/src\ngit clone https://github.com/engcang/TensorRT_YOLOv9_ROS.git\n\n*** Check the paths of TensorRT in CMakeLists.txt ***\ncd ~/\u003cyour_workspace\u003e\ncatkin build -DCMAKE_BUILD_TYPE=Release\n```\n\n\u003cbr\u003e\n\n## How to use\n+ Check the paths of files, params in `config/config.yaml`\n+ Then run\n\n```bash\nroslaunch tensorrt_yolov9_ros run.launch\n```\n\n\u003cbr\u003e\n\n## You may also want to see\n+ [tkdnn-ros](https://github.com/engcang/tkdnn-ros): `YOLO` (v3, v4, v7) accelerated with `TensorRT` using `tkdnn`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengcang%2Ftensorrt_yolov9_ros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fengcang%2Ftensorrt_yolov9_ros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengcang%2Ftensorrt_yolov9_ros/lists"}