HUB CI #1533
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ultralytics HUB Continuous Integration (CI) GitHub Actions tests | |
name: HUB CI | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
schedule: | |
- cron: "0 2 * * *" # runs every 24 hours, starting at 02:00 UTC | |
env: | |
API_KEY: ${{ secrets.ULTRALYTICS_HUB_API_KEY }} | |
MODEL_ID: ${{ secrets.ULTRALYTICS_HUB_MODEL_ID }} | |
HUB_TEAM_SLACK_ID: ${{ secrets.HUB_TEAM_SLACK_ID }} | |
jobs: | |
Tests: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest] | |
python-version: ["3.11"] | |
timeout-minutes: 60 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: "pip" # caching pip dependencies | |
- name: Install requirements | |
run: | | |
python -m pip install --upgrade pip wheel | |
pip install ultralytics --extra-index-url https://download.pytorch.org/whl/cpu | |
- name: Check environment | |
run: | | |
yolo checks | |
pip list | |
- name: Test HUB training | |
continue-on-error: false | |
shell: python | |
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 | |
run: | | |
import os | |
import requests | |
import json | |
from io import BytesIO | |
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} | |
f = BytesIO(requests.get("https://github.com/ultralytics/assets/releases/download/v0.0.0/zidane.jpg").content) | |
response = requests.post(url, headers=headers, data=data, files={"image": f}) | |
response.raise_for_status() # ensure we got a successful response | |
print(json.dumps(response.json(), indent=2)) | |
- name: Test HUB export | |
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
shell: python | |
run: | | |
import os | |
import time | |
from ultralytics import YOLO, checks, hub | |
checks() | |
api_key, model_id = os.environ['API_KEY'], os.environ['MODEL_ID'] | |
hub.login(api_key) | |
success = [] | |
for f in ('torchscript', 'onnx', 'openvino', 'coreml', 'saved_model', 'pb', 'tflite', 'edgetpu', 'tfjs', | |
'paddle', 'ultralytics_tflite', 'ultralytics_coreml', 'ncnn'): | |
backoff_times = [60, 120, 240, 480] # exponential backoff waits in seconds | |
for wait_time in backoff_times: | |
try: | |
print(f'Starting {f} export... ', end='') | |
hub.export_model(model_id, format=f) | |
time.sleep(wait_time) # wait for export to complete | |
success.append(hub.get_export(model_id, format=f)['success']) | |
print('done ✅' if success[-1] else 'Error ❌') | |
break # exit the loop if no exception is raised | |
except Exception as e: | |
if wait_time == backoff_times[-1]: # if it's the last backoff time | |
success.append(False) | |
print(f'Error ❌ {f} export {e}') | |
else: | |
print(f'Retrying {f} export in {wait_time // 60} minutes due to error: {e}') | |
time.sleep(wait_time) | |
assert all(success) | |
- name: Notify on failure | |
if: (cancelled() || failure()) && github.repository == 'ultralytics/hub' && (github.event_name == 'schedule' || github.event_name == 'push') | |
uses: slackapi/[email protected] | |
with: | |
payload: | | |
{"text": "<!subteam^${{ secrets.HUB_TEAM_SLACK_ID }}|@hub-team> 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_HUBWEB }} |