ci.yaml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. # YOLO Continuous Integration (CI) GitHub Actions tests
  3. name: Ultralytics CI
  4. on:
  5. push:
  6. branches: [main]
  7. pull_request:
  8. branches: [main]
  9. schedule:
  10. - cron: '0 0 * * *' # runs at 00:00 UTC every day
  11. workflow_dispatch:
  12. inputs:
  13. hub:
  14. description: 'Run HUB'
  15. default: false
  16. type: boolean
  17. tests:
  18. description: 'Run Tests'
  19. default: false
  20. type: boolean
  21. benchmarks:
  22. description: 'Run Benchmarks'
  23. default: false
  24. type: boolean
  25. jobs:
  26. HUB:
  27. if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.hub == 'true'))
  28. runs-on: ${{ matrix.os }}
  29. strategy:
  30. fail-fast: false
  31. matrix:
  32. os: [ubuntu-latest]
  33. python-version: ['3.11']
  34. steps:
  35. - uses: actions/checkout@v3
  36. - uses: actions/setup-python@v4
  37. with:
  38. python-version: ${{ matrix.python-version }}
  39. cache: 'pip' # caching pip dependencies
  40. - name: Install requirements
  41. shell: bash # for Windows compatibility
  42. run: |
  43. python -m pip install --upgrade pip wheel
  44. pip install -e . --extra-index-url https://download.pytorch.org/whl/cpu
  45. - name: Check environment
  46. run: |
  47. echo "RUNNER_OS is ${{ runner.os }}"
  48. echo "GITHUB_EVENT_NAME is ${{ github.event_name }}"
  49. echo "GITHUB_WORKFLOW is ${{ github.workflow }}"
  50. echo "GITHUB_ACTOR is ${{ github.actor }}"
  51. echo "GITHUB_REPOSITORY is ${{ github.repository }}"
  52. echo "GITHUB_REPOSITORY_OWNER is ${{ github.repository_owner }}"
  53. python --version
  54. pip --version
  55. pip list
  56. - name: Test HUB training
  57. shell: python
  58. env:
  59. API_KEY: ${{ secrets.ULTRALYTICS_HUB_API_KEY }}
  60. MODEL_ID: ${{ secrets.ULTRALYTICS_HUB_MODEL_ID }}
  61. run: |
  62. import os
  63. from ultralytics import YOLO, hub
  64. api_key, model_id = os.environ['API_KEY'], os.environ['MODEL_ID']
  65. hub.login(api_key)
  66. hub.reset_model(model_id)
  67. model = YOLO('https://hub.ultralytics.com/models/' + model_id)
  68. model.train()
  69. - name: Test HUB inference API
  70. shell: python
  71. env:
  72. API_KEY: ${{ secrets.ULTRALYTICS_HUB_API_KEY }}
  73. MODEL_ID: ${{ secrets.ULTRALYTICS_HUB_MODEL_ID }}
  74. run: |
  75. import os
  76. import requests
  77. import json
  78. api_key, model_id = os.environ['API_KEY'], os.environ['MODEL_ID']
  79. url = f"https://api.ultralytics.com/v1/predict/{model_id}"
  80. headers = {"x-api-key": api_key}
  81. data = {"size": 320, "confidence": 0.25, "iou": 0.45}
  82. with open("ultralytics/assets/zidane.jpg", "rb") as f:
  83. response = requests.post(url, headers=headers, data=data, files={"image": f})
  84. assert response.status_code == 200, f'Status code {response.status_code}, Reason {response.reason}'
  85. print(json.dumps(response.json(), indent=2))
  86. Benchmarks:
  87. if: github.event_name != 'workflow_dispatch' || github.event.inputs.benchmarks == 'true'
  88. runs-on: ${{ matrix.os }}
  89. strategy:
  90. fail-fast: false
  91. matrix:
  92. os: [ubuntu-latest]
  93. python-version: ['3.10']
  94. model: [yolov8n]
  95. steps:
  96. - uses: actions/checkout@v3
  97. - uses: actions/setup-python@v4
  98. with:
  99. python-version: ${{ matrix.python-version }}
  100. cache: 'pip' # caching pip dependencies
  101. - name: Install requirements
  102. shell: bash # for Windows compatibility
  103. run: |
  104. python -m pip install --upgrade pip wheel
  105. pip install -e ".[export]" coverage --extra-index-url https://download.pytorch.org/whl/cpu
  106. yolo export format=tflite imgsz=32 || true
  107. - name: Check environment
  108. run: |
  109. echo "RUNNER_OS is ${{ runner.os }}"
  110. echo "GITHUB_EVENT_NAME is ${{ github.event_name }}"
  111. echo "GITHUB_WORKFLOW is ${{ github.workflow }}"
  112. echo "GITHUB_ACTOR is ${{ github.actor }}"
  113. echo "GITHUB_REPOSITORY is ${{ github.repository }}"
  114. echo "GITHUB_REPOSITORY_OWNER is ${{ github.repository_owner }}"
  115. python --version
  116. pip --version
  117. pip list
  118. - name: Benchmark DetectionModel
  119. shell: bash
  120. run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}.pt' imgsz=160 verbose=0.26
  121. - name: Benchmark SegmentationModel
  122. shell: bash
  123. run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}-seg.pt' imgsz=160 verbose=0.30
  124. - name: Benchmark ClassificationModel
  125. shell: bash
  126. run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}-cls.pt' imgsz=160 verbose=0.36
  127. - name: Benchmark PoseModel
  128. shell: bash
  129. run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}-pose.pt' imgsz=160 verbose=0.17
  130. - name: Merge Coverage Reports
  131. run: |
  132. coverage xml -o coverage-benchmarks.xml
  133. - name: Upload Coverage Reports to CodeCov
  134. uses: codecov/codecov-action@v3
  135. with:
  136. flags: Benchmarks
  137. env:
  138. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  139. - name: Benchmark Summary
  140. run: |
  141. cat benchmarks.log
  142. echo "$(cat benchmarks.log)" >> $GITHUB_STEP_SUMMARY
  143. Tests:
  144. if: github.event_name != 'workflow_dispatch' || github.event.inputs.tests == 'true'
  145. timeout-minutes: 60
  146. runs-on: ${{ matrix.os }}
  147. strategy:
  148. fail-fast: false
  149. matrix:
  150. os: [ubuntu-latest]
  151. python-version: ['3.11']
  152. torch: [latest]
  153. include:
  154. - os: ubuntu-latest
  155. python-version: '3.8' # torch 1.8.0 requires python >=3.6, <=3.8
  156. torch: '1.8.0' # min torch version CI https://pypi.org/project/torchvision/
  157. steps:
  158. - uses: actions/checkout@v3
  159. - uses: actions/setup-python@v4
  160. with:
  161. python-version: ${{ matrix.python-version }}
  162. cache: 'pip' # caching pip dependencies
  163. - name: Install requirements
  164. shell: bash # for Windows compatibility
  165. run: | # CoreML must be installed before export due to protobuf error from AutoInstall
  166. python -m pip install --upgrade pip wheel
  167. if [ "${{ matrix.torch }}" == "1.8.0" ]; then
  168. pip install -e . torch==1.8.0 torchvision==0.9.0 pytest-cov "coremltools>=7.0.b1" --extra-index-url https://download.pytorch.org/whl/cpu
  169. else
  170. pip install -e . pytest-cov "coremltools>=7.0.b1" --extra-index-url https://download.pytorch.org/whl/cpu
  171. fi
  172. - name: Check environment
  173. run: |
  174. echo "RUNNER_OS is ${{ runner.os }}"
  175. echo "GITHUB_EVENT_NAME is ${{ github.event_name }}"
  176. echo "GITHUB_WORKFLOW is ${{ github.workflow }}"
  177. echo "GITHUB_ACTOR is ${{ github.actor }}"
  178. echo "GITHUB_REPOSITORY is ${{ github.repository }}"
  179. echo "GITHUB_REPOSITORY_OWNER is ${{ github.repository_owner }}"
  180. python --version
  181. pip --version
  182. pip list
  183. - name: Pytest tests
  184. shell: bash # for Windows compatibility
  185. run: pytest --cov=ultralytics/ --cov-report xml tests/
  186. - name: Upload Coverage Reports to CodeCov
  187. if: github.repository == 'ultralytics/ultralytics' && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
  188. uses: codecov/codecov-action@v3
  189. with:
  190. flags: Tests
  191. env:
  192. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  193. Summary:
  194. runs-on: ubuntu-latest
  195. needs: [HUB, Benchmarks, Tests] # Add job names that you want to check for failure
  196. if: always() # This ensures the job runs even if previous jobs fail
  197. steps:
  198. - name: Check for failure and notify
  199. if: (needs.HUB.result == 'failure' || needs.Benchmarks.result == 'failure' || needs.Tests.result == 'failure') && github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event_name == 'push')
  200. uses: slackapi/slack-github-action@v1.24.0
  201. with:
  202. payload: |
  203. {"text": "<!channel> 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"}
  204. env:
  205. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }}