├── .dockerignore ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── config.yml │ ├── feature-request.yml │ └── question.yml └── workflows │ ├── ci-testing.yml │ ├── cla.yml │ ├── docker.yml │ ├── format.yml │ ├── links.yml │ ├── merge-main-into-prs.yml │ └── stale.yml ├── .gitignore ├── CITATION.cff ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── README.zh-CN.md ├── benchmarks.py ├── classify ├── predict.py ├── train.py ├── tutorial.ipynb └── val.py ├── data ├── Argoverse.yaml ├── GlobalWheat2020.yaml ├── ImageNet.yaml ├── SKU-110K.yaml ├── VisDrone.yaml ├── coco.yaml ├── coco128-seg.yaml ├── coco128.yaml ├── hyps │ ├── hyp.Objects365.yaml │ ├── hyp.VOC.yaml │ ├── hyp.no-augmentation.yaml │ ├── hyp.scratch-high.yaml │ ├── hyp.scratch-low.yaml │ └── hyp.scratch-med.yaml ├── images │ ├── bus.jpg │ └── zidane.jpg ├── objects365.yaml ├── scripts │ ├── download_weights.sh │ ├── get_coco.sh │ ├── get_coco128.sh │ └── get_imagenet.sh ├── voc.yaml └── xView.yaml ├── detect.py ├── export.py ├── hubconf.py ├── models ├── __init__.py ├── common.py ├── experimental.py ├── hub │ ├── anchors.yaml │ ├── yolov5-bifpn.yaml │ ├── yolov5-fpn.yaml │ ├── yolov5-p2.yaml │ ├── yolov5-p34.yaml │ ├── yolov5-p6.yaml │ ├── yolov5-p7.yaml │ ├── yolov5-panet.yaml │ ├── yolov5l6.yaml │ ├── yolov5m6.yaml │ ├── yolov5n6.yaml │ ├── yolov5s-LeakyReLU.yaml │ ├── yolov5s-ghost.yaml │ ├── yolov5s-transformer.yaml │ ├── yolov5s6.yaml │ └── yolov5x6.yaml ├── segment │ ├── yolov5l-seg.yaml │ ├── yolov5m-seg.yaml │ ├── yolov5n-seg.yaml │ ├── yolov5s-seg.yaml │ └── yolov5x-seg.yaml ├── tf.py ├── yolo.py ├── yolov3-spp.yaml ├── yolov3-tiny.yaml ├── yolov3.yaml ├── yolov5l.yaml ├── yolov5m.yaml ├── yolov5n.yaml ├── yolov5s.yaml └── yolov5x.yaml ├── pyproject.toml ├── requirements.txt ├── segment ├── predict.py ├── train.py ├── tutorial.ipynb └── val.py ├── train.py ├── tutorial.ipynb ├── utils ├── __init__.py ├── activations.py ├── augmentations.py ├── autoanchor.py ├── autobatch.py ├── aws │ ├── __init__.py │ ├── mime.sh │ ├── resume.py │ └── userdata.sh ├── callbacks.py ├── dataloaders.py ├── docker │ ├── Dockerfile │ ├── Dockerfile-arm64 │ └── Dockerfile-cpu ├── downloads.py ├── flask_rest_api │ ├── README.md │ ├── example_request.py │ └── restapi.py ├── general.py ├── google_app_engine │ ├── Dockerfile │ ├── additional_requirements.txt │ └── app.yaml ├── loggers │ ├── __init__.py │ ├── clearml │ │ ├── README.md │ │ ├── __init__.py │ │ ├── clearml_utils.py │ │ └── hpo.py │ ├── comet │ │ ├── README.md │ │ ├── __init__.py │ │ ├── comet_utils.py │ │ ├── hpo.py │ │ └── optimizer_config.json │ └── wandb │ │ ├── __init__.py │ │ └── wandb_utils.py ├── loss.py ├── metrics.py ├── plots.py ├── segment │ ├── __init__.py │ ├── augmentations.py │ ├── dataloaders.py │ ├── general.py │ ├── loss.py │ ├── metrics.py │ └── plots.py ├── torch_utils.py └── triton.py └── val.py /.dockerignore: -------------------------------------------------------------------------------- 1 | # Repo-specific DockerIgnore ------------------------------------------------------------------------------------------- 2 | .git 3 | .cache 4 | .idea 5 | runs 6 | output 7 | coco 8 | storage.googleapis.com 9 | 10 | data/samples/* 11 | **/results*.csv 12 | *.jpg 13 | 14 | # Neural Network weights ----------------------------------------------------------------------------------------------- 15 | **/*.pt 16 | **/*.pth 17 | **/*.onnx 18 | **/*.engine 19 | **/*.mlmodel 20 | **/*.torchscript 21 | **/*.torchscript.pt 22 | **/*.tflite 23 | **/*.h5 24 | **/*.pb 25 | *_saved_model/ 26 | *_web_model/ 27 | *_openvino_model/ 28 | 29 | # Below Copied From .gitignore ----------------------------------------------------------------------------------------- 30 | # Below Copied From .gitignore ----------------------------------------------------------------------------------------- 31 | 32 | 33 | # GitHub Python GitIgnore ---------------------------------------------------------------------------------------------- 34 | # Byte-compiled / optimized / DLL files 35 | __pycache__/ 36 | *.py[cod] 37 | *$py.class 38 | 39 | # C extensions 40 | *.so 41 | 42 | # Distribution / packaging 43 | .Python 44 | env/ 45 | build/ 46 | develop-eggs/ 47 | dist/ 48 | downloads/ 49 | eggs/ 50 | .eggs/ 51 | lib/ 52 | lib64/ 53 | parts/ 54 | sdist/ 55 | var/ 56 | wheels/ 57 | *.egg-info/ 58 | wandb/ 59 | .installed.cfg 60 | *.egg 61 | 62 | # PyInstaller 63 | # Usually these files are written by a python script from a template 64 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 65 | *.manifest 66 | *.spec 67 | 68 | # Installer logs 69 | pip-log.txt 70 | pip-delete-this-directory.txt 71 | 72 | # Unit test / coverage reports 73 | htmlcov/ 74 | .tox/ 75 | .coverage 76 | .coverage.* 77 | .cache 78 | nosetests.xml 79 | coverage.xml 80 | *.cover 81 | .hypothesis/ 82 | 83 | # Translations 84 | *.mo 85 | *.pot 86 | 87 | # Django stuff: 88 | *.log 89 | local_settings.py 90 | 91 | # Flask stuff: 92 | instance/ 93 | .webassets-cache 94 | 95 | # Scrapy stuff: 96 | .scrapy 97 | 98 | # Sphinx documentation 99 | docs/_build/ 100 | 101 | # PyBuilder 102 | target/ 103 | 104 | # Jupyter Notebook 105 | .ipynb_checkpoints 106 | 107 | # pyenv 108 | .python-version 109 | 110 | # celery beat schedule file 111 | celerybeat-schedule 112 | 113 | # SageMath parsed files 114 | *.sage.py 115 | 116 | # dotenv 117 | .env 118 | 119 | # virtualenv 120 | .venv* 121 | venv*/ 122 | ENV*/ 123 | 124 | # Spyder project settings 125 | .spyderproject 126 | .spyproject 127 | 128 | # Rope project settings 129 | .ropeproject 130 | 131 | # mkdocs documentation 132 | /site 133 | 134 | # mypy 135 | .mypy_cache/ 136 | 137 | 138 | # https://github.com/github/gitignore/blob/master/Global/macOS.gitignore ----------------------------------------------- 139 | 140 | # General 141 | .DS_Store 142 | .AppleDouble 143 | .LSOverride 144 | 145 | # Icon must end with two \r 146 | Icon 147 | Icon? 148 | 149 | # Thumbnails 150 | ._* 151 | 152 | # Files that might appear in the root of a volume 153 | .DocumentRevisions-V100 154 | .fseventsd 155 | .Spotlight-V100 156 | .TemporaryItems 157 | .Trashes 158 | .VolumeIcon.icns 159 | .com.apple.timemachine.donotpresent 160 | 161 | # Directories potentially created on remote AFP share 162 | .AppleDB 163 | .AppleDesktop 164 | Network Trash Folder 165 | Temporary Items 166 | .apdisk 167 | 168 | 169 | # https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore 170 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 171 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 172 | 173 | # User-specific stuff: 174 | .idea/* 175 | .idea/**/workspace.xml 176 | .idea/**/tasks.xml 177 | .idea/dictionaries 178 | .html # Bokeh Plots 179 | .pg # TensorFlow Frozen Graphs 180 | .avi # videos 181 | 182 | # Sensitive or high-churn files: 183 | .idea/**/dataSources/ 184 | .idea/**/dataSources.ids 185 | .idea/**/dataSources.local.xml 186 | .idea/**/sqlDataSources.xml 187 | .idea/**/dynamic.xml 188 | .idea/**/uiDesigner.xml 189 | 190 | # Gradle: 191 | .idea/**/gradle.xml 192 | .idea/**/libraries 193 | 194 | # CMake 195 | cmake-build-debug/ 196 | cmake-build-release/ 197 | 198 | # Mongo Explorer plugin: 199 | .idea/**/mongoSettings.xml 200 | 201 | ## File-based project format: 202 | *.iws 203 | 204 | ## Plugin-specific files: 205 | 206 | # IntelliJ 207 | out/ 208 | 209 | # mpeltonen/sbt-idea plugin 210 | .idea_modules/ 211 | 212 | # JIRA plugin 213 | atlassian-ide-plugin.xml 214 | 215 | # Cursive Clojure plugin 216 | .idea/replstate.xml 217 | 218 | # Crashlytics plugin (for Android Studio and IntelliJ) 219 | com_crashlytics_export_strings.xml 220 | crashlytics.properties 221 | crashlytics-build.properties 222 | fabric.properties 223 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | name: 🐛 Bug Report 4 | # title: " " 5 | description: Problems with YOLOv3 6 | labels: [bug, triage] 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | Thank you for submitting a YOLOv3 🐛 Bug Report! 12 | 13 | - type: checkboxes 14 | attributes: 15 | label: Search before asking 16 | description: > 17 | Please search the [issues](https://github.com/ultralytics/yolov3/issues) to see if a similar bug report already exists. 18 | options: 19 | - label: > 20 | I have searched the YOLOv3 [issues](https://github.com/ultralytics/yolov3/issues) and found no similar bug report. 21 | required: true 22 | 23 | - type: dropdown 24 | attributes: 25 | label: YOLOv3 Component 26 | description: | 27 | Please select the part of YOLOv3 where you found the bug. 28 | multiple: true 29 | options: 30 | - "Training" 31 | - "Validation" 32 | - "Detection" 33 | - "Export" 34 | - "PyTorch Hub" 35 | - "Multi-GPU" 36 | - "Evolution" 37 | - "Integrations" 38 | - "Other" 39 | validations: 40 | required: false 41 | 42 | - type: textarea 43 | attributes: 44 | label: Bug 45 | description: Provide console output with error messages and/or screenshots of the bug. 46 | placeholder: | 47 | 💡 ProTip! Include as much information as possible (screenshots, logs, tracebacks etc.) to receive the most helpful response. 48 | validations: 49 | required: true 50 | 51 | - type: textarea 52 | attributes: 53 | label: Environment 54 | description: Please specify the software and hardware you used to produce the bug. 55 | placeholder: | 56 | - YOLO: YOLOv3 🚀 v6.0-67-g60e42e1 torch 1.9.0+cu111 CUDA:0 (A100-SXM4-40GB, 40536MiB) 57 | - OS: Ubuntu 20.04 58 | - Python: 3.9.0 59 | validations: 60 | required: false 61 | 62 | - type: textarea 63 | attributes: 64 | label: Minimal Reproducible Example 65 | description: > 66 | When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to **reproduce** the problem. 67 | This is referred to by community members as creating a [minimal reproducible example](https://docs.ultralytics.com/help/minimum_reproducible_example/). 68 | placeholder: | 69 | ``` 70 | # Code to reproduce your issue here 71 | ``` 72 | validations: 73 | required: false 74 | 75 | - type: textarea 76 | attributes: 77 | label: Additional 78 | description: Anything else you would like to share? 79 | 80 | - type: checkboxes 81 | attributes: 82 | label: Are you willing to submit a PR? 83 | description: > 84 | (Optional) We encourage you to submit a [Pull Request](https://github.com/ultralytics/yolov3/pulls) (PR) to help improve YOLOv3 for everyone, especially if you have a good understanding of how to implement a fix or feature. 85 | See the YOLOv3 [Contributing Guide](https://docs.ultralytics.com/help/contributing) to get started. 86 | options: 87 | - label: Yes I'd like to help by submitting a PR! 88 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | blank_issues_enabled: true 4 | contact_links: 5 | - name: 📄 Docs 6 | url: https://docs.ultralytics.com/ 7 | about: View Ultralytics YOLOv3 Docs 8 | - name: 💬 Forum 9 | url: https://community.ultralytics.com/ 10 | about: Ask on Ultralytics Community Forum 11 | - name: 🎧 Discord 12 | url: https://ultralytics.com/discord 13 | about: Ask on Ultralytics Discord 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | name: 🚀 Feature Request 4 | description: Suggest a YOLOv3 idea 5 | # title: " " 6 | labels: [enhancement] 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | Thank you for submitting a YOLOv3 🚀 Feature Request! 12 | 13 | - type: checkboxes 14 | attributes: 15 | label: Search before asking 16 | description: > 17 | Please search the [issues](https://github.com/ultralytics/yolov3/issues) to see if a similar feature request already exists. 18 | options: 19 | - label: > 20 | I have searched the YOLOv3 [issues](https://github.com/ultralytics/yolov3/issues) and found no similar feature requests. 21 | required: true 22 | 23 | - type: textarea 24 | attributes: 25 | label: Description 26 | description: A short description of your feature. 27 | placeholder: | 28 | What new feature would you like to see in YOLOv3? 29 | validations: 30 | required: true 31 | 32 | - type: textarea 33 | attributes: 34 | label: Use case 35 | description: | 36 | Describe the use case of your feature request. It will help us understand and prioritize the feature request. 37 | placeholder: | 38 | How would this feature be used, and who would use it? 39 | 40 | - type: textarea 41 | attributes: 42 | label: Additional 43 | description: Anything else you would like to share? 44 | 45 | - type: checkboxes 46 | attributes: 47 | label: Are you willing to submit a PR? 48 | description: > 49 | (Optional) We encourage you to submit a [Pull Request](https://github.com/ultralytics/yolov3/pulls) (PR) to help improve YOLOv3 for everyone, especially if you have a good understanding of how to implement a fix or feature. 50 | See the YOLOv3 [Contributing Guide](https://docs.ultralytics.com/help/contributing) to get started. 51 | options: 52 | - label: Yes I'd like to help by submitting a PR! 53 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | name: ❓ Question 4 | description: Ask a YOLOv3 question 5 | # title: " " 6 | labels: [question] 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | Thank you for asking a YOLOv3 ❓ Question! 12 | 13 | - type: checkboxes 14 | attributes: 15 | label: Search before asking 16 | description: > 17 | Please search the [issues](https://github.com/ultralytics/yolov3/issues) and [discussions](https://github.com/ultralytics/yolov3/discussions) to see if a similar question already exists. 18 | options: 19 | - label: > 20 | I have searched the YOLOv3 [issues](https://github.com/ultralytics/yolov3/issues) and [discussions](https://github.com/ultralytics/yolov3/discussions) and found no similar questions. 21 | required: true 22 | 23 | - type: textarea 24 | attributes: 25 | label: Question 26 | description: What is your question? 27 | placeholder: | 28 | 💡 ProTip! Include as much information as possible (screenshots, logs, tracebacks etc.) to receive the most helpful response. 29 | validations: 30 | required: true 31 | 32 | - type: textarea 33 | attributes: 34 | label: Additional 35 | description: Anything else you would like to share? 36 | -------------------------------------------------------------------------------- /.github/workflows/ci-testing.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # YOLOv3 Continuous Integration (CI) GitHub Actions tests 4 | 5 | name: YOLOv3 CI 6 | 7 | on: 8 | push: 9 | branches: [master] 10 | pull_request: 11 | branches: [master] 12 | schedule: 13 | - cron: "0 0 * * *" # runs at 00:00 UTC every day 14 | workflow_dispatch: 15 | 16 | jobs: 17 | Tests: 18 | timeout-minutes: 60 19 | runs-on: ${{ matrix.os }} 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | os: [ubuntu-latest, windows-latest] # macos-latest bug https://github.com/ultralytics/yolov5/pull/9049 24 | python-version: ["3.11"] 25 | model: [yolov5n] 26 | include: 27 | # - os: ubuntu-latest 28 | # python-version: "3.8" # '3.6.8' min (warning, this test is failing) 29 | # model: yolov5n 30 | - os: ubuntu-latest 31 | python-version: "3.9" 32 | model: yolov5n 33 | - os: ubuntu-latest 34 | python-version: "3.8" # torch 1.8.0 requires python >=3.6, <=3.8 35 | model: yolov5n 36 | torch: "1.8.0" # min torch version CI https://pypi.org/project/torchvision/ 37 | steps: 38 | - uses: actions/checkout@v4 39 | - uses: actions/setup-python@v5 40 | with: 41 | python-version: ${{ matrix.python-version }} 42 | cache: "pip" # caching pip dependencies 43 | - name: Install requirements 44 | run: | 45 | python -m pip install --upgrade pip wheel 46 | torch="" 47 | if [ "${{ matrix.torch }}" == "1.8.0" ]; then 48 | torch="torch==1.8.0 torchvision==0.9.0" 49 | fi 50 | pip install -r requirements.txt $torch --extra-index-url https://download.pytorch.org/whl/cpu 51 | shell: bash # for Windows compatibility 52 | - name: Check environment 53 | run: | 54 | yolo checks 55 | pip list 56 | - name: Test detection 57 | shell: bash # for Windows compatibility 58 | run: | 59 | # export PYTHONPATH="$PWD" # to run '$ python *.py' files in subdirectories 60 | m=${{ matrix.model }} # official weights 61 | b=runs/train/exp/weights/best # best.pt checkpoint 62 | python train.py --imgsz 64 --batch 32 --weights $m.pt --cfg $m.yaml --epochs 1 --device cpu # train 63 | for d in cpu; do # devices 64 | for w in $m $b; do # weights 65 | python val.py --imgsz 64 --batch 32 --weights $w.pt --device $d # val 66 | python detect.py --imgsz 64 --weights $w.pt --device $d # detect 67 | done 68 | done 69 | python hubconf.py --model $m # hub 70 | # python models/tf.py --weights $m.pt # build TF model 71 | python models/yolo.py --cfg $m.yaml # build PyTorch model 72 | python export.py --weights $m.pt --img 64 --include torchscript # export 73 | python - < GitHub Actions error for ${{ github.workflow }} ❌\n\n\n*Repository:* https://github.com/${{ github.repository }}\n*Action:* https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n*Author:* ${{ github.actor }}\n*Event:* ${{ github.event_name }}\n" 125 | -------------------------------------------------------------------------------- /.github/workflows/cla.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Ultralytics Contributor License Agreement (CLA) action https://docs.ultralytics.com/help/CLA 4 | # This workflow automatically requests Pull Requests (PR) authors to sign the Ultralytics CLA before PRs can be merged 5 | 6 | name: CLA Assistant 7 | on: 8 | issue_comment: 9 | types: 10 | - created 11 | pull_request_target: 12 | types: 13 | - reopened 14 | - opened 15 | - synchronize 16 | 17 | permissions: 18 | actions: write 19 | contents: write 20 | pull-requests: write 21 | statuses: write 22 | 23 | jobs: 24 | CLA: 25 | if: github.repository == 'ultralytics/yolov3' 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: CLA Assistant 29 | if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I sign the CLA') || github.event_name == 'pull_request_target' 30 | uses: contributor-assistant/github-action@v2.6.1 31 | env: 32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 33 | # Must be repository secret PAT 34 | PERSONAL_ACCESS_TOKEN: ${{ secrets._GITHUB_TOKEN }} 35 | with: 36 | path-to-signatures: "signatures/version1/cla.json" 37 | path-to-document: "https://docs.ultralytics.com/help/CLA" # CLA document 38 | # Branch must not be protected 39 | branch: cla-signatures 40 | allowlist: dependabot[bot],github-actions,[pre-commit*,pre-commit*,bot* 41 | 42 | remote-organization-name: ultralytics 43 | remote-repository-name: cla 44 | custom-pr-sign-comment: "I have read the CLA Document and I sign the CLA" 45 | custom-allsigned-prcomment: All Contributors have signed the CLA. ✅ 46 | -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Builds ultralytics/yolov3:latest images on DockerHub https://hub.docker.com/r/ultralytics/yolov3 4 | 5 | name: Publish Docker Images 6 | 7 | on: 8 | push: 9 | branches: [master] 10 | workflow_dispatch: 11 | 12 | jobs: 13 | docker: 14 | if: github.repository == 'ultralytics/yolov3' 15 | name: Push Docker image to Docker Hub 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Checkout repo 19 | uses: actions/checkout@v4 20 | 21 | - name: Set up QEMU 22 | uses: docker/setup-qemu-action@v3 23 | 24 | - name: Set up Docker Buildx 25 | uses: docker/setup-buildx-action@v3 26 | 27 | - name: Login to Docker Hub 28 | uses: docker/login-action@v3 29 | with: 30 | username: ${{ secrets.DOCKERHUB_USERNAME }} 31 | password: ${{ secrets.DOCKERHUB_TOKEN }} 32 | 33 | - name: Build and push arm64 image 34 | uses: docker/build-push-action@v6 35 | continue-on-error: true 36 | with: 37 | context: . 38 | platforms: linux/arm64 39 | file: utils/docker/Dockerfile-arm64 40 | push: true 41 | tags: ultralytics/yolov3:latest-arm64 42 | 43 | - name: Build and push CPU image 44 | uses: docker/build-push-action@v6 45 | continue-on-error: true 46 | with: 47 | context: . 48 | file: utils/docker/Dockerfile-cpu 49 | push: true 50 | tags: ultralytics/yolov3:latest-cpu 51 | 52 | - name: Build and push GPU image 53 | uses: docker/build-push-action@v6 54 | continue-on-error: true 55 | with: 56 | context: . 57 | file: utils/docker/Dockerfile 58 | push: true 59 | tags: ultralytics/yolov3:latest 60 | -------------------------------------------------------------------------------- /.github/workflows/format.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Ultralytics Actions https://github.com/ultralytics/actions 4 | # This workflow formats code and documentation in PRs to Ultralytics standards 5 | 6 | name: Ultralytics Actions 7 | 8 | on: 9 | issues: 10 | types: [opened] 11 | pull_request: 12 | branches: [main, master] 13 | types: [opened, closed, synchronize, review_requested] 14 | 15 | permissions: 16 | contents: write # Modify code in PRs 17 | pull-requests: write # Add comments and labels to PRs 18 | issues: write # Add comments and labels to issues 19 | 20 | jobs: 21 | actions: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Run Ultralytics Actions 25 | uses: ultralytics/actions@main 26 | with: 27 | token: ${{ secrets._GITHUB_TOKEN || secrets.GITHUB_TOKEN }} # Auto-generated token 28 | labels: true # Auto-label issues/PRs using AI 29 | python: true # Format Python with Ruff and docformatter 30 | prettier: true # Format YAML, JSON, Markdown, CSS 31 | spelling: true # Check spelling with codespell 32 | links: false # Check broken links with Lychee 33 | summary: true # Generate AI-powered PR summaries 34 | openai_api_key: ${{ secrets.OPENAI_API_KEY }} # Powers PR summaries, labels and comments 35 | brave_api_key: ${{ secrets.BRAVE_API_KEY }} # Used for broken link resolution 36 | -------------------------------------------------------------------------------- /.github/workflows/links.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Continuous Integration (CI) GitHub Actions tests broken link checker using https://github.com/lycheeverse/lychee 4 | # Ignores the following status codes to reduce false positives: 5 | # - 403(OpenVINO, 'forbidden') 6 | # - 429(Instagram, 'too many requests') 7 | # - 500(Zenodo, 'cached') 8 | # - 502(Zenodo, 'bad gateway') 9 | # - 999(LinkedIn, 'unknown status code') 10 | 11 | name: Check Broken links 12 | 13 | on: 14 | workflow_dispatch: 15 | schedule: 16 | - cron: "0 0 * * *" # runs at 00:00 UTC every day 17 | 18 | jobs: 19 | Links: 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v4 23 | 24 | - name: Download and install lychee 25 | run: | 26 | LYCHEE_URL=$(curl -s https://api.github.com/repos/lycheeverse/lychee/releases/latest | grep "browser_download_url" | grep "x86_64-unknown-linux-gnu.tar.gz" | cut -d '"' -f 4) 27 | curl -L $LYCHEE_URL | tar xz -C /usr/local/bin 28 | 29 | - name: Test Markdown and HTML links with retry 30 | uses: ultralytics/actions/retry@main 31 | with: 32 | timeout_minutes: 5 33 | retry_delay_seconds: 60 34 | retries: 2 35 | run: | 36 | lychee \ 37 | --scheme 'https' \ 38 | --timeout 60 \ 39 | --insecure \ 40 | --accept 403,429,500,502,999 \ 41 | --exclude-all-private \ 42 | --exclude 'https?://(www\.)?(linkedin\.com|twitter\.com|x\.com|instagram\.com|kaggle\.com|fonts\.gstatic\.com|url\.com)' \ 43 | --exclude-path '**/ci.yaml' \ 44 | --github-token ${{ secrets.GITHUB_TOKEN }} \ 45 | --header "User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.183 Safari/537.36" \ 46 | './**/*.md' \ 47 | './**/*.html' | tee -a $GITHUB_STEP_SUMMARY 48 | 49 | # Raise error if broken links found 50 | if ! grep -q "0 Errors" $GITHUB_STEP_SUMMARY; then 51 | exit 1 52 | fi 53 | 54 | - name: Test Markdown, HTML, YAML, Python and Notebook links with retry 55 | if: github.event_name == 'workflow_dispatch' 56 | uses: ultralytics/actions/retry@main 57 | with: 58 | timeout_minutes: 5 59 | retry_delay_seconds: 60 60 | retries: 2 61 | run: | 62 | lychee \ 63 | --scheme 'https' \ 64 | --timeout 60 \ 65 | --insecure \ 66 | --accept 429,999 \ 67 | --exclude-all-private \ 68 | --exclude 'https?://(www\.)?(linkedin\.com|twitter\.com|x\.com|instagram\.com|kaggle\.com|fonts\.gstatic\.com|url\.com)' \ 69 | --exclude-path '**/ci.yaml' \ 70 | --github-token ${{ secrets.GITHUB_TOKEN }} \ 71 | --header "User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.183 Safari/537.36" \ 72 | './**/*.md' \ 73 | './**/*.html' \ 74 | './**/*.yml' \ 75 | './**/*.yaml' \ 76 | './**/*.py' \ 77 | './**/*.ipynb' | tee -a $GITHUB_STEP_SUMMARY 78 | 79 | # Raise error if broken links found 80 | if ! grep -q "0 Errors" $GITHUB_STEP_SUMMARY; then 81 | exit 1 82 | fi 83 | -------------------------------------------------------------------------------- /.github/workflows/merge-main-into-prs.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Automatically merges repository 'main' branch into all open PRs to keep them up-to-date 4 | # Action runs on updates to main branch so when one PR merges to main all others update 5 | 6 | name: Merge main into PRs 7 | 8 | on: 9 | workflow_dispatch: 10 | # push: 11 | # branches: 12 | # - ${{ github.event.repository.default_branch }} 13 | 14 | jobs: 15 | Merge: 16 | if: github.repository == 'ultralytics/yolov3' 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v4 21 | with: 22 | fetch-depth: 0 23 | - uses: actions/setup-python@v5 24 | with: 25 | python-version: "3.x" 26 | cache: "pip" 27 | - name: Install requirements 28 | run: | 29 | pip install pygithub 30 | - name: Merge default branch into PRs 31 | shell: python 32 | run: | 33 | from github import Github 34 | import os 35 | 36 | g = Github(os.getenv('GITHUB_TOKEN')) 37 | repo = g.get_repo(os.getenv('GITHUB_REPOSITORY')) 38 | 39 | # Fetch the default branch name 40 | default_branch_name = repo.default_branch 41 | default_branch = repo.get_branch(default_branch_name) 42 | 43 | for pr in repo.get_pulls(state='open', sort='created'): 44 | try: 45 | # Get full names for repositories and branches 46 | base_repo_name = repo.full_name 47 | head_repo_name = pr.head.repo.full_name 48 | base_branch_name = pr.base.ref 49 | head_branch_name = pr.head.ref 50 | 51 | # Check if PR is behind the default branch 52 | comparison = repo.compare(default_branch.commit.sha, pr.head.sha) 53 | 54 | if comparison.behind_by > 0: 55 | print(f"⚠️ PR #{pr.number} ({head_repo_name}:{head_branch_name} -> {base_repo_name}:{base_branch_name}) is behind {default_branch_name} by {comparison.behind_by} commit(s).") 56 | 57 | # Attempt to update the branch 58 | try: 59 | success = pr.update_branch() 60 | assert success, "Branch update failed" 61 | print(f"✅ Successfully merged '{default_branch_name}' into PR #{pr.number} ({head_repo_name}:{head_branch_name} -> {base_repo_name}:{base_branch_name}).") 62 | except Exception as update_error: 63 | print(f"❌ Could not update PR #{pr.number} ({head_repo_name}:{head_branch_name} -> {base_repo_name}:{base_branch_name}): {update_error}") 64 | print(" This might be due to branch protection rules or insufficient permissions.") 65 | else: 66 | print(f"✅ PR #{pr.number} ({head_repo_name}:{head_branch_name} -> {base_repo_name}:{base_branch_name}) is up to date with {default_branch_name}.") 67 | except Exception as e: 68 | print(f"❌ Could not process PR #{pr.number}: {e}") 69 | 70 | env: 71 | GITHUB_TOKEN: ${{ secrets._GITHUB_TOKEN }} 72 | GITHUB_REPOSITORY: ${{ github.repository }} 73 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | name: Close stale issues 4 | on: 5 | schedule: 6 | - cron: "0 0 * * *" # Runs at 00:00 UTC every day 7 | 8 | jobs: 9 | stale: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/stale@v9 13 | with: 14 | repo-token: ${{ secrets.GITHUB_TOKEN }} 15 | 16 | stale-issue-message: | 17 | 👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help. 18 | 19 | For additional resources and information, please see the links below: 20 | 21 | - **Docs**: https://docs.ultralytics.com 22 | - **HUB**: https://hub.ultralytics.com 23 | - **Community**: https://community.ultralytics.com 24 | 25 | Feel free to inform us of any other **issues** you discover or **feature requests** that come to mind in the future. Pull Requests (PRs) are also always welcomed! 26 | 27 | Thank you for your contributions to YOLO 🚀 and Vision AI ⭐ 28 | 29 | stale-pr-message: | 30 | 👋 Hello there! We wanted to let you know that we've decided to close this pull request due to inactivity. We appreciate the effort you put into contributing to our project, but unfortunately, not all contributions are suitable or aligned with our product roadmap. 31 | 32 | We hope you understand our decision, and please don't let it discourage you from contributing to open source projects in the future. We value all of our community members and their contributions, and we encourage you to keep exploring new projects and ways to get involved. 33 | 34 | For additional resources and information, please see the links below: 35 | 36 | - **Docs**: https://docs.ultralytics.com 37 | - **HUB**: https://hub.ultralytics.com 38 | - **Community**: https://community.ultralytics.com 39 | 40 | Thank you for your contributions to YOLO 🚀 and Vision AI ⭐ 41 | 42 | days-before-issue-stale: 30 43 | days-before-issue-close: 10 44 | days-before-pr-stale: 90 45 | days-before-pr-close: 30 46 | exempt-issue-labels: "documentation,tutorial,TODO" 47 | operations-per-run: 300 # The maximum number of operations per run, used to control rate limiting. 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Repo-specific GitIgnore ---------------------------------------------------------------------------------------------- 2 | *.jpg 3 | *.jpeg 4 | *.png 5 | *.bmp 6 | *.tif 7 | *.tiff 8 | *.heic 9 | *.JPG 10 | *.JPEG 11 | *.PNG 12 | *.BMP 13 | *.TIF 14 | *.TIFF 15 | *.HEIC 16 | *.mp4 17 | *.mov 18 | *.MOV 19 | *.avi 20 | *.data 21 | *.json 22 | *.cfg 23 | !setup.cfg 24 | !cfg/yolov3*.cfg 25 | 26 | storage.googleapis.com 27 | runs/* 28 | data/* 29 | data/images/* 30 | !data/*.yaml 31 | !data/hyps 32 | !data/scripts 33 | !data/images 34 | !data/images/zidane.jpg 35 | !data/images/bus.jpg 36 | !data/*.sh 37 | 38 | results*.csv 39 | 40 | # Datasets ------------------------------------------------------------------------------------------------------------- 41 | coco/ 42 | coco128/ 43 | VOC/ 44 | 45 | # MATLAB GitIgnore ----------------------------------------------------------------------------------------------------- 46 | *.m~ 47 | *.mat 48 | !targets*.mat 49 | 50 | # Neural Network weights ----------------------------------------------------------------------------------------------- 51 | *.weights 52 | *.pt 53 | *.pb 54 | *.onnx 55 | *.engine 56 | *.mlmodel 57 | *.torchscript 58 | *.tflite 59 | *.h5 60 | *_saved_model/ 61 | *_web_model/ 62 | *_openvino_model/ 63 | *_paddle_model/ 64 | darknet53.conv.74 65 | yolov3-tiny.conv.15 66 | 67 | # GitHub Python GitIgnore ---------------------------------------------------------------------------------------------- 68 | # Byte-compiled / optimized / DLL files 69 | __pycache__/ 70 | *.py[cod] 71 | *$py.class 72 | 73 | # C extensions 74 | *.so 75 | 76 | # Distribution / packaging 77 | .Python 78 | env/ 79 | build/ 80 | develop-eggs/ 81 | dist/ 82 | downloads/ 83 | eggs/ 84 | .eggs/ 85 | lib/ 86 | lib64/ 87 | parts/ 88 | sdist/ 89 | var/ 90 | wheels/ 91 | *.egg-info/ 92 | /wandb/ 93 | .installed.cfg 94 | *.egg 95 | 96 | 97 | # PyInstaller 98 | # Usually these files are written by a python script from a template 99 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 100 | *.manifest 101 | *.spec 102 | 103 | # Installer logs 104 | pip-log.txt 105 | pip-delete-this-directory.txt 106 | 107 | # Unit test / coverage reports 108 | htmlcov/ 109 | .tox/ 110 | .coverage 111 | .coverage.* 112 | .cache 113 | nosetests.xml 114 | coverage.xml 115 | *.cover 116 | .hypothesis/ 117 | 118 | # Translations 119 | *.mo 120 | *.pot 121 | 122 | # Django stuff: 123 | *.log 124 | local_settings.py 125 | 126 | # Flask stuff: 127 | instance/ 128 | .webassets-cache 129 | 130 | # Scrapy stuff: 131 | .scrapy 132 | 133 | # Sphinx documentation 134 | docs/_build/ 135 | 136 | # PyBuilder 137 | target/ 138 | 139 | # Jupyter Notebook 140 | .ipynb_checkpoints 141 | 142 | # pyenv 143 | .python-version 144 | 145 | # celery beat schedule file 146 | celerybeat-schedule 147 | 148 | # SageMath parsed files 149 | *.sage.py 150 | 151 | # dotenv 152 | .env 153 | 154 | # virtualenv 155 | .venv* 156 | venv*/ 157 | ENV*/ 158 | 159 | # Spyder project settings 160 | .spyderproject 161 | .spyproject 162 | 163 | # Rope project settings 164 | .ropeproject 165 | 166 | # mkdocs documentation 167 | /site 168 | 169 | # mypy 170 | .mypy_cache/ 171 | 172 | 173 | # https://github.com/github/gitignore/blob/master/Global/macOS.gitignore ----------------------------------------------- 174 | 175 | # General 176 | .DS_Store 177 | .AppleDouble 178 | .LSOverride 179 | 180 | # Icon must end with two \r 181 | Icon 182 | Icon? 183 | 184 | # Thumbnails 185 | ._* 186 | 187 | # Files that might appear in the root of a volume 188 | .DocumentRevisions-V100 189 | .fseventsd 190 | .Spotlight-V100 191 | .TemporaryItems 192 | .Trashes 193 | .VolumeIcon.icns 194 | .com.apple.timemachine.donotpresent 195 | 196 | # Directories potentially created on remote AFP share 197 | .AppleDB 198 | .AppleDesktop 199 | Network Trash Folder 200 | Temporary Items 201 | .apdisk 202 | 203 | 204 | # https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore 205 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 206 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 207 | 208 | # User-specific stuff: 209 | .idea/* 210 | .idea/**/workspace.xml 211 | .idea/**/tasks.xml 212 | .idea/dictionaries 213 | .html # Bokeh Plots 214 | .pg # TensorFlow Frozen Graphs 215 | .avi # videos 216 | 217 | # Sensitive or high-churn files: 218 | .idea/**/dataSources/ 219 | .idea/**/dataSources.ids 220 | .idea/**/dataSources.local.xml 221 | .idea/**/sqlDataSources.xml 222 | .idea/**/dynamic.xml 223 | .idea/**/uiDesigner.xml 224 | 225 | # Gradle: 226 | .idea/**/gradle.xml 227 | .idea/**/libraries 228 | 229 | # CMake 230 | cmake-build-debug/ 231 | cmake-build-release/ 232 | 233 | # Mongo Explorer plugin: 234 | .idea/**/mongoSettings.xml 235 | 236 | ## File-based project format: 237 | *.iws 238 | 239 | ## Plugin-specific files: 240 | 241 | # IntelliJ 242 | out/ 243 | 244 | # mpeltonen/sbt-idea plugin 245 | .idea_modules/ 246 | 247 | # JIRA plugin 248 | atlassian-ide-plugin.xml 249 | 250 | # Cursive Clojure plugin 251 | .idea/replstate.xml 252 | 253 | # Crashlytics plugin (for Android Studio and IntelliJ) 254 | com_crashlytics_export_strings.xml 255 | crashlytics.properties 256 | crashlytics-build.properties 257 | fabric.properties 258 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | preferred-citation: 3 | type: software 4 | message: If you use YOLOv5, please cite it as below. 5 | authors: 6 | - family-names: Jocher 7 | given-names: Glenn 8 | orcid: "https://orcid.org/0000-0001-5950-6979" 9 | title: "YOLOv5 by Ultralytics" 10 | version: 7.0 11 | doi: 10.5281/zenodo.3908559 12 | date-released: 2020-5-29 13 | license: AGPL-3.0 14 | url: "https://github.com/ultralytics/yolov5" 15 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing To YOLOv3 🚀 2 | 3 | We value your input and welcome your contributions to Ultralytics YOLOv3! Whether you're interested in: 4 | 5 | - Reporting a bug 6 | - Discussing the current state of the codebase 7 | - Submitting a fix 8 | - Proposing a new feature 9 | - Becoming a maintainer 10 | 11 | Ultralytics YOLO models are successful thanks to the collective efforts of our community. Every improvement you contribute helps advance the possibilities of AI and computer vision! 😃 12 | 13 | ## Submitting A Pull Request (PR) 🛠️ 14 | 15 | Contributing a PR is straightforward! Here’s a step-by-step example for updating `requirements.txt`: 16 | 17 | ### 1. Select The File To Update 18 | 19 | Click on `requirements.txt` in the GitHub repository to open it. 20 | 21 |

PR_step1

22 | 23 | ### 2. Click 'Edit This File' 24 | 25 | Use the pencil icon in the top-right corner to begin editing. 26 | 27 |

PR_step2

28 | 29 | ### 3. Make Your Changes 30 | 31 | For example, update the `matplotlib` version from `3.2.2` to `3.3`. 32 | 33 |

PR_step3

34 | 35 | ### 4. Preview And Submit Your PR 36 | 37 | Switch to the **Preview changes** tab to review your edits. At the bottom, select 'Create a new branch for this commit', give your branch a descriptive name like `fix/matplotlib_version`, and click the green **Propose changes** button. Your PR is now submitted for review! 😃 38 | 39 |

PR_step4

40 | 41 | ### PR Best Practices 42 | 43 | To ensure your contribution is integrated smoothly, please: 44 | 45 | - ✅ Ensure your PR is **up-to-date** with the `ultralytics/yolov3` `master` branch. If your PR is behind, update your code by clicking the 'Update branch' button or by running `git pull` and `git merge master` locally. 46 | 47 |

Screenshot 2022-08-29 at 22 47 15

48 | 49 | - ✅ Confirm that all Continuous Integration (CI) **checks are passing**. 50 | 51 |

Screenshot 2022-08-29 at 22 47 03

52 | 53 | - ✅ Limit your changes to the **minimum required** for your bug fix or feature. 54 | _"It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is."_ — Bruce Lee 55 | 56 | ## Submitting A Bug Report 🐛 57 | 58 | If you encounter an issue with Ultralytics YOLOv3, please submit a bug report! 59 | 60 | To help us investigate, please provide a [minimum reproducible example](https://docs.ultralytics.com/help/minimum-reproducible-example/). Your code should be: 61 | 62 | - ✅ **Minimal** – Use as little code as possible that still produces the issue. 63 | - ✅ **Complete** – Include all parts needed for someone else to reproduce the problem. 64 | - ✅ **Reproducible** – Test your code to ensure it reliably triggers the issue. 65 | 66 | Additionally, for [Ultralytics](https://www.ultralytics.com/) to assist, your code should be: 67 | 68 | - ✅ **Current** – Ensure your code is up-to-date with the latest [master branch](https://github.com/ultralytics/yolov3/tree/master). Use `git pull` or `git clone` to get the latest version. 69 | - ✅ **Unmodified** – The problem must be reproducible without custom modifications to the repository. [Ultralytics](https://www.ultralytics.com/) does not provide support for custom code. 70 | 71 | If your issue meets these criteria, please close your current issue and open a new one using the 🐛 **Bug Report** [template](https://github.com/ultralytics/yolov3/issues/new/choose), including your [minimum reproducible example](https://docs.ultralytics.com/help/minimum-reproducible-example/) to help us diagnose and resolve your problem. 72 | 73 | ## License 74 | 75 | By contributing, you agree that your submissions will be licensed under the [AGPL-3.0 license](https://choosealicense.com/licenses/agpl-3.0/). 76 | 77 | --- 78 | 79 | Thank you for helping improve Ultralytics YOLOv3! Your contributions make a difference. For more on open-source best practices, check out the [Ultralytics open-source community](https://www.ultralytics.com/blog/tips-to-start-contributing-to-ultralytics-open-source-projects) and [GitHub's open source guides](https://opensource.guide/how-to-contribute/). 80 | -------------------------------------------------------------------------------- /data/Argoverse.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Argoverse-HD dataset (ring-front-center camera) http://www.cs.cmu.edu/~mengtial/proj/streaming/ by Argo AI 4 | # Example usage: python train.py --data Argoverse.yaml 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── Argoverse ← downloads here (31.3 GB) 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | path: ../datasets/Argoverse # dataset root dir 12 | train: Argoverse-1.1/images/train/ # train images (relative to 'path') 39384 images 13 | val: Argoverse-1.1/images/val/ # val images (relative to 'path') 15062 images 14 | test: Argoverse-1.1/images/test/ # test images (optional) https://eval.ai/web/challenges/challenge-page/800/overview 15 | 16 | # Classes 17 | names: 18 | 0: person 19 | 1: bicycle 20 | 2: car 21 | 3: motorcycle 22 | 4: bus 23 | 5: truck 24 | 6: traffic_light 25 | 7: stop_sign 26 | 27 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 28 | download: | 29 | import json 30 | 31 | from tqdm import tqdm 32 | from utils.general import download, Path 33 | 34 | 35 | def argoverse2yolo(set): 36 | labels = {} 37 | a = json.load(open(set, "rb")) 38 | for annot in tqdm(a['annotations'], desc=f"Converting {set} to YOLOv5 format..."): 39 | img_id = annot['image_id'] 40 | img_name = a['images'][img_id]['name'] 41 | img_label_name = f'{img_name[:-3]}txt' 42 | 43 | cls = annot['category_id'] # instance class id 44 | x_center, y_center, width, height = annot['bbox'] 45 | x_center = (x_center + width / 2) / 1920.0 # offset and scale 46 | y_center = (y_center + height / 2) / 1200.0 # offset and scale 47 | width /= 1920.0 # scale 48 | height /= 1200.0 # scale 49 | 50 | img_dir = set.parents[2] / 'Argoverse-1.1' / 'labels' / a['seq_dirs'][a['images'][annot['image_id']]['sid']] 51 | if not img_dir.exists(): 52 | img_dir.mkdir(parents=True, exist_ok=True) 53 | 54 | k = str(img_dir / img_label_name) 55 | if k not in labels: 56 | labels[k] = [] 57 | labels[k].append(f"{cls} {x_center} {y_center} {width} {height}\n") 58 | 59 | for k in labels: 60 | with open(k, "w") as f: 61 | f.writelines(labels[k]) 62 | 63 | 64 | # Download 65 | dir = Path(yaml['path']) # dataset root dir 66 | urls = ['https://argoverse-hd.s3.us-east-2.amazonaws.com/Argoverse-HD-Full.zip'] 67 | download(urls, dir=dir, delete=False) 68 | 69 | # Convert 70 | annotations_dir = 'Argoverse-HD/annotations/' 71 | (dir / 'Argoverse-1.1' / 'tracking').rename(dir / 'Argoverse-1.1' / 'images') # rename 'tracking' to 'images' 72 | for d in "train.json", "val.json": 73 | argoverse2yolo(dir / annotations_dir / d) # convert VisDrone annotations to YOLO labels 74 | -------------------------------------------------------------------------------- /data/GlobalWheat2020.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Global Wheat 2020 dataset http://www.global-wheat.com/ by University of Saskatchewan 4 | # Example usage: python train.py --data GlobalWheat2020.yaml 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── GlobalWheat2020 ← downloads here (7.0 GB) 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | path: ../datasets/GlobalWheat2020 # dataset root dir 12 | train: # train images (relative to 'path') 3422 images 13 | - images/arvalis_1 14 | - images/arvalis_2 15 | - images/arvalis_3 16 | - images/ethz_1 17 | - images/rres_1 18 | - images/inrae_1 19 | - images/usask_1 20 | val: # val images (relative to 'path') 748 images (WARNING: train set contains ethz_1) 21 | - images/ethz_1 22 | test: # test images (optional) 1276 images 23 | - images/utokyo_1 24 | - images/utokyo_2 25 | - images/nau_1 26 | - images/uq_1 27 | 28 | # Classes 29 | names: 30 | 0: wheat_head 31 | 32 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 33 | download: | 34 | from utils.general import download, Path 35 | 36 | 37 | # Download 38 | dir = Path(yaml['path']) # dataset root dir 39 | urls = ['https://zenodo.org/record/4298502/files/global-wheat-codalab-official.zip', 40 | 'https://github.com/ultralytics/assets/releases/download/v0.0.0/GlobalWheat2020_labels.zip'] 41 | download(urls, dir=dir) 42 | 43 | # Make Directories 44 | for p in 'annotations', 'images', 'labels': 45 | (dir / p).mkdir(parents=True, exist_ok=True) 46 | 47 | # Move 48 | for p in 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'rres_1', 'inrae_1', 'usask_1', \ 49 | 'utokyo_1', 'utokyo_2', 'nau_1', 'uq_1': 50 | (dir / p).rename(dir / 'images' / p) # move to /images 51 | f = (dir / p).with_suffix('.json') # json file 52 | if f.exists(): 53 | f.rename((dir / 'annotations' / p).with_suffix('.json')) # move to /annotations 54 | -------------------------------------------------------------------------------- /data/SKU-110K.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # SKU-110K retail items dataset https://github.com/eg4000/SKU110K_CVPR19 by Trax Retail 4 | # Example usage: python train.py --data SKU-110K.yaml 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── SKU-110K ← downloads here (13.6 GB) 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | path: ../datasets/SKU-110K # dataset root dir 12 | train: train.txt # train images (relative to 'path') 8219 images 13 | val: val.txt # val images (relative to 'path') 588 images 14 | test: test.txt # test images (optional) 2936 images 15 | 16 | # Classes 17 | names: 18 | 0: object 19 | 20 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 21 | download: | 22 | import shutil 23 | from tqdm import tqdm 24 | from utils.general import np, pd, Path, download, xyxy2xywh 25 | 26 | 27 | # Download 28 | dir = Path(yaml['path']) # dataset root dir 29 | parent = Path(dir.parent) # download dir 30 | urls = ['http://trax-geometry.s3.amazonaws.com/cvpr_challenge/SKU110K_fixed.tar.gz'] 31 | download(urls, dir=parent, delete=False) 32 | 33 | # Rename directories 34 | if dir.exists(): 35 | shutil.rmtree(dir) 36 | (parent / 'SKU110K_fixed').rename(dir) # rename dir 37 | (dir / 'labels').mkdir(parents=True, exist_ok=True) # create labels dir 38 | 39 | # Convert labels 40 | names = 'image', 'x1', 'y1', 'x2', 'y2', 'class', 'image_width', 'image_height' # column names 41 | for d in 'annotations_train.csv', 'annotations_val.csv', 'annotations_test.csv': 42 | x = pd.read_csv(dir / 'annotations' / d, names=names).values # annotations 43 | images, unique_images = x[:, 0], np.unique(x[:, 0]) 44 | with open((dir / d).with_suffix('.txt').__str__().replace('annotations_', ''), 'w') as f: 45 | f.writelines(f'./images/{s}\n' for s in unique_images) 46 | for im in tqdm(unique_images, desc=f'Converting {dir / d}'): 47 | cls = 0 # single-class dataset 48 | with open((dir / 'labels' / im).with_suffix('.txt'), 'a') as f: 49 | for r in x[images == im]: 50 | w, h = r[6], r[7] # image width, height 51 | xywh = xyxy2xywh(np.array([[r[1] / w, r[2] / h, r[3] / w, r[4] / h]]))[0] # instance 52 | f.write(f"{cls} {xywh[0]:.5f} {xywh[1]:.5f} {xywh[2]:.5f} {xywh[3]:.5f}\n") # write label 53 | -------------------------------------------------------------------------------- /data/VisDrone.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # VisDrone2019-DET dataset https://github.com/VisDrone/VisDrone-Dataset by Tianjin University 4 | # Example usage: python train.py --data VisDrone.yaml 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── VisDrone ← downloads here (2.3 GB) 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | path: ../datasets/VisDrone # dataset root dir 12 | train: VisDrone2019-DET-train/images # train images (relative to 'path') 6471 images 13 | val: VisDrone2019-DET-val/images # val images (relative to 'path') 548 images 14 | test: VisDrone2019-DET-test-dev/images # test images (optional) 1610 images 15 | 16 | # Classes 17 | names: 18 | 0: pedestrian 19 | 1: people 20 | 2: bicycle 21 | 3: car 22 | 4: van 23 | 5: truck 24 | 6: tricycle 25 | 7: awning-tricycle 26 | 8: bus 27 | 9: motor 28 | 29 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 30 | download: | 31 | from utils.general import download, os, Path 32 | 33 | def visdrone2yolo(dir): 34 | from PIL import Image 35 | from tqdm import tqdm 36 | 37 | def convert_box(size, box): 38 | # Convert VisDrone box to YOLO xywh box 39 | dw = 1. / size[0] 40 | dh = 1. / size[1] 41 | return (box[0] + box[2] / 2) * dw, (box[1] + box[3] / 2) * dh, box[2] * dw, box[3] * dh 42 | 43 | (dir / 'labels').mkdir(parents=True, exist_ok=True) # make labels directory 44 | pbar = tqdm((dir / 'annotations').glob('*.txt'), desc=f'Converting {dir}') 45 | for f in pbar: 46 | img_size = Image.open((dir / 'images' / f.name).with_suffix('.jpg')).size 47 | lines = [] 48 | with open(f, 'r') as file: # read annotation.txt 49 | for row in [x.split(',') for x in file.read().strip().splitlines()]: 50 | if row[4] == '0': # VisDrone 'ignored regions' class 0 51 | continue 52 | cls = int(row[5]) - 1 53 | box = convert_box(img_size, tuple(map(int, row[:4]))) 54 | lines.append(f"{cls} {' '.join(f'{x:.6f}' for x in box)}\n") 55 | with open(str(f).replace(os.sep + 'annotations' + os.sep, os.sep + 'labels' + os.sep), 'w') as fl: 56 | fl.writelines(lines) # write label.txt 57 | 58 | 59 | # Download 60 | dir = Path(yaml['path']) # dataset root dir 61 | urls = ['https://github.com/ultralytics/assets/releases/download/v0.0.0/VisDrone2019-DET-train.zip', 62 | 'https://github.com/ultralytics/assets/releases/download/v0.0.0/VisDrone2019-DET-val.zip', 63 | 'https://github.com/ultralytics/assets/releases/download/v0.0.0/VisDrone2019-DET-test-dev.zip', 64 | 'https://github.com/ultralytics/assets/releases/download/v0.0.0/VisDrone2019-DET-test-challenge.zip'] 65 | download(urls, dir=dir, curl=True, threads=4) 66 | 67 | # Convert 68 | for d in 'VisDrone2019-DET-train', 'VisDrone2019-DET-val', 'VisDrone2019-DET-test-dev': 69 | visdrone2yolo(dir / d) # convert VisDrone annotations to YOLO labels 70 | -------------------------------------------------------------------------------- /data/coco.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # COCO 2017 dataset http://cocodataset.org by Microsoft 4 | # Example usage: python train.py --data coco.yaml 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── coco ← downloads here (20.1 GB) 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | path: ../datasets/coco # dataset root dir 12 | train: train2017.txt # train images (relative to 'path') 118287 images 13 | val: val2017.txt # val images (relative to 'path') 5000 images 14 | test: test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 15 | 16 | # Classes 17 | names: 18 | 0: person 19 | 1: bicycle 20 | 2: car 21 | 3: motorcycle 22 | 4: airplane 23 | 5: bus 24 | 6: train 25 | 7: truck 26 | 8: boat 27 | 9: traffic light 28 | 10: fire hydrant 29 | 11: stop sign 30 | 12: parking meter 31 | 13: bench 32 | 14: bird 33 | 15: cat 34 | 16: dog 35 | 17: horse 36 | 18: sheep 37 | 19: cow 38 | 20: elephant 39 | 21: bear 40 | 22: zebra 41 | 23: giraffe 42 | 24: backpack 43 | 25: umbrella 44 | 26: handbag 45 | 27: tie 46 | 28: suitcase 47 | 29: frisbee 48 | 30: skis 49 | 31: snowboard 50 | 32: sports ball 51 | 33: kite 52 | 34: baseball bat 53 | 35: baseball glove 54 | 36: skateboard 55 | 37: surfboard 56 | 38: tennis racket 57 | 39: bottle 58 | 40: wine glass 59 | 41: cup 60 | 42: fork 61 | 43: knife 62 | 44: spoon 63 | 45: bowl 64 | 46: banana 65 | 47: apple 66 | 48: sandwich 67 | 49: orange 68 | 50: broccoli 69 | 51: carrot 70 | 52: hot dog 71 | 53: pizza 72 | 54: donut 73 | 55: cake 74 | 56: chair 75 | 57: couch 76 | 58: potted plant 77 | 59: bed 78 | 60: dining table 79 | 61: toilet 80 | 62: tv 81 | 63: laptop 82 | 64: mouse 83 | 65: remote 84 | 66: keyboard 85 | 67: cell phone 86 | 68: microwave 87 | 69: oven 88 | 70: toaster 89 | 71: sink 90 | 72: refrigerator 91 | 73: book 92 | 74: clock 93 | 75: vase 94 | 76: scissors 95 | 77: teddy bear 96 | 78: hair drier 97 | 79: toothbrush 98 | 99 | # Download script/URL (optional) 100 | download: | 101 | from utils.general import download, Path 102 | 103 | 104 | # Download labels 105 | segments = False # segment or box labels 106 | dir = Path(yaml['path']) # dataset root dir 107 | url = 'https://github.com/ultralytics/assets/releases/download/v0.0.0/' 108 | urls = [url + ('coco2017labels-segments.zip' if segments else 'coco2017labels.zip')] # labels 109 | download(urls, dir=dir.parent) 110 | 111 | # Download data 112 | urls = ['http://images.cocodataset.org/zips/train2017.zip', # 19G, 118k images 113 | 'http://images.cocodataset.org/zips/val2017.zip', # 1G, 5k images 114 | 'http://images.cocodataset.org/zips/test2017.zip'] # 7G, 41k images (optional) 115 | download(urls, dir=dir / 'images', threads=3) 116 | -------------------------------------------------------------------------------- /data/coco128-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # COCO128-seg dataset https://www.kaggle.com/datasets/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics 4 | # Example usage: python train.py --data coco128.yaml 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── coco128-seg ← downloads here (7 MB) 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | path: ../datasets/coco128-seg # dataset root dir 12 | train: images/train2017 # train images (relative to 'path') 128 images 13 | val: images/train2017 # val images (relative to 'path') 128 images 14 | test: # test images (optional) 15 | 16 | # Classes 17 | names: 18 | 0: person 19 | 1: bicycle 20 | 2: car 21 | 3: motorcycle 22 | 4: airplane 23 | 5: bus 24 | 6: train 25 | 7: truck 26 | 8: boat 27 | 9: traffic light 28 | 10: fire hydrant 29 | 11: stop sign 30 | 12: parking meter 31 | 13: bench 32 | 14: bird 33 | 15: cat 34 | 16: dog 35 | 17: horse 36 | 18: sheep 37 | 19: cow 38 | 20: elephant 39 | 21: bear 40 | 22: zebra 41 | 23: giraffe 42 | 24: backpack 43 | 25: umbrella 44 | 26: handbag 45 | 27: tie 46 | 28: suitcase 47 | 29: frisbee 48 | 30: skis 49 | 31: snowboard 50 | 32: sports ball 51 | 33: kite 52 | 34: baseball bat 53 | 35: baseball glove 54 | 36: skateboard 55 | 37: surfboard 56 | 38: tennis racket 57 | 39: bottle 58 | 40: wine glass 59 | 41: cup 60 | 42: fork 61 | 43: knife 62 | 44: spoon 63 | 45: bowl 64 | 46: banana 65 | 47: apple 66 | 48: sandwich 67 | 49: orange 68 | 50: broccoli 69 | 51: carrot 70 | 52: hot dog 71 | 53: pizza 72 | 54: donut 73 | 55: cake 74 | 56: chair 75 | 57: couch 76 | 58: potted plant 77 | 59: bed 78 | 60: dining table 79 | 61: toilet 80 | 62: tv 81 | 63: laptop 82 | 64: mouse 83 | 65: remote 84 | 66: keyboard 85 | 67: cell phone 86 | 68: microwave 87 | 69: oven 88 | 70: toaster 89 | 71: sink 90 | 72: refrigerator 91 | 73: book 92 | 74: clock 93 | 75: vase 94 | 76: scissors 95 | 77: teddy bear 96 | 78: hair drier 97 | 79: toothbrush 98 | 99 | # Download script/URL (optional) 100 | download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco128-seg.zip 101 | -------------------------------------------------------------------------------- /data/coco128.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # COCO128 dataset https://www.kaggle.com/datasets/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics 4 | # Example usage: python train.py --data coco128.yaml 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── coco128 ← downloads here (7 MB) 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | path: ../datasets/coco128 # dataset root dir 12 | train: images/train2017 # train images (relative to 'path') 128 images 13 | val: images/train2017 # val images (relative to 'path') 128 images 14 | test: # test images (optional) 15 | 16 | # Classes 17 | names: 18 | 0: person 19 | 1: bicycle 20 | 2: car 21 | 3: motorcycle 22 | 4: airplane 23 | 5: bus 24 | 6: train 25 | 7: truck 26 | 8: boat 27 | 9: traffic light 28 | 10: fire hydrant 29 | 11: stop sign 30 | 12: parking meter 31 | 13: bench 32 | 14: bird 33 | 15: cat 34 | 16: dog 35 | 17: horse 36 | 18: sheep 37 | 19: cow 38 | 20: elephant 39 | 21: bear 40 | 22: zebra 41 | 23: giraffe 42 | 24: backpack 43 | 25: umbrella 44 | 26: handbag 45 | 27: tie 46 | 28: suitcase 47 | 29: frisbee 48 | 30: skis 49 | 31: snowboard 50 | 32: sports ball 51 | 33: kite 52 | 34: baseball bat 53 | 35: baseball glove 54 | 36: skateboard 55 | 37: surfboard 56 | 38: tennis racket 57 | 39: bottle 58 | 40: wine glass 59 | 41: cup 60 | 42: fork 61 | 43: knife 62 | 44: spoon 63 | 45: bowl 64 | 46: banana 65 | 47: apple 66 | 48: sandwich 67 | 49: orange 68 | 50: broccoli 69 | 51: carrot 70 | 52: hot dog 71 | 53: pizza 72 | 54: donut 73 | 55: cake 74 | 56: chair 75 | 57: couch 76 | 58: potted plant 77 | 59: bed 78 | 60: dining table 79 | 61: toilet 80 | 62: tv 81 | 63: laptop 82 | 64: mouse 83 | 65: remote 84 | 66: keyboard 85 | 67: cell phone 86 | 68: microwave 87 | 69: oven 88 | 70: toaster 89 | 71: sink 90 | 72: refrigerator 91 | 73: book 92 | 74: clock 93 | 75: vase 94 | 76: scissors 95 | 77: teddy bear 96 | 78: hair drier 97 | 79: toothbrush 98 | 99 | # Download script/URL (optional) 100 | download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco128.zip 101 | -------------------------------------------------------------------------------- /data/hyps/hyp.Objects365.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Hyperparameters for Objects365 training 4 | # python train.py --weights yolov5m.pt --data Objects365.yaml --evolve 5 | # See Hyperparameter Evolution tutorial for details https://github.com/ultralytics/yolov5#tutorials 6 | 7 | lr0: 0.00258 8 | lrf: 0.17 9 | momentum: 0.779 10 | weight_decay: 0.00058 11 | warmup_epochs: 1.33 12 | warmup_momentum: 0.86 13 | warmup_bias_lr: 0.0711 14 | box: 0.0539 15 | cls: 0.299 16 | cls_pw: 0.825 17 | obj: 0.632 18 | obj_pw: 1.0 19 | iou_t: 0.2 20 | anchor_t: 3.44 21 | anchors: 3.2 22 | fl_gamma: 0.0 23 | hsv_h: 0.0188 24 | hsv_s: 0.704 25 | hsv_v: 0.36 26 | degrees: 0.0 27 | translate: 0.0902 28 | scale: 0.491 29 | shear: 0.0 30 | perspective: 0.0 31 | flipud: 0.0 32 | fliplr: 0.5 33 | mosaic: 1.0 34 | mixup: 0.0 35 | copy_paste: 0.0 36 | -------------------------------------------------------------------------------- /data/hyps/hyp.VOC.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Hyperparameters for VOC training 4 | # python train.py --batch 128 --weights yolov5m6.pt --data VOC.yaml --epochs 50 --img 512 --hyp hyp.scratch-med.yaml --evolve 5 | # See Hyperparameter Evolution tutorial for details https://github.com/ultralytics/yolov5#tutorials 6 | 7 | # YOLOv3 Hyperparameter Evolution Results 8 | # Best generation: 467 9 | # Last generation: 996 10 | # metrics/precision, metrics/recall, metrics/mAP_0.5, metrics/mAP_0.5:0.95, val/box_loss, val/obj_loss, val/cls_loss 11 | # 0.87729, 0.85125, 0.91286, 0.72664, 0.0076739, 0.0042529, 0.0013865 12 | 13 | lr0: 0.00334 14 | lrf: 0.15135 15 | momentum: 0.74832 16 | weight_decay: 0.00025 17 | warmup_epochs: 3.3835 18 | warmup_momentum: 0.59462 19 | warmup_bias_lr: 0.18657 20 | box: 0.02 21 | cls: 0.21638 22 | cls_pw: 0.5 23 | obj: 0.51728 24 | obj_pw: 0.67198 25 | iou_t: 0.2 26 | anchor_t: 3.3744 27 | fl_gamma: 0.0 28 | hsv_h: 0.01041 29 | hsv_s: 0.54703 30 | hsv_v: 0.27739 31 | degrees: 0.0 32 | translate: 0.04591 33 | scale: 0.75544 34 | shear: 0.0 35 | perspective: 0.0 36 | flipud: 0.0 37 | fliplr: 0.5 38 | mosaic: 0.85834 39 | mixup: 0.04266 40 | copy_paste: 0.0 41 | anchors: 3.412 42 | -------------------------------------------------------------------------------- /data/hyps/hyp.no-augmentation.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Hyperparameters when using Albumentations frameworks 4 | # python train.py --hyp hyp.no-augmentation.yaml 5 | # See https://github.com/ultralytics/yolov5/pull/3882 for YOLOv3 + Albumentations Usage examples 6 | 7 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 8 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 9 | momentum: 0.937 # SGD momentum/Adam beta1 10 | weight_decay: 0.0005 # optimizer weight decay 5e-4 11 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 12 | warmup_momentum: 0.8 # warmup initial momentum 13 | warmup_bias_lr: 0.1 # warmup initial bias lr 14 | box: 0.05 # box loss gain 15 | cls: 0.3 # cls loss gain 16 | cls_pw: 1.0 # cls BCELoss positive_weight 17 | obj: 0.7 # obj loss gain (scale with pixels) 18 | obj_pw: 1.0 # obj BCELoss positive_weight 19 | iou_t: 0.20 # IoU training threshold 20 | anchor_t: 4.0 # anchor-multiple threshold 21 | # anchors: 3 # anchors per output layer (0 to ignore) 22 | # this parameters are all zero since we want to use albumentation framework 23 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 24 | hsv_h: 0 # image HSV-Hue augmentation (fraction) 25 | hsv_s: 0 # image HSV-Saturation augmentation (fraction) 26 | hsv_v: 0 # image HSV-Value augmentation (fraction) 27 | degrees: 0.0 # image rotation (+/- deg) 28 | translate: 0 # image translation (+/- fraction) 29 | scale: 0 # image scale (+/- gain) 30 | shear: 0 # image shear (+/- deg) 31 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 32 | flipud: 0.0 # image flip up-down (probability) 33 | fliplr: 0.0 # image flip left-right (probability) 34 | mosaic: 0.0 # image mosaic (probability) 35 | mixup: 0.0 # image mixup (probability) 36 | copy_paste: 0.0 # segment copy-paste (probability) 37 | -------------------------------------------------------------------------------- /data/hyps/hyp.scratch-high.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Hyperparameters for high-augmentation COCO training from scratch 4 | # python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300 5 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 6 | 7 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 8 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 9 | momentum: 0.937 # SGD momentum/Adam beta1 10 | weight_decay: 0.0005 # optimizer weight decay 5e-4 11 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 12 | warmup_momentum: 0.8 # warmup initial momentum 13 | warmup_bias_lr: 0.1 # warmup initial bias lr 14 | box: 0.05 # box loss gain 15 | cls: 0.3 # cls loss gain 16 | cls_pw: 1.0 # cls BCELoss positive_weight 17 | obj: 0.7 # obj loss gain (scale with pixels) 18 | obj_pw: 1.0 # obj BCELoss positive_weight 19 | iou_t: 0.20 # IoU training threshold 20 | anchor_t: 4.0 # anchor-multiple threshold 21 | # anchors: 3 # anchors per output layer (0 to ignore) 22 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 23 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 24 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 25 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 26 | degrees: 0.0 # image rotation (+/- deg) 27 | translate: 0.1 # image translation (+/- fraction) 28 | scale: 0.9 # image scale (+/- gain) 29 | shear: 0.0 # image shear (+/- deg) 30 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 31 | flipud: 0.0 # image flip up-down (probability) 32 | fliplr: 0.5 # image flip left-right (probability) 33 | mosaic: 1.0 # image mosaic (probability) 34 | mixup: 0.1 # image mixup (probability) 35 | copy_paste: 0.1 # segment copy-paste (probability) 36 | -------------------------------------------------------------------------------- /data/hyps/hyp.scratch-low.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Hyperparameters for low-augmentation COCO training from scratch 4 | # python train.py --batch 64 --cfg yolov5n6.yaml --weights '' --data coco.yaml --img 640 --epochs 300 --linear 5 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 6 | 7 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 8 | lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf) 9 | momentum: 0.937 # SGD momentum/Adam beta1 10 | weight_decay: 0.0005 # optimizer weight decay 5e-4 11 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 12 | warmup_momentum: 0.8 # warmup initial momentum 13 | warmup_bias_lr: 0.1 # warmup initial bias lr 14 | box: 0.05 # box loss gain 15 | cls: 0.5 # cls loss gain 16 | cls_pw: 1.0 # cls BCELoss positive_weight 17 | obj: 1.0 # obj loss gain (scale with pixels) 18 | obj_pw: 1.0 # obj BCELoss positive_weight 19 | iou_t: 0.20 # IoU training threshold 20 | anchor_t: 4.0 # anchor-multiple threshold 21 | # anchors: 3 # anchors per output layer (0 to ignore) 22 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 23 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 24 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 25 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 26 | degrees: 0.0 # image rotation (+/- deg) 27 | translate: 0.1 # image translation (+/- fraction) 28 | scale: 0.5 # image scale (+/- gain) 29 | shear: 0.0 # image shear (+/- deg) 30 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 31 | flipud: 0.0 # image flip up-down (probability) 32 | fliplr: 0.5 # image flip left-right (probability) 33 | mosaic: 1.0 # image mosaic (probability) 34 | mixup: 0.0 # image mixup (probability) 35 | copy_paste: 0.0 # segment copy-paste (probability) 36 | -------------------------------------------------------------------------------- /data/hyps/hyp.scratch-med.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Hyperparameters for medium-augmentation COCO training from scratch 4 | # python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300 5 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials 6 | 7 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3) 8 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf) 9 | momentum: 0.937 # SGD momentum/Adam beta1 10 | weight_decay: 0.0005 # optimizer weight decay 5e-4 11 | warmup_epochs: 3.0 # warmup epochs (fractions ok) 12 | warmup_momentum: 0.8 # warmup initial momentum 13 | warmup_bias_lr: 0.1 # warmup initial bias lr 14 | box: 0.05 # box loss gain 15 | cls: 0.3 # cls loss gain 16 | cls_pw: 1.0 # cls BCELoss positive_weight 17 | obj: 0.7 # obj loss gain (scale with pixels) 18 | obj_pw: 1.0 # obj BCELoss positive_weight 19 | iou_t: 0.20 # IoU training threshold 20 | anchor_t: 4.0 # anchor-multiple threshold 21 | # anchors: 3 # anchors per output layer (0 to ignore) 22 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) 23 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction) 24 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) 25 | hsv_v: 0.4 # image HSV-Value augmentation (fraction) 26 | degrees: 0.0 # image rotation (+/- deg) 27 | translate: 0.1 # image translation (+/- fraction) 28 | scale: 0.9 # image scale (+/- gain) 29 | shear: 0.0 # image shear (+/- deg) 30 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 31 | flipud: 0.0 # image flip up-down (probability) 32 | fliplr: 0.5 # image flip left-right (probability) 33 | mosaic: 1.0 # image mosaic (probability) 34 | mixup: 0.1 # image mixup (probability) 35 | copy_paste: 0.0 # segment copy-paste (probability) 36 | -------------------------------------------------------------------------------- /data/images/bus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ultralytics/yolov3/6c16b2be18ff3e0e7c4a60c29ebaff7d7b0df892/data/images/bus.jpg -------------------------------------------------------------------------------- /data/images/zidane.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ultralytics/yolov3/6c16b2be18ff3e0e7c4a60c29ebaff7d7b0df892/data/images/zidane.jpg -------------------------------------------------------------------------------- /data/scripts/download_weights.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 3 | 4 | # Download latest models from https://github.com/ultralytics/yolov5/releases 5 | # Example usage: bash data/scripts/download_weights.sh 6 | # parent 7 | # └── yolov5 8 | # ├── yolov5s.pt ← downloads here 9 | # ├── yolov5m.pt 10 | # └── ... 11 | 12 | python - << EOF 13 | from utils.downloads import attempt_download 14 | 15 | p5 = list('nsmlx') # P5 models 16 | p6 = [f'{x}6' for x in p5] # P6 models 17 | cls = [f'{x}-cls' for x in p5] # classification models 18 | seg = [f'{x}-seg' for x in p5] # classification models 19 | 20 | for x in p5 + p6 + cls + seg: 21 | attempt_download(f'weights/yolov5{x}.pt') 22 | 23 | EOF 24 | -------------------------------------------------------------------------------- /data/scripts/get_coco.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 3 | 4 | # Download COCO 2017 dataset http://cocodataset.org 5 | # Example usage: bash data/scripts/get_coco.sh 6 | # parent 7 | # ├── yolov5 8 | # └── datasets 9 | # └── coco ← downloads here 10 | 11 | # Arguments (optional) Usage: bash data/scripts/get_coco.sh --train --val --test --segments 12 | if [ "$#" -gt 0 ]; then 13 | for opt in "$@"; do 14 | case "${opt}" in 15 | --train) train=true ;; 16 | --val) val=true ;; 17 | --test) test=true ;; 18 | --segments) segments=true ;; 19 | esac 20 | done 21 | else 22 | train=true 23 | val=true 24 | test=false 25 | segments=false 26 | fi 27 | 28 | # Download/unzip labels 29 | d='../datasets' # unzip directory 30 | url=https://github.com/ultralytics/yolov5/releases/download/v1.0/ 31 | if [ "$segments" == "true" ]; then 32 | f='coco2017labels-segments.zip' # 168 MB 33 | else 34 | f='coco2017labels.zip' # 46 MB 35 | fi 36 | echo 'Downloading' $url$f ' ...' 37 | curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f & 38 | 39 | # Download/unzip images 40 | d='../datasets/coco/images' # unzip directory 41 | url=http://images.cocodataset.org/zips/ 42 | if [ "$train" == "true" ]; then 43 | f='train2017.zip' # 19G, 118k images 44 | echo 'Downloading' $url$f '...' 45 | curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f & 46 | fi 47 | if [ "$val" == "true" ]; then 48 | f='val2017.zip' # 1G, 5k images 49 | echo 'Downloading' $url$f '...' 50 | curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f & 51 | fi 52 | if [ "$test" == "true" ]; then 53 | f='test2017.zip' # 7G, 41k images (optional) 54 | echo 'Downloading' $url$f '...' 55 | curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f & 56 | fi 57 | wait # finish background tasks 58 | -------------------------------------------------------------------------------- /data/scripts/get_coco128.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 3 | 4 | # Download COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) 5 | # Example usage: bash data/scripts/get_coco128.sh 6 | # parent 7 | # ├── yolov5 8 | # └── datasets 9 | # └── coco128 ← downloads here 10 | 11 | # Download/unzip images and labels 12 | d='../datasets' # unzip directory 13 | url=https://github.com/ultralytics/yolov5/releases/download/v1.0/ 14 | f='coco128.zip' # or 'coco128-segments.zip', 68 MB 15 | echo 'Downloading' $url$f ' ...' 16 | curl -L $url$f -o $f -# && unzip -q $f -d $d && rm $f & 17 | 18 | wait # finish background tasks 19 | -------------------------------------------------------------------------------- /data/scripts/get_imagenet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 3 | 4 | # Download ILSVRC2012 ImageNet dataset https://image-net.org 5 | # Example usage: bash data/scripts/get_imagenet.sh 6 | # parent 7 | # ├── yolov5 8 | # └── datasets 9 | # └── imagenet ← downloads here 10 | 11 | # Arguments (optional) Usage: bash data/scripts/get_imagenet.sh --train --val 12 | if [ "$#" -gt 0 ]; then 13 | for opt in "$@"; do 14 | case "${opt}" in 15 | --train) train=true ;; 16 | --val) val=true ;; 17 | esac 18 | done 19 | else 20 | train=true 21 | val=true 22 | fi 23 | 24 | # Make dir 25 | d='../datasets/imagenet' # unzip directory 26 | mkdir -p $d && cd $d 27 | 28 | # Download/unzip train 29 | if [ "$train" == "true" ]; then 30 | wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_train.tar # download 138G, 1281167 images 31 | mkdir train && mv ILSVRC2012_img_train.tar train/ && cd train 32 | tar -xf ILSVRC2012_img_train.tar && rm -f ILSVRC2012_img_train.tar 33 | find . -name "*.tar" | while read NAME; do 34 | mkdir -p "${NAME%.tar}" 35 | tar -xf "${NAME}" -C "${NAME%.tar}" 36 | rm -f "${NAME}" 37 | done 38 | cd .. 39 | fi 40 | 41 | # Download/unzip val 42 | if [ "$val" == "true" ]; then 43 | wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar # download 6.3G, 50000 images 44 | mkdir val && mv ILSVRC2012_img_val.tar val/ && cd val && tar -xf ILSVRC2012_img_val.tar 45 | wget -qO- https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh | bash # move into subdirs 46 | fi 47 | 48 | # Delete corrupted image (optional: PNG under JPEG name that may cause dataloaders to fail) 49 | # rm train/n04266014/n04266014_10835.JPEG 50 | 51 | # TFRecords (optional) 52 | # wget https://raw.githubusercontent.com/tensorflow/models/master/research/slim/datasets/imagenet_lsvrc_2015_synsets.txt 53 | -------------------------------------------------------------------------------- /data/voc.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC by University of Oxford 4 | # Example usage: python train.py --data VOC.yaml 5 | # parent 6 | # ├── yolov5 7 | # └── datasets 8 | # └── VOC ← downloads here (2.8 GB) 9 | 10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 11 | path: ../datasets/VOC 12 | train: # train images (relative to 'path') 16551 images 13 | - images/train2012 14 | - images/train2007 15 | - images/val2012 16 | - images/val2007 17 | val: # val images (relative to 'path') 4952 images 18 | - images/test2007 19 | test: # test images (optional) 20 | - images/test2007 21 | 22 | # Classes 23 | names: 24 | 0: aeroplane 25 | 1: bicycle 26 | 2: bird 27 | 3: boat 28 | 4: bottle 29 | 5: bus 30 | 6: car 31 | 7: cat 32 | 8: chair 33 | 9: cow 34 | 10: diningtable 35 | 11: dog 36 | 12: horse 37 | 13: motorbike 38 | 14: person 39 | 15: pottedplant 40 | 16: sheep 41 | 17: sofa 42 | 18: train 43 | 19: tvmonitor 44 | 45 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 46 | download: | 47 | import xml.etree.ElementTree as ET 48 | 49 | from tqdm import tqdm 50 | from utils.general import download, Path 51 | 52 | 53 | def convert_label(path, lb_path, year, image_id): 54 | def convert_box(size, box): 55 | dw, dh = 1. / size[0], 1. / size[1] 56 | x, y, w, h = (box[0] + box[1]) / 2.0 - 1, (box[2] + box[3]) / 2.0 - 1, box[1] - box[0], box[3] - box[2] 57 | return x * dw, y * dh, w * dw, h * dh 58 | 59 | in_file = open(path / f'VOC{year}/Annotations/{image_id}.xml') 60 | out_file = open(lb_path, 'w') 61 | tree = ET.parse(in_file) 62 | root = tree.getroot() 63 | size = root.find('size') 64 | w = int(size.find('width').text) 65 | h = int(size.find('height').text) 66 | 67 | names = list(yaml['names'].values()) # names list 68 | for obj in root.iter('object'): 69 | cls = obj.find('name').text 70 | if cls in names and int(obj.find('difficult').text) != 1: 71 | xmlbox = obj.find('bndbox') 72 | bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax')]) 73 | cls_id = names.index(cls) # class id 74 | out_file.write(" ".join([str(a) for a in (cls_id, *bb)]) + '\n') 75 | 76 | 77 | # Download 78 | dir = Path(yaml['path']) # dataset root dir 79 | url = 'https://github.com/ultralytics/assets/releases/download/v0.0.0/' 80 | urls = [f'{url}VOCtrainval_06-Nov-2007.zip', # 446MB, 5012 images 81 | f'{url}VOCtest_06-Nov-2007.zip', # 438MB, 4953 images 82 | f'{url}VOCtrainval_11-May-2012.zip'] # 1.95GB, 17126 images 83 | download(urls, dir=dir / 'images', delete=False, curl=True, threads=3) 84 | 85 | # Convert 86 | path = dir / 'images/VOCdevkit' 87 | for year, image_set in ('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test'): 88 | imgs_path = dir / 'images' / f'{image_set}{year}' 89 | lbs_path = dir / 'labels' / f'{image_set}{year}' 90 | imgs_path.mkdir(exist_ok=True, parents=True) 91 | lbs_path.mkdir(exist_ok=True, parents=True) 92 | 93 | with open(path / f'VOC{year}/ImageSets/Main/{image_set}.txt') as f: 94 | image_ids = f.read().strip().split() 95 | for id in tqdm(image_ids, desc=f'{image_set}{year}'): 96 | f = path / f'VOC{year}/JPEGImages/{id}.jpg' # old img path 97 | lb_path = (lbs_path / f.name).with_suffix('.txt') # new label path 98 | f.rename(imgs_path / f.name) # move image 99 | convert_label(path, lb_path, year, id) # convert labels to YOLO format 100 | -------------------------------------------------------------------------------- /data/xView.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # DIUx xView 2018 Challenge https://challenge.xviewdataset.org by U.S. National Geospatial-Intelligence Agency (NGA) 4 | # -------- DOWNLOAD DATA MANUALLY and jar xf val_images.zip to 'datasets/xView' before running train command! -------- 5 | # Example usage: python train.py --data xView.yaml 6 | # parent 7 | # ├── yolov5 8 | # └── datasets 9 | # └── xView ← downloads here (20.7 GB) 10 | 11 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] 12 | path: ../datasets/xView # dataset root dir 13 | train: images/autosplit_train.txt # train images (relative to 'path') 90% of 847 train images 14 | val: images/autosplit_val.txt # train images (relative to 'path') 10% of 847 train images 15 | 16 | # Classes 17 | names: 18 | 0: Fixed-wing Aircraft 19 | 1: Small Aircraft 20 | 2: Cargo Plane 21 | 3: Helicopter 22 | 4: Passenger Vehicle 23 | 5: Small Car 24 | 6: Bus 25 | 7: Pickup Truck 26 | 8: Utility Truck 27 | 9: Truck 28 | 10: Cargo Truck 29 | 11: Truck w/Box 30 | 12: Truck Tractor 31 | 13: Trailer 32 | 14: Truck w/Flatbed 33 | 15: Truck w/Liquid 34 | 16: Crane Truck 35 | 17: Railway Vehicle 36 | 18: Passenger Car 37 | 19: Cargo Car 38 | 20: Flat Car 39 | 21: Tank car 40 | 22: Locomotive 41 | 23: Maritime Vessel 42 | 24: Motorboat 43 | 25: Sailboat 44 | 26: Tugboat 45 | 27: Barge 46 | 28: Fishing Vessel 47 | 29: Ferry 48 | 30: Yacht 49 | 31: Container Ship 50 | 32: Oil Tanker 51 | 33: Engineering Vehicle 52 | 34: Tower crane 53 | 35: Container Crane 54 | 36: Reach Stacker 55 | 37: Straddle Carrier 56 | 38: Mobile Crane 57 | 39: Dump Truck 58 | 40: Haul Truck 59 | 41: Scraper/Tractor 60 | 42: Front loader/Bulldozer 61 | 43: Excavator 62 | 44: Cement Mixer 63 | 45: Ground Grader 64 | 46: Hut/Tent 65 | 47: Shed 66 | 48: Building 67 | 49: Aircraft Hangar 68 | 50: Damaged Building 69 | 51: Facility 70 | 52: Construction Site 71 | 53: Vehicle Lot 72 | 54: Helipad 73 | 55: Storage Tank 74 | 56: Shipping container lot 75 | 57: Shipping Container 76 | 58: Pylon 77 | 59: Tower 78 | 79 | # Download script/URL (optional) --------------------------------------------------------------------------------------- 80 | download: | 81 | import json 82 | import os 83 | from pathlib import Path 84 | 85 | import numpy as np 86 | from PIL import Image 87 | from tqdm import tqdm 88 | 89 | from utils.dataloaders import autosplit 90 | from utils.general import download, xyxy2xywhn 91 | 92 | 93 | def convert_labels(fname=Path('xView/xView_train.geojson')): 94 | # Convert xView geoJSON labels to YOLO format 95 | path = fname.parent 96 | with open(fname) as f: 97 | print(f'Loading {fname}...') 98 | data = json.load(f) 99 | 100 | # Make dirs 101 | labels = Path(path / 'labels' / 'train') 102 | os.system(f'rm -rf {labels}') 103 | labels.mkdir(parents=True, exist_ok=True) 104 | 105 | # xView classes 11-94 to 0-59 106 | xview_class2index = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, -1, 3, -1, 4, 5, 6, 7, 8, -1, 9, 10, 11, 107 | 12, 13, 14, 15, -1, -1, 16, 17, 18, 19, 20, 21, 22, -1, 23, 24, 25, -1, 26, 27, -1, 28, -1, 108 | 29, 30, 31, 32, 33, 34, 35, 36, 37, -1, 38, 39, 40, 41, 42, 43, 44, 45, -1, -1, -1, -1, 46, 109 | 47, 48, 49, -1, 50, 51, -1, 52, -1, -1, -1, 53, 54, -1, 55, -1, -1, 56, -1, 57, -1, 58, 59] 110 | 111 | shapes = {} 112 | for feature in tqdm(data['features'], desc=f'Converting {fname}'): 113 | p = feature['properties'] 114 | if p['bounds_imcoords']: 115 | id = p['image_id'] 116 | file = path / 'train_images' / id 117 | if file.exists(): # 1395.tif missing 118 | try: 119 | box = np.array([int(num) for num in p['bounds_imcoords'].split(",")]) 120 | assert box.shape[0] == 4, f'incorrect box shape {box.shape[0]}' 121 | cls = p['type_id'] 122 | cls = xview_class2index[int(cls)] # xView class to 0-60 123 | assert 59 >= cls >= 0, f'incorrect class index {cls}' 124 | 125 | # Write YOLO label 126 | if id not in shapes: 127 | shapes[id] = Image.open(file).size 128 | box = xyxy2xywhn(box[None].astype(np.float), w=shapes[id][0], h=shapes[id][1], clip=True) 129 | with open((labels / id).with_suffix('.txt'), 'a') as f: 130 | f.write(f"{cls} {' '.join(f'{x:.6f}' for x in box[0])}\n") # write label.txt 131 | except Exception as e: 132 | print(f'WARNING: skipping one label for {file}: {e}') 133 | 134 | 135 | # Download manually from https://challenge.xviewdataset.org 136 | dir = Path(yaml['path']) # dataset root dir 137 | # urls = ['https://d307kc0mrhucc3.cloudfront.net/train_labels.zip', # train labels 138 | # 'https://d307kc0mrhucc3.cloudfront.net/train_images.zip', # 15G, 847 train images 139 | # 'https://d307kc0mrhucc3.cloudfront.net/val_images.zip'] # 5G, 282 val images (no labels) 140 | # download(urls, dir=dir, delete=False) 141 | 142 | # Convert labels 143 | convert_labels(dir / 'xView_train.geojson') 144 | 145 | # Move images 146 | images = Path(dir / 'images') 147 | images.mkdir(parents=True, exist_ok=True) 148 | Path(dir / 'train_images').rename(dir / 'images' / 'train') 149 | Path(dir / 'val_images').rename(dir / 'images' / 'val') 150 | 151 | # Split 152 | autosplit(dir / 'images' / 'train') 153 | -------------------------------------------------------------------------------- /models/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | -------------------------------------------------------------------------------- /models/experimental.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Experimental modules.""" 3 | 4 | import math 5 | 6 | import numpy as np 7 | import torch 8 | import torch.nn as nn 9 | 10 | from utils.downloads import attempt_download 11 | 12 | 13 | class Sum(nn.Module): 14 | """Computes the weighted or unweighted sum of multiple input layers per https://arxiv.org/abs/1911.09070.""" 15 | 16 | def __init__(self, n, weight=False): # n: number of inputs 17 | """ 18 | Initializes a module to compute weighted/unweighted sum of n inputs, with optional learning weights. 19 | 20 | https://arxiv.org/abs/1911.09070 21 | """ 22 | super().__init__() 23 | self.weight = weight # apply weights boolean 24 | self.iter = range(n - 1) # iter object 25 | if weight: 26 | self.w = nn.Parameter(-torch.arange(1.0, n) / 2, requires_grad=True) # layer weights 27 | 28 | def forward(self, x): 29 | """ 30 | Performs forward pass, blending `x` elements with optional learnable weights. 31 | 32 | See https://arxiv.org/abs/1911.09070 for more. 33 | """ 34 | y = x[0] # no weight 35 | if self.weight: 36 | w = torch.sigmoid(self.w) * 2 37 | for i in self.iter: 38 | y = y + x[i + 1] * w[i] 39 | else: 40 | for i in self.iter: 41 | y = y + x[i + 1] 42 | return y 43 | 44 | 45 | class MixConv2d(nn.Module): 46 | """Implements mixed depth-wise convolutions for efficient neural networks; see https://arxiv.org/abs/1907.09595.""" 47 | 48 | def __init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True): # ch_in, ch_out, kernel, stride, ch_strategy 49 | """Initializes MixConv2d with mixed depth-wise convolution layers; details at 50 | https://arxiv.org/abs/1907.09595. 51 | """ 52 | super().__init__() 53 | n = len(k) # number of convolutions 54 | if equal_ch: # equal c_ per group 55 | i = torch.linspace(0, n - 1e-6, c2).floor() # c2 indices 56 | c_ = [(i == g).sum() for g in range(n)] # intermediate channels 57 | else: # equal weight.numel() per group 58 | b = [c2] + [0] * n 59 | a = np.eye(n + 1, n, k=-1) 60 | a -= np.roll(a, 1, axis=1) 61 | a *= np.array(k) ** 2 62 | a[0] = 1 63 | c_ = np.linalg.lstsq(a, b, rcond=None)[0].round() # solve for equal weight indices, ax = b 64 | 65 | self.m = nn.ModuleList( 66 | [nn.Conv2d(c1, int(c_), k, s, k // 2, groups=math.gcd(c1, int(c_)), bias=False) for k, c_ in zip(k, c_)] 67 | ) 68 | self.bn = nn.BatchNorm2d(c2) 69 | self.act = nn.SiLU() 70 | 71 | def forward(self, x): 72 | """Applies a series of convolutions, batch normalization, and SiLU activation to input tensor `x`.""" 73 | return self.act(self.bn(torch.cat([m(x) for m in self.m], 1))) 74 | 75 | 76 | class Ensemble(nn.ModuleList): 77 | """Combines outputs from multiple models to improve inference results.""" 78 | 79 | def __init__(self): 80 | """Initializes an ensemble of models to combine their outputs.""" 81 | super().__init__() 82 | 83 | def forward(self, x, augment=False, profile=False, visualize=False): 84 | """Applies ensemble of models on input `x`, with options for augmentation, profiling, and visualization, 85 | returning inference outputs. 86 | """ 87 | y = [module(x, augment, profile, visualize)[0] for module in self] 88 | # y = torch.stack(y).max(0)[0] # max ensemble 89 | # y = torch.stack(y).mean(0) # mean ensemble 90 | y = torch.cat(y, 1) # nms ensemble 91 | return y, None # inference, train output 92 | 93 | 94 | def attempt_load(weights, device=None, inplace=True, fuse=True): 95 | """Loads an ensemble or single model weights, supports device placement and model fusion.""" 96 | from models.yolo import Detect, Model 97 | 98 | model = Ensemble() 99 | for w in weights if isinstance(weights, list) else [weights]: 100 | ckpt = torch.load(attempt_download(w), map_location="cpu") # load 101 | ckpt = (ckpt.get("ema") or ckpt["model"]).to(device).float() # FP32 model 102 | 103 | # Model compatibility updates 104 | if not hasattr(ckpt, "stride"): 105 | ckpt.stride = torch.tensor([32.0]) 106 | if hasattr(ckpt, "names") and isinstance(ckpt.names, (list, tuple)): 107 | ckpt.names = dict(enumerate(ckpt.names)) # convert to dict 108 | 109 | model.append(ckpt.fuse().eval() if fuse and hasattr(ckpt, "fuse") else ckpt.eval()) # model in eval mode 110 | 111 | # Module compatibility updates 112 | for m in model.modules(): 113 | t = type(m) 114 | if t in (nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model): 115 | m.inplace = inplace # torch 1.7.0 compatibility 116 | if t is Detect and not isinstance(m.anchor_grid, list): 117 | delattr(m, "anchor_grid") 118 | setattr(m, "anchor_grid", [torch.zeros(1)] * m.nl) 119 | elif t is nn.Upsample and not hasattr(m, "recompute_scale_factor"): 120 | m.recompute_scale_factor = None # torch 1.11.0 compatibility 121 | 122 | # Return model 123 | if len(model) == 1: 124 | return model[-1] 125 | 126 | # Return detection ensemble 127 | print(f"Ensemble created with {weights}\n") 128 | for k in "names", "nc", "yaml": 129 | setattr(model, k, getattr(model[0], k)) 130 | model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride # max stride 131 | assert all(model[0].nc == m.nc for m in model), f"Models have different class counts: {[m.nc for m in model]}" 132 | return model 133 | -------------------------------------------------------------------------------- /models/hub/anchors.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Default anchors for COCO data 4 | 5 | # P5 ------------------------------------------------------------------------------------------------------------------- 6 | # P5-640: 7 | anchors_p5_640: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # P6 ------------------------------------------------------------------------------------------------------------------- 13 | # P6-640: thr=0.25: 0.9964 BPR, 5.54 anchors past thr, n=12, img_size=640, metric_all=0.281/0.716-mean/best, past_thr=0.469-mean: 9,11, 21,19, 17,41, 43,32, 39,70, 86,64, 65,131, 134,130, 120,265, 282,180, 247,354, 512,387 14 | anchors_p6_640: 15 | - [9, 11, 21, 19, 17, 41] # P3/8 16 | - [43, 32, 39, 70, 86, 64] # P4/16 17 | - [65, 131, 134, 130, 120, 265] # P5/32 18 | - [282, 180, 247, 354, 512, 387] # P6/64 19 | 20 | # P6-1280: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792 21 | anchors_p6_1280: 22 | - [19, 27, 44, 40, 38, 94] # P3/8 23 | - [96, 68, 86, 152, 180, 137] # P4/16 24 | - [140, 301, 303, 264, 238, 542] # P5/32 25 | - [436, 615, 739, 380, 925, 792] # P6/64 26 | 27 | # P6-1920: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1920, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 28,41, 67,59, 57,141, 144,103, 129,227, 270,205, 209,452, 455,396, 358,812, 653,922, 1109,570, 1387,1187 28 | anchors_p6_1920: 29 | - [28, 41, 67, 59, 57, 141] # P3/8 30 | - [144, 103, 129, 227, 270, 205] # P4/16 31 | - [209, 452, 455, 396, 358, 812] # P5/32 32 | - [653, 922, 1109, 570, 1387, 1187] # P6/64 33 | 34 | # P7 ------------------------------------------------------------------------------------------------------------------- 35 | # P7-640: thr=0.25: 0.9962 BPR, 6.76 anchors past thr, n=15, img_size=640, metric_all=0.275/0.733-mean/best, past_thr=0.466-mean: 11,11, 13,30, 29,20, 30,46, 61,38, 39,92, 78,80, 146,66, 79,163, 149,150, 321,143, 157,303, 257,402, 359,290, 524,372 36 | anchors_p7_640: 37 | - [11, 11, 13, 30, 29, 20] # P3/8 38 | - [30, 46, 61, 38, 39, 92] # P4/16 39 | - [78, 80, 146, 66, 79, 163] # P5/32 40 | - [149, 150, 321, 143, 157, 303] # P6/64 41 | - [257, 402, 359, 290, 524, 372] # P7/128 42 | 43 | # P7-1280: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1280, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 19,22, 54,36, 32,77, 70,83, 138,71, 75,173, 165,159, 148,334, 375,151, 334,317, 251,626, 499,474, 750,326, 534,814, 1079,818 44 | anchors_p7_1280: 45 | - [19, 22, 54, 36, 32, 77] # P3/8 46 | - [70, 83, 138, 71, 75, 173] # P4/16 47 | - [165, 159, 148, 334, 375, 151] # P5/32 48 | - [334, 317, 251, 626, 499, 474] # P6/64 49 | - [750, 326, 534, 814, 1079, 818] # P7/128 50 | 51 | # P7-1920: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1920, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 29,34, 81,55, 47,115, 105,124, 207,107, 113,259, 247,238, 222,500, 563,227, 501,476, 376,939, 749,711, 1126,489, 801,1222, 1618,1227 52 | anchors_p7_1920: 53 | - [29, 34, 81, 55, 47, 115] # P3/8 54 | - [105, 124, 207, 107, 113, 259] # P4/16 55 | - [247, 238, 222, 500, 563, 227] # P5/32 56 | - [501, 476, 376, 939, 749, 711] # P6/64 57 | - [1126, 489, 801, 1222, 1618, 1227] # P7/128 58 | -------------------------------------------------------------------------------- /models/hub/yolov5-bifpn.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 BiFPN head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14, 6], 1, Concat, [1]], # cat P4 <--- BiFPN change 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/hub/yolov5-fpn.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 FPN head 29 | head: [ 30 | [-1, 3, C3, [1024, False]], # 10 (P5/32-large) 31 | 32 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 33 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 34 | [-1, 1, Conv, [512, 1, 1]], 35 | [-1, 3, C3, [512, False]], # 14 (P4/16-medium) 36 | 37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 38 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 39 | [-1, 1, Conv, [256, 1, 1]], 40 | [-1, 3, C3, [256, False]], # 18 (P3/8-small) 41 | 42 | [[18, 14, 10], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 43 | ] 44 | -------------------------------------------------------------------------------- /models/hub/yolov5-p2.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer 8 | 9 | # YOLOv5 v6.0 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [ 13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 15 | [-1, 3, C3, [128]], 16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 17 | [-1, 6, C3, [256]], 18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 19 | [-1, 9, C3, [512]], 20 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 21 | [-1, 3, C3, [1024]], 22 | [-1, 1, SPPF, [1024, 5]], # 9 23 | ] 24 | 25 | # YOLOv5 v6.0 head with (P2, P3, P4, P5) outputs 26 | head: [ 27 | [-1, 1, Conv, [512, 1, 1]], 28 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 29 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 30 | [-1, 3, C3, [512, False]], # 13 31 | 32 | [-1, 1, Conv, [256, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 34 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 35 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 36 | 37 | [-1, 1, Conv, [128, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 39 | [[-1, 2], 1, Concat, [1]], # cat backbone P2 40 | [-1, 1, C3, [128, False]], # 21 (P2/4-xsmall) 41 | 42 | [-1, 1, Conv, [128, 3, 2]], 43 | [[-1, 18], 1, Concat, [1]], # cat head P3 44 | [-1, 3, C3, [256, False]], # 24 (P3/8-small) 45 | 46 | [-1, 1, Conv, [256, 3, 2]], 47 | [[-1, 14], 1, Concat, [1]], # cat head P4 48 | [-1, 3, C3, [512, False]], # 27 (P4/16-medium) 49 | 50 | [-1, 1, Conv, [512, 3, 2]], 51 | [[-1, 10], 1, Concat, [1]], # cat head P5 52 | [-1, 3, C3, [1024, False]], # 30 (P5/32-large) 53 | 54 | [[21, 24, 27, 30], 1, Detect, [nc, anchors]], # Detect(P2, P3, P4, P5) 55 | ] 56 | -------------------------------------------------------------------------------- /models/hub/yolov5-p34.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer 8 | 9 | # YOLOv5 v6.0 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [ 13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 15 | [-1, 3, C3, [128]], 16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 17 | [-1, 6, C3, [256]], 18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 19 | [-1, 9, C3, [512]], 20 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 21 | [-1, 3, C3, [1024]], 22 | [-1, 1, SPPF, [1024, 5]], # 9 23 | ] 24 | 25 | # YOLOv5 v6.0 head with (P3, P4) outputs 26 | head: [ 27 | [-1, 1, Conv, [512, 1, 1]], 28 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 29 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 30 | [-1, 3, C3, [512, False]], # 13 31 | 32 | [-1, 1, Conv, [256, 1, 1]], 33 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 34 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 35 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 36 | 37 | [-1, 1, Conv, [256, 3, 2]], 38 | [[-1, 14], 1, Concat, [1]], # cat head P4 39 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 40 | 41 | [[17, 20], 1, Detect, [nc, anchors]], # Detect(P3, P4) 42 | ] 43 | -------------------------------------------------------------------------------- /models/hub/yolov5-p6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer 8 | 9 | # YOLOv5 v6.0 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [ 13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 15 | [-1, 3, C3, [128]], 16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 17 | [-1, 6, C3, [256]], 18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 19 | [-1, 9, C3, [512]], 20 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 21 | [-1, 3, C3, [768]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, SPPF, [1024, 5]], # 11 25 | ] 26 | 27 | # YOLOv5 v6.0 head with (P3, P4, P5, P6) outputs 28 | head: [ 29 | [-1, 1, Conv, [768, 1, 1]], 30 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 31 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 32 | [-1, 3, C3, [768, False]], # 15 33 | 34 | [-1, 1, Conv, [512, 1, 1]], 35 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 36 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 37 | [-1, 3, C3, [512, False]], # 19 38 | 39 | [-1, 1, Conv, [256, 1, 1]], 40 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 41 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 42 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 43 | 44 | [-1, 1, Conv, [256, 3, 2]], 45 | [[-1, 20], 1, Concat, [1]], # cat head P4 46 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 47 | 48 | [-1, 1, Conv, [512, 3, 2]], 49 | [[-1, 16], 1, Concat, [1]], # cat head P5 50 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 51 | 52 | [-1, 1, Conv, [768, 3, 2]], 53 | [[-1, 12], 1, Concat, [1]], # cat head P6 54 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 55 | 56 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 57 | ] 58 | -------------------------------------------------------------------------------- /models/hub/yolov5-p7.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer 8 | 9 | # YOLOv5 v6.0 backbone 10 | backbone: 11 | # [from, number, module, args] 12 | [ 13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 15 | [-1, 3, C3, [128]], 16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 17 | [-1, 6, C3, [256]], 18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 19 | [-1, 9, C3, [512]], 20 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 21 | [-1, 3, C3, [768]], 22 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 23 | [-1, 3, C3, [1024]], 24 | [-1, 1, Conv, [1280, 3, 2]], # 11-P7/128 25 | [-1, 3, C3, [1280]], 26 | [-1, 1, SPPF, [1280, 5]], # 13 27 | ] 28 | 29 | # YOLOv5 v6.0 head with (P3, P4, P5, P6, P7) outputs 30 | head: [ 31 | [-1, 1, Conv, [1024, 1, 1]], 32 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 33 | [[-1, 10], 1, Concat, [1]], # cat backbone P6 34 | [-1, 3, C3, [1024, False]], # 17 35 | 36 | [-1, 1, Conv, [768, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 38 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 39 | [-1, 3, C3, [768, False]], # 21 40 | 41 | [-1, 1, Conv, [512, 1, 1]], 42 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 43 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 44 | [-1, 3, C3, [512, False]], # 25 45 | 46 | [-1, 1, Conv, [256, 1, 1]], 47 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 48 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 49 | [-1, 3, C3, [256, False]], # 29 (P3/8-small) 50 | 51 | [-1, 1, Conv, [256, 3, 2]], 52 | [[-1, 26], 1, Concat, [1]], # cat head P4 53 | [-1, 3, C3, [512, False]], # 32 (P4/16-medium) 54 | 55 | [-1, 1, Conv, [512, 3, 2]], 56 | [[-1, 22], 1, Concat, [1]], # cat head P5 57 | [-1, 3, C3, [768, False]], # 35 (P5/32-large) 58 | 59 | [-1, 1, Conv, [768, 3, 2]], 60 | [[-1, 18], 1, Concat, [1]], # cat head P6 61 | [-1, 3, C3, [1024, False]], # 38 (P6/64-xlarge) 62 | 63 | [-1, 1, Conv, [1024, 3, 2]], 64 | [[-1, 14], 1, Concat, [1]], # cat head P7 65 | [-1, 3, C3, [1280, False]], # 41 (P7/128-xxlarge) 66 | 67 | [[29, 32, 35, 38, 41], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6, P7) 68 | ] 69 | -------------------------------------------------------------------------------- /models/hub/yolov5-panet.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 PANet head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/hub/yolov5l6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 19 | [-1, 3, C3, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 21 | [-1, 6, C3, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 23 | [-1, 9, C3, [512]], 24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 25 | [-1, 3, C3, [768]], 26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 27 | [-1, 3, C3, [1024]], 28 | [-1, 1, SPPF, [1024, 5]], # 11 29 | ] 30 | 31 | # YOLOv5 v6.0 head 32 | head: [ 33 | [-1, 1, Conv, [768, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 36 | [-1, 3, C3, [768, False]], # 15 37 | 38 | [-1, 1, Conv, [512, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 41 | [-1, 3, C3, [512, False]], # 19 42 | 43 | [-1, 1, Conv, [256, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 47 | 48 | [-1, 1, Conv, [256, 3, 2]], 49 | [[-1, 20], 1, Concat, [1]], # cat head P4 50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 51 | 52 | [-1, 1, Conv, [512, 3, 2]], 53 | [[-1, 16], 1, Concat, [1]], # cat head P5 54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 55 | 56 | [-1, 1, Conv, [768, 3, 2]], 57 | [[-1, 12], 1, Concat, [1]], # cat head P6 58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 59 | 60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /models/hub/yolov5m6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 19 | [-1, 3, C3, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 21 | [-1, 6, C3, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 23 | [-1, 9, C3, [512]], 24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 25 | [-1, 3, C3, [768]], 26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 27 | [-1, 3, C3, [1024]], 28 | [-1, 1, SPPF, [1024, 5]], # 11 29 | ] 30 | 31 | # YOLOv5 v6.0 head 32 | head: [ 33 | [-1, 1, Conv, [768, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 36 | [-1, 3, C3, [768, False]], # 15 37 | 38 | [-1, 1, Conv, [512, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 41 | [-1, 3, C3, [512, False]], # 19 42 | 43 | [-1, 1, Conv, [256, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 47 | 48 | [-1, 1, Conv, [256, 3, 2]], 49 | [[-1, 20], 1, Concat, [1]], # cat head P4 50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 51 | 52 | [-1, 1, Conv, [512, 3, 2]], 53 | [[-1, 16], 1, Concat, [1]], # cat head P5 54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 55 | 56 | [-1, 1, Conv, [768, 3, 2]], 57 | [[-1, 12], 1, Concat, [1]], # cat head P6 58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 59 | 60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /models/hub/yolov5n6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 19 | [-1, 3, C3, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 21 | [-1, 6, C3, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 23 | [-1, 9, C3, [512]], 24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 25 | [-1, 3, C3, [768]], 26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 27 | [-1, 3, C3, [1024]], 28 | [-1, 1, SPPF, [1024, 5]], # 11 29 | ] 30 | 31 | # YOLOv5 v6.0 head 32 | head: [ 33 | [-1, 1, Conv, [768, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 36 | [-1, 3, C3, [768, False]], # 15 37 | 38 | [-1, 1, Conv, [512, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 41 | [-1, 3, C3, [512, False]], # 19 42 | 43 | [-1, 1, Conv, [256, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 47 | 48 | [-1, 1, Conv, [256, 3, 2]], 49 | [[-1, 20], 1, Concat, [1]], # cat head P4 50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 51 | 52 | [-1, 1, Conv, [512, 3, 2]], 53 | [[-1, 16], 1, Concat, [1]], # cat head P5 54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 55 | 56 | [-1, 1, Conv, [768, 3, 2]], 57 | [[-1, 12], 1, Concat, [1]], # cat head P6 58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 59 | 60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /models/hub/yolov5s-LeakyReLU.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | activation: nn.LeakyReLU(0.1) # <----- Conv() activation used throughout entire YOLOv5 model 6 | depth_multiple: 0.33 # model depth multiple 7 | width_multiple: 0.50 # layer channel multiple 8 | anchors: 9 | - [10, 13, 16, 30, 33, 23] # P3/8 10 | - [30, 61, 62, 45, 59, 119] # P4/16 11 | - [116, 90, 156, 198, 373, 326] # P5/32 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 19 | [-1, 3, C3, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 21 | [-1, 6, C3, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 23 | [-1, 9, C3, [512]], 24 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 25 | [-1, 3, C3, [1024]], 26 | [-1, 1, SPPF, [1024, 5]], # 9 27 | ] 28 | 29 | # YOLOv5 v6.0 head 30 | head: [ 31 | [-1, 1, Conv, [512, 1, 1]], 32 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 33 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 34 | [-1, 3, C3, [512, False]], # 13 35 | 36 | [-1, 1, Conv, [256, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 38 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 39 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 40 | 41 | [-1, 1, Conv, [256, 3, 2]], 42 | [[-1, 14], 1, Concat, [1]], # cat head P4 43 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 44 | 45 | [-1, 1, Conv, [512, 3, 2]], 46 | [[-1, 10], 1, Concat, [1]], # cat head P5 47 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 48 | 49 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 50 | ] 51 | -------------------------------------------------------------------------------- /models/hub/yolov5s-ghost.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, GhostConv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3Ghost, [128]], 19 | [-1, 1, GhostConv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3Ghost, [256]], 21 | [-1, 1, GhostConv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3Ghost, [512]], 23 | [-1, 1, GhostConv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3Ghost, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, GhostConv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3Ghost, [512, False]], # 13 34 | 35 | [-1, 1, GhostConv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3Ghost, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, GhostConv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3Ghost, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, GhostConv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3Ghost, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/hub/yolov5s-transformer.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3TR, [1024]], # 9 <--- C3TR() Transformer module 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/hub/yolov5s6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 19 | [-1, 3, C3, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 21 | [-1, 6, C3, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 23 | [-1, 9, C3, [512]], 24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 25 | [-1, 3, C3, [768]], 26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 27 | [-1, 3, C3, [1024]], 28 | [-1, 1, SPPF, [1024, 5]], # 11 29 | ] 30 | 31 | # YOLOv5 v6.0 head 32 | head: [ 33 | [-1, 1, Conv, [768, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 36 | [-1, 3, C3, [768, False]], # 15 37 | 38 | [-1, 1, Conv, [512, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 41 | [-1, 3, C3, [512, False]], # 19 42 | 43 | [-1, 1, Conv, [256, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 47 | 48 | [-1, 1, Conv, [256, 3, 2]], 49 | [[-1, 20], 1, Concat, [1]], # cat head P4 50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 51 | 52 | [-1, 1, Conv, [512, 3, 2]], 53 | [[-1, 16], 1, Concat, [1]], # cat head P5 54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 55 | 56 | [-1, 1, Conv, [768, 3, 2]], 57 | [[-1, 12], 1, Concat, [1]], # cat head P6 58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 59 | 60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /models/hub/yolov5x6.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.33 # model depth multiple 6 | width_multiple: 1.25 # layer channel multiple 7 | anchors: 8 | - [19, 27, 44, 40, 38, 94] # P3/8 9 | - [96, 68, 86, 152, 180, 137] # P4/16 10 | - [140, 301, 303, 264, 238, 542] # P5/32 11 | - [436, 615, 739, 380, 925, 792] # P6/64 12 | 13 | # YOLOv5 v6.0 backbone 14 | backbone: 15 | # [from, number, module, args] 16 | [ 17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 19 | [-1, 3, C3, [128]], 20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 21 | [-1, 6, C3, [256]], 22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 23 | [-1, 9, C3, [512]], 24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 25 | [-1, 3, C3, [768]], 26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 27 | [-1, 3, C3, [1024]], 28 | [-1, 1, SPPF, [1024, 5]], # 11 29 | ] 30 | 31 | # YOLOv5 v6.0 head 32 | head: [ 33 | [-1, 1, Conv, [768, 1, 1]], 34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5 36 | [-1, 3, C3, [768, False]], # 15 37 | 38 | [-1, 1, Conv, [512, 1, 1]], 39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 41 | [-1, 3, C3, [512, False]], # 19 42 | 43 | [-1, 1, Conv, [256, 1, 1]], 44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small) 47 | 48 | [-1, 1, Conv, [256, 3, 2]], 49 | [[-1, 20], 1, Concat, [1]], # cat head P4 50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium) 51 | 52 | [-1, 1, Conv, [512, 3, 2]], 53 | [[-1, 16], 1, Concat, [1]], # cat head P5 54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large) 55 | 56 | [-1, 1, Conv, [768, 3, 2]], 57 | [[-1, 12], 1, Concat, [1]], # cat head P6 58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) 59 | 60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6) 61 | ] 62 | -------------------------------------------------------------------------------- /models/segment/yolov5l-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/segment/yolov5m-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/segment/yolov5n-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/segment/yolov5s-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.5 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/segment/yolov5x-seg.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.33 # model depth multiple 6 | width_multiple: 1.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/yolov3-spp.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # darknet53 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [32, 3, 1]], # 0 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 18 | [-1, 1, Bottleneck, [64]], 19 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 20 | [-1, 2, Bottleneck, [128]], 21 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 22 | [-1, 8, Bottleneck, [256]], 23 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 24 | [-1, 8, Bottleneck, [512]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 26 | [-1, 4, Bottleneck, [1024]], # 10 27 | ] 28 | 29 | # YOLOv3-SPP head 30 | head: [ 31 | [-1, 1, Bottleneck, [1024, False]], 32 | [-1, 1, SPP, [512, [5, 9, 13]]], 33 | [-1, 1, Conv, [1024, 3, 1]], 34 | [-1, 1, Conv, [512, 1, 1]], 35 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 36 | 37 | [-2, 1, Conv, [256, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 39 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 40 | [-1, 1, Bottleneck, [512, False]], 41 | [-1, 1, Bottleneck, [512, False]], 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 44 | 45 | [-2, 1, Conv, [128, 1, 1]], 46 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 47 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 48 | [-1, 1, Bottleneck, [256, False]], 49 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 50 | 51 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 52 | ] 53 | -------------------------------------------------------------------------------- /models/yolov3-tiny.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 14, 23, 27, 37, 58] # P4/16 9 | - [81, 82, 135, 169, 344, 319] # P5/32 10 | 11 | # YOLOv3-tiny backbone 12 | backbone: 13 | # [from, number, module, args] 14 | [ 15 | [-1, 1, Conv, [16, 3, 1]], # 0 16 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 1-P1/2 17 | [-1, 1, Conv, [32, 3, 1]], 18 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 3-P2/4 19 | [-1, 1, Conv, [64, 3, 1]], 20 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 5-P3/8 21 | [-1, 1, Conv, [128, 3, 1]], 22 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 7-P4/16 23 | [-1, 1, Conv, [256, 3, 1]], 24 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 9-P5/32 25 | [-1, 1, Conv, [512, 3, 1]], 26 | [-1, 1, nn.ZeroPad2d, [[0, 1, 0, 1]]], # 11 27 | [-1, 1, nn.MaxPool2d, [2, 1, 0]], # 12 28 | ] 29 | 30 | # YOLOv3-tiny head 31 | head: [ 32 | [-1, 1, Conv, [1024, 3, 1]], 33 | [-1, 1, Conv, [256, 1, 1]], 34 | [-1, 1, Conv, [512, 3, 1]], # 15 (P5/32-large) 35 | 36 | [-2, 1, Conv, [128, 1, 1]], 37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 39 | [-1, 1, Conv, [256, 3, 1]], # 19 (P4/16-medium) 40 | 41 | [[19, 15], 1, Detect, [nc, anchors]], # Detect(P4, P5) 42 | ] 43 | -------------------------------------------------------------------------------- /models/yolov3.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # darknet53 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [32, 3, 1]], # 0 17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2 18 | [-1, 1, Bottleneck, [64]], 19 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4 20 | [-1, 2, Bottleneck, [128]], 21 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8 22 | [-1, 8, Bottleneck, [256]], 23 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16 24 | [-1, 8, Bottleneck, [512]], 25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32 26 | [-1, 4, Bottleneck, [1024]], # 10 27 | ] 28 | 29 | # YOLOv3 head 30 | head: [ 31 | [-1, 1, Bottleneck, [1024, False]], 32 | [-1, 1, Conv, [512, 1, 1]], 33 | [-1, 1, Conv, [1024, 3, 1]], 34 | [-1, 1, Conv, [512, 1, 1]], 35 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large) 36 | 37 | [-2, 1, Conv, [256, 1, 1]], 38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 39 | [[-1, 8], 1, Concat, [1]], # cat backbone P4 40 | [-1, 1, Bottleneck, [512, False]], 41 | [-1, 1, Bottleneck, [512, False]], 42 | [-1, 1, Conv, [256, 1, 1]], 43 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium) 44 | 45 | [-2, 1, Conv, [128, 1, 1]], 46 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 47 | [[-1, 6], 1, Concat, [1]], # cat backbone P3 48 | [-1, 1, Bottleneck, [256, False]], 49 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small) 50 | 51 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 52 | ] 53 | -------------------------------------------------------------------------------- /models/yolov5l.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.0 # model depth multiple 6 | width_multiple: 1.0 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/yolov5m.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.67 # model depth multiple 6 | width_multiple: 0.75 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/yolov5n.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/yolov5s.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 0.33 # model depth multiple 6 | width_multiple: 0.50 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /models/yolov5x.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Parameters 4 | nc: 80 # number of classes 5 | depth_multiple: 1.33 # model depth multiple 6 | width_multiple: 1.25 # layer channel multiple 7 | anchors: 8 | - [10, 13, 16, 30, 33, 23] # P3/8 9 | - [30, 61, 62, 45, 59, 119] # P4/16 10 | - [116, 90, 156, 198, 373, 326] # P5/32 11 | 12 | # YOLOv5 v6.0 backbone 13 | backbone: 14 | # [from, number, module, args] 15 | [ 16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 18 | [-1, 3, C3, [128]], 19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 20 | [-1, 6, C3, [256]], 21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 22 | [-1, 9, C3, [512]], 23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 24 | [-1, 3, C3, [1024]], 25 | [-1, 1, SPPF, [1024, 5]], # 9 26 | ] 27 | 28 | # YOLOv5 v6.0 head 29 | head: [ 30 | [-1, 1, Conv, [512, 1, 1]], 31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4 33 | [-1, 3, C3, [512, False]], # 13 34 | 35 | [-1, 1, Conv, [256, 1, 1]], 36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]], 37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3 38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small) 39 | 40 | [-1, 1, Conv, [256, 3, 2]], 41 | [[-1, 14], 1, Concat, [1]], # cat head P4 42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium) 43 | 44 | [-1, 1, Conv, [512, 3, 2]], 45 | [[-1, 10], 1, Concat, [1]], # cat head P5 46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large) 47 | 48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5) 49 | ] 50 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Overview: 4 | # This pyproject.toml file manages the build, packaging, and distribution of the Ultralytics library. 5 | # It defines essential project metadata, dependencies, and settings used to develop and deploy the library. 6 | 7 | # Key Sections: 8 | # - [build-system]: Specifies the build requirements and backend (e.g., setuptools, wheel). 9 | # - [project]: Includes details like name, version, description, authors, dependencies and more. 10 | # - [project.optional-dependencies]: Provides additional, optional packages for extended features. 11 | # - [tool.*]: Configures settings for various tools (pytest, yapf, etc.) used in the project. 12 | 13 | # Installation: 14 | # The Ultralytics library can be installed using the command: 'pip install ultralytics' 15 | # For development purposes, you can install the package in editable mode with: 'pip install -e .' 16 | # This approach allows for real-time code modifications without the need for re-installation. 17 | 18 | # Documentation: 19 | # For comprehensive documentation and usage instructions, visit: https://docs.ultralytics.com 20 | 21 | [build-system] 22 | requires = ["setuptools>=43.0.0", "wheel"] 23 | build-backend = "setuptools.build_meta" 24 | 25 | # Project settings ----------------------------------------------------------------------------------------------------- 26 | [project] 27 | name = "YOLOv3" 28 | description = "Ultralytics YOLOv3 for object detection." 29 | readme = "README.md" 30 | requires-python = ">=3.8" 31 | license = { "text" = "AGPL-3.0" } 32 | keywords = ["machine-learning", "deep-learning", "computer-vision", "ML", "DL", "AI", "YOLO", "YOLOv3", "YOLOv5", "YOLOv8", "HUB", "Ultralytics"] 33 | authors = [ 34 | { name = "Glenn Jocher" }, 35 | { name = "Ayush Chaurasia" }, 36 | { name = "Jing Qiu" } 37 | ] 38 | maintainers = [ 39 | { name = "Glenn Jocher" }, 40 | { name = "Ayush Chaurasia" }, 41 | { name = "Jing Qiu" } 42 | ] 43 | classifiers = [ 44 | "Development Status :: 4 - Beta", 45 | "Intended Audience :: Developers", 46 | "Intended Audience :: Education", 47 | "Intended Audience :: Science/Research", 48 | "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", 49 | "Programming Language :: Python :: 3", 50 | "Programming Language :: Python :: 3.8", 51 | "Programming Language :: Python :: 3.9", 52 | "Programming Language :: Python :: 3.10", 53 | "Programming Language :: Python :: 3.11", 54 | "Topic :: Software Development", 55 | "Topic :: Scientific/Engineering", 56 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 57 | "Topic :: Scientific/Engineering :: Image Recognition", 58 | "Operating System :: POSIX :: Linux", 59 | "Operating System :: MacOS", 60 | "Operating System :: Microsoft :: Windows", 61 | ] 62 | 63 | # Required dependencies ------------------------------------------------------------------------------------------------ 64 | dependencies = [ 65 | "matplotlib>=3.3.0", 66 | "numpy>=1.22.2", 67 | "opencv-python>=4.6.0", 68 | "pillow>=7.1.2", 69 | "pyyaml>=5.3.1", 70 | "requests>=2.23.0", 71 | "scipy>=1.4.1", 72 | "torch>=1.8.0", 73 | "torchvision>=0.9.0", 74 | "tqdm>=4.64.0", # progress bars 75 | "psutil", # system utilization 76 | "py-cpuinfo", # display CPU info 77 | "thop>=0.1.1", # FLOPs computation 78 | "pandas>=1.1.4", 79 | "seaborn>=0.11.0", # plotting 80 | "ultralytics>=8.0.232" 81 | ] 82 | 83 | # Optional dependencies ------------------------------------------------------------------------------------------------ 84 | [project.optional-dependencies] 85 | dev = [ 86 | "ipython", 87 | "check-manifest", 88 | "pre-commit", 89 | "pytest", 90 | "pytest-cov", 91 | "coverage[toml]", 92 | "mkdocs-material", 93 | "mkdocstrings[python]", 94 | "mkdocs-redirects", # for 301 redirects 95 | "mkdocs-ultralytics-plugin>=0.0.34", # for meta descriptions and images, dates and authors 96 | ] 97 | export = [ 98 | "onnx>=1.12.0", # ONNX export 99 | "coremltools>=7.0; platform_system != 'Windows'", # CoreML only supported on macOS and Linux 100 | "openvino-dev>=2023.0", # OpenVINO export 101 | "tensorflow>=2.0.0", # TF bug https://github.com/ultralytics/ultralytics/issues/5161 102 | "tensorflowjs>=3.9.0", # TF.js export, automatically installs tensorflow 103 | ] 104 | # tensorflow>=2.4.1,<=2.13.1 # TF exports (-cpu, -aarch64, -macos) 105 | # tflite-support # for TFLite model metadata 106 | # scikit-learn==0.19.2 # CoreML quantization 107 | # nvidia-pyindex # TensorRT export 108 | # nvidia-tensorrt # TensorRT export 109 | logging = [ 110 | "comet", # https://docs.ultralytics.com/integrations/comet/ 111 | "tensorboard>=2.13.0", 112 | "dvclive>=2.12.0", 113 | ] 114 | extra = [ 115 | "ipython", # interactive notebook 116 | "albumentations>=1.0.3", # training augmentations 117 | "pycocotools>=2.0.6", # COCO mAP 118 | ] 119 | 120 | [project.urls] 121 | "Bug Reports" = "https://github.com/ultralytics/yolov3/issues" 122 | "Funding" = "https://ultralytics.com" 123 | "Source" = "https://github.com/ultralytics/yolov3/" 124 | 125 | # Tools settings ------------------------------------------------------------------------------------------------------- 126 | [tool.pytest] 127 | norecursedirs = [".git", "dist", "build"] 128 | addopts = "--doctest-modules --durations=30 --color=yes" 129 | 130 | [tool.isort] 131 | line_length = 120 132 | multi_line_output = 0 133 | 134 | [tool.ruff] 135 | line-length = 120 136 | 137 | [tool.docformatter] 138 | wrap-summaries = 120 139 | wrap-descriptions = 120 140 | in-place = true 141 | pre-summary-newline = true 142 | close-quotes-on-newline = true 143 | 144 | [tool.codespell] 145 | ignore-words-list = "crate,nd,strack,dota,ane,segway,fo,gool,winn,commend" 146 | skip = '*.csv,*venv*,docs/??/,docs/mkdocs_??.yml' 147 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # YOLOv3 requirements 2 | # Usage: pip install -r requirements.txt 3 | 4 | # Base ------------------------------------------------------------------------ 5 | gitpython>=3.1.30 6 | matplotlib>=3.3 7 | numpy>=1.23.5 8 | opencv-python>=4.1.1 9 | Pillow>=10.3.0 10 | psutil # system resources 11 | PyYAML>=5.3.1 12 | requests>=2.32.2 13 | scipy>=1.4.1 14 | thop>=0.1.1 # FLOPs computation 15 | torch>=1.8.0 # see https://pytorch.org/get-started/locally (recommended) 16 | torchvision>=0.9.0 17 | tqdm>=4.66.3 18 | ultralytics>=8.2.34 # https://ultralytics.com 19 | # protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012 20 | 21 | # Logging --------------------------------------------------------------------- 22 | # tensorboard>=2.4.1 23 | # clearml>=1.2.0 24 | # comet 25 | 26 | # Plotting -------------------------------------------------------------------- 27 | pandas>=1.1.4 28 | seaborn>=0.11.0 29 | 30 | # Export ---------------------------------------------------------------------- 31 | # coremltools>=6.0 # CoreML export 32 | # onnx>=1.10.0 # ONNX export 33 | # onnx-simplifier>=0.4.1 # ONNX simplifier 34 | # nvidia-pyindex # TensorRT export 35 | # nvidia-tensorrt # TensorRT export 36 | # scikit-learn<=1.1.2 # CoreML quantization 37 | # tensorflow>=2.4.0 # TF exports (-cpu, -aarch64, -macos) 38 | # tensorflowjs>=3.9.0 # TF.js export 39 | # openvino-dev>=2023.0 # OpenVINO export 40 | 41 | # Deploy ---------------------------------------------------------------------- 42 | setuptools>=70.0.0 # Snyk vulnerability fix 43 | # tritonclient[all]~=2.24.0 44 | 45 | # Extras ---------------------------------------------------------------------- 46 | # ipython # interactive notebook 47 | # mss # screenshots 48 | # albumentations>=1.0.3 49 | # pycocotools>=2.0.6 # COCO mAP 50 | -------------------------------------------------------------------------------- /utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """utils/initialization.""" 3 | 4 | import contextlib 5 | import platform 6 | import threading 7 | 8 | 9 | def emojis(str=""): 10 | """Returns platform-dependent emoji-safe version of str; ignores emojis on Windows, else returns original str.""" 11 | return str.encode().decode("ascii", "ignore") if platform.system() == "Windows" else str 12 | 13 | 14 | class TryExcept(contextlib.ContextDecorator): 15 | """A context manager and decorator for handling exceptions with optional custom messages.""" 16 | 17 | def __init__(self, msg=""): 18 | """Initializes TryExcept with optional custom message, used as decorator or context manager for exception 19 | handling. 20 | """ 21 | self.msg = msg 22 | 23 | def __enter__(self): 24 | """Begin exception-handling block, optionally customizing exception message when used with TryExcept context 25 | manager. 26 | """ 27 | pass 28 | 29 | def __exit__(self, exc_type, value, traceback): 30 | """Ends exception-handling block, optionally prints custom message with exception, suppressing exceptions within 31 | context. 32 | """ 33 | if value: 34 | print(emojis(f"{self.msg}{': ' if self.msg else ''}{value}")) 35 | return True 36 | 37 | 38 | def threaded(func): 39 | """ 40 | Decorates a function to run in a separate thread, returning the thread object. 41 | 42 | Usage: @threaded. 43 | """ 44 | 45 | def wrapper(*args, **kwargs): 46 | """ 47 | Runs the decorated function in a separate thread and returns the thread object. 48 | 49 | Usage: @threaded. 50 | """ 51 | thread = threading.Thread(target=func, args=args, kwargs=kwargs, daemon=True) 52 | thread.start() 53 | return thread 54 | 55 | return wrapper 56 | 57 | 58 | def join_threads(verbose=False): 59 | """Joins all daemon threads, excluding the main thread, with an optional verbose flag for logging.""" 60 | main_thread = threading.current_thread() 61 | for t in threading.enumerate(): 62 | if t is not main_thread: 63 | if verbose: 64 | print(f"Joining thread {t.name}") 65 | t.join() 66 | 67 | 68 | def notebook_init(verbose=True): 69 | """Initializes notebook environment by checking hardware, software requirements, and cleaning up if in Colab.""" 70 | print("Checking setup...") 71 | 72 | import os 73 | import shutil 74 | 75 | from ultralytics.utils.checks import check_requirements 76 | 77 | from utils.general import check_font, is_colab 78 | from utils.torch_utils import select_device # imports 79 | 80 | check_font() 81 | 82 | import psutil 83 | 84 | if check_requirements("wandb", install=False): 85 | os.system("pip uninstall -y wandb") # eliminate unexpected account creation prompt with infinite hang 86 | if is_colab(): 87 | shutil.rmtree("/content/sample_data", ignore_errors=True) # remove colab /sample_data directory 88 | 89 | # System info 90 | display = None 91 | if verbose: 92 | gb = 1 << 30 # bytes to GiB (1024 ** 3) 93 | ram = psutil.virtual_memory().total 94 | total, used, free = shutil.disk_usage("/") 95 | with contextlib.suppress(Exception): # clear display if ipython is installed 96 | from IPython import display 97 | 98 | display.clear_output() 99 | s = f"({os.cpu_count()} CPUs, {ram / gb:.1f} GB RAM, {(total - free) / gb:.1f}/{total / gb:.1f} GB disk)" 100 | else: 101 | s = "" 102 | 103 | select_device(newline=False) 104 | print(emojis(f"Setup complete ✅ {s}")) 105 | return display 106 | -------------------------------------------------------------------------------- /utils/activations.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Activation functions.""" 3 | 4 | import torch 5 | import torch.nn as nn 6 | import torch.nn.functional as F 7 | 8 | 9 | class SiLU(nn.Module): 10 | """Applies the SiLU activation function to the input tensor as described in https://arxiv.org/pdf/1606.08415.pdf.""" 11 | 12 | @staticmethod 13 | def forward(x): 14 | """Applies the SiLU activation function, as detailed in https://arxiv.org/pdf/1606.08415.pdf, on input tensor 15 | `x`. 16 | """ 17 | return x * torch.sigmoid(x) 18 | 19 | 20 | class Hardswish(nn.Module): 21 | """Applies the Hardswish activation function to the input tensor `x`.""" 22 | 23 | @staticmethod 24 | def forward(x): 25 | """Applies Hardswish activation, suitable for TorchScript, CoreML, ONNX, modifying input `x` as per Hard-SiLU 26 | definition. 27 | """ 28 | return x * F.hardtanh(x + 3, 0.0, 6.0) / 6.0 # for TorchScript, CoreML and ONNX 29 | 30 | 31 | class Mish(nn.Module): 32 | """Applies the Mish activation function to improve model performance; see https://github.com/digantamisra98/Mish.""" 33 | 34 | @staticmethod 35 | def forward(x): 36 | """ 37 | Applies the Mish activation function, enhancing model performance and convergence. 38 | 39 | Reference: https://github.com/digantamisra98/Mish 40 | """ 41 | return x * F.softplus(x).tanh() 42 | 43 | 44 | class MemoryEfficientMish(nn.Module): 45 | """Applies the memory-efficient Mish activation function for improved model performance and reduced memory usage.""" 46 | 47 | class F(torch.autograd.Function): 48 | """Memory-efficient implementation of the Mish activation function for enhanced model performance.""" 49 | 50 | @staticmethod 51 | def forward(ctx, x): 52 | """Applies the Mish activation function in a memory-efficient manner, useful for enhancing model 53 | performance. 54 | """ 55 | ctx.save_for_backward(x) 56 | return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x))) 57 | 58 | @staticmethod 59 | def backward(ctx, grad_output): 60 | """Computes gradient of the Mish activation function for backpropagation, returning the derivative with 61 | respect to the input. 62 | """ 63 | x = ctx.saved_tensors[0] 64 | sx = torch.sigmoid(x) 65 | fx = F.softplus(x).tanh() 66 | return grad_output * (fx + x * sx * (1 - fx * fx)) 67 | 68 | def forward(self, x): 69 | """Applies Mish activation function, useful in neural networks for nonlinear transformation of inputs.""" 70 | return self.F.apply(x) 71 | 72 | 73 | class FReLU(nn.Module): 74 | """Implements the FReLU activation, combining ReLU and convolution from https://arxiv.org/abs/2007.11824.""" 75 | 76 | def __init__(self, c1, k=3): # ch_in, kernel 77 | """Initializes FReLU with specified channel size and kernel, implementing activation from 78 | https://arxiv.org/abs/2007.11824. 79 | """ 80 | super().__init__() 81 | self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1, bias=False) 82 | self.bn = nn.BatchNorm2d(c1) 83 | 84 | def forward(self, x): 85 | """Performs FReLU activation on input, returning the max of input and its 2D convolution.""" 86 | return torch.max(x, self.bn(self.conv(x))) 87 | 88 | 89 | class AconC(nn.Module): 90 | r"""ACON activation (activate or not) 91 | AconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is a learnable parameter 92 | according to "Activate or Not: Learning Customized Activation" . 93 | """ 94 | 95 | def __init__(self, c1): 96 | """Initializes ACON activation with learnable parameters p1, p2, and beta as per 97 | https://arxiv.org/pdf/2009.04759.pdf. 98 | """ 99 | super().__init__() 100 | self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1)) 101 | self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1)) 102 | self.beta = nn.Parameter(torch.ones(1, c1, 1, 1)) 103 | 104 | def forward(self, x): 105 | """Applies a parametric activation function to tensor x; see https://arxiv.org/pdf/2009.04759.pdf for 106 | details. 107 | """ 108 | dpx = (self.p1 - self.p2) * x 109 | return dpx * torch.sigmoid(self.beta * dpx) + self.p2 * x 110 | 111 | 112 | class MetaAconC(nn.Module): 113 | r"""ACON activation (activate or not) 114 | MetaAconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is generated by a small network 115 | according to "Activate or Not: Learning Customized Activation" . 116 | """ 117 | 118 | def __init__(self, c1, k=1, s=1, r=16): # ch_in, kernel, stride, r 119 | """Initializes MetaAconC activation with params c1, optional k (kernel=1), s (stride=1), r (16), defining 120 | activation dynamics. 121 | """ 122 | super().__init__() 123 | c2 = max(r, c1 // r) 124 | self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1)) 125 | self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1)) 126 | self.fc1 = nn.Conv2d(c1, c2, k, s, bias=True) 127 | self.fc2 = nn.Conv2d(c2, c1, k, s, bias=True) 128 | # self.bn1 = nn.BatchNorm2d(c2) 129 | # self.bn2 = nn.BatchNorm2d(c1) 130 | 131 | def forward(self, x): 132 | """Applies a forward pass transforming input `x` using parametric operations and returns the modified tensor.""" 133 | y = x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True) 134 | # batch-size 1 bug/instabilities https://github.com/ultralytics/yolov5/issues/2891 135 | # beta = torch.sigmoid(self.bn2(self.fc2(self.bn1(self.fc1(y))))) # bug/unstable 136 | beta = torch.sigmoid(self.fc2(self.fc1(y))) # bug patch BN layers removed 137 | dpx = (self.p1 - self.p2) * x 138 | return dpx * torch.sigmoid(beta * dpx) + self.p2 * x 139 | -------------------------------------------------------------------------------- /utils/autobatch.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Auto-batch utils.""" 3 | 4 | from copy import deepcopy 5 | 6 | import numpy as np 7 | import torch 8 | 9 | from utils.general import LOGGER, colorstr 10 | from utils.torch_utils import profile 11 | 12 | 13 | def check_train_batch_size(model, imgsz=640, amp=True): 14 | """Checks and computes the optimal training batch size for YOLOv3, given model and image size.""" 15 | with torch.cuda.amp.autocast(amp): 16 | return autobatch(deepcopy(model).train(), imgsz) # compute optimal batch size 17 | 18 | 19 | def autobatch(model, imgsz=640, fraction=0.8, batch_size=16): 20 | """Estimates optimal YOLOv3 batch size using available CUDA memory; imgsz:int=640, fraction:float=0.8, 21 | batch_size:int=16. 22 | """ 23 | # Usage: 24 | # import torch 25 | # from utils.autobatch import autobatch 26 | # model = torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False) 27 | # print(autobatch(model)) 28 | 29 | # Check device 30 | prefix = colorstr("AutoBatch: ") 31 | LOGGER.info(f"{prefix}Computing optimal batch size for --imgsz {imgsz}") 32 | device = next(model.parameters()).device # get model device 33 | if device.type == "cpu": 34 | LOGGER.info(f"{prefix}CUDA not detected, using default CPU batch-size {batch_size}") 35 | return batch_size 36 | if torch.backends.cudnn.benchmark: 37 | LOGGER.info(f"{prefix} ⚠️ Requires torch.backends.cudnn.benchmark=False, using default batch-size {batch_size}") 38 | return batch_size 39 | 40 | # Inspect CUDA memory 41 | gb = 1 << 30 # bytes to GiB (1024 ** 3) 42 | d = str(device).upper() # 'CUDA:0' 43 | properties = torch.cuda.get_device_properties(device) # device properties 44 | t = properties.total_memory / gb # GiB total 45 | r = torch.cuda.memory_reserved(device) / gb # GiB reserved 46 | a = torch.cuda.memory_allocated(device) / gb # GiB allocated 47 | f = t - (r + a) # GiB free 48 | LOGGER.info(f"{prefix}{d} ({properties.name}) {t:.2f}G total, {r:.2f}G reserved, {a:.2f}G allocated, {f:.2f}G free") 49 | 50 | # Profile batch sizes 51 | batch_sizes = [1, 2, 4, 8, 16] 52 | try: 53 | img = [torch.empty(b, 3, imgsz, imgsz) for b in batch_sizes] 54 | results = profile(img, model, n=3, device=device) 55 | except Exception as e: 56 | LOGGER.warning(f"{prefix}{e}") 57 | 58 | # Fit a solution 59 | y = [x[2] for x in results if x] # memory [2] 60 | p = np.polyfit(batch_sizes[: len(y)], y, deg=1) # first degree polynomial fit 61 | b = int((f * fraction - p[1]) / p[0]) # y intercept (optimal batch size) 62 | if None in results: # some sizes failed 63 | i = results.index(None) # first fail index 64 | if b >= batch_sizes[i]: # y intercept above failure point 65 | b = batch_sizes[max(i - 1, 0)] # select prior safe point 66 | if b < 1 or b > 1024: # b outside of safe range 67 | b = batch_size 68 | LOGGER.warning(f"{prefix}WARNING ⚠️ CUDA anomaly detected, recommend restart environment and retry command.") 69 | 70 | fraction = (np.polyval(p, b) + r + a) / t # actual fraction predicted 71 | LOGGER.info(f"{prefix}Using batch-size {b} for {d} {t * fraction:.2f}G/{t:.2f}G ({fraction * 100:.0f}%) ✅") 72 | return b 73 | -------------------------------------------------------------------------------- /utils/aws/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | -------------------------------------------------------------------------------- /utils/aws/mime.sh: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # AWS EC2 instance startup 'MIME' script https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/ 4 | # This script will run on every instance restart, not only on first start 5 | # --- DO NOT COPY ABOVE COMMENTS WHEN PASTING INTO USERDATA --- 6 | 7 | Content-Type: multipart/mixed 8 | boundary="//" 9 | MIME-Version: 1.0 10 | 11 | --// 12 | Content-Type: text/cloud-config 13 | charset="us-ascii" 14 | MIME-Version: 1.0 15 | Content-Transfer-Encoding: 7bit 16 | Content-Disposition: attachment 17 | filename="cloud-config.txt" 18 | 19 | #cloud-config 20 | cloud_final_modules: 21 | - [scripts-user, always] 22 | 23 | --// 24 | Content-Type: text/x-shellscript 25 | charset="us-ascii" 26 | MIME-Version: 1.0 27 | Content-Transfer-Encoding: 7bit 28 | Content-Disposition: attachment 29 | filename="userdata.txt" 30 | 31 | #!/bin/bash 32 | # --- paste contents of userdata.sh here --- 33 | --// 34 | -------------------------------------------------------------------------------- /utils/aws/resume.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Resume all interrupted trainings in yolov5/ dir including DDP trainings 4 | # Usage: $ python utils/aws/resume.py 5 | 6 | import os 7 | import sys 8 | from pathlib import Path 9 | 10 | import torch 11 | import yaml 12 | 13 | FILE = Path(__file__).resolve() 14 | ROOT = FILE.parents[2] # YOLOv3 root directory 15 | if str(ROOT) not in sys.path: 16 | sys.path.append(str(ROOT)) # add ROOT to PATH 17 | 18 | port = 0 # --master_port 19 | path = Path("").resolve() 20 | for last in path.rglob("*/**/last.pt"): 21 | ckpt = torch.load(last) 22 | if ckpt["optimizer"] is None: 23 | continue 24 | 25 | # Load opt.yaml 26 | with open(last.parent.parent / "opt.yaml", errors="ignore") as f: 27 | opt = yaml.safe_load(f) 28 | 29 | # Get device count 30 | d = opt["device"].split(",") # devices 31 | nd = len(d) # number of devices 32 | ddp = nd > 1 or (nd == 0 and torch.cuda.device_count() > 1) # distributed data parallel 33 | 34 | if ddp: # multi-GPU 35 | port += 1 36 | cmd = f"python -m torch.distributed.run --nproc_per_node {nd} --master_port {port} train.py --resume {last}" 37 | else: # single-GPU 38 | cmd = f"python train.py --resume {last}" 39 | 40 | cmd += " > /dev/null 2>&1 &" # redirect output to dev/null and run in daemon thread 41 | print(cmd) 42 | os.system(cmd) 43 | -------------------------------------------------------------------------------- /utils/aws/userdata.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 3 | 4 | # AWS EC2 instance startup script https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html 5 | # This script will run only once on first instance start (for a re-start script see mime.sh) 6 | # /home/ubuntu (ubuntu) or /home/ec2-user (amazon-linux) is working dir 7 | # Use >300 GB SSD 8 | 9 | cd home/ubuntu 10 | if [ ! -d yolov5 ]; then 11 | echo "Running first-time script." # install dependencies, download COCO, pull Docker 12 | git clone https://github.com/ultralytics/yolov5 -b master && sudo chmod -R 777 yolov5 13 | cd yolov5 14 | bash data/scripts/get_coco.sh && echo "COCO done." & 15 | sudo docker pull ultralytics/yolov5:latest && echo "Docker done." & 16 | python -m pip install --upgrade pip && pip install -r requirements.txt && python detect.py && echo "Requirements done." & 17 | wait && echo "All tasks done." # finish background tasks 18 | else 19 | echo "Running re-start script." # resume interrupted runs 20 | i=0 21 | list=$(sudo docker ps -qa) # container list i.e. $'one\ntwo\nthree\nfour' 22 | while IFS= read -r id; do 23 | ((i++)) 24 | echo "restarting container $i: $id" 25 | sudo docker start $id 26 | # sudo docker exec -it $id python train.py --resume # single-GPU 27 | sudo docker exec -d $id python utils/aws/resume.py # multi-scenario 28 | done <<< "$list" 29 | fi 30 | -------------------------------------------------------------------------------- /utils/callbacks.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Callback utils.""" 3 | 4 | import threading 5 | 6 | 7 | class Callbacks: 8 | """Handles all registered callbacks for YOLOv3 Hooks.""" 9 | 10 | def __init__(self): 11 | """Initializes a Callbacks object to manage YOLOv3 training hooks with various event triggers.""" 12 | self._callbacks = { 13 | "on_pretrain_routine_start": [], 14 | "on_pretrain_routine_end": [], 15 | "on_train_start": [], 16 | "on_train_epoch_start": [], 17 | "on_train_batch_start": [], 18 | "optimizer_step": [], 19 | "on_before_zero_grad": [], 20 | "on_train_batch_end": [], 21 | "on_train_epoch_end": [], 22 | "on_val_start": [], 23 | "on_val_batch_start": [], 24 | "on_val_image_end": [], 25 | "on_val_batch_end": [], 26 | "on_val_end": [], 27 | "on_fit_epoch_end": [], # fit = train + val 28 | "on_model_save": [], 29 | "on_train_end": [], 30 | "on_params_update": [], 31 | "teardown": [], 32 | } 33 | self.stop_training = False # set True to interrupt training 34 | 35 | def register_action(self, hook, name="", callback=None): 36 | """ 37 | Register a new action to a callback hook. 38 | 39 | Args: 40 | hook: The callback hook name to register the action to 41 | name: The name of the action for later reference 42 | callback: The callback to fire 43 | """ 44 | assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}" 45 | assert callable(callback), f"callback '{callback}' is not callable" 46 | self._callbacks[hook].append({"name": name, "callback": callback}) 47 | 48 | def get_registered_actions(self, hook=None): 49 | """ 50 | " Returns all the registered actions by callback hook. 51 | 52 | Args: 53 | hook: The name of the hook to check, defaults to all 54 | """ 55 | return self._callbacks[hook] if hook else self._callbacks 56 | 57 | def run(self, hook, *args, thread=False, **kwargs): 58 | """ 59 | Loop through the registered actions and fire all callbacks on main thread. 60 | 61 | Args: 62 | hook: The name of the hook to check, defaults to all 63 | args: Arguments to receive from YOLOv3 64 | thread: (boolean) Run callbacks in daemon thread 65 | kwargs: Keyword Arguments to receive from YOLOv3 66 | """ 67 | assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}" 68 | for logger in self._callbacks[hook]: 69 | if thread: 70 | threading.Thread(target=logger["callback"], args=args, kwargs=kwargs, daemon=True).start() 71 | else: 72 | logger["callback"](*args, **kwargs) 73 | -------------------------------------------------------------------------------- /utils/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Builds ultralytics/yolov5:latest image on DockerHub https://hub.docker.com/r/ultralytics/yolov3 4 | # Image is CUDA-optimized for YOLOv5 single/multi-GPU training and inference 5 | 6 | # Start FROM PyTorch image https://hub.docker.com/r/pytorch/pytorch 7 | FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime 8 | 9 | # Downloads to user config dir 10 | ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/ 11 | 12 | # Install linux packages 13 | ENV DEBIAN_FRONTEND noninteractive 14 | RUN apt update 15 | RUN TZ=Etc/UTC apt install -y tzdata 16 | RUN apt install --no-install-recommends -y gcc git zip curl htop libgl1 libglib2.0-0 libpython3-dev gnupg 17 | # RUN alias python=python3 18 | 19 | # Security updates 20 | # https://security.snyk.io/vuln/SNYK-UBUNTU1804-OPENSSL-3314796 21 | RUN apt upgrade --no-install-recommends -y openssl 22 | 23 | # Create working directory 24 | RUN rm -rf /usr/src/app && mkdir -p /usr/src/app 25 | WORKDIR /usr/src/app 26 | 27 | # Copy contents 28 | # COPY . /usr/src/app (issues as not a .git directory) 29 | RUN git clone https://github.com/ultralytics/yolov5 /usr/src/app 30 | 31 | # Install pip packages 32 | COPY requirements.txt . 33 | RUN python3 -m pip install --upgrade pip wheel 34 | RUN pip install --no-cache -r requirements.txt albumentations comet gsutil notebook \ 35 | coremltools onnx onnx-simplifier onnxruntime 'openvino-dev>=2023.0' 36 | # tensorflow tensorflowjs \ 37 | 38 | # Set environment variables 39 | ENV OMP_NUM_THREADS=1 40 | 41 | # Cleanup 42 | ENV DEBIAN_FRONTEND teletype 43 | 44 | 45 | # Usage Examples ------------------------------------------------------------------------------------------------------- 46 | 47 | # Build and Push 48 | # t=ultralytics/yolov5:latest && sudo docker build -f utils/docker/Dockerfile -t $t . && sudo docker push $t 49 | 50 | # Pull and Run 51 | # t=ultralytics/yolov5:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all $t 52 | 53 | # Pull and Run with local directory access 54 | # t=ultralytics/yolov5:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all -v "$(pwd)"/datasets:/usr/src/datasets $t 55 | 56 | # Kill all 57 | # sudo docker kill $(sudo docker ps -q) 58 | 59 | # Kill all image-based 60 | # sudo docker kill $(sudo docker ps -qa --filter ancestor=ultralytics/yolov5:latest) 61 | 62 | # DockerHub tag update 63 | # t=ultralytics/yolov5:latest tnew=ultralytics/yolov5:v6.2 && sudo docker pull $t && sudo docker tag $t $tnew && sudo docker push $tnew 64 | 65 | # Clean up 66 | # sudo docker system prune -a --volumes 67 | 68 | # Update Ubuntu drivers 69 | # https://www.maketecheasier.com/install-nvidia-drivers-ubuntu/ 70 | 71 | # DDP test 72 | # python -m torch.distributed.run --nproc_per_node 2 --master_port 1 train.py --epochs 3 73 | 74 | # GCP VM from Image 75 | # docker.io/ultralytics/yolov5:latest 76 | -------------------------------------------------------------------------------- /utils/docker/Dockerfile-arm64: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Builds ultralytics/yolov5:latest-arm64 image on DockerHub https://hub.docker.com/r/ultralytics/yolov3 4 | # Image is aarch64-compatible for Apple M1 and other ARM architectures i.e. Jetson Nano and Raspberry Pi 5 | 6 | # Start FROM Ubuntu image https://hub.docker.com/_/ubuntu 7 | FROM arm64v8/ubuntu:22.10 8 | 9 | # Downloads to user config dir 10 | ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/ 11 | 12 | # Install linux packages 13 | ENV DEBIAN_FRONTEND noninteractive 14 | RUN apt update 15 | RUN TZ=Etc/UTC apt install -y tzdata 16 | RUN apt install --no-install-recommends -y python3-pip git zip curl htop gcc libgl1 libglib2.0-0 libpython3-dev 17 | # RUN alias python=python3 18 | 19 | # Install pip packages 20 | COPY requirements.txt . 21 | RUN python3 -m pip install --upgrade pip wheel 22 | RUN pip install --no-cache -r requirements.txt albumentations gsutil notebook \ 23 | coremltools onnx onnxruntime 24 | # tensorflow-aarch64 tensorflowjs \ 25 | 26 | # Create working directory 27 | RUN mkdir -p /usr/src/app 28 | WORKDIR /usr/src/app 29 | 30 | # Copy contents 31 | # COPY . /usr/src/app (issues as not a .git directory) 32 | RUN git clone https://github.com/ultralytics/yolov5 /usr/src/app 33 | ENV DEBIAN_FRONTEND teletype 34 | 35 | 36 | # Usage Examples ------------------------------------------------------------------------------------------------------- 37 | 38 | # Build and Push 39 | # t=ultralytics/yolov5:latest-arm64 && sudo docker build --platform linux/arm64 -f utils/docker/Dockerfile-arm64 -t $t . && sudo docker push $t 40 | 41 | # Pull and Run 42 | # t=ultralytics/yolov5:latest-arm64 && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/datasets:/usr/src/datasets $t 43 | -------------------------------------------------------------------------------- /utils/docker/Dockerfile-cpu: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | # Builds ultralytics/yolov5:latest-cpu image on DockerHub https://hub.docker.com/r/ultralytics/yolov3 4 | # Image is CPU-optimized for ONNX, OpenVINO and PyTorch YOLOv5 deployments 5 | 6 | # Start FROM Ubuntu image https://hub.docker.com/_/ubuntu 7 | FROM ubuntu:23.10 8 | 9 | # Downloads to user config dir 10 | ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/ 11 | 12 | # Install linux packages 13 | # g++ required to build 'tflite_support' and 'lap' packages, libusb-1.0-0 required for 'tflite_support' package 14 | RUN apt update \ 15 | && apt install --no-install-recommends -y python3-pip git zip curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0 16 | # RUN alias python=python3 17 | 18 | # Remove python3.11/EXTERNALLY-MANAGED or use 'pip install --break-system-packages' avoid 'externally-managed-environment' Ubuntu nightly error 19 | RUN rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED 20 | 21 | # Install pip packages 22 | COPY requirements.txt . 23 | RUN python3 -m pip install --upgrade pip wheel 24 | RUN pip install --no-cache -r requirements.txt albumentations gsutil notebook \ 25 | coremltools onnx onnx-simplifier onnxruntime 'openvino-dev>=2023.0' \ 26 | # tensorflow tensorflowjs \ 27 | --extra-index-url https://download.pytorch.org/whl/cpu 28 | 29 | # Create working directory 30 | RUN mkdir -p /usr/src/app 31 | WORKDIR /usr/src/app 32 | 33 | # Copy contents 34 | # COPY . /usr/src/app (issues as not a .git directory) 35 | RUN git clone https://github.com/ultralytics/yolov5 /usr/src/app 36 | 37 | 38 | # Usage Examples ------------------------------------------------------------------------------------------------------- 39 | 40 | # Build and Push 41 | # t=ultralytics/yolov5:latest-cpu && sudo docker build -f utils/docker/Dockerfile-cpu -t $t . && sudo docker push $t 42 | 43 | # Pull and Run 44 | # t=ultralytics/yolov5:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/datasets:/usr/src/datasets $t 45 | -------------------------------------------------------------------------------- /utils/downloads.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Download utils.""" 3 | 4 | import logging 5 | import subprocess 6 | import urllib 7 | from pathlib import Path 8 | 9 | import requests 10 | import torch 11 | 12 | 13 | def is_url(url, check=True): 14 | """Determines if a string is a valid URL and optionally checks its existence online.""" 15 | try: 16 | url = str(url) 17 | result = urllib.parse.urlparse(url) 18 | assert all([result.scheme, result.netloc]) # check if is url 19 | return (urllib.request.urlopen(url).getcode() == 200) if check else True # check if exists online 20 | except (AssertionError, urllib.request.HTTPError): 21 | return False 22 | 23 | 24 | def gsutil_getsize(url=""): 25 | """Returns the size of a file at a 'gs://' URL using gsutil du command; 0 if file not found or command fails.""" 26 | output = subprocess.check_output(["gsutil", "du", url], shell=True, encoding="utf-8") 27 | return int(output.split()[0]) if output else 0 28 | 29 | 30 | def url_getsize(url="https://ultralytics.com/images/bus.jpg"): 31 | """Fetches file size in bytes from a URL using an HTTP HEAD request; defaults to -1 if not found.""" 32 | response = requests.head(url, allow_redirects=True) 33 | return int(response.headers.get("content-length", -1)) 34 | 35 | 36 | def curl_download(url, filename, *, silent: bool = False) -> bool: 37 | """Download a file from a url to a filename using curl.""" 38 | silent_option = "sS" if silent else "" # silent 39 | proc = subprocess.run( 40 | [ 41 | "curl", 42 | "-#", 43 | f"-{silent_option}L", 44 | url, 45 | "--output", 46 | filename, 47 | "--retry", 48 | "9", 49 | "-C", 50 | "-", 51 | ] 52 | ) 53 | return proc.returncode == 0 54 | 55 | 56 | def safe_download(file, url, url2=None, min_bytes=1e0, error_msg=""): 57 | """Downloads a file from 'url' or 'url2' to 'file', ensuring size > 'min_bytes'; removes incomplete downloads.""" 58 | from utils.general import LOGGER 59 | 60 | file = Path(file) 61 | assert_msg = f"Downloaded file '{file}' does not exist or size is < min_bytes={min_bytes}" 62 | try: # url1 63 | LOGGER.info(f"Downloading {url} to {file}...") 64 | torch.hub.download_url_to_file(url, str(file), progress=LOGGER.level <= logging.INFO) 65 | assert file.exists() and file.stat().st_size > min_bytes, assert_msg # check 66 | except Exception as e: # url2 67 | if file.exists(): 68 | file.unlink() # remove partial downloads 69 | LOGGER.info(f"ERROR: {e}\nRe-attempting {url2 or url} to {file}...") 70 | # curl download, retry and resume on fail 71 | curl_download(url2 or url, file) 72 | finally: 73 | if not file.exists() or file.stat().st_size < min_bytes: # check 74 | if file.exists(): 75 | file.unlink() # remove partial downloads 76 | LOGGER.info(f"ERROR: {assert_msg}\n{error_msg}") 77 | LOGGER.info("") 78 | 79 | 80 | def attempt_download(file, repo="ultralytics/yolov5", release="v7.0"): 81 | """Attempts to download a file from a specified URL or GitHub release, ensuring file integrity with a minimum size 82 | check. 83 | """ 84 | from utils.general import LOGGER 85 | 86 | def github_assets(repository, version="latest"): 87 | """Returns GitHub tag and assets for a given repository and version from the GitHub API.""" 88 | if version != "latest": 89 | version = f"tags/{version}" # i.e. tags/v7.0 90 | response = requests.get(f"https://api.github.com/repos/{repository}/releases/{version}").json() # github api 91 | return response["tag_name"], [x["name"] for x in response["assets"]] # tag, assets 92 | 93 | file = Path(str(file).strip().replace("'", "")) 94 | if not file.exists(): 95 | # URL specified 96 | name = Path(urllib.parse.unquote(str(file))).name # decode '%2F' to '/' etc. 97 | if str(file).startswith(("http:/", "https:/")): # download 98 | url = str(file).replace(":/", "://") # Pathlib turns :// -> :/ 99 | file = name.split("?")[0] # parse authentication https://url.com/file.txt?auth... 100 | if Path(file).is_file(): 101 | LOGGER.info(f"Found {url} locally at {file}") # file already exists 102 | else: 103 | safe_download(file=file, url=url, min_bytes=1e5) 104 | return file 105 | 106 | # GitHub assets 107 | assets = [f"yolov5{size}{suffix}.pt" for size in "nsmlx" for suffix in ("", "6", "-cls", "-seg")] # default 108 | try: 109 | tag, assets = github_assets(repo, release) 110 | except Exception: 111 | try: 112 | tag, assets = github_assets(repo) # latest release 113 | except Exception: 114 | try: 115 | tag = subprocess.check_output("git tag", shell=True, stderr=subprocess.STDOUT).decode().split()[-1] 116 | except Exception: 117 | tag = release 118 | 119 | if name in assets: 120 | file.parent.mkdir(parents=True, exist_ok=True) # make parent dir (if required) 121 | safe_download( 122 | file, 123 | url=f"https://github.com/{repo}/releases/download/{tag}/{name}", 124 | min_bytes=1e5, 125 | error_msg=f"{file} missing, try downloading from https://github.com/{repo}/releases/{tag}", 126 | ) 127 | 128 | return str(file) 129 | -------------------------------------------------------------------------------- /utils/flask_rest_api/README.md: -------------------------------------------------------------------------------- 1 | Ultralytics logo 2 | 3 | # Flask REST API Example for YOLO Models 4 | 5 | [Representational State Transfer (REST)](https://en.wikipedia.org/wiki/Representational_state_transfer) [Application Programming Interfaces (APIs)](https://developer.mozilla.org/en-US/docs/Web/API) are a standard way to expose [Machine Learning (ML)](https://www.ultralytics.com/glossary/machine-learning-ml) models, allowing other services or applications to interact with them over a network. This directory provides an example REST API built using the [Flask](https://palletsprojects.com/projects/flask/) microframework to serve predictions from an [Ultralytics YOLOv3](https://docs.ultralytics.com/models/yolov3/) model, potentially loaded via [PyTorch Hub](https://pytorch.org/hub/) or other standard PyTorch methods. 6 | 7 | Deploying models via APIs is a crucial step in [MLOps](https://www.ultralytics.com/glossary/machine-learning-operations-mlops) and enables integration into larger systems. You can explore various [model deployment options](https://docs.ultralytics.com/guides/model-deployment-options/) for different scenarios. 8 | 9 | ## 🔧 Requirements 10 | 11 | Ensure you have the necessary Python packages installed. The primary requirement is Flask. 12 | 13 | Install Flask using pip: 14 | 15 | ```shell 16 | pip install Flask torch torchvision 17 | ``` 18 | 19 | _Note: `torch` and `torchvision` are required for loading and running PyTorch-based models like YOLOv3._ 20 | 21 | ## ▶️ Run the API 22 | 23 | Once Flask and dependencies are installed, you can start the API server. 24 | 25 | Execute the Python script: 26 | 27 | ```shell 28 | python restapi.py --port 5000 29 | ``` 30 | 31 | The API server will start listening on the specified port (default is 5000). 32 | 33 | ## 🚀 Make a Prediction Request 34 | 35 | You can send prediction requests to the running API using tools like [`curl`](https://curl.se/) or scripting languages. 36 | 37 | Send a POST request with an image file (`zidane.jpg` in this example) to the `/v1/object-detection/yolov3` endpoint: 38 | 39 | ```shell 40 | curl -X POST -F image=@zidane.jpg 'http://localhost:5000/v1/object-detection/yolov3' 41 | ``` 42 | 43 | _Ensure `zidane.jpg` (or your test image) is present in the directory where you run the `curl` command._ 44 | 45 | ## 📄 Understand the Response 46 | 47 | The API processes the image and returns the [object detection](https://www.ultralytics.com/glossary/object-detection) results in [JSON](https://www.ultralytics.com/glossary/json) format. Each object detected includes its class ID, confidence score, bounding box coordinates (normalized), and class name. 48 | 49 | Example JSON response: 50 | 51 | ```json 52 | [ 53 | { 54 | "class": 0, 55 | "confidence": 0.8900438547, 56 | "height": 0.9318675399, 57 | "name": "person", 58 | "width": 0.3264600933, 59 | "xcenter": 0.7438579798, 60 | "ycenter": 0.5207948685 61 | }, 62 | { 63 | "class": 0, 64 | "confidence": 0.8440024257, 65 | "height": 0.7155083418, 66 | "name": "person", 67 | "width": 0.6546785235, 68 | "xcenter": 0.427829951, 69 | "ycenter": 0.6334488392 70 | }, 71 | { 72 | "class": 27, 73 | "confidence": 0.3771208823, 74 | "height": 0.3902671337, 75 | "name": "tie", 76 | "width": 0.0696444362, 77 | "xcenter": 0.3675483763, 78 | "ycenter": 0.7991207838 79 | }, 80 | { 81 | "class": 27, 82 | "confidence": 0.3527112305, 83 | "height": 0.1540903747, 84 | "name": "tie", 85 | "width": 0.0336618312, 86 | "xcenter": 0.7814827561, 87 | "ycenter": 0.5065554976 88 | } 89 | ] 90 | ``` 91 | 92 | An example Python script (`example_request.py`) demonstrating how to send requests using the popular [requests](https://requests.readthedocs.io/en/latest/) library is also included in this directory. 93 | 94 | ## 🤝 Contributing 95 | 96 | Contributions to enhance this example or add support for other Ultralytics models are welcome! Please see the main Ultralytics [CONTRIBUTING](https://docs.ultralytics.com/help/contributing/) guide for more information on how to get involved. 97 | -------------------------------------------------------------------------------- /utils/flask_rest_api/example_request.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Perform test request.""" 3 | 4 | import pprint 5 | 6 | import requests 7 | 8 | DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s" 9 | IMAGE = "zidane.jpg" 10 | 11 | # Read image 12 | with open(IMAGE, "rb") as f: 13 | image_data = f.read() 14 | 15 | response = requests.post(DETECTION_URL, files={"image": image_data}).json() 16 | 17 | pprint.pprint(response) 18 | -------------------------------------------------------------------------------- /utils/flask_rest_api/restapi.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Run a Flask REST API exposing one or more YOLOv5s models.""" 3 | 4 | import argparse 5 | import io 6 | 7 | import torch 8 | from flask import Flask, request 9 | from PIL import Image 10 | 11 | app = Flask(__name__) 12 | models = {} 13 | 14 | DETECTION_URL = "/v1/object-detection/" 15 | 16 | 17 | @app.route(DETECTION_URL, methods=["POST"]) 18 | def predict(model): 19 | """Predicts objects in an image using YOLOv5s models exposed via Flask REST API; expects 'image' file in POST 20 | request. 21 | """ 22 | if request.method != "POST": 23 | return 24 | 25 | if request.files.get("image"): 26 | # Method 1 27 | # with request.files["image"] as f: 28 | # im = Image.open(io.BytesIO(f.read())) 29 | 30 | # Method 2 31 | im_file = request.files["image"] 32 | im_bytes = im_file.read() 33 | im = Image.open(io.BytesIO(im_bytes)) 34 | 35 | if model in models: 36 | results = models[model](im, size=640) # reduce size=320 for faster inference 37 | return results.pandas().xyxy[0].to_json(orient="records") 38 | 39 | 40 | if __name__ == "__main__": 41 | parser = argparse.ArgumentParser(description="Flask API exposing YOLOv3 model") 42 | parser.add_argument("--port", default=5000, type=int, help="port number") 43 | parser.add_argument("--model", nargs="+", default=["yolov5s"], help="model(s) to run, i.e. --model yolov5n yolov5s") 44 | opt = parser.parse_args() 45 | 46 | for m in opt.model: 47 | models[m] = torch.hub.load("ultralytics/yolov5", m, force_reload=True, skip_validation=True) 48 | 49 | app.run(host="0.0.0.0", port=opt.port) # debug=True causes Restarting with stat 50 | -------------------------------------------------------------------------------- /utils/google_app_engine/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gcr.io/google-appengine/python 2 | 3 | # Create a virtualenv for dependencies. This isolates these packages from 4 | # system-level packages. 5 | # Use -p python3 or -p python3.7 to select python version. Default is version 2. 6 | RUN virtualenv /env -p python3 7 | 8 | # Setting these environment variables are the same as running 9 | # source /env/bin/activate. 10 | ENV VIRTUAL_ENV /env 11 | ENV PATH /env/bin:$PATH 12 | 13 | RUN apt-get update && apt-get install -y python-opencv 14 | 15 | # Copy the application's requirements.txt and run pip to install all 16 | # dependencies into the virtualenv. 17 | ADD requirements.txt /app/requirements.txt 18 | RUN pip install -r /app/requirements.txt 19 | 20 | # Add the application source code. 21 | ADD . /app 22 | 23 | # Run a WSGI server to serve the application. gunicorn must be declared as 24 | # a dependency in requirements.txt. 25 | CMD gunicorn -b :$PORT main:app 26 | -------------------------------------------------------------------------------- /utils/google_app_engine/additional_requirements.txt: -------------------------------------------------------------------------------- 1 | # add these requirements in your app on top of the existing ones 2 | pip==23.3 3 | Flask==2.3.2 4 | gunicorn==23.0.0 5 | werkzeug>=3.0.1 # not directly required, pinned by Snyk to avoid a vulnerability 6 | zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability 7 | -------------------------------------------------------------------------------- /utils/google_app_engine/app.yaml: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | runtime: custom 4 | env: flex 5 | 6 | service: yolov5app 7 | 8 | liveness_check: 9 | initial_delay_sec: 600 10 | 11 | manual_scaling: 12 | instances: 1 13 | resources: 14 | cpu: 1 15 | memory_gb: 4 16 | disk_size_gb: 20 17 | -------------------------------------------------------------------------------- /utils/loggers/clearml/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | -------------------------------------------------------------------------------- /utils/loggers/clearml/hpo.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | from clearml import Task 4 | 5 | # Connecting ClearML with the current process, 6 | # from here on everything is logged automatically 7 | from clearml.automation import HyperParameterOptimizer, UniformParameterRange 8 | from clearml.automation.optuna import OptimizerOptuna 9 | 10 | task = Task.init( 11 | project_name="Hyper-Parameter Optimization", 12 | task_name="YOLOv3", 13 | task_type=Task.TaskTypes.optimizer, 14 | reuse_last_task_id=False, 15 | ) 16 | 17 | # Example use case: 18 | optimizer = HyperParameterOptimizer( 19 | # This is the experiment we want to optimize 20 | base_task_id="", 21 | # here we define the hyper-parameters to optimize 22 | # Notice: The parameter name should exactly match what you see in the UI: / 23 | # For Example, here we see in the base experiment a section Named: "General" 24 | # under it a parameter named "batch_size", this becomes "General/batch_size" 25 | # If you have `argparse` for example, then arguments will appear under the "Args" section, 26 | # and you should instead pass "Args/batch_size" 27 | hyper_parameters=[ 28 | UniformParameterRange("Hyperparameters/lr0", min_value=1e-5, max_value=1e-1), 29 | UniformParameterRange("Hyperparameters/lrf", min_value=0.01, max_value=1.0), 30 | UniformParameterRange("Hyperparameters/momentum", min_value=0.6, max_value=0.98), 31 | UniformParameterRange("Hyperparameters/weight_decay", min_value=0.0, max_value=0.001), 32 | UniformParameterRange("Hyperparameters/warmup_epochs", min_value=0.0, max_value=5.0), 33 | UniformParameterRange("Hyperparameters/warmup_momentum", min_value=0.0, max_value=0.95), 34 | UniformParameterRange("Hyperparameters/warmup_bias_lr", min_value=0.0, max_value=0.2), 35 | UniformParameterRange("Hyperparameters/box", min_value=0.02, max_value=0.2), 36 | UniformParameterRange("Hyperparameters/cls", min_value=0.2, max_value=4.0), 37 | UniformParameterRange("Hyperparameters/cls_pw", min_value=0.5, max_value=2.0), 38 | UniformParameterRange("Hyperparameters/obj", min_value=0.2, max_value=4.0), 39 | UniformParameterRange("Hyperparameters/obj_pw", min_value=0.5, max_value=2.0), 40 | UniformParameterRange("Hyperparameters/iou_t", min_value=0.1, max_value=0.7), 41 | UniformParameterRange("Hyperparameters/anchor_t", min_value=2.0, max_value=8.0), 42 | UniformParameterRange("Hyperparameters/fl_gamma", min_value=0.0, max_value=4.0), 43 | UniformParameterRange("Hyperparameters/hsv_h", min_value=0.0, max_value=0.1), 44 | UniformParameterRange("Hyperparameters/hsv_s", min_value=0.0, max_value=0.9), 45 | UniformParameterRange("Hyperparameters/hsv_v", min_value=0.0, max_value=0.9), 46 | UniformParameterRange("Hyperparameters/degrees", min_value=0.0, max_value=45.0), 47 | UniformParameterRange("Hyperparameters/translate", min_value=0.0, max_value=0.9), 48 | UniformParameterRange("Hyperparameters/scale", min_value=0.0, max_value=0.9), 49 | UniformParameterRange("Hyperparameters/shear", min_value=0.0, max_value=10.0), 50 | UniformParameterRange("Hyperparameters/perspective", min_value=0.0, max_value=0.001), 51 | UniformParameterRange("Hyperparameters/flipud", min_value=0.0, max_value=1.0), 52 | UniformParameterRange("Hyperparameters/fliplr", min_value=0.0, max_value=1.0), 53 | UniformParameterRange("Hyperparameters/mosaic", min_value=0.0, max_value=1.0), 54 | UniformParameterRange("Hyperparameters/mixup", min_value=0.0, max_value=1.0), 55 | UniformParameterRange("Hyperparameters/copy_paste", min_value=0.0, max_value=1.0), 56 | ], 57 | # this is the objective metric we want to maximize/minimize 58 | objective_metric_title="metrics", 59 | objective_metric_series="mAP_0.5", 60 | # now we decide if we want to maximize it or minimize it (accuracy we maximize) 61 | objective_metric_sign="max", 62 | # let us limit the number of concurrent experiments, 63 | # this in turn will make sure we do dont bombard the scheduler with experiments. 64 | # if we have an auto-scaler connected, this, by proxy, will limit the number of machine 65 | max_number_of_concurrent_tasks=1, 66 | # this is the optimizer class (actually doing the optimization) 67 | # Currently, we can choose from GridSearch, RandomSearch or OptimizerBOHB (Bayesian optimization Hyper-Band) 68 | optimizer_class=OptimizerOptuna, 69 | # If specified only the top K performing Tasks will be kept, the others will be automatically archived 70 | save_top_k_tasks_only=5, # 5, 71 | compute_time_limit=None, 72 | total_max_jobs=20, 73 | min_iteration_per_job=None, 74 | max_iteration_per_job=None, 75 | ) 76 | 77 | # report every 10 seconds, this is way too often, but we are testing here 78 | optimizer.set_report_period(10 / 60) 79 | # You can also use the line below instead to run all the optimizer tasks locally, without using queues or agent 80 | # an_optimizer.start_locally(job_complete_callback=job_complete_callback) 81 | # set the time limit for the optimization process (2 hours) 82 | optimizer.set_time_limit(in_minutes=120.0) 83 | # Start the optimization process in the local environment 84 | optimizer.start_locally() 85 | # wait until process is done (notice we are controlling the optimization process in the background) 86 | optimizer.wait() 87 | # make sure background optimization stopped 88 | optimizer.stop() 89 | 90 | print("We are done, good bye") 91 | -------------------------------------------------------------------------------- /utils/loggers/comet/comet_utils.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | 3 | import logging 4 | import os 5 | from urllib.parse import urlparse 6 | 7 | try: 8 | import comet_ml 9 | except ImportError: 10 | comet_ml = None 11 | 12 | import yaml 13 | 14 | logger = logging.getLogger(__name__) 15 | 16 | COMET_PREFIX = "comet://" 17 | COMET_MODEL_NAME = os.getenv("COMET_MODEL_NAME", "yolov5") 18 | COMET_DEFAULT_CHECKPOINT_FILENAME = os.getenv("COMET_DEFAULT_CHECKPOINT_FILENAME", "last.pt") 19 | 20 | 21 | def download_model_checkpoint(opt, experiment): 22 | """Downloads the model checkpoint from Comet ML; updates `opt.weights` with the downloaded file path.""" 23 | model_dir = f"{opt.project}/{experiment.name}" 24 | os.makedirs(model_dir, exist_ok=True) 25 | 26 | model_name = COMET_MODEL_NAME 27 | model_asset_list = experiment.get_model_asset_list(model_name) 28 | 29 | if len(model_asset_list) == 0: 30 | logger.error(f"COMET ERROR: No checkpoints found for model name : {model_name}") 31 | return 32 | 33 | model_asset_list = sorted( 34 | model_asset_list, 35 | key=lambda x: x["step"], 36 | reverse=True, 37 | ) 38 | logged_checkpoint_map = {asset["fileName"]: asset["assetId"] for asset in model_asset_list} 39 | 40 | resource_url = urlparse(opt.weights) 41 | checkpoint_filename = resource_url.query 42 | 43 | if checkpoint_filename: 44 | asset_id = logged_checkpoint_map.get(checkpoint_filename) 45 | else: 46 | asset_id = logged_checkpoint_map.get(COMET_DEFAULT_CHECKPOINT_FILENAME) 47 | checkpoint_filename = COMET_DEFAULT_CHECKPOINT_FILENAME 48 | 49 | if asset_id is None: 50 | logger.error(f"COMET ERROR: Checkpoint {checkpoint_filename} not found in the given Experiment") 51 | return 52 | 53 | try: 54 | logger.info(f"COMET INFO: Downloading checkpoint {checkpoint_filename}") 55 | asset_filename = checkpoint_filename 56 | 57 | model_binary = experiment.get_asset(asset_id, return_type="binary", stream=False) 58 | model_download_path = f"{model_dir}/{asset_filename}" 59 | with open(model_download_path, "wb") as f: 60 | f.write(model_binary) 61 | 62 | opt.weights = model_download_path 63 | 64 | except Exception as e: 65 | logger.warning("COMET WARNING: Unable to download checkpoint from Comet") 66 | logger.exception(e) 67 | 68 | 69 | def set_opt_parameters(opt, experiment): 70 | """ 71 | Update the opts Namespace with parameters from Comet's ExistingExperiment when resuming a run. 72 | 73 | Args: 74 | opt (argparse.Namespace): Namespace of command line options 75 | experiment (comet_ml.APIExperiment): Comet API Experiment object 76 | """ 77 | asset_list = experiment.get_asset_list() 78 | resume_string = opt.resume 79 | 80 | for asset in asset_list: 81 | if asset["fileName"] == "opt.yaml": 82 | asset_id = asset["assetId"] 83 | asset_binary = experiment.get_asset(asset_id, return_type="binary", stream=False) 84 | opt_dict = yaml.safe_load(asset_binary) 85 | for key, value in opt_dict.items(): 86 | setattr(opt, key, value) 87 | opt.resume = resume_string 88 | 89 | # Save hyperparameters to YAML file 90 | # Necessary to pass checks in training script 91 | save_dir = f"{opt.project}/{experiment.name}" 92 | os.makedirs(save_dir, exist_ok=True) 93 | 94 | hyp_yaml_path = f"{save_dir}/hyp.yaml" 95 | with open(hyp_yaml_path, "w") as f: 96 | yaml.dump(opt.hyp, f) 97 | opt.hyp = hyp_yaml_path 98 | 99 | 100 | def check_comet_weights(opt): 101 | """ 102 | Downloads model weights from Comet and updates the weights path to point to saved weights location. 103 | 104 | Args: 105 | opt (argparse.Namespace): Command Line arguments passed 106 | to YOLOv3 training script 107 | 108 | Returns: 109 | None/bool: Return True if weights are successfully downloaded 110 | else return None 111 | """ 112 | if comet_ml is None: 113 | return 114 | 115 | if isinstance(opt.weights, str) and opt.weights.startswith(COMET_PREFIX): 116 | api = comet_ml.API() 117 | resource = urlparse(opt.weights) 118 | experiment_path = f"{resource.netloc}{resource.path}" 119 | experiment = api.get(experiment_path) 120 | download_model_checkpoint(opt, experiment) 121 | return True 122 | 123 | return None 124 | 125 | 126 | def check_comet_resume(opt): 127 | """ 128 | Restores run parameters to its original state based on the model checkpoint and logged Experiment parameters. 129 | 130 | Args: 131 | opt (argparse.Namespace): Command Line arguments passed 132 | to YOLOv3 training script 133 | 134 | Returns: 135 | None/bool: Return True if the run is restored successfully 136 | else return None 137 | """ 138 | if comet_ml is None: 139 | return 140 | 141 | if isinstance(opt.resume, str) and opt.resume.startswith(COMET_PREFIX): 142 | api = comet_ml.API() 143 | resource = urlparse(opt.resume) 144 | experiment_path = f"{resource.netloc}{resource.path}" 145 | experiment = api.get(experiment_path) 146 | set_opt_parameters(opt, experiment) 147 | download_model_checkpoint(opt, experiment) 148 | 149 | return True 150 | 151 | return None 152 | -------------------------------------------------------------------------------- /utils/loggers/comet/optimizer_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "algorithm": "random", 3 | "parameters": { 4 | "anchor_t": { 5 | "type": "discrete", 6 | "values": [2, 8] 7 | }, 8 | "batch_size": { 9 | "type": "discrete", 10 | "values": [16, 32, 64] 11 | }, 12 | "box": { 13 | "type": "discrete", 14 | "values": [0.02, 0.2] 15 | }, 16 | "cls": { 17 | "type": "discrete", 18 | "values": [0.2] 19 | }, 20 | "cls_pw": { 21 | "type": "discrete", 22 | "values": [0.5] 23 | }, 24 | "copy_paste": { 25 | "type": "discrete", 26 | "values": [1] 27 | }, 28 | "degrees": { 29 | "type": "discrete", 30 | "values": [0, 45] 31 | }, 32 | "epochs": { 33 | "type": "discrete", 34 | "values": [5] 35 | }, 36 | "fl_gamma": { 37 | "type": "discrete", 38 | "values": [0] 39 | }, 40 | "fliplr": { 41 | "type": "discrete", 42 | "values": [0] 43 | }, 44 | "flipud": { 45 | "type": "discrete", 46 | "values": [0] 47 | }, 48 | "hsv_h": { 49 | "type": "discrete", 50 | "values": [0] 51 | }, 52 | "hsv_s": { 53 | "type": "discrete", 54 | "values": [0] 55 | }, 56 | "hsv_v": { 57 | "type": "discrete", 58 | "values": [0] 59 | }, 60 | "iou_t": { 61 | "type": "discrete", 62 | "values": [0.7] 63 | }, 64 | "lr0": { 65 | "type": "discrete", 66 | "values": [1e-5, 0.1] 67 | }, 68 | "lrf": { 69 | "type": "discrete", 70 | "values": [0.01, 1] 71 | }, 72 | "mixup": { 73 | "type": "discrete", 74 | "values": [1] 75 | }, 76 | "momentum": { 77 | "type": "discrete", 78 | "values": [0.6] 79 | }, 80 | "mosaic": { 81 | "type": "discrete", 82 | "values": [0] 83 | }, 84 | "obj": { 85 | "type": "discrete", 86 | "values": [0.2] 87 | }, 88 | "obj_pw": { 89 | "type": "discrete", 90 | "values": [0.5] 91 | }, 92 | "optimizer": { 93 | "type": "categorical", 94 | "values": ["SGD", "Adam", "AdamW"] 95 | }, 96 | "perspective": { 97 | "type": "discrete", 98 | "values": [0] 99 | }, 100 | "scale": { 101 | "type": "discrete", 102 | "values": [0] 103 | }, 104 | "shear": { 105 | "type": "discrete", 106 | "values": [0] 107 | }, 108 | "translate": { 109 | "type": "discrete", 110 | "values": [0] 111 | }, 112 | "warmup_bias_lr": { 113 | "type": "discrete", 114 | "values": [0, 0.2] 115 | }, 116 | "warmup_epochs": { 117 | "type": "discrete", 118 | "values": [5] 119 | }, 120 | "warmup_momentum": { 121 | "type": "discrete", 122 | "values": [0, 0.95] 123 | }, 124 | "weight_decay": { 125 | "type": "discrete", 126 | "values": [0, 0.001] 127 | } 128 | }, 129 | "spec": { 130 | "maxCombo": 0, 131 | "metric": "metrics/mAP_0.5", 132 | "objective": "maximize" 133 | }, 134 | "trials": 1 135 | } 136 | -------------------------------------------------------------------------------- /utils/loggers/wandb/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | -------------------------------------------------------------------------------- /utils/segment/__init__.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | -------------------------------------------------------------------------------- /utils/segment/augmentations.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Image augmentation functions.""" 3 | 4 | import math 5 | import random 6 | 7 | import cv2 8 | import numpy as np 9 | 10 | from ..augmentations import box_candidates 11 | from ..general import resample_segments, segment2box 12 | 13 | 14 | def mixup(im, labels, segments, im2, labels2, segments2): 15 | """Applies MixUp augmentation by blending pairs of images, labels, and segments; see 16 | https://arxiv.org/pdf/1710.09412.pdf. 17 | """ 18 | r = np.random.beta(32.0, 32.0) # mixup ratio, alpha=beta=32.0 19 | im = (im * r + im2 * (1 - r)).astype(np.uint8) 20 | labels = np.concatenate((labels, labels2), 0) 21 | segments = np.concatenate((segments, segments2), 0) 22 | return im, labels, segments 23 | 24 | 25 | def random_perspective( 26 | im, targets=(), segments=(), degrees=10, translate=0.1, scale=0.1, shear=10, perspective=0.0, border=(0, 0) 27 | ): 28 | # torchvision.transforms.RandomAffine(degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-10, 10)) 29 | # targets = [cls, xyxy] 30 | """Applies random perspective augmentation including rotation, translation, scale, and shear transformations.""" 31 | height = im.shape[0] + border[0] * 2 # shape(h,w,c) 32 | width = im.shape[1] + border[1] * 2 33 | 34 | # Center 35 | C = np.eye(3) 36 | C[0, 2] = -im.shape[1] / 2 # x translation (pixels) 37 | C[1, 2] = -im.shape[0] / 2 # y translation (pixels) 38 | 39 | # Perspective 40 | P = np.eye(3) 41 | P[2, 0] = random.uniform(-perspective, perspective) # x perspective (about y) 42 | P[2, 1] = random.uniform(-perspective, perspective) # y perspective (about x) 43 | 44 | # Rotation and Scale 45 | R = np.eye(3) 46 | a = random.uniform(-degrees, degrees) 47 | # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations 48 | s = random.uniform(1 - scale, 1 + scale) 49 | # s = 2 ** random.uniform(-scale, scale) 50 | R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s) 51 | 52 | # Shear 53 | S = np.eye(3) 54 | S[0, 1] = math.tan(random.uniform(-shear, shear) * math.pi / 180) # x shear (deg) 55 | S[1, 0] = math.tan(random.uniform(-shear, shear) * math.pi / 180) # y shear (deg) 56 | 57 | # Translation 58 | T = np.eye(3) 59 | T[0, 2] = random.uniform(0.5 - translate, 0.5 + translate) * width # x translation (pixels) 60 | T[1, 2] = random.uniform(0.5 - translate, 0.5 + translate) * height # y translation (pixels) 61 | 62 | # Combined rotation matrix 63 | M = T @ S @ R @ P @ C # order of operations (right to left) is IMPORTANT 64 | if (border[0] != 0) or (border[1] != 0) or (M != np.eye(3)).any(): # image changed 65 | if perspective: 66 | im = cv2.warpPerspective(im, M, dsize=(width, height), borderValue=(114, 114, 114)) 67 | else: # affine 68 | im = cv2.warpAffine(im, M[:2], dsize=(width, height), borderValue=(114, 114, 114)) 69 | 70 | new_segments = [] 71 | if n := len(targets): 72 | new = np.zeros((n, 4)) 73 | segments = resample_segments(segments) # upsample 74 | for i, segment in enumerate(segments): 75 | xy = np.ones((len(segment), 3)) 76 | xy[:, :2] = segment 77 | xy = xy @ M.T # transform 78 | xy = xy[:, :2] / xy[:, 2:3] if perspective else xy[:, :2] # perspective rescale or affine 79 | 80 | # clip 81 | new[i] = segment2box(xy, width, height) 82 | new_segments.append(xy) 83 | 84 | # filter candidates 85 | i = box_candidates(box1=targets[:, 1:5].T * s, box2=new.T, area_thr=0.01) 86 | targets = targets[i] 87 | targets[:, 1:5] = new[i] 88 | new_segments = np.array(new_segments)[i] 89 | 90 | return im, targets, new_segments 91 | -------------------------------------------------------------------------------- /utils/triton.py: -------------------------------------------------------------------------------- 1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 2 | """Utils to interact with the Triton Inference Server.""" 3 | 4 | import typing 5 | from urllib.parse import urlparse 6 | 7 | import torch 8 | 9 | 10 | class TritonRemoteModel: 11 | """ 12 | A wrapper over a model served by the Triton Inference Server. 13 | 14 | It can be configured to communicate over GRPC or HTTP. It accepts Torch Tensors as input and returns them as 15 | outputs. 16 | """ 17 | 18 | def __init__(self, url: str): 19 | """ 20 | Keyword Arguments: 21 | url: Fully qualified address of the Triton server - for e.g. grpc://localhost:8000. 22 | """ 23 | parsed_url = urlparse(url) 24 | if parsed_url.scheme == "grpc": 25 | from tritonclient.grpc import InferenceServerClient, InferInput 26 | 27 | self.client = InferenceServerClient(parsed_url.netloc) # Triton GRPC client 28 | model_repository = self.client.get_model_repository_index() 29 | self.model_name = model_repository.models[0].name 30 | self.metadata = self.client.get_model_metadata(self.model_name, as_json=True) 31 | 32 | def create_input_placeholders() -> typing.List[InferInput]: 33 | return [ 34 | InferInput(i["name"], [int(s) for s in i["shape"]], i["datatype"]) for i in self.metadata["inputs"] 35 | ] 36 | 37 | else: 38 | from tritonclient.http import InferenceServerClient, InferInput 39 | 40 | self.client = InferenceServerClient(parsed_url.netloc) # Triton HTTP client 41 | model_repository = self.client.get_model_repository_index() 42 | self.model_name = model_repository[0]["name"] 43 | self.metadata = self.client.get_model_metadata(self.model_name) 44 | 45 | def create_input_placeholders() -> typing.List[InferInput]: 46 | return [ 47 | InferInput(i["name"], [int(s) for s in i["shape"]], i["datatype"]) for i in self.metadata["inputs"] 48 | ] 49 | 50 | self._create_input_placeholders_fn = create_input_placeholders 51 | 52 | @property 53 | def runtime(self): 54 | """Returns the model runtime.""" 55 | return self.metadata.get("backend", self.metadata.get("platform")) 56 | 57 | def __call__(self, *args, **kwargs) -> typing.Union[torch.Tensor, typing.Tuple[torch.Tensor, ...]]: 58 | """ 59 | Invokes the model. 60 | 61 | Parameters can be provided via args or kwargs. args, if provided, are assumed to match the order of inputs of 62 | the model. kwargs are matched with the model input names. 63 | """ 64 | inputs = self._create_inputs(*args, **kwargs) 65 | response = self.client.infer(model_name=self.model_name, inputs=inputs) 66 | result = [] 67 | for output in self.metadata["outputs"]: 68 | tensor = torch.as_tensor(response.as_numpy(output["name"])) 69 | result.append(tensor) 70 | return result[0] if len(result) == 1 else result 71 | 72 | def _create_inputs(self, *args, **kwargs): 73 | """Generates model inputs from args or kwargs, not allowing both; raises error if neither or both are 74 | provided. 75 | """ 76 | args_len, kwargs_len = len(args), len(kwargs) 77 | if not args_len and not kwargs_len: 78 | raise RuntimeError("No inputs provided.") 79 | if args_len and kwargs_len: 80 | raise RuntimeError("Cannot specify args and kwargs at the same time") 81 | 82 | placeholders = self._create_input_placeholders_fn() 83 | if args_len: 84 | if args_len != len(placeholders): 85 | raise RuntimeError(f"Expected {len(placeholders)} inputs, got {args_len}.") 86 | for input, value in zip(placeholders, args): 87 | input.set_data_from_numpy(value.cpu().numpy()) 88 | else: 89 | for input in placeholders: 90 | value = kwargs[input.name] 91 | input.set_data_from_numpy(value.cpu().numpy()) 92 | return placeholders 93 | --------------------------------------------------------------------------------