Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 10 additions & 29 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,33 @@ jobs:
build_test_push:
name: Build, Test & Push Model
runs-on: ubuntu-latest
strategy:
matrix:
model: [yolo11n]
steps:
#- name: Cleanup disk space
# uses: ultralytics/actions/cleanup-disk@main

- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Setup uv
uses: astral-sh/setup-uv@v6

- name: Install dependencies
run: uv pip install --system ultralytics --extra-index-url https://download.pytorch.org/whl/cpu

- name: Setup Cog
uses: replicate/setup-cog@v2
with:
token: ${{ secrets.REPLICATE_API_TOKEN }}

- name: Download YOLO11n weights
run: |
python << 'EOF'
from ultralytics import YOLO
model = YOLO('yolo11n.pt')
EOF
ls -la yolo11n*
mv yolo11n.pt yolo11n/
echo "Files in yolo11n directory:"
ls -la yolo11n/

run: python ${{ matrix.model }}/download.py
- name: Build model image
run: |
cd yolo11n
cog build

working-directory: ${{ matrix.model }}
run: cog build
- name: Test model
run: |
cd yolo11n
cog predict -i image=@../assets/bus.jpg -i conf=0.25 -i iou=0.45

working-directory: ${{ matrix.model }}
run: cog predict -i image=@../assets/bus.jpg -i conf=0.25 -i iou=0.45
- name: Push to Replicate
if: github.ref == 'refs/heads/main'
run: |
cd yolo11n
cog push
working-directory: ${{ matrix.model }}
run: cog push
5 changes: 0 additions & 5 deletions yolo11n/cog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ build:
- "ffmpeg"
python_packages:
- "ultralytics>=8.3.0"
- "torch==2.3.1"
- "torchvision"
- "numpy>=1.24.0"
- "opencv-python"
- "pillow"

predict: predict.py:Predictor
image: r8.im/ultralytics/yolo11n
20 changes: 20 additions & 0 deletions yolo11n/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

from pathlib import Path

from ultralytics import YOLO


def main():
"""Download YOLO11n weights and move to model directory."""
current_dir = Path(__file__).parent
YOLO(current_dir / "yolo11n.pt")

# List files in model directory
print(f"Files in {current_dir.name} directory:")
for file in sorted(current_dir.iterdir()):
print(f" {file.stat().st_size:>10} {file.name}")


if __name__ == "__main__":
main()
9 changes: 3 additions & 6 deletions yolo11n/predict.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Ultralytics πŸš€ AGPL-3.0 License - https://ultralytics.com/license

import json
from typing import Optional

from cog import BaseModel, BasePredictor, Input, Path
from ultralytics import YOLO
from cog import BasePredictor, Input, Path, BaseModel


class Output(BaseModel):
Expand Down Expand Up @@ -32,9 +32,6 @@ def predict(
result.save(image_path)

if return_json:
return Output(
image=Path(image_path),
json_str=result.to_json()
)
return Output(image=Path(image_path), json_str=result.to_json())
else:
return Output(image=Path(image_path))
Loading