diff --git a/.gitattributes b/.gitattributes index 084697181669a8f199e3048e6800e53606c21b8a..8a256efafcab33117d2317d018492aa0d69924b1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -37,3 +37,4 @@ ultralytics/assets/bus.jpg filter=lfs diff=lfs merge=lfs -text ultralytics/data/__pycache__/augment.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text ultralytics/data/__pycache__/augment.cpython-38.pyc filter=lfs diff=lfs merge=lfs -text ultralytics/data/__pycache__/augment.cpython-39.pyc filter=lfs diff=lfs merge=lfs -text +ultralytics-main/ultralytics/assets/bus.jpg filter=lfs diff=lfs merge=lfs -text diff --git a/ultralytics-main/.dockerignore b/ultralytics-main/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..4903d51fa8001c3ed072c24d8db41364bb5bd224 --- /dev/null +++ b/ultralytics-main/.dockerignore @@ -0,0 +1,35 @@ +# Python +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +*.py[cod] +*$py.class +.pytest_cache +.coverage +coverage.xml +.ruff_cache +*.egg-info +dist +build + +# Development +.env +.venv +env/ +venv/ +ENV/ +.idea +.vscode +*.swp +*.swo +.DS_Store + +# Project specific +*.log +benchmarks.log +runs/ + +# Dependencies +node_modules/ diff --git a/ultralytics-main/.github/ISSUE_TEMPLATE/bug-report.yml b/ultralytics-main/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 0000000000000000000000000000000000000000..2e584865d3a0399cd584b929fbd289ba485fae9f --- /dev/null +++ b/ultralytics-main/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,98 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +name: 🐛 Bug Report +# title: " " +description: Problems with Ultralytics YOLO +labels: [bug, triage] +type: "bug" +body: + - type: markdown + attributes: + value: | + Thank you for submitting an Ultralytics YOLO 🐛 Bug Report! + + - type: checkboxes + attributes: + label: Search before asking + description: > + Please search the Ultralytics [Docs](https://docs.ultralytics.com/) and [issues](https://github.com/ultralytics/ultralytics/issues) to see if a similar bug report already exists. + options: + - label: > + I have searched the Ultralytics YOLO [issues](https://github.com/ultralytics/ultralytics/issues) and found no similar bug report. + required: true + + - type: dropdown + attributes: + label: Ultralytics YOLO Component + description: | + Please select the Ultralytics YOLO component where you found the bug. + multiple: true + options: + - "Install" + - "Train" + - "Val" + - "Predict" + - "Export" + - "Multi-GPU" + - "Augmentation" + - "Hyperparameter Tuning" + - "Integrations" + - "Other" + validations: + required: false + + - type: textarea + attributes: + label: Bug + description: Please provide as much information as possible. Copy and paste console output and error messages including the _full_ traceback. Use [Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) to format text, code and logs. If necessary, include screenshots for visual elements only. Providing detailed information will help us resolve the issue more efficiently. + placeholder: | + 💡 ProTip! Include as much information as possible (logs, tracebacks, screenshots, etc.) to receive the most helpful response. + validations: + required: true + + - type: textarea + attributes: + label: Environment + description: Try the latest version (`pip install -U ultralytics`) before reporting a bug. If it's still present, please provide the output of `yolo checks` (CLI) or `ultralytics.utils.checks.collect_system_info()` (Python) command to help us diagnose the problem. + placeholder: | + Paste output of `yolo checks` (CLI) or `ultralytics.utils.checks.collect_system_info()` (Python) command, i.e.: + ``` + Ultralytics 8.3.2 🚀 Python-3.11.2 torch-2.4.1 CPU (Apple M3) + Setup complete ✅ (8 CPUs, 16.0 GB RAM, 266.5/460.4 GB disk) + + OS macOS-13.5.2 + Environment Jupyter + Python 3.11.2 + Install git + RAM 16.00 GB + CPU Apple M3 + CUDA None + ``` + validations: + required: true + + - type: textarea + attributes: + label: Minimal Reproducible Example + description: > + 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. This is referred to by community members as creating a [minimal reproducible example](https://docs.ultralytics.com/help/minimum-reproducible-example/). + placeholder: | + ``` + # Code to reproduce your issue here + ``` + validations: + required: true + + - type: textarea + attributes: + label: Additional + description: Anything else you would like to share? + + - type: checkboxes + attributes: + label: Are you willing to submit a PR? + description: > + (Optional) We encourage you to submit a [Pull Request](https://github.com/ultralytics/ultralytics/pulls) (PR) to help improve Ultralytics YOLO for everyone, especially if you have a good understanding of how to implement a fix or feature. + See the Ultralytics YOLO [Contributing Guide](https://docs.ultralytics.com/help/contributing/) to get started. + options: + - label: Yes I'd like to help by submitting a PR! diff --git a/ultralytics-main/.github/ISSUE_TEMPLATE/config.yml b/ultralytics-main/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000000000000000000000000000000000000..0da481e9fb9c5478cec3fe33f6e0186a1f100f49 --- /dev/null +++ b/ultralytics-main/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,16 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +blank_issues_enabled: true +contact_links: + - name: 📄 Docs + url: https://docs.ultralytics.com/ + about: Full Ultralytics YOLO Documentation + - name: 💬 Forum + url: https://community.ultralytics.com/ + about: Ask on Ultralytics Community Forum + - name: 🎧 Discord + url: https://ultralytics.com/discord + about: Ask on Ultralytics Discord + - name: ⌨️ Reddit + url: https://reddit.com/r/ultralytics + about: Ask on Ultralytics Subreddit diff --git a/ultralytics-main/.github/ISSUE_TEMPLATE/feature-request.yml b/ultralytics-main/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000000000000000000000000000000000000..2b37d456d8f2a31c2c88a554baf6e26fc5405897 --- /dev/null +++ b/ultralytics-main/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,53 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +name: 🚀 Feature Request +description: Suggest an Ultralytics YOLO idea +# title: " " +labels: [enhancement] +type: "feature" +body: + - type: markdown + attributes: + value: | + Thank you for submitting an Ultralytics 🚀 Feature Request! + + - type: checkboxes + attributes: + label: Search before asking + description: > + Please search the Ultralytics [Docs](https://docs.ultralytics.com/) and [issues](https://github.com/ultralytics/ultralytics/issues) to see if a similar feature request already exists. + options: + - label: > + I have searched the Ultralytics [issues](https://github.com/ultralytics/ultralytics/issues) and found no similar feature requests. + required: true + + - type: textarea + attributes: + label: Description + description: A short description of your feature. + placeholder: | + What new feature would you like to see in YOLO? + validations: + required: true + + - type: textarea + attributes: + label: Use case + description: | + Describe the use case of your feature request. It will help us understand and prioritize the feature request. + placeholder: | + How would this feature be used, and who would use it? + + - type: textarea + attributes: + label: Additional + description: Anything else you would like to share? + + - type: checkboxes + attributes: + label: Are you willing to submit a PR? + description: > + (Optional) We encourage you to submit a [Pull Request](https://github.com/ultralytics/ultralytics/pulls) (PR) to help improve YOLO for everyone, especially if you have a good understanding of how to implement a fix or feature. + See the Ultralytics [Contributing Guide](https://docs.ultralytics.com/help/contributing/) to get started. + options: + - label: Yes I'd like to help by submitting a PR! diff --git a/ultralytics-main/.github/ISSUE_TEMPLATE/question.yml b/ultralytics-main/.github/ISSUE_TEMPLATE/question.yml new file mode 100644 index 0000000000000000000000000000000000000000..5c6c2f39a21ed63ef702aba797dbe89053f0b751 --- /dev/null +++ b/ultralytics-main/.github/ISSUE_TEMPLATE/question.yml @@ -0,0 +1,35 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +name: ❓ Question +description: Ask an Ultralytics YOLO question +# title: " " +labels: [question] +body: + - type: markdown + attributes: + value: | + Thank you for asking an Ultralytics YOLO ❓ Question! + + - type: checkboxes + attributes: + label: Search before asking + description: > + Please search the Ultralytics [Docs](https://docs.ultralytics.com/), [issues](https://github.com/ultralytics/ultralytics/issues) and [discussions](https://github.com/orgs/ultralytics/discussions) to see if a similar question already exists. + options: + - label: > + I have searched the Ultralytics YOLO [issues](https://github.com/ultralytics/ultralytics/issues) and [discussions](https://github.com/orgs/ultralytics/discussions) and found no similar questions. + required: true + + - type: textarea + attributes: + label: Question + description: What is your question? Please provide as much information as possible. Include detailed code examples to reproduce the problem and describe the context in which the issue occurs. Format your text and code using [Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) for clarity and readability. Following these guidelines will help us assist you more effectively. + placeholder: | + 💡 ProTip! Include as much information as possible (logs, tracebacks, screenshots etc.) to receive the most helpful response. + validations: + required: true + + - type: textarea + attributes: + label: Additional + description: Anything else you would like to share? diff --git a/ultralytics-main/.github/dependabot.yml b/ultralytics-main/.github/dependabot.yml new file mode 100644 index 0000000000000000000000000000000000000000..b862521eebbab7464c96d4f9aaced3b16d7c0586 --- /dev/null +++ b/ultralytics-main/.github/dependabot.yml @@ -0,0 +1,24 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Dependabot for package version updates +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: pip + directory: "/" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 10 + labels: + - dependencies + + - package-ecosystem: github-actions + directory: "/.github/workflows" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 5 + labels: + - dependencies diff --git a/ultralytics-main/.github/workflows/ci.yml b/ultralytics-main/.github/workflows/ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..3f6c3a139a9139c70c61f9413f68e12a89ff5fa8 --- /dev/null +++ b/ultralytics-main/.github/workflows/ci.yml @@ -0,0 +1,523 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Ultralytics YOLO Continuous Integration (CI) GitHub Actions tests + +name: CI + +permissions: + contents: read + +env: + PYTHONFAULTHANDLER: 1 + +on: + push: + branches: [main] + pull_request: + schedule: + - cron: "0 8 * * *" # runs at 08:00 UTC every day + workflow_dispatch: + inputs: + hub: + description: "Run HUB" + default: true + type: boolean + benchmarks: + description: "Run Benchmarks" + default: true + type: boolean + tests: + description: "Run Tests" + default: true + type: boolean + gpu: + description: "Run GPU" + default: true + type: boolean + raspberrypi: + description: "Run Raspberry Pi" + default: true + type: boolean + nvidia-jetson: + description: "Run NVIDIA Jetson" + default: true + type: boolean + conda: + description: "Run Conda" + default: true + 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: ["3.12"] + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python }} + - uses: astral-sh/setup-uv@v7 + - name: Install requirements + shell: bash # for Windows compatibility + run: | + uv pip install --system . --extra-index-url https://download.pytorch.org/whl/cpu + - name: Check environment + run: | + yolo checks + uv 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: + # Temporarily disable windows-latest due to https://github.com/ultralytics/ultralytics/actions/runs/13020330819/job/36319338854?pr=18921 + os: [ubuntu-latest, macos-26, ubuntu-24.04-arm] + python: ["3.12"] + model: [yolo11n] + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python }} + - uses: astral-sh/setup-uv@v7 + - name: Install requirements + shell: bash # for Windows compatibility + run: | + uv pip install --system -e ".[export]" "coverage[toml]" --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match + - name: Check environment + run: | + yolo checks + uv 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.309 + - 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.249 + - name: Benchmark YOLOWorld DetectionModel + shell: bash + run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/yolov8s-worldv2.pt' imgsz=160 verbose=0.337 + - 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.195 + - 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.197 + - name: Benchmark OBBModel + shell: bash + run: coverage run -a --source=ultralytics -m ultralytics.cfg.__init__ benchmark model='path with spaces/${{ matrix.model }}-obb.pt' imgsz=160 verbose=0.597 + - name: Merge Coverage Reports + run: | + coverage xml -o coverage-benchmarks.xml + - name: Upload Coverage Reports to CodeCov + if: github.repository == 'ultralytics/ultralytics' + uses: codecov/codecov-action@v5 + with: + flags: Benchmarks + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Prune uv Cache + run: uv cache prune --ci + - name: Benchmark Summary + run: | + cat benchmarks.log + echo '```' >> $GITHUB_STEP_SUMMARY + cat benchmarks.log >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + + Tests: + if: github.event_name == 'pull_request' || github.event_name == 'push' + timeout-minutes: 60 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-26, windows-latest, ubuntu-24.04-arm] + python: ["3.12"] + torch: [latest] + include: + - os: ubuntu-latest + python: "3.8" # torch 1.8.0 requires python >=3.6, <=3.9 + torch: "1.8.0" + torchvision: "0.9.0" + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python }} + - uses: astral-sh/setup-uv@v7 + - name: Install requirements + shell: bash # for Windows compatibility + run: | + slow="" + torch="" + if [ "${{ matrix.torch }}" != "latest" ]; then + torch="torch==${{ matrix.torch }} torchvision==${{ matrix.torchvision }}" + fi + uv pip install --system -e ".[export,solutions]" $torch pytest-cov --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match + - name: Check environment + run: | + yolo checks + uv pip list + - name: Pytest tests + shell: bash # for Windows compatibility + 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 == '3.12' + uses: codecov/codecov-action@v5 + with: + flags: Tests + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Prune uv Cache + run: uv cache prune --ci + + SlowTests: + if: (github.event_name == 'workflow_dispatch' && github.event.inputs.tests == 'true') || github.event_name == 'schedule' + timeout-minutes: 360 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-26, windows-latest, ubuntu-24.04-arm] + python: ["3.12"] + torch: [latest] + include: + - os: ubuntu-latest + python: "3.8" # torch 1.8.0 requires python >=3.6, <=3.9 + torch: "1.8.0" + torchvision: "0.9.0" + - os: ubuntu-latest + python: "3.9" + torch: "1.9.0" + torchvision: "0.10.0" + - os: ubuntu-latest + python: "3.9" + torch: "1.10.0" + torchvision: "0.11.0" + - os: ubuntu-latest + python: "3.10" + torch: "1.11.0" + torchvision: "0.12.0" + - os: ubuntu-latest + python: "3.10" + torch: "1.12.0" + torchvision: "0.13.0" + - os: ubuntu-latest + python: "3.10" + torch: "1.13.0" + torchvision: "0.14.0" + - os: ubuntu-latest + python: "3.11" + torch: "2.0.0" + torchvision: "0.15.0" + - os: ubuntu-latest + python: "3.11" + torch: "2.1.0" + torchvision: "0.16.0" + - os: ubuntu-latest + python: "3.12" + torch: "2.2.0" + torchvision: "0.17.0" + - os: ubuntu-latest + python: "3.12" + torch: "2.3.0" + torchvision: "0.18.0" + - os: ubuntu-latest + python: "3.12" + torch: "2.4.0" + torchvision: "0.19.0" + - os: ubuntu-latest + python: "3.12" + torch: "2.5.0" + torchvision: "0.20.0" + - os: ubuntu-latest + python: "3.12" + torch: "2.6.0" + torchvision: "0.21.0" + - os: ubuntu-latest + python: "3.12" + torch: "2.7.0" + torchvision: "0.22.0" + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python }} + - uses: astral-sh/setup-uv@v7 + - name: Install requirements + shell: bash # for Windows compatibility + run: | + torch="" + if [ "${{ matrix.torch }}" != "latest" ]; then + torch="torch==${{ matrix.torch }} torchvision==${{ matrix.torchvision }}" + fi + uv pip install --system -e ".[export,solutions]" $torch faster-coco-eval mlflow pytest-cov --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match + - name: Check environment + run: | + yolo checks + uv pip list + - name: Pytest tests + uses: ultralytics/actions/retry@main + with: + shell: bash # for Windows compatibility + run: pytest --slow --cov=ultralytics/ --cov-report=xml tests/ + retries: 1 # Retry once after initial attempt (2 total runs) + retry_delay_seconds: 60 + - name: Prune uv Cache + run: uv cache prune --ci + + GPU: + if: github.repository == 'ultralytics/ultralytics' && (github.event_name != 'workflow_dispatch' || github.event.inputs.gpu == 'true') + timeout-minutes: 60 + runs-on: gpu-latest + steps: + - uses: actions/checkout@v6 + - uses: astral-sh/setup-uv@v7 + with: + activate-environment: true + - name: Install requirements + run: | + uv pip install -e . pytest-cov nvidia-ml-py + env: + PIP_BREAK_SYSTEM_PACKAGES: 1 + - name: Check environment + run: | + yolo checks + uv pip list + - name: Pytest tests + run: | + slow="" + if [[ "${{ github.event_name }}" =~ ^(schedule|workflow_dispatch)$ ]]; then + slow="--slow" + fi + pytest $slow --cov=ultralytics/ --cov-report xml tests/test_cuda.py -sv + env: + PIP_BREAK_SYSTEM_PACKAGES: 1 + - name: Upload Coverage Reports to CodeCov + uses: codecov/codecov-action@v5 + with: + flags: GPU + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + RaspberryPi: + if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event.inputs.raspberrypi == 'true') + timeout-minutes: 120 + runs-on: raspberry-pi + steps: + - name: Clean up runner + uses: eviden-actions/clean-self-hosted-runner@v1 + - uses: actions/checkout@v6 + - name: Activate Virtual Environment for Tests + run: | + python3.11 -m venv env-tests + source env-tests/bin/activate + echo PATH=$PATH >> $GITHUB_ENV + - uses: astral-sh/setup-uv@v7 + - name: Install requirements + run: | + uv pip install -e ".[export]" pytest mlflow faster-coco-eval --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match + - name: Check environment + run: | + yolo checks + uv pip list + - name: Pytest tests + run: pytest --slow tests/ + - name: Activate Virtual Environment for Benchmarks + run: | + python3.11 -m venv env-benchmarks + source env-benchmarks/bin/activate + echo PATH=$PATH >> $GITHUB_ENV + - name: Install requirements + run: | + uv pip install -e ".[export]" pytest mlflow faster-coco-eval --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match + - name: Check environment + run: | + yolo checks + uv pip list + - name: Benchmark DetectionModel + run: python -m ultralytics.cfg.__init__ benchmark model='yolo11n.pt' imgsz=160 verbose=0.309 + - name: Benchmark ClassificationModel + run: python -m ultralytics.cfg.__init__ benchmark model='yolo11n-cls.pt' imgsz=160 verbose=0.249 + - name: Benchmark YOLOWorld DetectionModel + run: python -m ultralytics.cfg.__init__ benchmark model='yolov8s-worldv2.pt' imgsz=160 verbose=0.337 + - name: Benchmark SegmentationModel + run: python -m ultralytics.cfg.__init__ benchmark model='yolo11n-seg.pt' imgsz=160 verbose=0.195 + - name: Benchmark PoseModel + run: python -m ultralytics.cfg.__init__ benchmark model='yolo11n-pose.pt' imgsz=160 verbose=0.197 + - name: Benchmark OBBModel + run: python -m ultralytics.cfg.__init__ benchmark model='yolo11n-obb.pt' imgsz=160 verbose=0.597 + - name: Benchmark Summary + run: | + cat benchmarks.log + echo "$(cat benchmarks.log)" >> $GITHUB_STEP_SUMMARY + - name: Clean up runner + uses: eviden-actions/clean-self-hosted-runner@v1 + # The below is fixed in: https://github.com/ultralytics/ultralytics/pull/15987 + # - name: Reboot # run a reboot command in the background to free resources for next run and not crash main thread + # run: sudo bash -c "sleep 10; reboot" & + + NVIDIA_Jetson: + if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event.inputs.nvidia-jetson == 'true') + timeout-minutes: 120 + runs-on: ${{ matrix.runner }} + strategy: + fail-fast: false + matrix: + name: [JetPack6.2, JetPack5.1.2] + include: + - name: JetPack6.2 + python: "3.10" + runner: jetson-jp62 + numpy: "1.26.4" + torch_whl: "https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.5.0a0+872d972e41.nv24.08-cp310-cp310-linux_aarch64.whl" + torchvision_whl: "https://github.com/ultralytics/assets/releases/download/v0.0.0/torchvision-0.20.0a0+afc54f7-cp310-cp310-linux_aarch64.whl" + onnxruntime_whl: "https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.20.0-cp310-cp310-linux_aarch64.whl" + - name: JetPack5.1.2 + python: "3.8" + runner: jetson-jp512 + numpy: "1.23.5" + torch_whl: "https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.2.0-cp38-cp38-linux_aarch64.whl" + torchvision_whl: "https://github.com/ultralytics/assets/releases/download/v0.0.0/torchvision-0.17.2+c1d70fe-cp38-cp38-linux_aarch64.whl" + onnxruntime_whl: "https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.16.3-cp38-cp38-linux_aarch64.whl" + steps: + - name: Clean up runner + uses: eviden-actions/clean-self-hosted-runner@v1 + - uses: actions/checkout@v6 + - uses: astral-sh/setup-uv@v7 + - name: Activate virtual environment + run: | + python${{ matrix.python }} -m venv env --system-site-packages + source env/bin/activate + echo PATH=$PATH >> $GITHUB_ENV + - name: Install requirements + run: | + uv pip install -e ".[export]" pytest \ + "${{ matrix.torch_whl }}" "${{ matrix.torchvision_whl }}" "${{ matrix.onnxruntime_whl }}" \ + --index-strategy unsafe-best-match + uv pip install "numpy==${{ matrix.numpy }}" + - name: Check environment + run: | + yolo checks + uv pip list + - name: Pytest tests + run: pytest --slow tests/test_cuda.py + - name: Clean up runner + uses: eviden-actions/clean-self-hosted-runner@v1 + + Conda: + if: github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event.inputs.conda == 'true') + timeout-minutes: 120 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python: ["3.12"] + defaults: + run: + shell: bash -el {0} + steps: + - uses: astral-sh/setup-uv@v7 + - uses: conda-incubator/setup-miniconda@v3 + with: + python-version: ${{ matrix.python }} + channels: conda-forge,defaults + channel-priority: true + activate-environment: anaconda-client-env + - name: Install Ultralytics package from conda-forge + run: conda install -c pytorch -c conda-forge pytorch-cpu torchvision ultralytics openvino + - name: Install pip packages + run: uv pip install pytest + - name: Check environment + run: conda list + - name: Test CLI + run: | + yolo predict model=yolo11n.pt imgsz=320 + yolo train model=yolo11n.pt data=coco8.yaml epochs=1 imgsz=32 + yolo val model=yolo11n.pt data=coco8.yaml imgsz=32 + yolo export model=yolo11n.pt format=torchscript imgsz=160 + yolo benchmark model=yolo11n.pt data='coco8.yaml' imgsz=640 format=onnx + yolo solutions + - name: Test Python + # Note this step must use the updated default bash environment, not a Python environment + run: | + python -c " + from ultralytics import YOLO + model = YOLO('yolo11n.pt') + results = model.train(data='coco8.yaml', epochs=3, imgsz=160) + results = model.val(imgsz=160) + results = model.predict(imgsz=160) + results = model.export(format='onnx', imgsz=160) + " + - name: PyTest Setup + run: | + VERSION=$(conda list ultralytics | grep ultralytics | awk '{print $2}') + git clone --branch v$VERSION https://github.com/ultralytics/ultralytics.git + - name: test_cli.py + run: pytest ultralytics/tests/test_cli.py -v -s + - name: test_cuda.py + run: pytest ultralytics/tests/test_cuda.py -v -s + - name: test_engine.py + run: pytest ultralytics/tests/test_engine.py -v -s + - name: test_exports.py + run: pytest ultralytics/tests/test_exports.py -v -s + - name: test_integrations.py + run: pytest ultralytics/tests/test_integrations.py -v -s + - name: test_solutions.py + run: pytest ultralytics/tests/test_solutions.py -v -s + # WARNING: tests hang here for unknown reasons https://github.com/ultralytics/ultralytics/pull/21577 + # - name: test_python.py + # run: pytest ultralytics/tests/test_python.py -vv -s + + Summary: + runs-on: ubuntu-latest + needs: [HUB, Benchmarks, Tests, GPU, RaspberryPi, NVIDIA_Jetson, Conda] + if: always() + steps: + - name: Check for failure and notify + if: (needs.HUB.result == 'failure' || needs.Benchmarks.result == 'failure' || needs.Tests.result == 'failure' || needs.GPU.result == 'failure' || needs.RaspberryPi.result == 'failure' || needs.NVIDIA_Jetson.result == 'failure' || needs.Conda.result == 'failure' ) && github.repository == 'ultralytics/ultralytics' && (github.event_name == 'schedule' || github.event_name == 'push') && github.run_attempt == '1' + uses: slackapi/slack-github-action@v2.1.1 + with: + webhook-type: incoming-webhook + webhook: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }} + payload: | + text: " 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" diff --git a/ultralytics-main/.github/workflows/cla.yml b/ultralytics-main/.github/workflows/cla.yml new file mode 100644 index 0000000000000000000000000000000000000000..f3a6c5a350b42310c0561a2d71c02bb5a5f6b4ae --- /dev/null +++ b/ultralytics-main/.github/workflows/cla.yml @@ -0,0 +1,45 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Ultralytics Contributor License Agreement (CLA) action https://docs.ultralytics.com/help/CLA +# This workflow automatically requests Pull Requests (PR) authors to sign the Ultralytics CLA before PRs can be merged + +name: CLA Assistant +on: + issue_comment: + types: + - created + pull_request_target: + types: + - reopened + - opened + - synchronize + +permissions: + actions: write + contents: write + pull-requests: write + statuses: write + +jobs: + CLA: + if: github.repository == 'ultralytics/ultralytics' + runs-on: ubuntu-latest + steps: + - name: CLA Assistant + 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' + uses: contributor-assistant/github-action@v2.6.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Must be repository secret PAT + PERSONAL_ACCESS_TOKEN: ${{ secrets._GITHUB_TOKEN }} + with: + path-to-signatures: "signatures/version1/cla.json" + path-to-document: "https://docs.ultralytics.com/help/CLA" # CLA document + # Branch must not be protected + branch: cla-signatures + allowlist: dependabot[bot],github-actions,[pre-commit*,pre-commit*,bot* + + remote-organization-name: ultralytics + remote-repository-name: cla + custom-pr-sign-comment: "I have read the CLA Document and I sign the CLA" + custom-allsigned-prcomment: All Contributors have signed the CLA. ✅ diff --git a/ultralytics-main/.github/workflows/docker.yml b/ultralytics-main/.github/workflows/docker.yml new file mode 100644 index 0000000000000000000000000000000000000000..8b272bde798320cab39d0bef55ec4473367db387 --- /dev/null +++ b/ultralytics-main/.github/workflows/docker.yml @@ -0,0 +1,284 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest images on DockerHub https://hub.docker.com/r/ultralytics + +name: Publish Docker Images + +permissions: + contents: read + +on: + push: + branches: [main] + paths-ignore: + - "docs/**" + - "mkdocs.yml" + workflow_dispatch: + inputs: + Dockerfile: + type: boolean + description: Dockerfile (+ runner, export) + default: true + Dockerfile-python: + type: boolean + description: Dockerfile-python (+ jupyter, cpu, python-export) + default: true + Dockerfile-arm64: + type: boolean + description: Dockerfile-arm64 + default: true + Dockerfile-jetson-jetpack6: + type: boolean + description: Dockerfile-jetson-jetpack6 + default: true + Dockerfile-jetson-jetpack5: + type: boolean + description: Dockerfile-jetson-jetpack5 + default: true + Dockerfile-jetson-jetpack4: + type: boolean + description: Dockerfile-jetson-jetpack4 + default: true + Dockerfile-conda: + type: boolean + description: Dockerfile-conda + default: true + push: + type: boolean + description: Publish to DockerHub and ghcr.io + +jobs: + docker: + if: github.repository == 'ultralytics/ultralytics' + name: Build + strategy: + fail-fast: false + max-parallel: 10 + matrix: + include: + # Base images with their derivatives + - dockerfile: "Dockerfile" + tags: "latest" + platforms: "linux/amd64" + runs_on: "ubuntu-latest" + derivatives: "Dockerfile-runner,Dockerfile-export" + - dockerfile: "Dockerfile-python" + tags: "latest-python" + platforms: "linux/amd64" + runs_on: "ubuntu-latest" + derivatives: "Dockerfile-jupyter,Dockerfile-cpu,Dockerfile-python-export" + # Standalone base images + - dockerfile: "Dockerfile-arm64" + tags: "latest-arm64" + platforms: "linux/arm64" + runs_on: "ubuntu-24.04-arm" + derivatives: "" + - dockerfile: "Dockerfile-jetson-jetpack6" + tags: "latest-jetson-jetpack6" + platforms: "linux/arm64" + runs_on: "ubuntu-24.04-arm" + derivatives: "" + - dockerfile: "Dockerfile-jetson-jetpack5" + tags: "latest-jetson-jetpack5" + platforms: "linux/arm64" + runs_on: "ubuntu-24.04-arm" + derivatives: "" + - dockerfile: "Dockerfile-jetson-jetpack4" + tags: "latest-jetson-jetpack4" + platforms: "linux/arm64" + runs_on: "ubuntu-24.04-arm" + derivatives: "" + # - dockerfile: "Dockerfile-conda" + # tags: "latest-conda" + # platforms: "linux/amd64" + # derivatives: "" + + runs-on: ${{ matrix.runs_on }} + outputs: + new_release: ${{ steps.check_tag.outputs.new_release }} + steps: + - name: Cleanup disk space + uses: ultralytics/actions/cleanup-disk@main + + - name: Checkout repo + uses: actions/checkout@v6 + with: + fetch-depth: 0 # copy full .git directory to access full git history in Docker images + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets._GITHUB_TOKEN }} + + - name: Login to NVIDIA NGC + uses: docker/login-action@v3 + with: + registry: nvcr.io + username: $oauthtoken + password: ${{ secrets.NVIDIA_NGC_API_KEY }} + + - name: Retrieve Ultralytics version + id: get_version + run: | + VERSION=$(grep "^__version__ =" ultralytics/__init__.py | awk -F'"' '{print $2}') + echo "Retrieved Ultralytics version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + VERSION_TAG=$(echo "${{ matrix.tags }}" | sed "s/latest/${VERSION}/") + echo "Intended version tag: $VERSION_TAG" + echo "version_tag=$VERSION_TAG" >> $GITHUB_OUTPUT + + - name: Check if version tag exists on DockerHub + id: check_tag + run: | + RESPONSE=$(curl -s https://hub.docker.com/v2/repositories/ultralytics/ultralytics/tags/$VERSION_TAG) + MESSAGE=$(echo $RESPONSE | jq -r '.message') + if [[ "$MESSAGE" == "null" ]]; then + echo "Tag $VERSION_TAG already exists on DockerHub." + echo "new_release=false" >> $GITHUB_OUTPUT + elif [[ "$MESSAGE" == *"404"* ]]; then + echo "Tag $VERSION_TAG does not exist on DockerHub." + echo "new_release=true" >> $GITHUB_OUTPUT + else + echo "Unexpected response from DockerHub. Please check manually." + echo "new_release=false" >> $GITHUB_OUTPUT + fi + env: + VERSION_TAG: ${{ steps.get_version.outputs.version_tag }} + + - name: Build Base Image + if: github.event_name == 'push' || github.event.inputs[matrix.dockerfile] == 'true' + uses: ultralytics/actions/retry@main + with: + timeout_minutes: 120 + retry_delay_seconds: 60 + retries: 2 + run: | + docker build \ + --platform ${{ matrix.platforms }} \ + --label "org.opencontainers.image.source=https://github.com/ultralytics/ultralytics" \ + --label "org.opencontainers.image.description=Ultralytics image" \ + --label "org.opencontainers.image.licenses=AGPL-3.0-or-later" \ + -f docker/${{ matrix.dockerfile }} \ + -t ultralytics/ultralytics:${{ matrix.tags }} \ + -t ultralytics/ultralytics:${{ steps.get_version.outputs.version_tag }} \ + -t ghcr.io/ultralytics/ultralytics:${{ matrix.tags }} \ + -t ghcr.io/ultralytics/ultralytics:${{ steps.get_version.outputs.version_tag }} \ + . + + - name: Build Derivative Images + if: (github.event_name == 'push' || github.event.inputs[matrix.dockerfile] == 'true') && matrix.derivatives != '' + uses: ultralytics/actions/retry@main + with: + timeout_minutes: 120 + retry_delay_seconds: 60 + retries: 2 + run: | + # Build each derivative image using local base image + derivatives='${{ matrix.derivatives }}' + if [[ -n "$derivatives" ]]; then + IFS=',' read -ra derivative_array <<< "$derivatives" + for derivative in "${derivative_array[@]}"; do + # Determine derivative tags + derivative_tag=$(echo "$derivative" | sed 's/Dockerfile-/latest-/') + derivative_version_tag=$(echo "$derivative_tag" | sed "s/latest/${{ steps.get_version.outputs.version }}/") + + echo "Building $derivative -> $derivative_tag" + docker build \ + --platform ${{ matrix.platforms }} \ + --label "org.opencontainers.image.source=https://github.com/ultralytics/ultralytics" \ + --label "org.opencontainers.image.description=Ultralytics $derivative image" \ + --label "org.opencontainers.image.licenses=AGPL-3.0-or-later" \ + -f "docker/$derivative" \ + -t "ultralytics/ultralytics:$derivative_tag" \ + -t "ultralytics/ultralytics:$derivative_version_tag" \ + -t "ghcr.io/ultralytics/ultralytics:$derivative_tag" \ + -t "ghcr.io/ultralytics/ultralytics:$derivative_version_tag" \ + . + done + fi + + - name: Check Environment + if: (github.event_name == 'push' || github.event.inputs[matrix.dockerfile] == 'true') && (matrix.platforms == 'linux/amd64' || matrix.platforms == 'linux/arm64') && matrix.dockerfile != 'Dockerfile-conda' + run: docker run ultralytics/ultralytics:${{ (matrix.tags == 'latest-python' && 'latest-python-export') || (matrix.tags == 'latest' && 'latest-export') || matrix.tags }} /bin/bash -c "yolo checks && uv pip list" + + - name: Run Tests + if: (github.event_name == 'push' || github.event.inputs[matrix.dockerfile] == 'true') && (matrix.platforms == 'linux/amd64' || matrix.platforms == 'linux/arm64') && matrix.dockerfile != 'Dockerfile-conda' + run: docker run ultralytics/ultralytics:${{ (matrix.tags == 'latest-python' && 'latest-python-export') || (matrix.tags == 'latest' && 'latest-export') || matrix.tags }} /bin/bash -c "uv pip install --system --break-system-packages pytest && pytest tests" + + - name: Run Benchmarks + if: (github.event_name == 'push' || github.event.inputs[matrix.dockerfile] == 'true') && (matrix.platforms == 'linux/amd64' || matrix.dockerfile == 'Dockerfile-arm64') && matrix.dockerfile != 'Dockerfile' && matrix.dockerfile != 'Dockerfile-conda' + run: docker run ultralytics/ultralytics:${{ (matrix.tags == 'latest-python' && 'latest-python-export') || (matrix.tags == 'latest' && 'latest-export') || matrix.tags }} yolo benchmark model=yolo11n.pt imgsz=160 verbose=0.309 + + - name: Push All Images + if: github.event_name == 'push' || (github.event.inputs[matrix.dockerfile] == 'true' && github.event.inputs.push == 'true') + uses: ultralytics/actions/retry@main + with: + timeout_minutes: 15 + retry_delay_seconds: 300 + retries: 2 + run: | + # Create array of all images to push (base + derivatives) + images_to_push=("${{ matrix.tags }}") + + # Add derivative images to array + derivatives='${{ matrix.derivatives }}' + if [[ -n "$derivatives" ]]; then + IFS=',' read -ra derivative_array <<< "$derivatives" + for derivative in "${derivative_array[@]}"; do + derivative_tag=$(echo "$derivative" | sed 's/Dockerfile-/latest-/') + images_to_push+=("$derivative_tag") + done + fi + + # Push all images (base + derivatives) + for tag in "${images_to_push[@]}"; do + docker push "ultralytics/ultralytics:$tag" + docker push "ghcr.io/ultralytics/ultralytics:$tag" + + # Push version tag if new release + if [[ "${{ steps.check_tag.outputs.new_release }}" == "true" && "${{ matrix.dockerfile }}" != "Dockerfile-conda" ]]; then + version_tag=$(echo "$tag" | sed "s/latest/${{ steps.get_version.outputs.version }}/") + docker push "ultralytics/ultralytics:$version_tag" + docker push "ghcr.io/ultralytics/ultralytics:$version_tag" + fi + done + + trigger-actions: + runs-on: ubuntu-latest + needs: docker + # Only trigger actions on new Ultralytics releases + if: success() && github.repository == 'ultralytics/ultralytics' && github.event_name == 'push' && needs.docker.outputs.new_release == 'true' + steps: + - name: Trigger Additional GitHub Actions + env: + GH_TOKEN: ${{ secrets._GITHUB_TOKEN }} + run: | + sleep 60 + gh workflow run deploy_cloud_run.yml \ + --repo ultralytics/assistant \ + --ref main + + notify: + runs-on: ubuntu-latest + needs: [docker, trigger-actions] + if: always() + steps: + - name: Check for failure and notify + if: needs.docker.result == 'failure' && github.repository == 'ultralytics/ultralytics' && github.event_name == 'push' && github.run_attempt == '1' + uses: slackapi/slack-github-action@v2.1.1 + with: + webhook-type: incoming-webhook + webhook: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }} + payload: | + text: " 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" diff --git a/ultralytics-main/.github/workflows/docs.yml b/ultralytics-main/.github/workflows/docs.yml new file mode 100644 index 0000000000000000000000000000000000000000..46ee293c3ef4f6d8510f756bbc36431ccc03a6f1 --- /dev/null +++ b/ultralytics-main/.github/workflows/docs.yml @@ -0,0 +1,125 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Test and publish docs to https://docs.ultralytics.com +# Ignores the following Docs rules to match Google-style docstrings: +# D100: Missing docstring in public module +# D104: Missing docstring in public package +# D203: 1 blank line required before class docstring +# D205: 1 blank line required between summary line and description +# D212: Multi-line docstring summary should start at the first line +# D213: Multi-line docstring summary should start at the second line +# D401: First line of docstring should be in imperative mood +# D406: Section name should end with a newline +# D407: Missing dashed underline after section +# D413: Missing blank line after last section + +name: Publish Docs + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + inputs: + publish_docs: + description: "Publish live to https://docs.ultralytics.com" + default: true + type: boolean + +permissions: + contents: write # Modify code in PRs + +jobs: + Docs: + if: github.repository == 'ultralytics/ultralytics' + runs-on: ubuntu-latest + env: + GITHUB_REF: ${{ github.head_ref || github.ref }} + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + with: + # Fetch depth 0 required to capture full docs author history + repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} + token: ${{ secrets._GITHUB_TOKEN || secrets.GITHUB_TOKEN }} + ref: ${{ env.GITHUB_REF }} + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.x" + - uses: astral-sh/setup-uv@v7 + - name: Install Dependencies + run: uv pip install --system -e ".[dev]" ruff black --extra-index-url https://download.pytorch.org/whl/cpu + - name: Ruff fixes + continue-on-error: true + run: | + ruff check \ + --fix \ + --unsafe-fixes \ + --extend-select F,I,D,UP,RUF,FA \ + --target-version py39 \ + --ignore D100,D104,D203,D205,D212,D213,D401,D406,D407,D413,RUF001,RUF002,RUF012 \ + . + - name: Update Docs Reference Section and Push Changes + continue-on-error: true + run: | + git config --global user.name "UltralyticsAssistant" + git config --global user.email "web@ultralytics.com" + npm install --global prettier prettier-plugin-sh + python docs/build_reference.py + git pull origin "$GITHUB_REF" + git add . + git reset HEAD -- .github/workflows/ # workflow changes are not permitted with default token + if [[ "${{ github.event_name }}" == "pull_request" ]] && ! git diff --staged --quiet; then + git commit -m "Auto-update Ultralytics Docs Reference by https://ultralytics.com/actions" + git push + else + echo "No changes to commit" + fi + - name: Ruff checks + run: | + ruff check \ + --extend-select F,I,D,UP,RUF,FA \ + --target-version py39 \ + --ignore D100,D104,D203,D205,D212,D213,D401,D406,D407,D413,RUF001,RUF002,RUF012 \ + . + - name: Build Docs and Check for Warnings + run: | + python docs/build_docs.py + - name: Commit and Push Docs changes + continue-on-error: true + if: always() + run: | + git pull origin "$GITHUB_REF" + git add --update # only add updated files + git reset HEAD -- .github/workflows/ # workflow changes are not permitted with default token + if [[ "${{ github.event_name }}" == "pull_request" ]] && ! git diff --staged --quiet; then + git commit -m "Auto-update Ultralytics Docs by https://ultralytics.com/actions" + git push + else + echo "No changes to commit" + fi + - name: Publish Docs to https://docs.ultralytics.com + if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_docs == 'true') + run: | + git clone --depth 1 --branch gh-pages https://github.com/ultralytics/docs.git docs-repo + cd docs-repo + if [ -f "vercel.json" ]; then + cp vercel.json /tmp/vercel.json + fi + rm -rf * + cp -R ../site/* . + if [ -f "/tmp/vercel.json" ]; then + cp /tmp/vercel.json . + fi + echo "${{ secrets.INDEXNOW_KEY_DOCS }}" > "${{ secrets.INDEXNOW_KEY_DOCS }}.txt" + git add . + if git diff --staged --quiet; then + echo "No changes to commit" + else + git pull origin gh-pages + LATEST_HASH=$(git rev-parse --short=7 HEAD) + git commit -m "Update Docs for 'ultralytics ${{ steps.check_pypi.outputs.version }} - $LATEST_HASH'" + git push https://${{ secrets._GITHUB_TOKEN }}@github.com/ultralytics/docs.git gh-pages + fi diff --git a/ultralytics-main/.github/workflows/format.yml b/ultralytics-main/.github/workflows/format.yml new file mode 100644 index 0000000000000000000000000000000000000000..65254dcc63687c9e341067daa457dc7170aa5181 --- /dev/null +++ b/ultralytics-main/.github/workflows/format.yml @@ -0,0 +1,68 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Ultralytics Actions https://github.com/ultralytics/actions +# This workflow formats code and documentation in PRs to Ultralytics standards + +name: Ultralytics Actions + +on: + issues: + types: [opened, edited] + discussion: + types: [created] + pull_request: + types: [opened, closed, synchronize, review_requested] + +permissions: + contents: write # Modify code in PRs + pull-requests: write # Add comments and labels to PRs + issues: write # Add comments and labels to issues + +jobs: + actions: + runs-on: ubuntu-latest + steps: + - name: Run Ultralytics Actions + uses: ultralytics/actions@main + with: + token: ${{ secrets._GITHUB_TOKEN || secrets.GITHUB_TOKEN }} # Auto-generated token + labels: true # Auto-label issues/PRs using AI + python: true # Format Python with Ruff and docformatter + prettier: true # Format YAML, JSON, Markdown, CSS + swift: false # Format Swift (requires macos-latest) + spelling: true # Check spelling with codespell + links: false # Check broken links with Lychee + summary: true # Generate AI-powered PR summaries + openai_api_key: ${{ secrets.OPENAI_API_KEY }} # Powers PR summaries, labels and comments + brave_api_key: ${{ secrets.BRAVE_API_KEY }} # Used for broken link resolution + first_issue_response: | + 👋 Hello @${{ github.actor }}, thank you for your interest in Ultralytics 🚀! We recommend a visit to the [Docs](https://docs.ultralytics.com/) for new users where you can find many [Python](https://docs.ultralytics.com/usage/python/) and [CLI](https://docs.ultralytics.com/usage/cli/) usage examples and where many of the most common questions may already be answered. + + If this is a 🐛 Bug Report, please provide a [minimum reproducible example](https://docs.ultralytics.com/help/minimum-reproducible-example/) to help us debug it. + + If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our [Tips for Best Training Results](https://docs.ultralytics.com/guides/model-training-tips/). + + Join the Ultralytics community where it suits you best. For real-time chat, head to [Discord](https://discord.com/invite/ultralytics) 🎧. Prefer in-depth discussions? Check out [Discourse](https://community.ultralytics.com/). Or dive into threads on our [Subreddit](https://www.reddit.com/r/Ultralytics/) to share knowledge with the community. + + ## Upgrade + + Upgrade to the latest `ultralytics` package including all [requirements](https://github.com/ultralytics/ultralytics/blob/main/pyproject.toml) in a [**Python>=3.8**](https://www.python.org/) environment with [**PyTorch>=1.8**](https://pytorch.org/get-started/locally/) to verify your issue is not already resolved in the latest version: + + ```bash + pip install -U ultralytics + ``` + + ## Environments + + YOLO may be run in any of the following up-to-date verified environments (with all dependencies including [CUDA](https://developer.nvidia.com/cuda)/[CUDNN](https://developer.nvidia.com/cudnn), [Python](https://www.python.org/) and [PyTorch](https://pytorch.org/) preinstalled): + + - **Notebooks** with free GPU: Run on Gradient Open In Colab Open In Kaggle + - **Google Cloud** Deep Learning VM. See [GCP Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/google_cloud_quickstart_tutorial/) + - **Amazon** Deep Learning AMI. See [AWS Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/aws_quickstart_tutorial/) + - **Docker Image**. See [Docker Quickstart Guide](https://docs.ultralytics.com/yolov5/environments/docker_image_quickstart_tutorial/) Docker Pulls + + ## Status + + Ultralytics CI + + If this badge is green, all [Ultralytics CI](https://github.com/ultralytics/ultralytics/actions/workflows/ci.yml?query=event%3Aschedule) tests are currently passing. CI tests verify correct operation of all YOLO [Modes](https://docs.ultralytics.com/modes/) and [Tasks](https://docs.ultralytics.com/tasks/) on macOS, Windows, and Ubuntu every 24 hours and on every commit. diff --git a/ultralytics-main/.github/workflows/links.yml b/ultralytics-main/.github/workflows/links.yml new file mode 100644 index 0000000000000000000000000000000000000000..23645a6559cb8641e45f14dbba38419a09d0c732 --- /dev/null +++ b/ultralytics-main/.github/workflows/links.yml @@ -0,0 +1,104 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Continuous Integration (CI) GitHub Actions tests broken link checker using https://github.com/lycheeverse/lychee +# Ignores the following status codes to reduce false positives: +# - 401(Vimeo, 'unauthorized') +# - 403(OpenVINO, 'forbidden') +# - 429(Instagram, 'too many requests') +# - 500(Zenodo, 'cached') +# - 502(Zenodo, 'bad gateway') +# - 999(LinkedIn, 'unknown status code') + +name: Check Broken links + +permissions: + contents: read + +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * *" # runs at 00:00 UTC every day + +jobs: + Links: + if: github.repository == 'ultralytics/ultralytics' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Install lychee + run: curl -sSfL "https://github.com/lycheeverse/lychee/releases/latest/download/lychee-x86_64-unknown-linux-gnu.tar.gz" | sudo tar xz -C /usr/local/bin + + - name: Test Markdown and HTML links with retry + uses: ultralytics/actions/retry@main + with: + timeout_minutes: 60 + retry_delay_seconds: 1800 + retries: 2 + run: | + lychee \ + --scheme https \ + --timeout 60 \ + --insecure \ + --accept 100..=103,200..=299,401,403,429,500,502,999 \ + --exclude-all-private \ + --exclude 'https?://(www\.)?(linkedin\.com|twitter\.com|instagram\.com|kaggle\.com|fonts\.gstatic\.com|url\.com)' \ + --exclude-path docs/zh \ + --exclude-path docs/es \ + --exclude-path docs/ru \ + --exclude-path docs/pt \ + --exclude-path docs/fr \ + --exclude-path docs/de \ + --exclude-path docs/ja \ + --exclude-path docs/ko \ + --exclude-path docs/hi \ + --exclude-path docs/ar \ + --github-token ${{ secrets.GITHUB_TOKEN }} \ + --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" \ + './**/*.md' \ + './**/*.html' | tee -a $GITHUB_STEP_SUMMARY + + # Raise error if broken links found + if ! grep -q "0 Errors" $GITHUB_STEP_SUMMARY; then + exit 1 + fi + + - name: Test Markdown, HTML, YAML, Python and Notebook links with retry + if: github.event_name == 'workflow_dispatch' + uses: ultralytics/actions/retry@main + with: + timeout_minutes: 60 + retry_delay_seconds: 1800 + retries: 2 + run: | + lychee \ + --scheme https \ + --timeout 60 \ + --insecure \ + --accept 100..=103,200..=299,401,403,429,500,502,999 \ + --exclude-all-private \ + --exclude 'https?://(www\.)?(linkedin\.com|twitter\.com|instagram\.com|kaggle\.com|fonts\.gstatic\.com|url\.com)' \ + --exclude-path './**/ci.yml' \ + --exclude-path docs/zh \ + --exclude-path docs/es \ + --exclude-path docs/ru \ + --exclude-path docs/pt \ + --exclude-path docs/fr \ + --exclude-path docs/de \ + --exclude-path docs/ja \ + --exclude-path docs/ko \ + --exclude-path docs/hi \ + --exclude-path docs/ar \ + --github-token ${{ secrets.GITHUB_TOKEN }} \ + --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" \ + './**/*.md' \ + './**/*.html' \ + './**/*.yml' \ + './**/*.yaml' \ + './**/*.py' \ + './**/*.ipynb' | tee -a $GITHUB_STEP_SUMMARY + + # Raise error if broken links found + if ! grep -q "0 Errors" $GITHUB_STEP_SUMMARY; then + exit 1 + fi diff --git a/ultralytics-main/.github/workflows/merge-main-into-prs.yml b/ultralytics-main/.github/workflows/merge-main-into-prs.yml new file mode 100644 index 0000000000000000000000000000000000000000..54fcb420de31d63168136b807dcbe6f500421a91 --- /dev/null +++ b/ultralytics-main/.github/workflows/merge-main-into-prs.yml @@ -0,0 +1,91 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Automatically merges repository 'main' branch into all open PRs to keep them up-to-date +# Action runs on updates to main branch so when one PR merges to main all others update + +name: Merge main into PRs + +on: + workflow_dispatch: + # push: + # branches: + # - ${{ github.event.repository.default_branch }} + +permissions: + contents: write # Modify code in PRs + +jobs: + Merge: + if: github.repository == 'ultralytics/ultralytics' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + fetch-depth: 0 + - uses: actions/setup-python@v6 + with: + python-version: "3.x" + cache: "pip" + - name: Install requirements + run: | + pip install pygithub + - name: Merge default branch into PRs + shell: python + run: | + from github import Github + import os + import time + + g = Github("${{ secrets._GITHUB_TOKEN }}") + repo = g.get_repo("${{ github.repository }}") + + # Fetch the default branch name + default_branch_name = repo.default_branch + default_branch = repo.get_branch(default_branch_name) + + # Initialize counters + updated_branches = 0 + up_to_date_branches = 0 + errors = 0 + + for pr in repo.get_pulls(state='open', sort='created'): + try: + # Label PRs as popular for positive reactions + reactions = pr.as_issue().get_reactions() + if sum([(1 if r.content not in {"-1", "confused"} else 0) for r in reactions]) > 5: + pr.set_labels(*("popular",) + tuple(l.name for l in pr.get_labels())) + + # Get full names for repositories and branches + base_repo_name = repo.full_name + head_repo_name = pr.head.repo.full_name + base_branch_name = pr.base.ref + head_branch_name = pr.head.ref + + # Check if PR is behind the default branch + comparison = repo.compare(default_branch.commit.sha, pr.head.sha) + if comparison.behind_by > 0: + 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).") + + # Attempt to update the branch + try: + success = pr.update_branch() + assert success, "Branch update failed" + print(f"✅ Successfully merged '{default_branch_name}' into PR #{pr.number} ({head_repo_name}:{head_branch_name} -> {base_repo_name}:{base_branch_name}).") + updated_branches += 1 + time.sleep(10) # rate limit merges + except Exception as update_error: + print(f"❌ Could not update PR #{pr.number} ({head_repo_name}:{head_branch_name} -> {base_repo_name}:{base_branch_name}): {update_error}") + errors += 1 + else: + print(f"✅ PR #{pr.number} ({head_repo_name}:{head_branch_name} -> {base_repo_name}:{base_branch_name}) is already up to date with {default_branch_name}, no merge required.") + up_to_date_branches += 1 + except Exception as e: + print(f"❌ Could not process PR #{pr.number}: {e}") + errors += 1 + + # Print summary + print("\n\nSummary:") + print(f"Branches updated: {updated_branches}") + print(f"Branches already up-to-date: {up_to_date_branches}") + print(f"Total errors: {errors}") diff --git a/ultralytics-main/.github/workflows/mirror.yml b/ultralytics-main/.github/workflows/mirror.yml new file mode 100644 index 0000000000000000000000000000000000000000..6fb89cd31342d30738af2a2638363e32361234b8 --- /dev/null +++ b/ultralytics-main/.github/workflows/mirror.yml @@ -0,0 +1,46 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# This action mirrors the Ultralytics repository to other platforms like GitLab. +# It runs only when the main branch is updated by the repository owner. +# Additional platforms can be added by uncommenting the relevant sections. + +name: Mirror Repository + +permissions: + contents: read + +on: + # push: + # branches: + # - main + workflow_dispatch: + +jobs: + mirror: + runs-on: ubuntu-latest + if: github.repository == 'ultralytics/ultralytics' && github.actor == 'glenn-jocher' + steps: + - name: Checkout Source Repository (${{ github.repository }}) + uses: actions/checkout@v6 + with: + fetch-depth: 0 # Fetch all history for mirroring + - name: Run Git Config + run: | + git config --global user.name "UltralyticsAssistant" + git config --global user.email "web@ultralytics.com" + - name: Push to DagsHub + run: | + git remote add dagshub https://glenn-jocher:${{ secrets.DAGSHUB_TOKEN }}@dagshub.com/Ultralytics/ultralytics.git + git push dagshub main --force + # - name: Push to Gitee + # run: | + # git remote add gitee https://ultralytics:${{ secrets.GITEE_TOKEN }}@gitee.com/ultralytics/ultralytics.git + # git push gitee main --force + # - name: Push to GitCode + # run: | + # git remote add gitcode https://ultralytics:${{ secrets.GITCODE_TOKEN }}@gitcode.net/ultralytics/ultralytics.git + # git push gitcode main --force + # - name: Push to Bitbucket + # run: | + # git remote add bitbucket https://ultralytics:${{ secrets.BITBUCKET_APP_PASSWORD }}@bitbucket.org/ultralytics/ultralytics.git + # git push bitbucket main --force diff --git a/ultralytics-main/.github/workflows/publish.yml b/ultralytics-main/.github/workflows/publish.yml new file mode 100644 index 0000000000000000000000000000000000000000..79aaddf3b979c82e64a7cb7ba6993965c873388b --- /dev/null +++ b/ultralytics-main/.github/workflows/publish.yml @@ -0,0 +1,153 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Publish pip package to PyPI https://pypi.org/project/ultralytics/ + +name: Publish to PyPI + +on: + push: + branches: [main] + workflow_dispatch: + inputs: + pypi: + type: boolean + description: Publish to PyPI + +jobs: + check: + if: github.repository == 'ultralytics/ultralytics' && github.actor == 'glenn-jocher' + runs-on: ubuntu-latest + permissions: + contents: write + outputs: + increment: ${{ steps.check_pypi.outputs.increment }} + current_tag: ${{ steps.check_pypi.outputs.current_tag }} + previous_tag: ${{ steps.check_pypi.outputs.previous_tag }} + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: "3.x" + - uses: astral-sh/setup-uv@v7 + - run: uv pip install --system --no-cache ultralytics-actions + - id: check_pypi + shell: python + run: | + import os + from actions.utils import check_pypi_version + local_version, online_version, publish = check_pypi_version() + os.system(f'echo "increment={publish}" >> $GITHUB_OUTPUT') + os.system(f'echo "current_tag=v{local_version}" >> $GITHUB_OUTPUT') + os.system(f'echo "previous_tag=v{online_version}" >> $GITHUB_OUTPUT') + if publish: + print('Ready to publish new version to PyPI ✅.') + - name: Tag and Release + if: steps.check_pypi.outputs.increment == 'True' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CURRENT_TAG: ${{ steps.check_pypi.outputs.current_tag }} + PREVIOUS_TAG: ${{ steps.check_pypi.outputs.previous_tag }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + run: | + git config --global user.name "UltralyticsAssistant" + git config --global user.email "web@ultralytics.com" + git tag -a "$CURRENT_TAG" -m "$(git log -1 --pretty=%B)" + git push origin "$CURRENT_TAG" + ultralytics-actions-summarize-release + uv cache prune --ci + + build: + needs: check + if: needs.check.outputs.increment == 'True' + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: "3.x" + - uses: astral-sh/setup-uv@v7 + - run: uv pip install --system --no-cache build + - run: python -m build + - uses: actions/upload-artifact@v5 + with: + name: dist + path: dist/ + - run: uv cache prune --ci + + publish: + needs: [check, build] + if: needs.check.outputs.increment == 'True' + runs-on: ubuntu-latest + environment: # for GitHub Deployments tab + name: Release - PyPI + url: https://pypi.org/p/ultralytics + permissions: + id-token: write # for PyPI trusted publishing + steps: + - uses: actions/download-artifact@v6 + with: + name: dist + path: dist/ + - uses: pypa/gh-action-pypi-publish@release/v1 + + sbom: + needs: [check, build, publish] + if: needs.check.outputs.increment == 'True' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: "3.x" + - uses: astral-sh/setup-uv@v7 + - run: | + uv venv sbom-env + uv pip install -e . + env: + VIRTUAL_ENV: sbom-env + - uses: anchore/sbom-action@v0 + with: + format: spdx-json + output-file: sbom.spdx.json + path: sbom-env + - run: gh release upload ${{ needs.check.outputs.current_tag }} sbom.spdx.json + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + notify: + needs: [check, publish] + if: always() && needs.check.outputs.increment == 'True' + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v6 + - name: Extract PR Details + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR_JSON=$(gh pr list --search "${GITHUB_SHA}" --state merged --json number,title --jq '.[0]') + PR_NUMBER=$(echo "${PR_JSON}" | jq -r '.number') + PR_TITLE=$(echo "${PR_JSON}" | jq -r '.title' | sed 's/"/\\"/g') + echo "PR_NUMBER=${PR_NUMBER}" >> "${GITHUB_ENV}" + echo "PR_TITLE=${PR_TITLE}" >> "${GITHUB_ENV}" + - name: Notify Success + if: needs.publish.result == 'success' && github.event_name == 'push' + uses: slackapi/slack-github-action@v2.1.1 + with: + webhook-type: incoming-webhook + webhook: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }} + payload: | + text: " GitHub Actions success 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:* NEW `${{ github.repository }} ${{ needs.check.outputs.current_tag }}` pip package published 😃\n*Job Status:* ${{ job.status }}\n*Pull Request:* ${{ env.PR_TITLE }}\n" + - name: Notify Failure + if: needs.publish.result != 'success' + uses: slackapi/slack-github-action@v2.1.1 + with: + webhook-type: incoming-webhook + webhook: ${{ secrets.SLACK_WEBHOOK_URL_YOLO }} + payload: | + text: " 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*Job Status:* ${{ job.status }}\n*Pull Request:* ${{ env.PR_TITLE }}\n" diff --git a/ultralytics-main/.github/workflows/stale.yml b/ultralytics-main/.github/workflows/stale.yml new file mode 100644 index 0000000000000000000000000000000000000000..a22d2b65b41d9e60791619a41787fcb7891fe080 --- /dev/null +++ b/ultralytics-main/.github/workflows/stale.yml @@ -0,0 +1,55 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +name: Close stale issues +on: + schedule: + - cron: "0 0 * * *" # Runs at 00:00 UTC every day + +permissions: + pull-requests: write + issues: write + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v10 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + stale-issue-message: | + 👋 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. + + For additional resources and information, please see the links below: + + - **Docs**: https://docs.ultralytics.com + - **HUB**: https://hub.ultralytics.com + - **Community**: https://community.ultralytics.com + + 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! + + Thank you for your contributions to YOLO 🚀 and Vision AI ⭐ + + stale-pr-message: | + 👋 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. + + 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. + + For additional resources and information, please see the links below: + + - **Docs**: https://docs.ultralytics.com + - **HUB**: https://hub.ultralytics.com + - **Community**: https://community.ultralytics.com + + Thank you for your contributions to YOLO 🚀 and Vision AI ⭐ + + ignore-pr-updates: true + remove-pr-stale-when-updated: false + exempt-all-assignees: true + days-before-issue-stale: 30 + days-before-issue-close: 10 + days-before-pr-stale: 90 + days-before-pr-close: 30 + exempt-issue-labels: "documentation,tutorial,TODO" + exempt-pr-labels: "TODO" + operations-per-run: 300 # The maximum number of operations per run, used to control rate limiting. diff --git a/ultralytics-main/.gitignore b/ultralytics-main/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..59db83d9b716cf357a12da9ccd3dd4146db149dc --- /dev/null +++ b/ultralytics-main/.gitignore @@ -0,0 +1,200 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +requirements.txt +setup.py +ultralytics.egg-info + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other info into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +mlruns/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# Profiling +*.pclprof + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +uv.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +.idea +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# VSCode project settings +.vscode/ +.devcontainer/ + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# datasets and projects (ignore /datasets dir at root only to allow for docs/en/datasets dir) +/datasets +runs/ +wandb/ +.DS_Store + +# Neural Network weights ----------------------------------------------------------------------------------------------- +weights/ +*.weights +*.pt +*.ts +*.pb +*.onnx +*.engine +*.mlmodel +*.mlpackage +*.torchscript +*.tflite +*.h5 +*.mnn +*_saved_model/ +*_web_model/ +*_openvino_model/ +*_paddle_model/ +*_ncnn_model/ +*_imx_model/ +pnnx* +*.rknn + +# Autogenerated files for tests +/ultralytics/assets/ + +# calibration image +calibration_*.npy + +# Videos and Pictures +*.mp4 +*.avi +*.mov +*.mkv +*.webm +*.jpg +*.jpeg +*.png +*.bmp +*.tiff +*.gif +*.svg +*.webp +*.heic +*.ico +*.raw diff --git a/ultralytics-main/CITATION.cff b/ultralytics-main/CITATION.cff new file mode 100644 index 0000000000000000000000000000000000000000..37931d7e7d32245791aab56aed44338601aed377 --- /dev/null +++ b/ultralytics-main/CITATION.cff @@ -0,0 +1,26 @@ +# This CITATION.cff file was generated with https://bit.ly/cffinit + +cff-version: 1.2.0 +title: Ultralytics YOLO +message: >- + If you use this software, please cite it using the + metadata from this file. +type: software +authors: + - given-names: Glenn + family-names: Jocher + affiliation: Ultralytics + orcid: "https://orcid.org/0000-0001-5950-6979" + - family-names: Qiu + given-names: Jing + affiliation: Ultralytics + orcid: "https://orcid.org/0000-0003-3783-7069" + - given-names: Ayush + family-names: Chaurasia + affiliation: Ultralytics + orcid: "https://orcid.org/0000-0002-7603-6750" +repository-code: "https://github.com/ultralytics/ultralytics" +url: "https://ultralytics.com" +license: AGPL-3.0 +version: 8.0.0 +date-released: "2023-01-10" diff --git a/ultralytics-main/CONTRIBUTING.md b/ultralytics-main/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..cd8757439fa628e817bd1285a31b8e69fd69775f --- /dev/null +++ b/ultralytics-main/CONTRIBUTING.md @@ -0,0 +1,241 @@ +Ultralytics logo + +# Contributing to Ultralytics Open-Source Projects + +Welcome! We're thrilled that you're considering contributing to our [Ultralytics](https://www.ultralytics.com/) [open-source](https://github.com/ultralytics) projects. Your involvement not only helps enhance the quality of our repositories but also benefits the entire [computer vision](https://www.ultralytics.com/glossary/computer-vision-cv) community. This guide provides clear guidelines and best practices to help you get started. + +[![Ultralytics open-source contributors](https://raw.githubusercontent.com/ultralytics/assets/main/im/image-contributors.png)](https://github.com/ultralytics/ultralytics/graphs/contributors) + +## 🤝 Code of Conduct + +To ensure a welcoming and inclusive environment for everyone, all contributors must adhere to our [Code of Conduct](https://docs.ultralytics.com/help/code-of-conduct/). **Respect**, **kindness**, and **professionalism** are at the heart of our community. + +## 🚀 Contributing via Pull Requests + +We greatly appreciate contributions in the form of [pull requests (PRs)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests). To make the review process as smooth as possible, please follow these steps: + +1. **[Fork the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo):** Start by forking the relevant Ultralytics repository (e.g., [ultralytics/ultralytics](https://github.com/ultralytics/ultralytics)) to your GitHub account. +2. **[Create a branch](https://docs.github.com/en/desktop/making-changes-in-a-branch/managing-branches-in-github-desktop):** Create a new branch in your forked repository with a clear, descriptive name reflecting your changes (e.g., `fix-issue-123`, `add-feature-xyz`). +3. **Make your changes:** Implement your improvements or fixes. Ensure your code adheres to the project's style guidelines and doesn't introduce new errors or warnings. +4. **Test your changes:** Before submitting, test your changes locally to confirm they work as expected and don't cause [regressions](https://en.wikipedia.org/wiki/Software_regression). Add tests if you're introducing new functionality. +5. **[Commit your changes](https://docs.github.com/en/desktop/making-changes-in-a-branch/committing-and-reviewing-changes-to-your-project-in-github-desktop):** Commit your changes with concise and descriptive commit messages. If your changes address a specific issue, include the issue number (e.g., `Fix #123: Corrected calculation error.`). +6. **[Create a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request):** Submit a pull request from your branch to the `main` branch of the original Ultralytics repository. Provide a clear title and a detailed description explaining the purpose and scope of your changes. + +### 📝 CLA Signing + +Before we can merge your pull request, you must sign our [Contributor License Agreement (CLA)](https://docs.ultralytics.com/help/CLA/). This legal agreement ensures that your contributions are properly licensed, allowing the project to continue being distributed under the [AGPL-3.0 license](https://www.ultralytics.com/legal/agpl-3-0-software-license). + +After submitting your pull request, the CLA bot will guide you through the signing process. To sign the CLA, simply add a comment in your PR stating: + +```text +I have read the CLA Document and I sign the CLA +``` + +### ✍️ Google-Style Docstrings + +When adding new functions or classes, please include [Google-style docstrings](https://google.github.io/styleguide/pyguide.html). These docstrings provide clear, standardized documentation that helps other developers understand and maintain your code. + +#### Example Google-style + +This example illustrates a Google-style docstring. Ensure that both input and output `types` are always enclosed in parentheses, e.g., `(bool)`. + +```python +def example_function(arg1, arg2=4): + """Example function demonstrating Google-style docstrings. + + Args: + arg1 (int): The first argument. + arg2 (int): The second argument, with a default value of 4. + + Returns: + (bool): True if successful, False otherwise. + + Examples: + >>> result = example_function(1, 2) # returns False + """ + if arg1 == arg2: + return True + return False +``` + +#### Example Google-style with type hints + +This example includes both a Google-style docstring and [type hints](https://docs.python.org/3/library/typing.html) for arguments and returns, though using either independently is also acceptable. + +```python +def example_function(arg1: int, arg2: int = 4) -> bool: + """Example function demonstrating Google-style docstrings. + + Args: + arg1: The first argument. + arg2: The second argument, with a default value of 4. + + Returns: + True if successful, False otherwise. + + Examples: + >>> result = example_function(1, 2) # returns False + """ + if arg1 == arg2: + return True + return False +``` + +#### Example Single-line + +For smaller or simpler functions, a single-line docstring may be sufficient. The docstring must use three double-quotes, be a complete sentence, start with a capital letter, and end with a period. + +```python +def example_small_function(arg1: int, arg2: int = 4) -> bool: + """Example function with a single-line docstring.""" + return arg1 == arg2 +``` + +### ✅ GitHub Actions CI Tests + +All pull requests must pass the [GitHub Actions](https://github.com/features/actions) [Continuous Integration](https://docs.ultralytics.com/help/CI/) (CI) tests before they can be merged. These tests include linting, unit tests, and other checks to ensure that your changes meet the project's quality standards. Review the CI output and address any issues that arise. + +## ✨ Best Practices for Code Contributions + +When contributing code to Ultralytics projects, keep these best practices in mind: + +- **Avoid code duplication:** Reuse existing code wherever possible and minimize unnecessary arguments. +- **Make smaller, focused changes:** Focus on targeted modifications rather than large-scale changes. +- **Simplify when possible:** Look for opportunities to simplify the code or remove unnecessary parts. +- **Consider compatibility:** Before making changes, consider whether they might break existing code using Ultralytics. +- **Use consistent formatting:** Tools like [Ruff Formatter](https://github.com/astral-sh/ruff) can help maintain stylistic consistency. +- **Add appropriate tests:** Include [tests](https://docs.ultralytics.com/guides/model-testing/) for new features to ensure they work as expected. + +## 👀 Reviewing Pull Requests + +Reviewing pull requests is another valuable way to contribute. When reviewing PRs: + +- **Check for unit tests:** Verify that the PR includes tests for new features or changes. +- **Review documentation updates:** Ensure [documentation](https://docs.ultralytics.com/) is updated to reflect changes. +- **Evaluate performance impact:** Consider how changes might affect [performance](https://docs.ultralytics.com/guides/yolo-performance-metrics/). +- **Verify CI tests:** Confirm all [Continuous Integration tests](https://docs.ultralytics.com/help/CI/) are passing. +- **Provide constructive feedback:** Offer specific, clear feedback about any issues or concerns. +- **Recognize effort:** Acknowledge the author's work to maintain a positive collaborative atmosphere. + +## 🐞 Reporting Bugs + +We highly value bug reports as they help us improve the quality and reliability of our projects. When reporting a bug via [GitHub Issues](https://github.com/ultralytics/ultralytics/issues): + +- **Check existing issues:** Search first to see if the bug has already been reported. +- **Provide a [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum-reproducible-example/):** Create a small, self-contained code snippet that consistently reproduces the issue. This is crucial for efficient debugging. +- **Describe the environment:** Specify your operating system, Python version, relevant library versions (e.g., [`torch`](https://pytorch.org/), [`ultralytics`](https://github.com/ultralytics/ultralytics)), and hardware ([CPU](https://en.wikipedia.org/wiki/Central_processing_unit)/[GPU](https://www.ultralytics.com/glossary/gpu-graphics-processing-unit)). +- **Explain expected vs. actual behavior:** Clearly state what you expected to happen and what actually occurred. Include any error messages or tracebacks. + +## 📜 License + +Ultralytics uses the [GNU Affero General Public License v3.0 (AGPL-3.0)](https://www.ultralytics.com/legal/agpl-3-0-software-license) for its repositories. This license promotes [openness](https://en.wikipedia.org/wiki/Openness), [transparency](https://www.ultralytics.com/glossary/transparency-in-ai), and [collaborative improvement](https://en.wikipedia.org/wiki/Collaborative_software) in software development. It ensures that all users have the freedom to use, modify, and share the software, fostering a strong community of collaboration and innovation. + +We encourage all contributors to familiarize themselves with the terms of the [AGPL-3.0 license](https://opensource.org/license/agpl-v3) to contribute effectively and ethically to the Ultralytics open-source community. + +## 🌍 Open-Sourcing Your YOLO Project Under AGPL-3.0 + +Using Ultralytics YOLO models or code in your project? The [AGPL-3.0 license](https://opensource.org/license/agpl-v3) requires that your entire derivative work also be open-sourced under AGPL-3.0. This ensures modifications and larger projects built upon open-source foundations remain open. + +### Why AGPL-3.0 Compliance Matters + +- **Keeps Software Open:** Ensures that improvements and derivative works benefit the community. +- **Legal Requirement:** Using AGPL-3.0 licensed code binds your project to its terms. +- **Fosters Collaboration:** Encourages sharing and transparency. + +If you prefer not to open-source your project, consider obtaining an [Enterprise License](https://www.ultralytics.com/license). + +### How to Comply with AGPL-3.0 + +Complying means making the **complete corresponding source code** of your project publicly available under the AGPL-3.0 license. + +1. **Choose Your Starting Point:** + - **Fork Ultralytics YOLO:** Directly fork the [Ultralytics YOLO repository](https://github.com/ultralytics/ultralytics) if building closely upon it. + - **Use Ultralytics Template:** Start with the [Ultralytics template repository](https://github.com/ultralytics/template) for a clean, modular setup integrating YOLO. + +2. **License Your Project:** + - Add a `LICENSE` file containing the full text of the [AGPL-3.0 license](https://opensource.org/license/agpl-v3). + - Add a notice at the top of each source file indicating the license. + +3. **Publish Your Source Code:** + - Make your **entire project's source code** publicly accessible (e.g., on GitHub). This includes: + - The complete larger application or system that incorporates the YOLO model or code. + - Any modifications made to the original Ultralytics YOLO code. + - Scripts for training, validation, inference. + - [Model weights](https://www.ultralytics.com/glossary/model-weights) if modified or fine-tuned. + - [Configuration files](https://docs.ultralytics.com/usage/cfg/), environment setups (`requirements.txt`, [`Dockerfiles`](https://docs.docker.com/reference/dockerfile/)). + - Backend and frontend code if it's part of a [web application](https://en.wikipedia.org/wiki/Web_application). + - Any [third-party libraries]() you've modified. + - [Training data](https://www.ultralytics.com/glossary/training-data) if required to run/retrain _and_ redistributable. + +4. **Document Clearly:** + - Update your `README.md` to state that the project is licensed under AGPL-3.0. + - Include clear instructions on how to set up, build, and run your project from the source code. + - Attribute Ultralytics YOLO appropriately, linking back to the [original repository](https://github.com/ultralytics/ultralytics). Example: + ```markdown + This project utilizes code from [Ultralytics YOLO](https://github.com/ultralytics/ultralytics), licensed under AGPL-3.0. + ``` + +### Example Repository Structure + +Refer to the [Ultralytics Template Repository](https://github.com/ultralytics/template) for a practical example structure: + +``` +my-yolo-project/ +│ +├── LICENSE # Full AGPL-3.0 license text +├── README.md # Project description, setup, usage, license info & attribution +├── pyproject.toml # Dependencies (or requirements.txt) +├── scripts/ # Training/inference scripts +│ └── train.py +├── src/ # Your project's source code +│ ├── __init__.py +│ ├── data_loader.py +│ └── model_wrapper.py # Code interacting with YOLO +├── tests/ # Unit/integration tests +├── configs/ # YAML/JSON config files +├── docker/ # Dockerfiles, if used +│ └── Dockerfile +└── .github/ # GitHub specific files (e.g., workflows for CI) + └── workflows/ + └── ci.yml +``` + +By following these guidelines, you ensure compliance with AGPL-3.0, supporting the open-source ecosystem that enables powerful tools like Ultralytics YOLO. + +## 🎉 Conclusion + +Thank you for your interest in contributing to [Ultralytics](https://www.ultralytics.com/) [open-source](https://github.com/ultralytics) YOLO projects. Your participation is essential in shaping the future of our software and building a vibrant community of innovation and collaboration. Whether you're enhancing code, reporting bugs, or suggesting new features, your contributions are invaluable. + +We're excited to see your ideas come to life and appreciate your commitment to advancing [object detection](https://www.ultralytics.com/glossary/object-detection) technology. Together, let's continue to grow and innovate in this exciting open-source journey. Happy coding! 🚀🌟 + +## FAQ + +### Why should I contribute to Ultralytics YOLO open-source repositories? + +Contributing to Ultralytics YOLO open-source repositories improves the software, making it more robust and feature-rich for the entire community. Contributions can include code enhancements, bug fixes, documentation improvements, and new feature implementations. Additionally, contributing allows you to collaborate with other skilled developers and experts in the field, enhancing your own skills and reputation. For details on how to get started, refer to the [Contributing via Pull Requests](#-contributing-via-pull-requests) section. + +### How do I sign the Contributor License Agreement (CLA) for Ultralytics YOLO? + +To sign the Contributor License Agreement (CLA), follow the instructions provided by the CLA bot after submitting your pull request. This process ensures that your contributions are properly licensed under the AGPL-3.0 license, maintaining the legal integrity of the open-source project. Add a comment in your pull request stating: + +```text +I have read the CLA Document and I sign the CLA +``` + +For more information, see the [CLA Signing](#-cla-signing) section. + +### What are Google-style docstrings, and why are they required for Ultralytics YOLO contributions? + +Google-style docstrings provide clear, concise documentation for functions and classes, improving code readability and maintainability. These docstrings outline the function's purpose, arguments, and return values with specific formatting rules. When contributing to Ultralytics YOLO, following Google-style docstrings ensures that your additions are well-documented and easily understood. For examples and guidelines, visit the [Google-Style Docstrings](#-google-style-docstrings) section. + +### How can I ensure my changes pass the GitHub Actions CI tests? + +Before your pull request can be merged, it must pass all GitHub Actions Continuous Integration (CI) tests. These tests include linting, unit tests, and other checks to ensure the code meets the project's quality standards. Review the CI output and fix any issues. For detailed information on the CI process and troubleshooting tips, see the [GitHub Actions CI Tests](#-github-actions-ci-tests) section. + +### How do I report a bug in Ultralytics YOLO repositories? + +To report a bug, provide a clear and concise [Minimum Reproducible Example](https://docs.ultralytics.com/help/minimum-reproducible-example/) along with your bug report. This helps developers quickly identify and fix the issue. Ensure your example is minimal yet sufficient to replicate the problem. For more detailed steps on reporting bugs, refer to the [Reporting Bugs](#-reporting-bugs) section. + +### What does the AGPL-3.0 license mean if I use Ultralytics YOLO in my own project? + +If you use Ultralytics YOLO code or models (licensed under AGPL-3.0) in your project, the AGPL-3.0 license requires that your entire project (the derivative work) must also be licensed under AGPL-3.0 and its complete source code must be made publicly available. This ensures that the open-source nature of the software is preserved throughout its derivatives. If you cannot meet these requirements, you need to obtain an [Enterprise License](https://www.ultralytics.com/license). See the [Open-Sourcing Your Project](#-open-sourcing-your-yolo-project-under-agpl-30) section for details. diff --git a/ultralytics-main/LICENSE b/ultralytics-main/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..be3f7b28e564e7dd05eaf59d64adba1a4065ac0e --- /dev/null +++ b/ultralytics-main/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/ultralytics-main/README.md b/ultralytics-main/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3767edec09ce49e1f0ad154204f67a048d154a2a --- /dev/null +++ b/ultralytics-main/README.md @@ -0,0 +1,285 @@ +
+

+ + Ultralytics YOLO banner +

+ +[中文](https://docs.ultralytics.com/zh/) | [한국어](https://docs.ultralytics.com/ko/) | [日本語](https://docs.ultralytics.com/ja/) | [Русский](https://docs.ultralytics.com/ru/) | [Deutsch](https://docs.ultralytics.com/de/) | [Français](https://docs.ultralytics.com/fr/) | [Español](https://docs.ultralytics.com/es) | [Português](https://docs.ultralytics.com/pt/) | [Türkçe](https://docs.ultralytics.com/tr/) | [Tiếng Việt](https://docs.ultralytics.com/vi/) | [العربية](https://docs.ultralytics.com/ar/)
+ +
+ Ultralytics CI + Ultralytics Downloads + Ultralytics YOLO Citation + Ultralytics Discord + Ultralytics Forums + Ultralytics Reddit +
+ Run Ultralytics on Gradient + Open Ultralytics In Colab + Open Ultralytics In Kaggle + Open Ultralytics In Binder +
+
+
+ +[Ultralytics](https://www.ultralytics.com/) creates cutting-edge, state-of-the-art (SOTA) [YOLO models](https://www.ultralytics.com/yolo) built on years of foundational research in computer vision and AI. Constantly updated for performance and flexibility, our models are **fast**, **accurate**, and **easy to use**. They excel at [object detection](https://docs.ultralytics.com/tasks/detect/), [tracking](https://docs.ultralytics.com/modes/track/), [instance segmentation](https://docs.ultralytics.com/tasks/segment/), [image classification](https://docs.ultralytics.com/tasks/classify/), and [pose estimation](https://docs.ultralytics.com/tasks/pose/) tasks. + +Find detailed documentation in the [Ultralytics Docs](https://docs.ultralytics.com/). Get support via [GitHub Issues](https://github.com/ultralytics/ultralytics/issues/new/choose). Join discussions on [Discord](https://discord.com/invite/ultralytics), [Reddit](https://www.reddit.com/r/ultralytics/), and the [Ultralytics Community Forums](https://community.ultralytics.com/)! + +Request an Enterprise License for commercial use at [Ultralytics Licensing](https://www.ultralytics.com/license). + + + YOLO11 performance plots + + +
+ Ultralytics GitHub + space + Ultralytics LinkedIn + space + Ultralytics Twitter + space + Ultralytics YouTube + space + Ultralytics TikTok + space + Ultralytics BiliBili + space + Ultralytics Discord +
+ +## 📄 Documentation + +See below for quickstart installation and usage examples. For comprehensive guidance on training, validation, prediction, and deployment, refer to our full [Ultralytics Docs](https://docs.ultralytics.com/). + +
+Install + +Install the `ultralytics` package, including all [requirements](https://github.com/ultralytics/ultralytics/blob/main/pyproject.toml), in a [**Python>=3.8**](https://www.python.org/) environment with [**PyTorch>=1.8**](https://pytorch.org/get-started/locally/). + +[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics/) [![Ultralytics Downloads](https://static.pepy.tech/badge/ultralytics)](https://clickpy.clickhouse.com/dashboard/ultralytics) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics/) + +```bash +pip install ultralytics +``` + +For alternative installation methods, including [Conda](https://anaconda.org/conda-forge/ultralytics), [Docker](https://hub.docker.com/r/ultralytics/ultralytics), and building from source via Git, please consult the [Quickstart Guide](https://docs.ultralytics.com/quickstart/). + +[![Conda Version](https://img.shields.io/conda/vn/conda-forge/ultralytics?logo=condaforge)](https://anaconda.org/conda-forge/ultralytics) [![Docker Image Version](https://img.shields.io/docker/v/ultralytics/ultralytics?sort=semver&logo=docker)](https://hub.docker.com/r/ultralytics/ultralytics) [![Ultralytics Docker Pulls](https://img.shields.io/docker/pulls/ultralytics/ultralytics?logo=docker)](https://hub.docker.com/r/ultralytics/ultralytics) + +
+ +
+Usage + +### CLI + +You can use Ultralytics YOLO directly from the Command Line Interface (CLI) with the `yolo` command: + +```bash +# Predict using a pretrained YOLO model (e.g., YOLO11n) on an image +yolo predict model=yolo11n.pt source='https://ultralytics.com/images/bus.jpg' +``` + +The `yolo` command supports various tasks and modes, accepting additional arguments like `imgsz=640`. Explore the YOLO [CLI Docs](https://docs.ultralytics.com/usage/cli/) for more examples. + +### Python + +Ultralytics YOLO can also be integrated directly into your Python projects. It accepts the same [configuration arguments](https://docs.ultralytics.com/usage/cfg/) as the CLI: + +```python +from ultralytics import YOLO + +# Load a pretrained YOLO11n model +model = YOLO("yolo11n.pt") + +# Train the model on the COCO8 dataset for 100 epochs +train_results = model.train( + data="coco8.yaml", # Path to dataset configuration file + epochs=100, # Number of training epochs + imgsz=640, # Image size for training + device="cpu", # Device to run on (e.g., 'cpu', 0, [0,1,2,3]) +) + +# Evaluate the model's performance on the validation set +metrics = model.val() + +# Perform object detection on an image +results = model("path/to/image.jpg") # Predict on an image +results[0].show() # Display results + +# Export the model to ONNX format for deployment +path = model.export(format="onnx") # Returns the path to the exported model +``` + +Discover more examples in the YOLO [Python Docs](https://docs.ultralytics.com/usage/python/). + +
+ +## ✨ Models + +Ultralytics supports a wide range of YOLO models, from early versions like [YOLOv3](https://docs.ultralytics.com/models/yolov3/) to the latest [YOLO11](https://docs.ultralytics.com/models/yolo11/). The tables below showcase YOLO11 models pretrained on the [COCO](https://docs.ultralytics.com/datasets/detect/coco/) dataset for [Detection](https://docs.ultralytics.com/tasks/detect/), [Segmentation](https://docs.ultralytics.com/tasks/segment/), and [Pose Estimation](https://docs.ultralytics.com/tasks/pose/). Additionally, [Classification](https://docs.ultralytics.com/tasks/classify/) models pretrained on the [ImageNet](https://docs.ultralytics.com/datasets/classify/imagenet/) dataset are available. [Tracking](https://docs.ultralytics.com/modes/track/) mode is compatible with all Detection, Segmentation, and Pose models. All [Models](https://docs.ultralytics.com/models/) are automatically downloaded from the latest Ultralytics [release](https://github.com/ultralytics/assets/releases) upon first use. + + + Ultralytics YOLO supported tasks + +
+
+ +
Detection (COCO) + +Explore the [Detection Docs](https://docs.ultralytics.com/tasks/detect/) for usage examples. These models are trained on the [COCO dataset](https://cocodataset.org/), featuring 80 object classes. + +| Model | size
(pixels) | mAPval
50-95 | Speed
CPU ONNX
(ms) | Speed
T4 TensorRT10
(ms) | params
(M) | FLOPs
(B) | +| ------------------------------------------------------------------------------------ | --------------------- | -------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | +| [YOLO11n](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt) | 640 | 39.5 | 56.1 ± 0.8 | 1.5 ± 0.0 | 2.6 | 6.5 | +| [YOLO11s](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s.pt) | 640 | 47.0 | 90.0 ± 1.2 | 2.5 ± 0.0 | 9.4 | 21.5 | +| [YOLO11m](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m.pt) | 640 | 51.5 | 183.2 ± 2.0 | 4.7 ± 0.1 | 20.1 | 68.0 | +| [YOLO11l](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l.pt) | 640 | 53.4 | 238.6 ± 1.4 | 6.2 ± 0.1 | 25.3 | 86.9 | +| [YOLO11x](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x.pt) | 640 | 54.7 | 462.8 ± 6.7 | 11.3 ± 0.2 | 56.9 | 194.9 | + +- **mAPval** values refer to single-model single-scale performance on the [COCO val2017](https://cocodataset.org/) dataset. See [YOLO Performance Metrics](https://docs.ultralytics.com/guides/yolo-performance-metrics/) for details.
Reproduce with `yolo val detect data=coco.yaml device=0` +- **Speed** metrics are averaged over COCO val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. CPU speeds measured with [ONNX](https://onnx.ai/) export. GPU speeds measured with [TensorRT](https://developer.nvidia.com/tensorrt) export.
Reproduce with `yolo val detect data=coco.yaml batch=1 device=0|cpu` + +
+ +
Segmentation (COCO) + +Refer to the [Segmentation Docs](https://docs.ultralytics.com/tasks/segment/) for usage examples. These models are trained on [COCO-Seg](https://docs.ultralytics.com/datasets/segment/coco/), including 80 classes. + +| Model | size
(pixels) | mAPbox
50-95 | mAPmask
50-95 | Speed
CPU ONNX
(ms) | Speed
T4 TensorRT10
(ms) | params
(M) | FLOPs
(B) | +| -------------------------------------------------------------------------------------------- | --------------------- | -------------------- | --------------------- | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | +| [YOLO11n-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-seg.pt) | 640 | 38.9 | 32.0 | 65.9 ± 1.1 | 1.8 ± 0.0 | 2.9 | 9.7 | +| [YOLO11s-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-seg.pt) | 640 | 46.6 | 37.8 | 117.6 ± 4.9 | 2.9 ± 0.0 | 10.1 | 33.0 | +| [YOLO11m-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-seg.pt) | 640 | 51.5 | 41.5 | 281.6 ± 1.2 | 6.3 ± 0.1 | 22.4 | 113.2 | +| [YOLO11l-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-seg.pt) | 640 | 53.4 | 42.9 | 344.2 ± 3.2 | 7.8 ± 0.2 | 27.6 | 132.2 | +| [YOLO11x-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-seg.pt) | 640 | 54.7 | 43.8 | 664.5 ± 3.2 | 15.8 ± 0.7 | 62.1 | 296.4 | + +- **mAPval** values are for single-model single-scale on the [COCO val2017](https://cocodataset.org/) dataset. See [YOLO Performance Metrics](https://docs.ultralytics.com/guides/yolo-performance-metrics/) for details.
Reproduce with `yolo val segment data=coco.yaml device=0` +- **Speed** metrics are averaged over COCO val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. CPU speeds measured with [ONNX](https://onnx.ai/) export. GPU speeds measured with [TensorRT](https://developer.nvidia.com/tensorrt) export.
Reproduce with `yolo val segment data=coco.yaml batch=1 device=0|cpu` + +
+ +
Classification (ImageNet) + +Consult the [Classification Docs](https://docs.ultralytics.com/tasks/classify/) for usage examples. These models are trained on [ImageNet](https://docs.ultralytics.com/datasets/classify/imagenet/), covering 1000 classes. + +| Model | size
(pixels) | acc
top1 | acc
top5 | Speed
CPU ONNX
(ms) | Speed
T4 TensorRT10
(ms) | params
(M) | FLOPs
(B) at 224 | +| -------------------------------------------------------------------------------------------- | --------------------- | ---------------- | ---------------- | ------------------------------ | ----------------------------------- | ------------------ | ------------------------ | +| [YOLO11n-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-cls.pt) | 224 | 70.0 | 89.4 | 5.0 ± 0.3 | 1.1 ± 0.0 | 2.8 | 0.5 | +| [YOLO11s-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-cls.pt) | 224 | 75.4 | 92.7 | 7.9 ± 0.2 | 1.3 ± 0.0 | 6.7 | 1.6 | +| [YOLO11m-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-cls.pt) | 224 | 77.3 | 93.9 | 17.2 ± 0.4 | 2.0 ± 0.0 | 11.6 | 4.9 | +| [YOLO11l-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-cls.pt) | 224 | 78.3 | 94.3 | 23.2 ± 0.3 | 2.8 ± 0.0 | 14.1 | 6.2 | +| [YOLO11x-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-cls.pt) | 224 | 79.5 | 94.9 | 41.4 ± 0.9 | 3.8 ± 0.0 | 29.6 | 13.6 | + +- **acc** values represent model accuracy on the [ImageNet](https://www.image-net.org/) dataset validation set.
Reproduce with `yolo val classify data=path/to/ImageNet device=0` +- **Speed** metrics are averaged over ImageNet val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. CPU speeds measured with [ONNX](https://onnx.ai/) export. GPU speeds measured with [TensorRT](https://developer.nvidia.com/tensorrt) export.
Reproduce with `yolo val classify data=path/to/ImageNet batch=1 device=0|cpu` + +
+ +
Pose (COCO) + +See the [Pose Estimation Docs](https://docs.ultralytics.com/tasks/pose/) for usage examples. These models are trained on [COCO-Pose](https://docs.ultralytics.com/datasets/pose/coco/), focusing on the 'person' class. + +| Model | size
(pixels) | mAPpose
50-95 | mAPpose
50 | Speed
CPU ONNX
(ms) | Speed
T4 TensorRT10
(ms) | params
(M) | FLOPs
(B) | +| ---------------------------------------------------------------------------------------------- | --------------------- | --------------------- | ------------------ | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | +| [YOLO11n-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-pose.pt) | 640 | 50.0 | 81.0 | 52.4 ± 0.5 | 1.7 ± 0.0 | 2.9 | 7.4 | +| [YOLO11s-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-pose.pt) | 640 | 58.9 | 86.3 | 90.5 ± 0.6 | 2.6 ± 0.0 | 9.9 | 23.1 | +| [YOLO11m-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-pose.pt) | 640 | 64.9 | 89.4 | 187.3 ± 0.8 | 4.9 ± 0.1 | 20.9 | 71.4 | +| [YOLO11l-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-pose.pt) | 640 | 66.1 | 89.9 | 247.7 ± 1.1 | 6.4 ± 0.1 | 26.1 | 90.3 | +| [YOLO11x-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-pose.pt) | 640 | 69.5 | 91.1 | 488.0 ± 13.9 | 12.1 ± 0.2 | 58.8 | 202.8 | + +- **mAPval** values are for single-model single-scale on the [COCO Keypoints val2017](https://docs.ultralytics.com/datasets/pose/coco/) dataset. See [YOLO Performance Metrics](https://docs.ultralytics.com/guides/yolo-performance-metrics/) for details.
Reproduce with `yolo val pose data=coco-pose.yaml device=0` +- **Speed** metrics are averaged over COCO val images using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. CPU speeds measured with [ONNX](https://onnx.ai/) export. GPU speeds measured with [TensorRT](https://developer.nvidia.com/tensorrt) export.
Reproduce with `yolo val pose data=coco-pose.yaml batch=1 device=0|cpu` + +
+ +
Oriented Bounding Boxes (DOTAv1) + +Check the [OBB Docs](https://docs.ultralytics.com/tasks/obb/) for usage examples. These models are trained on [DOTAv1](https://docs.ultralytics.com/datasets/obb/dota-v2/#dota-v10/), including 15 classes. + +| Model | size
(pixels) | mAPtest
50 | Speed
CPU ONNX
(ms) | Speed
T4 TensorRT10
(ms) | params
(M) | FLOPs
(B) | +| -------------------------------------------------------------------------------------------- | --------------------- | ------------------ | ------------------------------ | ----------------------------------- | ------------------ | ----------------- | +| [YOLO11n-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-obb.pt) | 1024 | 78.4 | 117.6 ± 0.8 | 4.4 ± 0.0 | 2.7 | 16.8 | +| [YOLO11s-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-obb.pt) | 1024 | 79.5 | 219.4 ± 4.0 | 5.1 ± 0.0 | 9.7 | 57.1 | +| [YOLO11m-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-obb.pt) | 1024 | 80.9 | 562.8 ± 2.9 | 10.1 ± 0.4 | 20.9 | 182.8 | +| [YOLO11l-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-obb.pt) | 1024 | 81.0 | 712.5 ± 5.0 | 13.5 ± 0.6 | 26.1 | 231.2 | +| [YOLO11x-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-obb.pt) | 1024 | 81.3 | 1408.6 ± 7.7 | 28.6 ± 1.0 | 58.8 | 519.1 | + +- **mAPtest** values are for single-model multiscale performance on the [DOTAv1 test set](https://captain-whu.github.io/DOTA/dataset.html).
Reproduce by `yolo val obb data=DOTAv1.yaml device=0 split=test` and submit merged results to the [DOTA evaluation server](https://captain-whu.github.io/DOTA/evaluation.html). +- **Speed** metrics are averaged over [DOTAv1 val images](https://docs.ultralytics.com/datasets/obb/dota-v2/#dota-v10) using an [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) instance. CPU speeds measured with [ONNX](https://onnx.ai/) export. GPU speeds measured with [TensorRT](https://developer.nvidia.com/tensorrt) export.
Reproduce by `yolo val obb data=DOTAv1.yaml batch=1 device=0|cpu` + +
+ +## 🧩 Integrations + +Our key integrations with leading AI platforms extend the functionality of Ultralytics' offerings, enhancing tasks like dataset labeling, training, visualization, and model management. Discover how Ultralytics, in collaboration with partners like [Weights & Biases](https://docs.ultralytics.com/integrations/weights-biases/), [Comet ML](https://docs.ultralytics.com/integrations/comet/), [Roboflow](https://docs.ultralytics.com/integrations/roboflow/), and [Intel OpenVINO](https://docs.ultralytics.com/integrations/openvino/), can optimize your AI workflow. Explore more at [Ultralytics Integrations](https://docs.ultralytics.com/integrations/). + + + Ultralytics active learning integrations + +
+
+ +
+ + Ultralytics HUB logo + space + + Weights & Biases logo + space + + Comet ML logo + space + + Neural Magic logo +
+ +| Ultralytics HUB 🌟 | Weights & Biases | Comet | Neural Magic | +| :-----------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------: | +| Streamline YOLO workflows: Label, train, and deploy effortlessly with [Ultralytics HUB](https://hub.ultralytics.com/). Try now! | Track experiments, hyperparameters, and results with [Weights & Biases](https://docs.ultralytics.com/integrations/weights-biases/). | Free forever, [Comet ML](https://docs.ultralytics.com/integrations/comet/) lets you save YOLO models, resume training, and interactively visualize predictions. | Run YOLO inference up to 6x faster with [Neural Magic DeepSparse](https://docs.ultralytics.com/integrations/neural-magic/). | + +## 🌟 Ultralytics HUB + +Experience seamless AI with [Ultralytics HUB](https://hub.ultralytics.com/), the all-in-one platform for data visualization, training YOLO models, and deployment—no coding required. Transform images into actionable insights and bring your AI visions to life effortlessly using our cutting-edge platform and user-friendly [Ultralytics App](https://www.ultralytics.com/app-install). Start your journey for **Free** today! + + +Ultralytics HUB preview image + +## 🤝 Contribute + +We thrive on community collaboration! Ultralytics YOLO wouldn't be the SOTA framework it is without contributions from developers like you. Please see our [Contributing Guide](https://docs.ultralytics.com/help/contributing/) to get started. We also welcome your feedback—share your experience by completing our [Survey](https://www.ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey). A huge **Thank You** 🙏 to everyone who contributes! + + + +[![Ultralytics open-source contributors](https://raw.githubusercontent.com/ultralytics/assets/main/im/image-contributors.png)](https://github.com/ultralytics/ultralytics/graphs/contributors) + +We look forward to your contributions to help make the Ultralytics ecosystem even better! + +## 📜 License + +Ultralytics offers two licensing options to suit different needs: + +- **AGPL-3.0 License**: This [OSI-approved](https://opensource.org/license/agpl-v3) open-source license is perfect for students, researchers, and enthusiasts. It encourages open collaboration and knowledge sharing. See the [LICENSE](https://github.com/ultralytics/ultralytics/blob/main/LICENSE) file for full details. +- **Ultralytics Enterprise License**: Designed for commercial use, this license allows for the seamless integration of Ultralytics software and AI models into commercial products and services, bypassing the open-source requirements of AGPL-3.0. If your use case involves commercial deployment, please contact us via [Ultralytics Licensing](https://www.ultralytics.com/license). + +## 📞 Contact + +For bug reports and feature requests related to Ultralytics software, please visit [GitHub Issues](https://github.com/ultralytics/ultralytics/issues). For questions, discussions, and community support, join our active communities on [Discord](https://discord.com/invite/ultralytics), [Reddit](https://www.reddit.com/r/ultralytics/), and the [Ultralytics Community Forums](https://community.ultralytics.com/). We're here to help with all things Ultralytics! + +
+
+ Ultralytics GitHub + space + Ultralytics LinkedIn + space + Ultralytics Twitter + space + Ultralytics YouTube + space + Ultralytics TikTok + space + Ultralytics BiliBili + space + Ultralytics Discord +
diff --git a/ultralytics-main/README.zh-CN.md b/ultralytics-main/README.zh-CN.md new file mode 100644 index 0000000000000000000000000000000000000000..da1d478a013115fdcc0439aa79132fcfac3fa885 --- /dev/null +++ b/ultralytics-main/README.zh-CN.md @@ -0,0 +1,285 @@ +
+

+ + Ultralytics YOLO banner +

+ +[中文](https://docs.ultralytics.com/zh/) | [한국어](https://docs.ultralytics.com/ko/) | [日本語](https://docs.ultralytics.com/ja/) | [Русский](https://docs.ultralytics.com/ru/) | [Deutsch](https://docs.ultralytics.com/de/) | [Français](https://docs.ultralytics.com/fr/) | [Español](https://docs.ultralytics.com/es) | [Português](https://docs.ultralytics.com/pt/) | [Türkçe](https://docs.ultralytics.com/tr/) | [Tiếng Việt](https://docs.ultralytics.com/vi/) | [العربية](https://docs.ultralytics.com/ar/)
+ +
+ Ultralytics CI + Ultralytics Downloads + Ultralytics YOLO Citation + Ultralytics Discord + Ultralytics Forums + Ultralytics Reddit +
+ Run Ultralytics on Gradient + Open Ultralytics In Colab + Open Ultralytics In Kaggle + Open Ultralytics In Binder +
+
+
+ +[Ultralytics](https://www.ultralytics.com/) 基于多年在计算机视觉和人工智能领域的基础研究,创造了尖端的、最先进的 (SOTA) [YOLO 模型](https://www.ultralytics.com/yolo)。我们的模型不断更新以提高性能和灵活性,具有**速度快**、**精度高**和**易于使用**的特点。它们在[目标检测](https://docs.ultralytics.com/tasks/detect/)、[跟踪](https://docs.ultralytics.com/modes/track/)、[实例分割](https://docs.ultralytics.com/tasks/segment/)、[图像分类](https://docs.ultralytics.com/tasks/classify/)和[姿态估计](https://docs.ultralytics.com/tasks/pose/)任务中表现出色。 + +在 [Ultralytics 文档](https://docs.ultralytics.com/)中查找详细文档。通过 [GitHub Issues](https://github.com/ultralytics/ultralytics/issues/new/choose) 获取支持。加入 [Discord](https://discord.com/invite/ultralytics)、[Reddit](https://www.reddit.com/r/ultralytics/) 和 [Ultralytics 社区论坛](https://community.ultralytics.com/)参与讨论! + +如需商业用途,请在 [Ultralytics 授权许可](https://www.ultralytics.com/license)申请企业许可证。 + + + YOLO11 performance plots + + +
+ Ultralytics GitHub + space + Ultralytics LinkedIn + space + Ultralytics Twitter + space + Ultralytics YouTube + space + Ultralytics TikTok + space + Ultralytics BiliBili + space + Ultralytics Discord +
+ +## 📄 文档 + +请参阅下文了解快速安装和使用示例。有关训练、验证、预测和部署的全面指南,请参阅我们的完整 [Ultralytics 文档](https://docs.ultralytics.com/)。 + +
+安装 + +在 [**Python>=3.8**](https://www.python.org/) 环境中安装 `ultralytics` 包,包括所有[依赖项](https://github.com/ultralytics/ultralytics/blob/main/pyproject.toml),并确保 [**PyTorch>=1.8**](https://pytorch.org/get-started/locally/)。 + +[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics/) [![Ultralytics Downloads](https://static.pepy.tech/badge/ultralytics)](https://clickpy.clickhouse.com/dashboard/ultralytics) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics/) + +```bash +pip install ultralytics +``` + +有关其他安装方法,包括 [Conda](https://anaconda.org/conda-forge/ultralytics)、[Docker](https://hub.docker.com/r/ultralytics/ultralytics) 以及通过 Git 从源代码构建,请查阅[快速入门指南](https://docs.ultralytics.com/quickstart/)。 + +[![Conda Version](https://img.shields.io/conda/vn/conda-forge/ultralytics?logo=condaforge)](https://anaconda.org/conda-forge/ultralytics) [![Docker Image Version](https://img.shields.io/docker/v/ultralytics/ultralytics?sort=semver&logo=docker)](https://hub.docker.com/r/ultralytics/ultralytics) [![Ultralytics Docker Pulls](https://img.shields.io/docker/pulls/ultralytics/ultralytics?logo=docker)](https://hub.docker.com/r/ultralytics/ultralytics) + +
+ +
+使用方法 + +### CLI + +您可以直接通过命令行界面 (CLI) 使用 `yolo` 命令来运行 Ultralytics YOLO: + +```bash +# 使用预训练的 YOLO 模型 (例如 YOLO11n) 对图像进行预测 +yolo predict model=yolo11n.pt source='https://ultralytics.com/images/bus.jpg' +``` + +`yolo` 命令支持各种任务和模式,并接受额外的参数,如 `imgsz=640`。浏览 YOLO [CLI 文档](https://docs.ultralytics.com/usage/cli/)获取更多示例。 + +### Python + +Ultralytics YOLO 也可以直接集成到您的 Python 项目中。它接受与 CLI 相同的[配置参数](https://docs.ultralytics.com/usage/cfg/): + +```python +from ultralytics import YOLO + +# 加载一个预训练的 YOLO11n 模型 +model = YOLO("yolo11n.pt") + +# 在 COCO8 数据集上训练模型 100 个周期 +train_results = model.train( + data="coco8.yaml", # 数据集配置文件路径 + epochs=100, # 训练周期数 + imgsz=640, # 训练图像尺寸 + device="cpu", # 运行设备 (例如 'cpu', 0, [0,1,2,3]) +) + +# 评估模型在验证集上的性能 +metrics = model.val() + +# 对图像执行目标检测 +results = model("path/to/image.jpg") # 对图像进行预测 +results[0].show() # 显示结果 + +# 将模型导出为 ONNX 格式以进行部署 +path = model.export(format="onnx") # 返回导出模型的路径 +``` + +在 YOLO [Python 文档](https://docs.ultralytics.com/usage/python/)中发现更多示例。 + +
+ +## ✨ 模型 + +Ultralytics 支持广泛的 YOLO 模型,从早期的版本如 [YOLOv3](https://docs.ultralytics.com/models/yolov3/) 到最新的 [YOLO11](https://docs.ultralytics.com/models/yolo11/)。下表展示了在 [COCO](https://docs.ultralytics.com/datasets/detect/coco/) 数据集上预训练的 YOLO11 模型,用于[检测](https://docs.ultralytics.com/tasks/detect/)、[分割](https://docs.ultralytics.com/tasks/segment/)和[姿态估计](https://docs.ultralytics.com/tasks/pose/)任务。此外,还提供了在 [ImageNet](https://docs.ultralytics.com/datasets/classify/imagenet/) 数据集上预训练的[分类](https://docs.ultralytics.com/tasks/classify/)模型。[跟踪](https://docs.ultralytics.com/modes/track/)模式与所有检测、分割和姿态模型兼容。所有[模型](https://docs.ultralytics.com/models/)在首次使用时都会自动从最新的 Ultralytics [发布版本](https://github.com/ultralytics/assets/releases)下载。 + + + Ultralytics YOLO supported tasks + +
+
+ +
检测 (COCO) + +浏览[检测文档](https://docs.ultralytics.com/tasks/detect/)获取使用示例。这些模型在 [COCO 数据集](https://cocodataset.org/)上训练,包含 80 个对象类别。 + +| 模型 | 尺寸
(像素) | mAPval
50-95 | 速度
CPU ONNX
(毫秒) | 速度
T4 TensorRT10
(毫秒) | 参数
(百万) | FLOPs
(十亿) | +| ------------------------------------------------------------------------------------ | ------------------- | -------------------- | ------------------------------- | ------------------------------------ | ------------------- | -------------------- | +| [YOLO11n](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt) | 640 | 39.5 | 56.1 ± 0.8 | 1.5 ± 0.0 | 2.6 | 6.5 | +| [YOLO11s](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s.pt) | 640 | 47.0 | 90.0 ± 1.2 | 2.5 ± 0.0 | 9.4 | 21.5 | +| [YOLO11m](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m.pt) | 640 | 51.5 | 183.2 ± 2.0 | 4.7 ± 0.1 | 20.1 | 68.0 | +| [YOLO11l](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l.pt) | 640 | 53.4 | 238.6 ± 1.4 | 6.2 ± 0.1 | 25.3 | 86.9 | +| [YOLO11x](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x.pt) | 640 | 54.7 | 462.8 ± 6.7 | 11.3 ± 0.2 | 56.9 | 194.9 | + +- **mAPval** 值指的是在 [COCO val2017](https://cocodataset.org/) 数据集上的单模型单尺度性能。详见 [YOLO 性能指标](https://docs.ultralytics.com/guides/yolo-performance-metrics/)。
使用 `yolo val detect data=coco.yaml device=0` 复现结果。 +- **速度** 指标是在 [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) 实例上对 COCO val 图像进行平均测量的。CPU 速度使用 [ONNX](https://onnx.ai/) 导出进行测量。GPU 速度使用 [TensorRT](https://developer.nvidia.com/tensorrt) 导出进行测量。
使用 `yolo val detect data=coco.yaml batch=1 device=0|cpu` 复现结果。 + +
+ +
分割 (COCO) + +请参阅[分割文档](https://docs.ultralytics.com/tasks/segment/)获取使用示例。这些模型在 [COCO-Seg](https://docs.ultralytics.com/datasets/segment/coco/) 数据集上训练,包含 80 个类别。 + +| 模型 | 尺寸
(像素) | mAPbox
50-95 | mAPmask
50-95 | 速度
CPU ONNX
(毫秒) | 速度
T4 TensorRT10
(毫秒) | 参数
(百万) | FLOPs
(十亿) | +| -------------------------------------------------------------------------------------------- | ------------------- | -------------------- | --------------------- | ------------------------------- | ------------------------------------ | ------------------- | -------------------- | +| [YOLO11n-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-seg.pt) | 640 | 38.9 | 32.0 | 65.9 ± 1.1 | 1.8 ± 0.0 | 2.9 | 9.7 | +| [YOLO11s-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-seg.pt) | 640 | 46.6 | 37.8 | 117.6 ± 4.9 | 2.9 ± 0.0 | 10.1 | 33.0 | +| [YOLO11m-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-seg.pt) | 640 | 51.5 | 41.5 | 281.6 ± 1.2 | 6.3 ± 0.1 | 22.4 | 113.2 | +| [YOLO11l-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-seg.pt) | 640 | 53.4 | 42.9 | 344.2 ± 3.2 | 7.8 ± 0.2 | 27.6 | 132.2 | +| [YOLO11x-seg](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-seg.pt) | 640 | 54.7 | 43.8 | 664.5 ± 3.2 | 15.8 ± 0.7 | 62.1 | 296.4 | + +- **mAPval** 值指的是在 [COCO val2017](https://cocodataset.org/) 数据集上的单模型单尺度性能。详见 [YOLO 性能指标](https://docs.ultralytics.com/guides/yolo-performance-metrics/)。
使用 `yolo val segment data=coco.yaml device=0` 复现结果。 +- **速度** 指标是在 [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) 实例上对 COCO val 图像进行平均测量的。CPU 速度使用 [ONNX](https://onnx.ai/) 导出进行测量。GPU 速度使用 [TensorRT](https://developer.nvidia.com/tensorrt) 导出进行测量。
使用 `yolo val segment data=coco.yaml batch=1 device=0|cpu` 复现结果。 + +
+ +
分类 (ImageNet) + +请查阅[分类文档](https://docs.ultralytics.com/tasks/classify/)获取使用示例。这些模型在 [ImageNet](https://docs.ultralytics.com/datasets/classify/imagenet/) 数据集上训练,涵盖 1000 个类别。 + +| 模型 | 尺寸
(像素) | acc
top1 | acc
top5 | 速度
CPU ONNX
(毫秒) | 速度
T4 TensorRT10
(毫秒) | 参数
(百万) | FLOPs
(十亿) @ 224 | +| -------------------------------------------------------------------------------------------- | ------------------- | ---------------- | ---------------- | ------------------------------- | ------------------------------------ | ------------------- | -------------------------- | +| [YOLO11n-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-cls.pt) | 224 | 70.0 | 89.4 | 5.0 ± 0.3 | 1.1 ± 0.0 | 2.8 | 0.5 | +| [YOLO11s-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-cls.pt) | 224 | 75.4 | 92.7 | 7.9 ± 0.2 | 1.3 ± 0.0 | 6.7 | 1.6 | +| [YOLO11m-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-cls.pt) | 224 | 77.3 | 93.9 | 17.2 ± 0.4 | 2.0 ± 0.0 | 11.6 | 4.9 | +| [YOLO11l-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-cls.pt) | 224 | 78.3 | 94.3 | 23.2 ± 0.3 | 2.8 ± 0.0 | 14.1 | 6.2 | +| [YOLO11x-cls](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-cls.pt) | 224 | 79.5 | 94.9 | 41.4 ± 0.9 | 3.8 ± 0.0 | 29.6 | 13.6 | + +- **acc** 值表示模型在 [ImageNet](https://www.image-net.org/) 数据集验证集上的准确率。
使用 `yolo val classify data=path/to/ImageNet device=0` 复现结果。 +- **速度** 指标是在 [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) 实例上对 ImageNet val 图像进行平均测量的。CPU 速度使用 [ONNX](https://onnx.ai/) 导出进行测量。GPU 速度使用 [TensorRT](https://developer.nvidia.com/tensorrt) 导出进行测量。
使用 `yolo val classify data=path/to/ImageNet batch=1 device=0|cpu` 复现结果。 + +
+ +
姿态估计 (COCO) + +请参阅[姿态估计文档](https://docs.ultralytics.com/tasks/pose/)获取使用示例。这些模型在 [COCO-Pose](https://docs.ultralytics.com/datasets/pose/coco/) 数据集上训练,专注于 'person' 类别。 + +| 模型 | 尺寸
(像素) | mAPpose
50-95 | mAPpose
50 | 速度
CPU ONNX
(毫秒) | 速度
T4 TensorRT10
(毫秒) | 参数
(百万) | FLOPs
(十亿) | +| ---------------------------------------------------------------------------------------------- | ------------------- | --------------------- | ------------------ | ------------------------------- | ------------------------------------ | ------------------- | -------------------- | +| [YOLO11n-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-pose.pt) | 640 | 50.0 | 81.0 | 52.4 ± 0.5 | 1.7 ± 0.0 | 2.9 | 7.4 | +| [YOLO11s-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-pose.pt) | 640 | 58.9 | 86.3 | 90.5 ± 0.6 | 2.6 ± 0.0 | 9.9 | 23.1 | +| [YOLO11m-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-pose.pt) | 640 | 64.9 | 89.4 | 187.3 ± 0.8 | 4.9 ± 0.1 | 20.9 | 71.4 | +| [YOLO11l-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-pose.pt) | 640 | 66.1 | 89.9 | 247.7 ± 1.1 | 6.4 ± 0.1 | 26.1 | 90.3 | +| [YOLO11x-pose](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-pose.pt) | 640 | 69.5 | 91.1 | 488.0 ± 13.9 | 12.1 ± 0.2 | 58.8 | 202.8 | + +- **mAPval** 值指的是在 [COCO Keypoints val2017](https://docs.ultralytics.com/datasets/pose/coco/) 数据集上的单模型单尺度性能。详见 [YOLO 性能指标](https://docs.ultralytics.com/guides/yolo-performance-metrics/)。
使用 `yolo val pose data=coco-pose.yaml device=0` 复现结果。 +- **速度** 指标是在 [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) 实例上对 COCO val 图像进行平均测量的。CPU 速度使用 [ONNX](https://onnx.ai/) 导出进行测量。GPU 速度使用 [TensorRT](https://developer.nvidia.com/tensorrt) 导出进行测量。
使用 `yolo val pose data=coco-pose.yaml batch=1 device=0|cpu` 复现结果。 + +
+ +
定向边界框 (DOTAv1) + +请查阅 [OBB 文档](https://docs.ultralytics.com/tasks/obb/)获取使用示例。这些模型在 [DOTAv1](https://docs.ultralytics.com/datasets/obb/dota-v2/#dota-v10) 数据集上训练,包含 15 个类别。 + +| 模型 | 尺寸
(像素) | mAPtest
50 | 速度
CPU ONNX
(毫秒) | 速度
T4 TensorRT10
(毫秒) | 参数
(百万) | FLOPs
(十亿) | +| -------------------------------------------------------------------------------------------- | ------------------- | ------------------ | ------------------------------- | ------------------------------------ | ------------------- | -------------------- | +| [YOLO11n-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n-obb.pt) | 1024 | 78.4 | 117.6 ± 0.8 | 4.4 ± 0.0 | 2.7 | 16.8 | +| [YOLO11s-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-obb.pt) | 1024 | 79.5 | 219.4 ± 4.0 | 5.1 ± 0.0 | 9.7 | 57.1 | +| [YOLO11m-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m-obb.pt) | 1024 | 80.9 | 562.8 ± 2.9 | 10.1 ± 0.4 | 20.9 | 182.8 | +| [YOLO11l-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l-obb.pt) | 1024 | 81.0 | 712.5 ± 5.0 | 13.5 ± 0.6 | 26.1 | 231.2 | +| [YOLO11x-obb](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x-obb.pt) | 1024 | 81.3 | 1408.6 ± 7.7 | 28.6 ± 1.0 | 58.8 | 519.1 | + +- **mAPtest** 值指的是在 [DOTAv1 测试集](https://captain-whu.github.io/DOTA/dataset.html)上的单模型多尺度性能。
通过 `yolo val obb data=DOTAv1.yaml device=0 split=test` 复现结果,并将合并后的结果提交到 [DOTA 评估服务器](https://captain-whu.github.io/DOTA/evaluation.html)。 +- **速度** 指标是在 [Amazon EC2 P4d](https://aws.amazon.com/ec2/instance-types/p4/) 实例上对 [DOTAv1 val 图像](https://docs.ultralytics.com/datasets/obb/dota-v2/#dota-v10)进行平均测量的。CPU 速度使用 [ONNX](https://onnx.ai/) 导出进行测量。GPU 速度使用 [TensorRT](https://developer.nvidia.com/tensorrt) 导出进行测量。
通过 `yolo val obb data=DOTAv1.yaml batch=1 device=0|cpu` 复现结果。 + +
+ +## 🧩 集成 + +我们与领先 AI 平台的关键集成扩展了 Ultralytics 产品的功能,增强了数据集标注、训练、可视化和模型管理等任务。了解 Ultralytics 如何与 [Weights & Biases](https://docs.ultralytics.com/integrations/weights-biases/)、[Comet ML](https://docs.ultralytics.com/integrations/comet/)、[Roboflow](https://docs.ultralytics.com/integrations/roboflow/) 和 [Intel OpenVINO](https://docs.ultralytics.com/integrations/openvino/) 等合作伙伴协作,优化您的 AI 工作流程。在 [Ultralytics 集成](https://docs.ultralytics.com/integrations/)了解更多信息。 + + + Ultralytics active learning integrations + +
+
+ +
+ + Ultralytics HUB logo + space + + Weights & Biases logo + space + + Comet ML logo + space + + Neural Magic logo +
+ +| Ultralytics HUB 🌟 | Weights & Biases | Comet | Neural Magic | +| :-----------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------: | +| 简化 YOLO 工作流程:使用 [Ultralytics HUB](https://hub.ultralytics.com/) 轻松进行标注、训练和部署。立即试用! | 使用 [Weights & Biases](https://docs.ultralytics.com/integrations/weights-biases/) 跟踪实验、超参数和结果。 | 永久免费的 [Comet ML](https://docs.ultralytics.com/integrations/comet/) 让您能够保存 YOLO 模型、恢复训练并交互式地可视化预测结果。 | 使用 [Neural Magic DeepSparse](https://docs.ultralytics.com/integrations/neural-magic/),将 YOLO 推理速度提高多达 6 倍。 | + +## 🌟 Ultralytics HUB + +通过 [Ultralytics HUB](https://hub.ultralytics.com/) 体验无缝 AI,这是一个集数据可视化、训练 YOLO 模型和部署于一体的平台——无需编码。使用我们尖端的平台和用户友好的 [Ultralytics App](https://www.ultralytics.com/app-install),轻松将图像转化为可操作的见解,并将您的 AI 愿景变为现实。立即**免费**开始您的旅程! + + +Ultralytics HUB preview image + +## 🤝 贡献 + +我们依靠社区协作蓬勃发展!没有像您这样的开发者的贡献,Ultralytics YOLO 就不会成为如今最先进的框架。请参阅我们的[贡献指南](https://docs.ultralytics.com/help/contributing/)开始贡献。我们也欢迎您的反馈——通过完成我们的[调查问卷](https://www.ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey)分享您的体验。非常**感谢** 🙏 每一位贡献者! + + + +[![Ultralytics open-source contributors](https://raw.githubusercontent.com/ultralytics/assets/main/im/image-contributors.png)](https://github.com/ultralytics/ultralytics/graphs/contributors) + +我们期待您的贡献,帮助 Ultralytics 生态系统变得更好! + +## 📜 许可证 + +Ultralytics 提供两种许可选项以满足不同需求: + +- **AGPL-3.0 许可证**:这种经 [OSI 批准](https://opensource.org/license/agpl-v3)的开源许可证非常适合学生、研究人员和爱好者。它鼓励开放协作和知识共享。有关完整详细信息,请参阅 [LICENSE](https://github.com/ultralytics/ultralytics/blob/main/LICENSE) 文件。 +- **Ultralytics 企业许可证**:专为商业用途设计,此许可证允许将 Ultralytics 软件和 AI 模型无缝集成到商业产品和服务中,绕过 AGPL-3.0 的开源要求。如果您的使用场景涉及商业部署,请通过 [Ultralytics 授权许可](https://www.ultralytics.com/license)与我们联系。 + +## 📞 联系方式 + +有关 Ultralytics 软件的错误报告和功能请求,请访问 [GitHub Issues](https://github.com/ultralytics/ultralytics/issues)。如有疑问、讨论和社区支持,请加入我们在 [Discord](https://discord.com/invite/ultralytics)、[Reddit](https://www.reddit.com/r/ultralytics/?rdt=44154) 和 [Ultralytics 社区论坛](https://community.ultralytics.com/)上的活跃社区。我们随时为您提供有关 Ultralytics 的所有帮助! + +
+
+ Ultralytics GitHub + space + Ultralytics LinkedIn + space + Ultralytics Twitter + space + Ultralytics YouTube + space + Ultralytics TikTok + space + Ultralytics BiliBili + space + Ultralytics Discord +
diff --git a/ultralytics-main/docker/Dockerfile b/ultralytics-main/docker/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d4121046abe036cddca2d006a8903dca9f2178c0 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile @@ -0,0 +1,81 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Image is CUDA-optimized for YOLO single/multi-GPU training and inference + +# Start FROM PyTorch image https://hub.docker.com/r/pytorch/pytorch or nvcr.io/nvidia/pytorch:25.02-py3 +FROM pytorch/pytorch:2.9.1-cuda12.8-cudnn9-runtime + +# Set environment variables +# Avoid DDP error "MKL_THREADING_LAYER=INTEL is incompatible with libgomp.so.1 library" +# Suppress TensorFlow cuDNN, cuBLAS, and cuFFT Registration Warnings +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=1 \ + PIP_BREAK_SYSTEM_PACKAGES=1 \ + MKL_THREADING_LAYER=GNU \ + OMP_NUM_THREADS=1 \ + TF_CPP_MIN_LOG_LEVEL=3 + +# Downloads to user config dir +ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \ + /root/.config/Ultralytics/ + +# Install linux packages +# gnupg required for Edge TPU install +# libsm6 required by libqxcb to create QT-based windows for visualization; set 'QT_DEBUG_PLUGINS=1' to test in docker +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc git zip unzip wget curl htop libgl1 libglib2.0-0 gnupg libsm6 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Create working directory +WORKDIR /ultralytics + +# Copy contents and configure git +COPY . . +RUN sed -i '/^\[http "https:\/\/github\.com\/"\]/,+1d' .git/config && \ + sed -i'' -e 's/"opencv-python/"opencv-python-headless/' pyproject.toml +ADD https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt . + +# Install pip packages +RUN uv pip install --system -e "." albumentations faster-coco-eval wandb && \ + # Remove extra build files \ + rm -rf tmp /root/.config/Ultralytics/persistent_cache.json + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest && sudo docker build -f docker/Dockerfile -t $t . && sudo docker push $t + +# Pull and Run with access to all GPUs +# t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all $t + +# Pull and Run with access to GPUs 2 and 3 (inside container CUDA devices will appear as 0 and 1) +# t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus '"device=2,3"' $t + +# Pull and Run with local directory access +# t=ultralytics/ultralytics:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all -v "$(pwd)"/shared/datasets:/datasets $t + +# Kill all +# sudo docker kill $(sudo docker ps -q) + +# Kill all image-based +# sudo docker kill $(sudo docker ps -qa --filter ancestor=ultralytics/ultralytics:latest) + +# DockerHub tag update +# t=ultralytics/ultralytics:latest tnew=ultralytics/ultralytics:v6.2 && sudo docker pull $t && sudo docker tag $t $tnew && sudo docker push $tnew + +# Clean up +# sudo docker system prune -a --volumes + +# Update Ubuntu drivers +# https://www.maketecheasier.com/install-nvidia-drivers-ubuntu/ + +# DDP test +# python -m torch.distributed.run --nproc_per_node 2 --master_port 1 train.py --epochs 3 + +# GCP VM from Image +# docker.io/ultralytics/ultralytics:latest diff --git a/ultralytics-main/docker/Dockerfile-arm64 b/ultralytics-main/docker/Dockerfile-arm64 new file mode 100644 index 0000000000000000000000000000000000000000..a8a9e26964155c4df32c424a2b5fb7b91d8f1adf --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-arm64 @@ -0,0 +1,61 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-arm64 image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Image is aarch64-compatible for Apple M1, M2, M3, Raspberry Pi and other ARM architectures + +# Start FROM Ubuntu image https://hub.docker.com/_/ubuntu with "FROM arm64v8/ubuntu:22.04" (deprecated) +# Start FROM Debian image for arm64v8 https://hub.docker.com/r/arm64v8/debian (deprecated) +# Start FROM official arm64v8 Ubuntu 24.04 image https://hub.docker.com/layers/arm64v8/ubuntu/24.04/ +FROM arm64v8/ubuntu:24.04 + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=1 \ + PIP_BREAK_SYSTEM_PACKAGES=1 + +# Downloads to user config dir +ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \ + /root/.config/Ultralytics/ + +# Install linux packages +# pkg-config and libhdf5-dev (not included) are needed to build 'h5py==3.11.0' aarch64 wheel required by 'tensorflow' +# gnupg required for Edge TPU install +RUN apt update && \ + apt upgrade -y && \ + apt install -y --no-install-recommends \ + python3-pip git zip unzip wget curl htop gcc libgl1 libglib2.0-0 gnupg && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +# Create working directory +WORKDIR /ultralytics + +# Copy contents and configure git +COPY . . +RUN sed -i '/^\[http "https:\/\/github\.com\/"\]/,+1d' .git/config && \ + sed -i'' -e 's/"opencv-python/"opencv-python-headless/' pyproject.toml +ADD https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt . + +# Install pip packages, create python symlink, and remove build files +RUN pip install uv && \ + uv pip install --system -e ".[export]" --break-system-packages && \ + # Creates a symbolic link to make 'python' point to 'python3' + ln -sf /usr/bin/python3 /usr/bin/python && \ + # Remove extra build files + rm -rf /root/.config/Ultralytics/persistent_cache.json + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-arm64 && sudo docker build --platform linux/arm64 -f docker/Dockerfile-arm64 -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-arm64 && sudo docker run -it --ipc=host $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-arm64 && sudo docker pull $t && sudo docker run -it --ipc=host $t + +# Pull and Run with local volume mounted +# t=ultralytics/ultralytics:latest-arm64 && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t diff --git a/ultralytics-main/docker/Dockerfile-conda b/ultralytics-main/docker/Dockerfile-conda new file mode 100644 index 0000000000000000000000000000000000000000..33c014cd03a30d11bd6523e9cf75dd0daed391c0 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-conda @@ -0,0 +1,46 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-conda image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Image is optimized for Ultralytics Anaconda (https://anaconda.org/conda-forge/ultralytics) installation and usage + +# Start FROM miniconda3 image https://hub.docker.com/r/continuumio/miniconda3 +FROM continuumio/miniconda3:latest + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=1 \ + PIP_BREAK_SYSTEM_PACKAGES=1 + +# Downloads to user config dir +ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \ + /root/.config/Ultralytics/ + +# Install linux packages and conda packages +RUN apt-get update && \ + apt-get install -y --no-install-recommends libgl1 && \ + # Install conda packages + # mkl required to fix 'OSError: libmkl_intel_lp64.so.2: cannot open shared object file: No such file or directory' + conda config --set solver libmamba && \ + conda install pytorch torchvision pytorch-cuda=12.1 -c pytorch -c nvidia && \ + conda install -c conda-forge ultralytics mkl && \ + # Remove extra build files + rm -rf /var/lib/apt/lists/* /root/.config/Ultralytics/persistent_cache.json + +# Copy model +ADD https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt . + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-conda && sudo docker build -f docker/Dockerfile-conda -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-conda && sudo docker run -it --ipc=host $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-conda && sudo docker pull $t && sudo docker run -it --ipc=host $t + +# Pull and Run with local volume mounted +# t=ultralytics/ultralytics:latest-conda && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t diff --git a/ultralytics-main/docker/Dockerfile-cpu b/ultralytics-main/docker/Dockerfile-cpu new file mode 100644 index 0000000000000000000000000000000000000000..a6911a7ccd25b2ab3835b760e65834ec3812a306 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-cpu @@ -0,0 +1,24 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-cpu image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Lightweight CPU image optimized for inference (extends latest-python) + +# Build from Ultralytics Python image +FROM ultralytics/ultralytics:latest-python + +# Set default command to bash +CMD ["/bin/bash"] + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-cpu && sudo docker build -f docker/Dockerfile-cpu -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-cpu && sudo docker run -it --ipc=host --name NAME $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host --name NAME $t + +# Pull and Run with local volume mounted +# t=ultralytics/ultralytics:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t diff --git a/ultralytics-main/docker/Dockerfile-export b/ultralytics-main/docker/Dockerfile-export new file mode 100644 index 0000000000000000000000000000000000000000..a03971f02fed1dbcfd115b6bfcfda88847092ac9 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-export @@ -0,0 +1,16 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Export-optimized derivative of ultralytics/ultralytics:latest for testing and benchmarks +# Includes all export format dependencies and pre-installed export packages + +FROM ultralytics/ultralytics:latest + +# Install export dependencies and run exports to AutoInstall packages +# Numpy 1.26.4 required due to TF export bug with torch 2.8 +# Note tensorrt installed on-demand as depends on runtime environment CUDA version +RUN uv pip install --system -e ".[export]" "onnxruntime-gpu" paddlepaddle x2paddle numpy==1.26.4 && \ + # Run exports to AutoInstall packages \ + yolo export model=tmp/yolo11n.pt format=edgetpu imgsz=32 && \ + yolo export model=tmp/yolo11n.pt format=ncnn imgsz=32 && \ + # Remove temporary files \ + rm -rf tmp /root/.config/Ultralytics/persistent_cache.json diff --git a/ultralytics-main/docker/Dockerfile-jetson-jetpack4 b/ultralytics-main/docker/Dockerfile-jetson-jetpack4 new file mode 100644 index 0000000000000000000000000000000000000000..f9b9a77220cb0b08a5b7620fba61c55c4ac35f76 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-jetson-jetpack4 @@ -0,0 +1,73 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-jetson-jetpack4 image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Supports JetPack4.x for YOLO on Jetson Nano, TX2, Xavier NX, AGX Xavier + +# Start FROM https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-cuda +FROM nvcr.io/nvidia/l4t-cuda:10.2.460-runtime + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 + +# Downloads to user config dir +ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \ + /root/.config/Ultralytics/ + +# Add NVIDIA repositories for TensorRT dependencies +RUN wget -q -O - https://repo.download.nvidia.com/jetson/jetson-ota-public.asc | apt-key add - && \ + echo "deb https://repo.download.nvidia.com/jetson/common r32.7 main" > /etc/apt/sources.list.d/nvidia-l4t-apt-source.list && \ + echo "deb https://repo.download.nvidia.com/jetson/t194 r32.7 main" >> /etc/apt/sources.list.d/nvidia-l4t-apt-source.list + +# Install dependencies +# pkg-config and libhdf5-dev (not included) are needed to build 'h5py==3.11.0' aarch64 wheel required by 'tensorflow' +# gnupg required for Edge TPU install +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + git python3.8 python3.8-dev python3-pip python3-libnvinfer libopenmpi-dev libopenblas-base libomp-dev gcc \ + && rm -rf /var/lib/apt/lists/* + +# Create symbolic links for python3.8 and pip3 +RUN ln -sf /usr/bin/python3.8 /usr/bin/python3 && \ + ln -s /usr/bin/pip3 /usr/bin/pip + +# Create working directory +WORKDIR /ultralytics + +# Copy contents and configure git +COPY . . +RUN sed -i '/^\[http "https:\/\/github\.com\/"\]/,+1d' .git/config && \ + sed -i'' -e 's/"opencv-python/"opencv-python-headless/' pyproject.toml +ADD https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt . + +# Replace pyproject.toml TF.js version with 'tensorflowjs>=3.9.0' for JetPack4 compatibility +RUN sed -i 's/^\( *"tensorflowjs\)>=.*\(".*\)/\1>=3.9.0\2/' pyproject.toml + +# Install pip packages (pip must be upgraded first before installing uv due to missing setuptools) +RUN python3 -m pip install --upgrade pip && \ + python3 -m pip install uv +# Install pip packages and remove extra build files +# Onnxruntime and TensorRT from https://elinux.org/Jetson_Zoo and https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048 +RUN uv pip install --system \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.8.0-cp38-cp38-linux_aarch64.whl \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/tensorrt-8.2.0.6-cp38-none-linux_aarch64.whl \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-1.11.0a0+gitbc2c6ed-cp38-cp38-linux_aarch64.whl \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/torchvision-0.12.0a0+9b5a3fe-cp38-cp38-linux_aarch64.whl && \ + uv pip install --system -e ".[export]" && \ + # Remove extra build files + rm -rf *.whl /root/.config/Ultralytics/persistent_cache.json + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-jetson-jetpack4 && sudo docker build --platform linux/arm64 -f docker/Dockerfile-jetson-jetpack4 -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-jetson-jetpack4 && sudo docker run -it --ipc=host $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-jetson-jetpack4 && sudo docker pull $t && sudo docker run -it --ipc=host $t + +# Pull and Run with NVIDIA runtime +# t=ultralytics/ultralytics:latest-jetson-jetpack4 && sudo docker pull $t && sudo docker run -it --ipc=host --runtime=nvidia $t diff --git a/ultralytics-main/docker/Dockerfile-jetson-jetpack5 b/ultralytics-main/docker/Dockerfile-jetson-jetpack5 new file mode 100644 index 0000000000000000000000000000000000000000..8ec8c85499e663966ee89e575b0e7c0c2b0405d6 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-jetson-jetpack5 @@ -0,0 +1,60 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-jetson-jetpack5 image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Supports JetPack5.1.2 for YOLO on Jetson Xavier NX, AGX Xavier, AGX Orin, Orin Nano and Orin NX + +# Start FROM https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-jetpack +FROM nvcr.io/nvidia/l4t-jetpack:r35.4.1 + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=1 \ + PIP_BREAK_SYSTEM_PACKAGES=1 + +# Downloads to user config dir +ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \ + /root/.config/Ultralytics/ + +# Install dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + git python3-pip libopenmpi-dev libopenblas-base libomp-dev \ + && rm -rf /var/lib/apt/lists/* + +# Create working directory +WORKDIR /ultralytics + +# Copy contents and configure git +COPY . . +RUN sed -i '/^\[http "https:\/\/github\.com\/"\]/,+1d' .git/config && \ + sed -i'' -e 's/"opencv-python/"opencv-python-headless/' pyproject.toml +ADD https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt . + +# Replace pyproject.toml TF.js version with 'tensorflowjs>=3.9.0' for JetPack5 compatibility and install packages +RUN sed -i 's/^\( *"tensorflowjs\)>=.*\(".*\)/\1>=3.9.0\2/' pyproject.toml && \ + python3 -m pip install --upgrade pip uv + +# Pip install onnxruntime-gpu, torch, torchvision and ultralytics, then remove build files +RUN uv pip install --system \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.18.0-cp38-cp38-linux_aarch64.whl \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.2.0-cp38-cp38-linux_aarch64.whl \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/torchvision-0.17.2+c1d70fe-cp38-cp38-linux_aarch64.whl && \ + uv pip install --system -e ".[export]" && \ + # Remove extra build files + rm -rf *.whl /root/.config/Ultralytics/persistent_cache.json + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-jetson-jetpack5 && sudo docker build --platform linux/arm64 -f docker/Dockerfile-jetson-jetpack5 -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-jetson-jetpack5 && sudo docker run -it --ipc=host $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-jetson-jetpack5 && sudo docker pull $t && sudo docker run -it --ipc=host $t + +# Pull and Run with NVIDIA runtime +# t=ultralytics/ultralytics:latest-jetson-jetpack5 && sudo docker pull $t && sudo docker run -it --ipc=host --runtime=nvidia $t diff --git a/ultralytics-main/docker/Dockerfile-jetson-jetpack6 b/ultralytics-main/docker/Dockerfile-jetson-jetpack6 new file mode 100644 index 0000000000000000000000000000000000000000..b4da060e9845d6c1e6e566129c7067d5d2882c10 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-jetson-jetpack6 @@ -0,0 +1,60 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-jetson-jetpack6 image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Supports JetPack6.1 for YOLO on Jetson AGX Orin, Orin NX and Orin Nano Series + +# Start FROM https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-jetpack +FROM nvcr.io/nvidia/l4t-jetpack:r36.4.0 + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=1 \ + PIP_BREAK_SYSTEM_PACKAGES=1 + +# Downloads to user config dir +ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \ + /root/.config/Ultralytics/ + +# Install dependencies and cleanup +ADD https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/arm64/cuda-keyring_1.1-1_all.deb . +RUN dpkg -i cuda-keyring_1.1-1_all.deb && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + git python3-pip libopenmpi-dev libopenblas-base libomp-dev libcusparselt0 libcusparselt-dev && \ + rm -rf /var/lib/apt/lists/* cuda-keyring_1.1-1_all.deb + +# Create working directory +WORKDIR /ultralytics + +# Copy contents and configure git +COPY . . +RUN sed -i '/^\[http "https:\/\/github\.com\/"\]/,+1d' .git/config && \ + sed -i'' -e 's/"opencv-python/"opencv-python-headless/' pyproject.toml +ADD https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt . + +# Pip install numpy, onnxruntime-gpu, torch, torchvision and ultralytics, then remove build files +RUN python3 -m pip install --upgrade pip uv && \ + uv pip install --system \ + numpy==1.26.4 \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.20.0-cp310-cp310-linux_aarch64.whl \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.5.0a0+872d972e41.nv24.08-cp310-cp310-linux_aarch64.whl \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/torchvision-0.20.0a0+afc54f7-cp310-cp310-linux_aarch64.whl && \ + uv pip install --system -e ".[export]" && \ + # Remove extra build files + rm -rf *.whl /root/.config/Ultralytics/persistent_cache.json + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-jetson-jetpack6 && sudo docker build --platform linux/arm64 -f docker/Dockerfile-jetson-jetpack6 -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-jetson-jetpack6 && sudo docker run -it --ipc=host $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-jetson-jetpack6 && sudo docker pull $t && sudo docker run -it --ipc=host $t + +# Pull and Run with NVIDIA runtime +# t=ultralytics/ultralytics:latest-jetson-jetpack6 && sudo docker pull $t && sudo docker run -it --ipc=host --runtime=nvidia $t diff --git a/ultralytics-main/docker/Dockerfile-jupyter b/ultralytics-main/docker/Dockerfile-jupyter new file mode 100644 index 0000000000000000000000000000000000000000..c11e6083eab39d59bdb4631f3cd9c6304b0b6989 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-jupyter @@ -0,0 +1,32 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-jupyter image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Image provides JupyterLab interface for interactive YOLO development and includes tutorial notebooks + +# Start from Python-based Ultralytics image for full Python environment +FROM ultralytics/ultralytics:latest-python + +# Install JupyterLab for interactive development +RUN uv pip install --system jupyterlab && \ + # Create persistent data directory structure + mkdir -p /data/{datasets,weights,runs} && \ + # Configure YOLO directories + yolo settings datasets_dir="/data/datasets" weights_dir="/data/weights" runs_dir="/data/runs" && \ + rm -rf tmp /root/.config/Ultralytics/persistent_cache.json + +# Start JupyterLab with tutorial notebook +ENTRYPOINT ["/usr/local/bin/jupyter", "lab", "--allow-root", "--ip=*", "/ultralytics/examples/tutorial.ipynb"] + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-jupyter && sudo docker build -f docker/Dockerfile-jupyter -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-jupyter && sudo docker run -it --ipc=host -p 8888:8888 $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-jupyter && sudo docker pull $t && sudo docker run -it --ipc=host -p 8888:8888 $t + +# Pull and Run with local volume mounted +# t=ultralytics/ultralytics:latest-jupyter && sudo docker pull $t && sudo docker run -it --ipc=host -p 8888:8888 -v "$(pwd)"/datasets:/data/datasets $t diff --git a/ultralytics-main/docker/Dockerfile-python b/ultralytics-main/docker/Dockerfile-python new file mode 100644 index 0000000000000000000000000000000000000000..9d2afc80204c3c1d6c3d69fcff5d62c3dc07da48 --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-python @@ -0,0 +1,54 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-python image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Lightweight CPU image optimized for YOLO inference + +# Use official Python base image for reproducibility (3.11.10 for export and 3.12.10 for inference) +FROM python:3.11.10-slim-bookworm + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=1 \ + PIP_BREAK_SYSTEM_PACKAGES=1 + +# Downloads to user config dir +ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \ + https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \ + /root/.config/Ultralytics/ + +# Install linux packages +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + python3-pip git zip unzip wget curl htop libgl1 libglib2.0-0 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Create working directory +WORKDIR /ultralytics + +# Copy contents and configure git +COPY . . +RUN sed -i '/^\[http "https:\/\/github\.com\/"\]/,+1d' .git/config && \ + sed -i'' -e 's/"opencv-python/"opencv-python-headless/' pyproject.toml +ADD https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt . + +# Install pip packages +RUN pip install uv && \ + uv pip install --system -e . --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match && \ + # Remove extra build files + rm -rf tmp ~/.cache /root/.config/Ultralytics/persistent_cache.json + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-python && sudo docker build -f docker/Dockerfile-python -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-python && sudo docker run -it --ipc=host $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-python && sudo docker pull $t && sudo docker run -it --ipc=host $t + +# Pull and Run with local volume mounted +# t=ultralytics/ultralytics:latest-python && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t diff --git a/ultralytics-main/docker/Dockerfile-python-export b/ultralytics-main/docker/Dockerfile-python-export new file mode 100644 index 0000000000000000000000000000000000000000..fca3639e73ba95ea622df28b5957753b3989d45a --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-python-export @@ -0,0 +1,43 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds ultralytics/ultralytics:latest-python-export image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Full-featured image with export capabilities for YOLO model conversion + +# Build from lightweight Ultralytics Python image +FROM ultralytics/ultralytics:latest-python + +# Install export-specific system packages +# gnupg required for Edge TPU install +# Java runtime environment (default-jre-headless) required for Sony IMX export +RUN apt-get update && \ + apt-get install -y --no-install-recommends gnupg default-jre-headless && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install export dependencies and run exports to AutoInstall packages +# Prevent torch upgrade to 2.9.0 which has issues with imx export +RUN sed -i -e 's/"torch>=1.8.0/"torch>=1.8.0,<=2.8.0/' pyproject.toml +RUN uv pip install --system -e ".[export]" && \ + # Need lower version of 'numpy' for Sony IMX export + uv pip install --system numpy==1.26.4 && \ + # Run exports to AutoInstall packages + yolo export model=tmp/yolo11n.pt format=edgetpu imgsz=32 && \ + yolo export model=tmp/yolo11n.pt format=ncnn imgsz=32 && \ + yolo export model=tmp/yolo11n.pt format=imx imgsz=32 && \ + uv pip install --system paddlepaddle x2paddle && \ + # Remove extra build files + rm -rf tmp /root/.config/Ultralytics/persistent_cache.json + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-python-export && sudo docker build -f docker/Dockerfile-python-export -t $t . && sudo docker push $t + +# Run +# t=ultralytics/ultralytics:latest-python-export && sudo docker run -it --ipc=host $t + +# Pull and Run +# t=ultralytics/ultralytics:latest-python-export && sudo docker pull $t && sudo docker run -it --ipc=host $t + +# Pull and Run with local volume mounted +# t=ultralytics/ultralytics:latest-python-export && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/shared/datasets:/datasets $t diff --git a/ultralytics-main/docker/Dockerfile-runner b/ultralytics-main/docker/Dockerfile-runner new file mode 100644 index 0000000000000000000000000000000000000000..9075cb5aa5b8ace2fb650df3bf4d37ad08ff61ca --- /dev/null +++ b/ultralytics-main/docker/Dockerfile-runner @@ -0,0 +1,36 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Builds GitHub actions CI runner image for deployment to DockerHub https://hub.docker.com/r/ultralytics/ultralytics +# Image is CUDA-optimized for YOLO single/multi-GPU training and inference tests + +# Start FROM Ultralytics GPU image +FROM ultralytics/ultralytics:latest + +# Set additional environment variables for runner +ARG RUNNER_VERSION=2.329.0 +ENV RUNNER_ALLOW_RUNASROOT=1 \ + DEBIAN_FRONTEND=noninteractive + +# Set the working directory +WORKDIR /actions-runner + +# Download and unpack the latest runner from https://github.com/actions/runner and install dependencies +RUN FILENAME=actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz && \ + curl -o "$FILENAME" -L "https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/${FILENAME}" && \ + tar xzf "$FILENAME" && \ + rm "$FILENAME" && \ + # Install runner dependencies \ + uv pip install --system pytest-cov && \ + ./bin/installdependencies.sh && \ + apt-get -y install libicu-dev + +# JSON ENTRYPOINT command to configure and start runner with default TOKEN and NAME +ENTRYPOINT ["sh", "-c", "./config.sh --url https://github.com/ultralytics/ultralytics --token ${GITHUB_RUNNER_TOKEN:-TOKEN} --name ${GITHUB_RUNNER_NAME:-NAME} --labels gpu-latest --replace && ./run.sh"] + +# Usage Examples ------------------------------------------------------------------------------------------------------- + +# Build and Push +# t=ultralytics/ultralytics:latest-runner && sudo docker build -f docker/Dockerfile-runner -t $t . && sudo docker push $t + +# Pull and Run in detached mode with access to GPUs 0 and 1 +# t=ultralytics/ultralytics:latest-runner && sudo docker run -d -e GITHUB_RUNNER_TOKEN=TOKEN -e GITHUB_RUNNER_NAME=NAME --ipc=host --gpus '"device=0,1"' $t diff --git a/ultralytics-main/docs/README.md b/ultralytics-main/docs/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ff7c862f1304b3a2b2e248f078fabbe6db6bac89 --- /dev/null +++ b/ultralytics-main/docs/README.md @@ -0,0 +1,145 @@ +Ultralytics logo + +# 📚 Ultralytics Docs + +Welcome to Ultralytics Docs, your comprehensive resource for understanding and utilizing our state-of-the-art [machine learning](https://www.ultralytics.com/glossary/machine-learning-ml) tools and models, including [Ultralytics YOLO](https://docs.ultralytics.com/models/yolo11/). These documents are actively maintained and deployed to [https://docs.ultralytics.com](https://docs.ultralytics.com/) for easy access. + +[![pages-build-deployment](https://github.com/ultralytics/docs/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/ultralytics/docs/actions/workflows/pages/pages-build-deployment) +[![Check Broken links](https://github.com/ultralytics/docs/actions/workflows/links.yml/badge.svg)](https://github.com/ultralytics/docs/actions/workflows/links.yml) +[![Check Domains](https://github.com/ultralytics/docs/actions/workflows/check_domains.yml/badge.svg)](https://github.com/ultralytics/docs/actions/workflows/check_domains.yml) +[![Ultralytics Actions](https://github.com/ultralytics/docs/actions/workflows/format.yml/badge.svg)](https://github.com/ultralytics/docs/actions/workflows/format.yml) + +Discord Ultralytics Forums Ultralytics Reddit + +## 🛠️ Installation + +[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics?logo=pypi&logoColor=white)](https://pypi.org/project/ultralytics/) +[![Downloads](https://static.pepy.tech/badge/ultralytics)](https://clickpy.clickhouse.com/dashboard/ultralytics) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics?logo=python&logoColor=gold)](https://pypi.org/project/ultralytics/) + +To install the `ultralytics` package in developer mode, which allows you to modify the source code directly, ensure you have [Git](https://git-scm.com/) and [Python](https://www.python.org/) 3.8 or later installed on your system. Then, follow these steps: + +1. Clone the `ultralytics` repository to your local machine using Git: + + ```bash + git clone https://github.com/ultralytics/ultralytics.git + ``` + +2. Navigate to the cloned repository's root directory: + + ```bash + cd ultralytics + ``` + +3. Install the package in editable mode (`-e`) along with its development dependencies (`[dev]`) using [pip](https://pip.pypa.io/en/stable/): + + ```bash + pip install -e '.[dev]' + ``` + + This command installs the `ultralytics` package such that changes to the source code are immediately reflected in your environment, ideal for development. + +## 🚀 Building and Serving Locally + +The `mkdocs serve` command builds and serves a local version of your [MkDocs](https://www.mkdocs.org/) documentation. This is highly useful during development and testing to preview changes. + +```bash +mkdocs serve +``` + +- **Command Breakdown:** + - `mkdocs`: The main MkDocs command-line interface tool. + - `serve`: The subcommand used to build and locally serve your documentation site. +- **Note:** + - `mkdocs serve` includes live reloading, automatically updating the preview in your browser as you save changes to the documentation files. + - To stop the local server, simply press `CTRL+C` in your terminal. + +## 🌍 Building and Serving Multi-Language + +If your documentation supports multiple languages, follow these steps to build and preview all versions: + +1. Stage all new or modified language Markdown (`.md`) files using Git: + + ```bash + git add docs/**/*.md -f + ``` + +2. Build all language versions into the `/site` directory. This script ensures that relevant root-level files are included and clears the previous build: + + ```bash + # Clear existing /site directory to prevent conflicts + rm -rf site + + # Build the default language site using the primary config file + mkdocs build -f docs/mkdocs.yml + + # Loop through each language-specific config file and build its site + for file in docs/mkdocs_*.yml; do + echo "Building MkDocs site with $file" + mkdocs build -f "$file" + done + ``` + +3. To preview the complete multi-language site locally, navigate into the build output directory and start a simple [Python HTTP server](https://docs.python.org/3/library/http.server.html): + ```bash + cd site + python -m http.server + # Open http://localhost:8000 in your preferred web browser + ``` + Access the live preview site at `http://localhost:8000`. + +## 📤 Deploying Your Documentation Site + +To deploy your MkDocs documentation site, choose a hosting provider and configure your deployment method. Common options include [GitHub Pages](https://pages.github.com/), GitLab Pages, or other static site hosting services. + +- Configure deployment settings within your `mkdocs.yml` file. +- Use your hosting provider's recommended workflow (for example running `mkdocs build` in CI or `mkdocs gh-deploy` for GitHub Pages) to publish the generated `site/` directory. + +* **GitHub Pages Deployment Example:** + If deploying to GitHub Pages, you can use the built-in command: + + ```bash + mkdocs gh-deploy + ``` + + After deployment, you might need to update the "Custom domain" settings in your repository's settings page if you wish to use a personalized URL. + + ![GitHub Pages Custom Domain Setting](https://github.com/ultralytics/docs/releases/download/0/github-pages-custom-domain-setting.avif) + +- For detailed instructions on various deployment methods, consult the official [MkDocs Deploying your docs guide](https://www.mkdocs.org/user-guide/deploying-your-docs/). + +## 💡 Contribute + +We deeply value contributions from the open-source community to enhance Ultralytics projects. Your input helps drive innovation! Please review our [Contributing Guide](https://docs.ultralytics.com/help/contributing/) for detailed information on how to get involved. You can also share your feedback and ideas through our [Survey](https://www.ultralytics.com/survey?utm_source=github&utm_medium=social&utm_campaign=Survey). A heartfelt thank you 🙏 to all our contributors for their dedication and support! + +![Ultralytics open-source contributors](https://raw.githubusercontent.com/ultralytics/assets/main/im/image-contributors.png) + +We look forward to your contributions! + +## 📜 License + +Ultralytics Docs are available under two licensing options to accommodate different usage scenarios: + +- **AGPL-3.0 License**: Ideal for students, researchers, and enthusiasts involved in academic pursuits and open collaboration. See the [LICENSE](https://github.com/ultralytics/docs/blob/main/LICENSE) file for full details. This license promotes sharing improvements back with the community. +- **Enterprise License**: Designed for commercial applications, this license allows seamless integration of Ultralytics software and [AI models](https://docs.ultralytics.com/models/) into commercial products and services. Visit [Ultralytics Licensing](https://www.ultralytics.com/license) for more information on obtaining an Enterprise License. + +## ✉️ Contact + +For bug reports, feature requests, and other issues related to the documentation, please use [GitHub Issues](https://github.com/ultralytics/docs/issues). For discussions, questions, and community support, join the conversation with peers and the Ultralytics team on our [Discord server](https://discord.com/invite/ultralytics)! + +
+
+ Ultralytics GitHub + space + Ultralytics LinkedIn + space + Ultralytics Twitter + space + Ultralytics YouTube + space + Ultralytics TikTok + space + Ultralytics BiliBili + space + Ultralytics Discord +
diff --git a/ultralytics-main/docs/build_docs.py b/ultralytics-main/docs/build_docs.py new file mode 100644 index 0000000000000000000000000000000000000000..f1e57117988f4badb28a236a90ea4b4fa41651f4 --- /dev/null +++ b/ultralytics-main/docs/build_docs.py @@ -0,0 +1,691 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license +""" +Automates building and post-processing of MkDocs documentation, especially for multilingual projects. + +This script streamlines generating localized documentation and updating HTML links for correct formatting. + +Key Features: + - Automated building of MkDocs documentation: Compiles main documentation and localized versions from separate + MkDocs configuration files. + - Post-processing of generated HTML files: Updates HTML files to remove '.md' from internal links, ensuring + correct navigation in web-based documentation. + +Usage: + - Run from the root directory of your MkDocs project. + - Ensure MkDocs is installed and configuration files (main and localized) are present. + - The script builds documentation using MkDocs, then scans HTML files in 'site' to update links. + - Ideal for projects with Markdown documentation served as a static website. + +Note: + - Requires Python and MkDocs to be installed and configured. +""" + +from __future__ import annotations + +import os +import re +import shutil +import subprocess +import tempfile +import time +from pathlib import Path + +import yaml +from bs4 import BeautifulSoup +from minijinja import Environment, load_from_path + +try: + from plugin import postprocess_site # mkdocs-ultralytics-plugin +except ImportError: + postprocess_site = None + +from build_reference import build_reference_docs, build_reference_for + +from ultralytics.utils import LINUX, LOGGER, MACOS +from ultralytics.utils.tqdm import TQDM + +os.environ["JUPYTER_PLATFORM_DIRS"] = "1" # fix DeprecationWarning: Jupyter is migrating to use standard platformdirs +DOCS = Path(__file__).parent.resolve() +SITE = DOCS.parent / "site" +LINK_PATTERN = re.compile(r"(https?://[^\s()<>]*[^\s()<>.,:;!?\'\"])") +TITLE_PATTERN = re.compile(r"(.*?)", flags=re.IGNORECASE | re.DOTALL) +MD_LINK_PATTERN = re.compile(r'(["\']?)([^"\'>\s]+?)\.md(["\']?)') +DOC_KIND_LABELS = {"Class", "Function", "Method", "Property"} +DOC_KIND_COLORS = { + "Class": "#039dfc", # blue + "Method": "#ef5eff", # magenta + "Function": "#fc9803", # orange + "Property": "#02e835", # green +} + + +def prepare_docs_markdown(clone_repos: bool = True): + """Build docs using mkdocs.""" + LOGGER.info("Removing existing build artifacts") + shutil.rmtree(SITE, ignore_errors=True) + shutil.rmtree(DOCS / "repos", ignore_errors=True) + + if clone_repos: + # Get hub-sdk repo + repo = "https://github.com/ultralytics/hub-sdk" + local_dir = DOCS / "repos" / Path(repo).name + subprocess.run( + ["git", "clone", "-q", "--depth=1", "--single-branch", "-b", "main", repo, str(local_dir)], check=True + ) + shutil.rmtree(DOCS / "en/hub/sdk", ignore_errors=True) # delete if exists + shutil.copytree(local_dir / "docs", DOCS / "en/hub/sdk") # for docs + LOGGER.info(f"Cloned/Updated {repo} in {local_dir}") + + # Get docs repo + repo = "https://github.com/ultralytics/docs" + local_dir = DOCS / "repos" / Path(repo).name + subprocess.run( + ["git", "clone", "-q", "--depth=1", "--single-branch", "-b", "main", repo, str(local_dir)], check=True + ) + shutil.rmtree(DOCS / "en/compare", ignore_errors=True) # delete if exists + shutil.copytree(local_dir / "docs/en/compare", DOCS / "en/compare") # for docs + LOGGER.info(f"Cloned/Updated {repo} in {local_dir}") + + # Add frontmatter + for file in TQDM((DOCS / "en").rglob("*.md"), desc="Adding frontmatter"): + update_markdown_files(file) + + +def update_markdown_files(md_filepath: Path): + """Create or update a Markdown file, ensuring frontmatter is present.""" + if md_filepath.exists(): + content = md_filepath.read_text().strip() + + # Replace apostrophes + content = content.replace("‘", "'").replace("’", "'") + + # Add frontmatter if missing + if not content.strip().startswith("---\n"): + header = "---\ncomments: true\ndescription: TODO ADD DESCRIPTION\nkeywords: TODO ADD KEYWORDS\n---\n\n" + content = header + content + + # Ensure MkDocs admonitions "=== " lines are preceded and followed by empty newlines + lines = content.split("\n") + new_lines = [] + for i, line in enumerate(lines): + stripped_line = line.strip() + if stripped_line.startswith("=== "): + if i > 0 and new_lines[-1] != "": + new_lines.append("") + new_lines.append(line) + if i < len(lines) - 1 and lines[i + 1].strip() != "": + new_lines.append("") + else: + new_lines.append(line) + content = "\n".join(new_lines) + + # Add EOF newline if missing + if not content.endswith("\n"): + content += "\n" + + # Save page + md_filepath.write_text(content) + return + + +def update_docs_html(): + """Update titles, edit links, and convert plaintext links in HTML documentation in one pass.""" + from concurrent.futures import ProcessPoolExecutor + + html_files = list(SITE.rglob("*.html")) + if not html_files: + LOGGER.info("Updated HTML files: 0") + return + desc = f"Updating HTML at {SITE}" + max_workers = os.cpu_count() or 1 + with ProcessPoolExecutor(max_workers=max_workers) as executor: + pbar = TQDM(executor.map(_process_html_file, html_files), total=len(html_files), desc=desc) + updated = 0 + for res in pbar: + updated += bool(res) + pbar.set_description(f"{desc} ({updated}/{len(html_files)} updated)") + + +def _process_html_file(html_file: Path) -> bool: + """Process a single HTML file; returns True if modified.""" + try: + content = html_file.read_text(encoding="utf-8") + except Exception as e: + LOGGER.warning(f"Could not read {html_file}: {e}") + return False + + changed = False + try: + rel_path = html_file.relative_to(SITE).as_posix() + except ValueError: + rel_path = html_file.name + + # For pages sourced from external repos (hub-sdk, compare), drop edit/copy buttons to avoid wrong links + if rel_path.startswith(("hub/sdk/", "compare/")): + before = content + content = re.sub( + r']*class="[^"]*md-content__button[^"]*"[^>]*>.*?', + "", + content, + flags=re.IGNORECASE | re.DOTALL, + ) + if content != before: + changed = True + + if rel_path == "404.html": + new_content = re.sub(r".*?", "Ultralytics Docs - Not Found", content) + if new_content != content: + content, changed = new_content, True + + new_content = update_docs_soup(content, html_file=html_file) + if new_content != content: + content, changed = new_content, True + + new_content = _rewrite_md_links(content) + if new_content != content: + content, changed = new_content, True + + if changed: + try: + html_file.write_text(content, encoding="utf-8") + return True + except Exception as e: + LOGGER.warning(f"Could not write {html_file}: {e}") + return False + + +def update_docs_soup(content: str, html_file: Path | None = None, max_title_length: int = 70) -> str: + """Convert plaintext links to HTML hyperlinks, truncate long meta titles, and remove code line hrefs.""" + title_match = TITLE_PATTERN.search(content) + needs_title_trim = bool( + title_match and len(title_match.group(1)) > max_title_length and "-" in title_match.group(1) + ) + needs_link_conversion = (" max_title_length and "-" in title_tag.text: + title_tag.string = title_tag.text.rsplit("-", 1)[0].strip() + modified = True + + # Find the main content area + main_content = soup.find("main") or soup.find("div", class_="md-content") + if not main_content: + return str(soup) if modified else content + + # Convert plaintext links to HTML hyperlinks + if needs_link_conversion: + for paragraph in main_content.select("p, li"): + for text_node in paragraph.find_all(string=True, recursive=False): + if text_node.parent.name not in {"a", "code"}: + new_text = LINK_PATTERN.sub(r'\1', str(text_node)) + if " 0: + tail = " " + if tail: + span.insert_after(tail) + modified = True + + highlight_labels(soup.select("main h1, main h2, main h3, main h4, main h5")) + highlight_labels(soup.select("nav.md-nav--secondary .md-ellipsis, nav.md-nav__list .md-ellipsis")) + + if "reference" in rel_path: + for ellipsis in soup.select("nav.md-nav--secondary .md-ellipsis"): + kind = ellipsis.find(class_=lambda c: c and "doc-kind" in c.split()) + text = str(kind.next_sibling).strip() if kind and kind.next_sibling else ellipsis.get_text(strip=True) + if "." not in text: + continue + ellipsis.clear() + short = text.rsplit(".", 1)[-1] + if kind: + ellipsis.append(kind) + ellipsis.append(f" {short}") + else: + ellipsis.append(short) + modified = True + + if needs_kind_highlight and not modified and soup.select(".doc-kind"): + # Ensure style injection when pre-existing badges are present + modified = True + + if modified: + head = soup.find("head") + if head and not soup.select("style[data-doc-kind]"): + style = soup.new_tag("style", attrs={"data-doc-kind": "true"}) + style.string = ( + ".doc-kind{display:inline-flex;align-items:center;gap:0.25em;padding:0.21em 0.59em;border-radius:999px;" + "font-weight:700;font-size:0.81em;letter-spacing:0.06em;text-transform:uppercase;" + "line-height:1;color:var(--doc-kind-color,#f8fafc);" + "background:var(--doc-kind-bg,rgba(255,255,255,0.12));}" + f".doc-kind-class{{--doc-kind-color:{DOC_KIND_COLORS['Class']};--doc-kind-bg:rgba(3,157,252,0.22);}}" + f".doc-kind-function{{--doc-kind-color:{DOC_KIND_COLORS['Function']};--doc-kind-bg:rgba(252,152,3,0.22);}}" + f".doc-kind-method{{--doc-kind-color:{DOC_KIND_COLORS['Method']};--doc-kind-bg:rgba(239,94,255,0.22);}}" + f".doc-kind-property{{--doc-kind-color:{DOC_KIND_COLORS['Property']};--doc-kind-bg:rgba(2,232,53,0.22);}}" + ) + head.append(style) + + return str(soup) if modified else content + + +def _rewrite_md_links(content: str) -> str: + """Replace .md references with trailing slashes in HTML content, skipping GitHub links.""" + if ".md" not in content: + return content + + lines = [] + for line in content.split("\n"): + if "github.com" not in line: + line = line.replace("index.md", "") + line = MD_LINK_PATTERN.sub(r"\1\2/\3", line) + lines.append(line) + return "\n".join(lines) + + +# Precompiled regex patterns for minification +HTML_COMMENT = re.compile(r"") +HTML_PRESERVE = re.compile(r"<(pre|code|textarea|script)[^>]*>[\s\S]*?", re.IGNORECASE) +HTML_TAG_SPACE = re.compile(r">\s+<") +HTML_MULTI_SPACE = re.compile(r"\s{2,}") +HTML_EMPTY_LINE = re.compile(r"^\s*$\n", re.MULTILINE) +CSS_COMMENT = re.compile(r"/\*[\s\S]*?\*/") + + +def remove_comments_and_empty_lines(content: str, file_type: str) -> str: + """Remove comments and empty lines from a string of code, preserving newlines and URLs. + + Args: + content (str): Code content to process. + file_type (str): Type of file ('html', 'css', or 'js'). + + Returns: + (str): Cleaned content with comments and empty lines removed. + + Notes: + Typical reductions for Ultralytics Docs are: + - Total HTML reduction: 2.83% (1301.56 KB saved) + - Total CSS reduction: 1.75% (2.61 KB saved) + - Total JS reduction: 13.51% (99.31 KB saved) + """ + if file_type == "html": + content = HTML_COMMENT.sub("", content) # Remove HTML comments + # Preserve whitespace in
, ,