| | |
| | |
| |
|
| | name: Ultralytics CI |
| |
|
| | on: |
| | push: |
| | branches: [main] |
| | pull_request: |
| | branches: [main] |
| | schedule: |
| | - cron: '0 0 * * *' |
| | workflow_dispatch: |
| | inputs: |
| | hub: |
| | description: 'Run HUB' |
| | default: false |
| | type: boolean |
| | tests: |
| | description: 'Run Tests' |
| | default: false |
| | type: boolean |
| | benchmarks: |
| | description: 'Run Benchmarks' |
| | default: false |
| | type: boolean |
| |
|
| | jobs: |
| | HUB: |
| | if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.hub == 'true')) |
| | runs-on: ${{ matrix.os }} |
| | strategy: |
| | fail-fast: false |
| | matrix: |
| | os: [ubuntu-latest] |
| | python-version: ['3.11'] |
| | steps: |
| | - uses: actions/checkout@v3 |
| | - uses: actions/setup-python@v4 |
| | with: |
| | python-version: ${{ matrix.python-version }} |
| | cache: 'pip' |
| | - name: Install requirements |
| | shell: bash |
| | run: | |
| | python -m pip install --upgrade pip wheel |
| | pip install -e . --extra-index-url https://download.pytorch.org/whl/cpu |
| | - name: Check environment |
| | run: | |
| | echo "RUNNER_OS is ${{ runner.os }}" |
| | echo "GITHUB_EVENT_NAME is ${{ github.event_name }}" |
| | echo "GITHUB_WORKFLOW is ${{ github.workflow }}" |
| | echo "GITHUB_ACTOR is ${{ github.actor }}" |
| | echo "GITHUB_REPOSITORY is ${{ github.repository }}" |
| | echo "GITHUB_REPOSITORY_OWNER is ${{ github.repository_owner }}" |
| | python --version |
| | pip --version |
| | pip list |
| | - name: Test HUB training |
| | shell: python |
| | env: |
| | API_KEY: ${{ secrets.ULTRALYTICS_HUB_API_KEY }} |
| | MODEL_ID: ${{ secrets.ULTRALYTICS_HUB_MODEL_ID }} |
| | run: | |
| | import os |
| | from ultralytics import YOLO, hub |
| | api_key, model_id = os.environ['API_KEY'], os.environ['MODEL_ID'] |
| | hub.login(api_key) |
| | hub.reset_model(model_id) |
| | model = YOLO('https://hub.ultralytics.com/models/' + model_id) |
| | model.train() |
| | - name: Test HUB inference API |
| | shell: python |
| | env: |
| | API_KEY: ${{ secrets.ULTRALYTICS_HUB_API_KEY }} |
| | MODEL_ID: ${{ secrets.ULTRALYTICS_HUB_MODEL_ID }} |
| | run: | |
| | import os |
| | import requests |
| | import json |
| | api_key, model_id = os.environ['API_KEY'], os.environ['MODEL_ID'] |
| | url = f"https://api.ultralytics.com/v1/predict/{model_id}" |
| | headers = {"x-api-key": api_key} |
| | data = {"size": 320, "confidence": 0.25, "iou": 0.45} |
| | with open("ultralytics/assets/zidane.jpg", "rb") as f: |
| | response = requests.post(url, headers=headers, data=data, files={"image": f}) |
| | assert response.status_code == 200, f'Status code {response.status_code}, Reason {response.reason}' |
| | print(json.dumps(response.json(), indent=2)) |
| | |
| | Benchmarks: |
| | if: github.event_name != 'workflow_dispatch' || github.event.inputs.benchmarks == 'true' |
| | runs-on: ${{ matrix.os }} |
| | strategy: |
| | fail-fast: false |
| | matrix: |
| | os: [ubuntu-latest] |
| | python-version: ['3.10'] |
| | model: [yolov8n] |
| | steps: |
| | - uses: actions/checkout@v3 |
| | - uses: actions/setup-python@v4 |
| | with: |
| | python-version: ${{ matrix.python-version }} |
| | cache: 'pip' |
| | - name: Install requirements |
| | shell: bash |
| | run: | |
| | python -m pip install --upgrade pip wheel |
| | pip install -e ".[export]" coverage --extra-index-url https://download.pytorch.org/whl/cpu |
| | yolo export format=tflite imgsz=32 || true |
| | - name: Check environment |
| | run: | |
| | echo "RUNNER_OS is ${{ runner.os }}" |
| | echo "GITHUB_EVENT_NAME is ${{ github.event_name }}" |
| | echo "GITHUB_WORKFLOW is ${{ github.workflow }}" |
| | echo "GITHUB_ACTOR is ${{ github.actor }}" |
| | echo "GITHUB_REPOSITORY is ${{ github.repository }}" |
| | echo "GITHUB_REPOSITORY_OWNER is ${{ github.repository_owner }}" |
| | python --version |
| | pip --version |
| | pip list |
| | - name: Benchmark DetectionModel |
| | shell: bash |
| | run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}.pt' imgsz=160 verbose=0.26 |
| | - name: Benchmark SegmentationModel |
| | shell: bash |
| | run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}-seg.pt' imgsz=160 verbose=0.30 |
| | - name: Benchmark ClassificationModel |
| | shell: bash |
| | run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}-cls.pt' imgsz=160 verbose=0.36 |
| | - name: Benchmark PoseModel |
| | shell: bash |
| | run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}-pose.pt' imgsz=160 verbose=0.17 |
| | - name: Merge Coverage Reports |
| | run: | |
| | coverage xml -o coverage-benchmarks.xml |
| | - name: Upload Coverage Reports to CodeCov |
| | uses: codecov/codecov-action@v3 |
| | with: |
| | flags: Benchmarks |
| | env: |
| | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| | - name: Benchmark Summary |
| | run: | |
| | cat benchmarks.log |
| | echo "$(cat benchmarks.log)" >> $GITHUB_STEP_SUMMARY |
| | |
| | Tests: |
| | if: github.event_name != 'workflow_dispatch' || github.event.inputs.tests == 'true' |
| | timeout-minutes: 60 |
| | runs-on: ${{ matrix.os }} |
| | strategy: |
| | fail-fast: false |
| | matrix: |
| | os: [ubuntu-latest] |
| | python-version: ['3.11'] |
| | torch: [latest] |
| | include: |
| | - os: ubuntu-latest |
| | python-version: '3.8' |
| | torch: '1.8.0' |
| | steps: |
| | - uses: actions/checkout@v3 |
| | - uses: actions/setup-python@v4 |
| | with: |
| | python-version: ${{ matrix.python-version }} |
| | cache: 'pip' |
| | - name: Install requirements |
| | shell: bash |
| | run: | |
| | python -m pip install --upgrade pip wheel |
| | if [ "${{ matrix.torch }}" == "1.8.0" ]; then |
| | 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 |
| | else |
| | pip install -e . pytest-cov "coremltools>=7.0.b1" --extra-index-url https://download.pytorch.org/whl/cpu |
| | fi |
| | - name: Check environment |
| | run: | |
| | echo "RUNNER_OS is ${{ runner.os }}" |
| | echo "GITHUB_EVENT_NAME is ${{ github.event_name }}" |
| | echo "GITHUB_WORKFLOW is ${{ github.workflow }}" |
| | echo "GITHUB_ACTOR is ${{ github.actor }}" |
| | echo "GITHUB_REPOSITORY is ${{ github.repository }}" |
| | echo "GITHUB_REPOSITORY_OWNER is ${{ github.repository_owner }}" |
| | python --version |
| | pip --version |
| | pip list |
| | - name: Pytest tests |
| | shell: bash |
| | run: pytest --cov=ultralytics/ --cov-report xml tests/ |
| | - name: Upload Coverage Reports to CodeCov |
| | if: github.repository == 'ultralytics/ultralytics' && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' |
| | uses: codecov/codecov-action@v3 |
| | with: |
| | flags: Tests |
| | env: |
| | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| |
|
| | Summary: |
| | runs-on: ubuntu-latest |
| | needs: [HUB, Benchmarks, Tests] |
| | if: always() |
| | steps: |
| | - name: Check for failure and notify |
| | 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') |
| | uses: slackapi/slack-github-action@v1.24.0 |
| | with: |
| | payload: | |
| | {"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"} |
| | env: |
| | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }} |
| |
|