{"id":23288530,"url":"https://github.com/kernferm/exporting-yolo","last_synced_at":"2025-08-24T14:38:09.729Z","repository":{"id":257532364,"uuid":"858560141","full_name":"KernFerm/exporting-YOLO","owner":"KernFerm","description":"This repository contains scripts and commands for exporting YOLO models to different formats, including TensorRT (.engine) and ONNX (.onnx).","archived":false,"fork":false,"pushed_at":"2024-12-07T02:54:57.000Z","size":724,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-07T03:25:02.744Z","etag":null,"topics":["amd","amd-gpu","engine","exporting","models","nvidia","nvidia-cuda","nvidia-gpu","onnx","python","ultralytics","yolo","yolov5","yolov8"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KernFerm.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-17T05:48:47.000Z","updated_at":"2024-12-07T02:55:00.000Z","dependencies_parsed_at":"2024-11-29T21:32:49.098Z","dependency_job_id":null,"html_url":"https://github.com/KernFerm/exporting-YOLO","commit_stats":null,"previous_names":["kernferm/exporting-yolo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernFerm%2Fexporting-YOLO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernFerm%2Fexporting-YOLO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernFerm%2Fexporting-YOLO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernFerm%2Fexporting-YOLO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KernFerm","download_url":"https://codeload.github.com/KernFerm/exporting-YOLO/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230528046,"owners_count":18240088,"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":["amd","amd-gpu","engine","exporting","models","nvidia","nvidia-cuda","nvidia-gpu","onnx","python","ultralytics","yolo","yolov5","yolov8"],"created_at":"2024-12-20T03:20:34.073Z","updated_at":"2025-08-21T19:31:43.884Z","avatar_url":"https://github.com/KernFerm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/KernFerm/exporting-YOLO/blob/main/Logo/yolo.png\" alt=\"yolo png\" width=\"400\"/\u003e\n\u003c/div\u003e\n\n## Support the Project ⭐\n\nIf you find this project useful, please give it a star! Your support is appreciated and helps keep the project growing. 🌟\n\n- [https://discord.gg/zQbJJgwbUv](https://discord.gg/zQbJJgwbUv)\n\n# YOLO Export Script\n\nThis repository contains scripts and commands for exporting YOLO models to different formats, including TensorRT (`.engine`) and ONNX (`.onnx`).\n\n## Requirements\n\nEnsure you have installed the necessary dependencies to run the export script:\n\n- Python 311 series\n- PyTorch 2.8.0 or higher\n- TorchVision 0.23.0\n- CUDA 12.6\n- ONNX\n- Engine\n- AMD GPU\n- Nvidia GPU\n- `Any **YOLO** Version`\n\n\n## Project Structure\n\n```\n.\n├── .github                           # GitHub configuration files\n│   └── dependabot.yml                # Configuration for Dependabot\n├── Logo                              # Directory for project logo or images\n│   └── yolo.png                      # YOLO logo image\n├── models                            # Directory for model-related files\n│   └── ...                           # (Files related to YOLO models)\n├── ultralytics1                      # YOLO-related utilities and scripts\n│   └── utils                         # Directory for additional utility scripts\n│       └── additional_requirements.txt  # Additional requirement files (YOLO-specific)\n├── utils                             # General utilities and scripts\n│   └── additional_requirements.txt   # Utility and helper functions or scripts\n├── CODE_OF_CONDUCT.md                # Code of conduct for contributors\n├── LICENSE                           # Project license file\n├── README.md                         # Main project README with documentation\n├── SECURITY.md                       # Security policies and guidelines\n├── amd_requirements.txt              # Requirements for AMD GPUs with DirectML\n├── commands-to-export.txt            # Useful commands for exporting YOLO models\n├── export.py                         # Main script to handle YOLO model export\n├── nvidia_requirements.txt           # Requirements for NVIDIA GPUs with CUDA support\n├── update_ultralytics.bat            # Batch script to update Ultralytics' YOLO version or utilities\n```\n\n### For NVIDIA GPUs (CUDA Support)\n\nYou can install the necessary Python packages for NVIDIA GPUs with the following command:\n\n```\npip3 install torch==2.8.0+cu126 torchvision==0.23.0+cu126 torchaudio==2.8.0+cu126 --index-url https://download.pytorch.org/whl/cu126\n```\n\n### Files in the Repository\n\n- **commands-to-export.txt:** A file containing useful commands for exporting your YOLO model.\n- **export.py:** The Python script responsible for handling the export process.\n\n## Exporting YOLO Models (NVIDIA and AMD GPUs)\n\n### Export to TensorRT Engine (For NVIDIA GPUs)\n\nTo export your YOLO model to a TensorRT engine (for NVIDIA GPUs only), use the following command:\n\n```\npython .\\export.py --weights ./\"your_model_path.pt\" --include engine --half --imgsz 320 320 --device 0\n```\n- Replace `\"your_model_path\"` with the path to your YOLO `.pt` file.\n- The `--half` flag enables half-precision inference for faster performance and lower memory usage.\n- `--imgsz 320 320` sets the image size to 320x320 pixels for export.\n- `--device 0` specifies the GPU device ID (use `--device cpu` for CPU-based inference).\n- **Note**: TensorRT is only compatible with **NVIDIA GPUs**.\n\n### Export to ONNX\n\nTo export your YOLO model to ONNX format, use the following command:\n\n```\npython .\\export.py --weights ./\"your_model_path.pt\" --include onnx --half --imgsz 320 320 --device 0\n```\n- Replace `\"your_model_path\"` with your YOLO `.pt` model.\n- The `--half` flag enables half-precision inference (if supported).\n- `--imgsz 320 320` sets the image size to 320x320 pixels.\n\n### Export for AMD GPU\n\nTo export your YOLO model for an AMD GPU, use the following command:\n\n```\npython .\\export.py --weights .\\your_model_path.pt --include onnx --imgsz 320 320\n```\n- Replace `\"your_model_path\"` with the path to your YOLO `.pt` file.\n- This command will export the model in the ONNX format for AMD GPU inference.\n\n## Troubleshooting\n\n- If you encounter issues during export, ensure that your `CUDA`, `cuDNN`, and `TensorRT` versions are compatible with the version of `PyTorch` you are using.\n- For `ONNX` export issues, ensure you have the `correct ONNX version` installed.\n\n\n# 🚀 NVIDIA CUDA Installation Guide\n\n### 1. **Download the NVIDIA CUDA Toolkit 12.6**\n\nFirst, download the CUDA Toolkit 12.6 from the official NVIDIA website:\n\n👉 [Nvidia CUDA Toolkit 12.6 - DOWNLOAD HERE](https://developer.download.nvidia.com/compute/cuda/12.6.0/local_installers/cuda_12.6.0_560.76_windows.exe)\n\n### 2. **Install the CUDA Toolkit**\n\n- After downloading, open the installer (`.exe`) and follow the instructions provided by the installer.\n- Make sure to select the following components during installation:\n  - CUDA Toolkit\n  - CUDA Samples\n  - CUDA Documentation (optional)\n\n### 3. **Verify the Installation**\n\n- After the installation completes, open the `cmd.exe` terminal and run the following command to ensure that CUDA has been installed correctly:\n  ```\n  nvcc --version\n  ```\nThis will display the installed CUDA version.\n\n### **4. Install Cupy**\nRun the following command in your terminal to install Cupy:\n  ```\n  pip install cupy-cuda12x\n  ```\n\n## 5. CUDNN Installation 🧩\nDownload cuDNN (CUDA Deep Neural Network library) from the NVIDIA website:\n\n👉 [Download CUDNN 9-3-0](https://developer.nvidia.com/cudnn-9-3-0-download-archive). (Requires an NVIDIA account – it's free).\n\n## 6. Unzip and Relocate 📁➡️\nOpen the `.zip` cuDNN file and move all the folders/files to the location where the CUDA Toolkit is installed on your machine, typically:\n- RUN THE EXE\n```\nC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\n```\n\n\n## 7. Get TensorRT 10.4 🔽\nDownload [TensorRT 10.4](https://github.com/NVIDIA/TensorRT/archive/refs/tags/v10.4.0.zip).\n\n## 8. Unzip and Relocate 📁➡️\nOpen the `.zip` TensorRT file and move all the folders/files to the CUDA Toolkit folder, typically located at:\n\n```\nC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\n```\n\n## 10. Set Your Environment Variables 🌎\nAdd the following paths to your environment variables:\n- system varaibles \n- edit `PATH`\n- add `NEW`\n- click okay \n\n```\nC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\lib\nC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\libnvvp\nC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\bin\n```\n\n# Setting Up CUDA 12.6 with cuDNN on Windows\n\nOnce you have CUDA 12.6 installed and cuDNN properly configured, you need to set up your environment via `cmd.exe` to ensure that the system uses the correct version of CUDA (especially if multiple CUDA versions are installed).\n\n## Steps to Set Up CUDA 12.6 Using `cmd.exe`\n\n### 1. Set the CUDA Path in `cmd.exe`\n\nYou need to add the CUDA 12.6 binaries to the environment variables in the current `cmd.exe` session.\n\nOpen `cmd.exe` and run the following commands:\n\n```\nset PATH=C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\bin;%PATH%\nset PATH=C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\libnvvp;%PATH%\nset PATH=C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\extras\\CUPTI\\lib64;%PATH%\n```\nThese commands add the CUDA 12.6 binary, lib, and CUPTI paths to your system's current session. Adjust the paths as necessary depending on your installation directory.\n\n2. Verify the CUDA Version\nAfter setting the paths, you can verify that your system is using CUDA 11.8 by running:\n```\nnvcc --version\n```\nThis should display the details of CUDA 12.6. If it shows a different version, check the paths and ensure the proper version is set.\n\n3. **Set the Environment Variables for a Persistent Session**\nIf you want to ensure CUDA 12.6 is used every time you open `cmd.exe`, you can add these paths to your system environment variables permanently:\n\n1. Open `Control Panel` -\u003e `System` -\u003e `Advanced System Settings`.\nClick on `Environment Variables`.\nUnder `System variables`, select `Path` and click `Edit`.\nAdd the following entries at the top of the list:\n```\nC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\bin\nC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\libnvvp\nC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.6\\extras\\CUPTI\\lib64\n```\nThis ensures that CUDA 12.6 is prioritized when running CUDA applications, even on systems with multiple CUDA versions.\n\n4. **Set CUDA Environment Variables for cuDNN**\nIf you're using cuDNN, ensure the `cudnn64_8.dll` is also in your system path:\n```\nset PATH=C:\\tools\\cuda\\bin;%PATH%\n```\nThis should properly set up CUDA 12.6 to be used for your projects via `cmd.exe`.\n\n#### Additional Information\n- Ensure that your GPU drivers are up to date.\n- You can check CUDA compatibility with other software (e.g., PyTorch or TensorFlow) by referring to their documentation for specific versions supported by CUDA 11.8.\n---\n---\n## 🚀 AMD GPU Setup Instructions (DirectML Support)\n\nWhile NVIDIA GPUs utilize CUDA for deep learning, AMD GPUs can be leveraged on Windows using DirectML, a GPU-accelerated backend for machine learning.\n\n### 1. Install PyTorch for AMD GPUs (DirectML)\n\nFor AMD GPUs on Windows, PyTorch supports DirectML as the backend. You can install PyTorch with DirectML using the following command:\n\n```\npip install torch==2.8.0+cpu torchvision==0.23.0+cpu torchaudio==2.8.0+cpu --extra-index-url https://download.pytorch.org/whl/cpu\n```\n\n### 2. Install ONNX Runtime with DirectML\nTo use ONNX with AMD GPUs, install the `onnxruntime-directml` package:\n\n```\npip install onnxruntime-directml\n```\n\n### 3. Verify AMD GPU Support\nTo ensure that your AMD GPU is properly set up, you can verify DirectML support by running the following script:\n\n```\nimport onnxruntime as ort\nprint(ort.get_device())\n```\n\nIf your setup is correct, this should return `\"DML\"`, indicating that ONNX Runtime is using DirectML.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkernferm%2Fexporting-yolo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkernferm%2Fexporting-yolo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkernferm%2Fexporting-yolo/lists"}