From 11c5e3c8ebc7e75360a7fb02b77d40e377332bfc Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Tue, 5 Aug 2025 17:48:13 +0300 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=F0=9F=9A=80=20add=20YOLOE-11S=20mo?= =?UTF-8?q?del=20deployment=20for=20replicate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- .../workflows/{push.yml => yolo11n-push.yml} | 6 +- .github/workflows/yoloe11s-push.yml | 69 +++++++++++++++++++ .gitignore | 22 ++++++ yoloe11s/README.md | 30 ++++++++ yoloe11s/cog.yaml | 20 ++++++ yoloe11s/predict.py | 49 +++++++++++++ 6 files changed, 195 insertions(+), 1 deletion(-) rename .github/workflows/{push.yml => yolo11n-push.yml} (94%) create mode 100644 .github/workflows/yoloe11s-push.yml create mode 100644 yoloe11s/README.md create mode 100644 yoloe11s/cog.yaml create mode 100644 yoloe11s/predict.py diff --git a/.github/workflows/push.yml b/.github/workflows/yolo11n-push.yml similarity index 94% rename from .github/workflows/push.yml rename to .github/workflows/yolo11n-push.yml index b995253..a8c5cd7 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/yolo11n-push.yml @@ -1,12 +1,16 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license -name: Push YOLO to Replicate +name: Push YOLO11n to Replicate on: push: branches: [main] + paths: + - yolo11n/** pull_request: branches: [main] + paths: + - yolo11n/** workflow_dispatch: jobs: diff --git a/.github/workflows/yoloe11s-push.yml b/.github/workflows/yoloe11s-push.yml new file mode 100644 index 0000000..dbe3d72 --- /dev/null +++ b/.github/workflows/yoloe11s-push.yml @@ -0,0 +1,69 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +name: Push YOLOE-11S to Replicate + +on: + push: + branches: [main] + paths: + - yoloe11s/** + pull_request: + branches: [main] + paths: + - yoloe11s/** + workflow_dispatch: + +jobs: + build_test_push: + name: Build, Test & Push Model + runs-on: ubuntu-latest + 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 YOLOE-11S weights + run: | + python << 'EOF' + from ultralytics import YOLO + model = YOLO('yoloe-11s-seg.pt') + EOF + ls -la yoloe11s* + mv yoloe-11s-seg.pt yoloe11s/ + mv mobileclip_blt.ts yoloe11s/ + echo "Files in yoloe11s directory:" + ls -la yoloe11s/ + + - name: Build model image + run: | + cd yoloe11s + cog build + + - name: Test model + run: | + cd yoloe11s + 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 yoloe11s + cog push diff --git a/.gitignore b/.gitignore index e857811..86010ef 100644 --- a/.gitignore +++ b/.gitignore @@ -182,3 +182,25 @@ weights/ *_openvino_model/ *_paddle_model/ pnnx* +*.ts + +# Replicate deployment folder and files +cog.json +cog.lock +.cog + +# Ignore Picture files +*.jpg +*.jpeg +*.png +*.gif +*.bmps + +# Ignore video files +*.mp4 +*.avi +*.mov +*.mkv +*.webm +*.flv +*.wmv diff --git a/yoloe11s/README.md b/yoloe11s/README.md new file mode 100644 index 0000000..8abe70d --- /dev/null +++ b/yoloe11s/README.md @@ -0,0 +1,30 @@ +# YOLO11n Demo Deployment + +Deploy the official YOLO11n model to Replicate with PyTorch inference at https://replicate.com/ultralytics/yoloe11s. + +## Setup + +1. **Deploy to Replicate:** + + ```bash + cog push r8.im/ultralytics/yoloe11s + ``` + +## Model Details + +- **Model**: YOLE11s (Small) +- **Parameters**: 2.6M +- **Format**: PyTorch (.pt) +- **Use Case**: Demonstration of official Ultralytics model deployment + +## Model Files + +**Note:** The model weights (`yoloe-11s-seg.pt`) and (`mobileclip_blt.ts`) will be automatically downloaded by ultralytics when the container starts. + +## Configuration + +- **GPU**: Disabled by default (CPU inference) +- **Python**: 3.12 with PyTorch 2.3.1+ +- **Framework**: Ultralytics 8.3+ +- **Input**: Single image with configurable confidence/IoU thresholds, image size, and class names. +- **Output**: Annotated image with detected objects diff --git a/yoloe11s/cog.yaml b/yoloe11s/cog.yaml new file mode 100644 index 0000000..22a28f3 --- /dev/null +++ b/yoloe11s/cog.yaml @@ -0,0 +1,20 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +build: + gpu: false + python_version: "3.12" + system_packages: + - "libgl1-mesa-glx" + - "libglib2.0-0" + - "ffmpeg" + python_packages: + - "ultralytics>=8.3.0" + - "torch==2.3.1" + - "torchvision" + - "numpy>=1.24.0" + - "opencv-python" + - "pillow" + - "clip @ git+https://github.com/ultralytics/CLIP.git@main#egg=clip" + +predict: predict.py:Predictor +image: r8.im/ultralytics/yoloe-11s diff --git a/yoloe11s/predict.py b/yoloe11s/predict.py new file mode 100644 index 0000000..7ab1254 --- /dev/null +++ b/yoloe11s/predict.py @@ -0,0 +1,49 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +from typing import Optional +from ultralytics import YOLO +from cog import BasePredictor, Input, Path, BaseModel + +class Output(BaseModel): + image: Optional[Path] = None + json_str: Optional[str] = None +class Predictor(BasePredictor): + """YOLOE: Real-Time Seeing Anything model predictor for Replicate deployment.""" + + def setup(self) -> None: + """Load YOLOE-11S model into memory.""" + self.model = YOLO("yoloe-11s-seg.pt") + + def re_init_model(self, class_names: str) -> None: + """Re-Initialize model with class names.""" + self.model = YOLO("yoloe-11s-seg.pt") + if class_names.strip() != "": + class_list = class_names.split(", ") + self.model.set_classes(class_list, self.model.get_text_pe(class_list)) + + def predict( + self, + image: Path = Input(description="Input image"), + conf: float = Input(description="Confidence threshold", default=0.25, ge=0.0, le=1.0), + iou: float = Input(description="IoU threshold for NMS", default=0.45, ge=0.0, le=1.0), + imgsz: int = Input(description="Image size", default=640, choices=[320, 416, 512, 640, 832, 1024, 1280]), + class_names: str = Input( + description="Comma-separated list of class names to filter results (e.g., 'person, bus, sign') You can also leave it empty to detect classes automatically.", + default="person, bus, sign", + ), + return_json: bool = Input(description="Return detection results as JSON", default=False), + ) -> Output: + """Run inference and return annotated image with optional JSON results.""" + + self.re_init_model(class_names) + result = self.model(str(image), conf=conf, iou=iou, imgsz=imgsz)[0] + image_path = "output.png" + result.save(image_path) + + if return_json: + return Output( + image=Path(image_path), + json_str=result.to_json() + ) + else: + return Output(image=Path(image_path)) From 7e4f6c14984b6227769fbccb3680170d0e7b02d9 Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Tue, 5 Aug 2025 15:24:36 +0000 Subject: [PATCH 2/8] Auto-format by https://ultralytics.com/actions --- yolo11n/predict.py | 9 +++------ yoloe11s/predict.py | 12 ++++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/yolo11n/predict.py b/yolo11n/predict.py index 4d80c42..3f23445 100644 --- a/yolo11n/predict.py +++ b/yolo11n/predict.py @@ -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): @@ -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)) diff --git a/yoloe11s/predict.py b/yoloe11s/predict.py index 7ab1254..e51db4c 100644 --- a/yoloe11s/predict.py +++ b/yoloe11s/predict.py @@ -1,12 +1,16 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license 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): image: Optional[Path] = None json_str: Optional[str] = None + + class Predictor(BasePredictor): """YOLOE: Real-Time Seeing Anything model predictor for Replicate deployment.""" @@ -34,16 +38,12 @@ def predict( return_json: bool = Input(description="Return detection results as JSON", default=False), ) -> Output: """Run inference and return annotated image with optional JSON results.""" - self.re_init_model(class_names) result = self.model(str(image), conf=conf, iou=iou, imgsz=imgsz)[0] image_path = "output.png" 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)) From 6c327f9fba0dc5469153e87a184c382e87359507 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Tue, 5 Aug 2025 19:10:54 +0300 Subject: [PATCH 3/8] =?UTF-8?q?ci:=20=F0=9F=91=B7=20add=20missing=20asset?= =?UTF-8?q?=20download=20for=20YOLOE-11S=20model=20(mobileclip=5Fblt.ts)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- .github/workflows/yoloe11s-push.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/yoloe11s-push.yml b/.github/workflows/yoloe11s-push.yml index dbe3d72..e6f0257 100644 --- a/.github/workflows/yoloe11s-push.yml +++ b/.github/workflows/yoloe11s-push.yml @@ -44,6 +44,8 @@ jobs: run: | python << 'EOF' from ultralytics import YOLO + from ultralytics.utils.downloads import attempt_download_asset + attempt_download_asset("mobileclip_blt.ts") model = YOLO('yoloe-11s-seg.pt') EOF ls -la yoloe11s* From 01506b787d3ad0a744ade3f8b821628050bc8230 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Tue, 5 Aug 2025 19:54:49 +0300 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20=F0=9F=90=9B=20correct=20model=20nam?= =?UTF-8?q?e=20and=20deployment=20instructions=20in=20README=20and=20use?= =?UTF-8?q?=20proper=20import=20for=20YOLOE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- yolo11n/predict.py | 2 ++ yoloe11s/README.md | 10 +++++----- yoloe11s/predict.py | 11 ++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/yolo11n/predict.py b/yolo11n/predict.py index 3f23445..ad27f4d 100644 --- a/yolo11n/predict.py +++ b/yolo11n/predict.py @@ -7,6 +7,8 @@ class Output(BaseModel): + """Output model for predictions.""" + image: Optional[Path] = None json_str: Optional[str] = None diff --git a/yoloe11s/README.md b/yoloe11s/README.md index 8abe70d..8347d24 100644 --- a/yoloe11s/README.md +++ b/yoloe11s/README.md @@ -1,19 +1,19 @@ -# YOLO11n Demo Deployment +# YOLOE-11S Demo Deployment -Deploy the official YOLO11n model to Replicate with PyTorch inference at https://replicate.com/ultralytics/yoloe11s. +Deploy the official YOLOE-11S model to Replicate with PyTorch inference at . ## Setup 1. **Deploy to Replicate:** ```bash - cog push r8.im/ultralytics/yoloe11s + cog push r8.im/ultralytics/yoloe-11s ``` ## Model Details -- **Model**: YOLE11s (Small) -- **Parameters**: 2.6M +- **Model**: YOLOE-11S (Small) +- **Parameters**: 10.2M - **Format**: PyTorch (.pt) - **Use Case**: Demonstration of official Ultralytics model deployment diff --git a/yoloe11s/predict.py b/yoloe11s/predict.py index e51db4c..20df8d2 100644 --- a/yoloe11s/predict.py +++ b/yoloe11s/predict.py @@ -3,10 +3,12 @@ from typing import Optional from cog import BaseModel, BasePredictor, Input, Path -from ultralytics import YOLO +from ultralytics import YOLOE class Output(BaseModel): + """Output model for predictions.""" + image: Optional[Path] = None json_str: Optional[str] = None @@ -16,14 +18,17 @@ class Predictor(BasePredictor): def setup(self) -> None: """Load YOLOE-11S model into memory.""" - self.model = YOLO("yoloe-11s-seg.pt") + self.model = YOLOE("yoloe-11s-seg.pt") def re_init_model(self, class_names: str) -> None: """Re-Initialize model with class names.""" - self.model = YOLO("yoloe-11s-seg.pt") if class_names.strip() != "": + self.model = YOLOE("yoloe-11s-seg.pt") class_list = class_names.split(", ") self.model.set_classes(class_list, self.model.get_text_pe(class_list)) + else: + # Load YOLOE-11s model prompt free model into memory + self.model = YOLOE("yoloe-11s-seg-pf.pt") def predict( self, From 7f6b560e208c5a4a6f99b6c8c9dc5c2a6f0cba6f Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Thu, 7 Aug 2025 10:43:03 +0300 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20=F0=9F=9A=80=20add=20download=20scr?= =?UTF-8?q?ipt=20for=20YOLOe-11s-seg=20and=20YOLOe-11s-seg-pf=20=20weights?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- yoloe11s/download.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 yoloe11s/download.py diff --git a/yoloe11s/download.py b/yoloe11s/download.py new file mode 100644 index 0000000..dc13a32 --- /dev/null +++ b/yoloe11s/download.py @@ -0,0 +1,21 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +from pathlib import Path + +from ultralytics import YOLOE + + +def main(): + """Download YOLOe-11s-seg and YOLOe-11s-seg-pf weights and move to model directory.""" + current_dir = Path(__file__).parent + YOLOE(current_dir / "yoloe-11s-seg.pt") + YOLOE(current_dir / "yoloe-11s-seg-pf.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() From 7cbcd99b853c8d8c86255d62398a3e85e77fc949 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Thu, 7 Aug 2025 19:08:49 +0300 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20=F0=9F=9A=80=20add=20YOLOv8s=20Worl?= =?UTF-8?q?dV2=20deployment=20workflow=20and=20model=20predictor=20(#21)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Glenn Jocher Signed-off-by: Onuralp SEZER Co-authored-by: UltralyticsAssistant Co-authored-by: Glenn Jocher --- .../workflows/{yolo11n-push.yml => push.yml} | 10 +-- .github/workflows/yoloe11s-push.yml | 71 ------------------- yolov8s-worldv2/README.md | 30 ++++++++ yolov8s-worldv2/cog.yaml | 15 ++++ yolov8s-worldv2/download.py | 20 ++++++ yolov8s-worldv2/predict.py | 50 +++++++++++++ 6 files changed, 118 insertions(+), 78 deletions(-) rename .github/workflows/{yolo11n-push.yml => push.yml} (88%) delete mode 100644 .github/workflows/yoloe11s-push.yml create mode 100644 yolov8s-worldv2/README.md create mode 100644 yolov8s-worldv2/cog.yaml create mode 100644 yolov8s-worldv2/download.py create mode 100644 yolov8s-worldv2/predict.py diff --git a/.github/workflows/yolo11n-push.yml b/.github/workflows/push.yml similarity index 88% rename from .github/workflows/yolo11n-push.yml rename to .github/workflows/push.yml index 7a9bc5e..b7281b0 100644 --- a/.github/workflows/yolo11n-push.yml +++ b/.github/workflows/push.yml @@ -1,16 +1,12 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license -name: Push YOLO11n to Replicate +name: Push YOLO to Replicate on: push: branches: [main] - paths: - - yolo11n/** pull_request: branches: [main] - paths: - - yolo11n/** workflow_dispatch: jobs: @@ -19,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - model: [yolo11n] + model: [yolo11n,yolov8s-worldv2,yolov8s-worldv2] steps: - name: Checkout uses: actions/checkout@v4 @@ -35,7 +31,7 @@ jobs: uses: replicate/setup-cog@v2 with: token: ${{ secrets.REPLICATE_API_TOKEN }} - - name: Download YOLO11n weights + - name: Download model weights run: python ${{ matrix.model }}/download.py - name: Build model image working-directory: ${{ matrix.model }} diff --git a/.github/workflows/yoloe11s-push.yml b/.github/workflows/yoloe11s-push.yml deleted file mode 100644 index e6f0257..0000000 --- a/.github/workflows/yoloe11s-push.yml +++ /dev/null @@ -1,71 +0,0 @@ -# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license - -name: Push YOLOE-11S to Replicate - -on: - push: - branches: [main] - paths: - - yoloe11s/** - pull_request: - branches: [main] - paths: - - yoloe11s/** - workflow_dispatch: - -jobs: - build_test_push: - name: Build, Test & Push Model - runs-on: ubuntu-latest - 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 YOLOE-11S weights - run: | - python << 'EOF' - from ultralytics import YOLO - from ultralytics.utils.downloads import attempt_download_asset - attempt_download_asset("mobileclip_blt.ts") - model = YOLO('yoloe-11s-seg.pt') - EOF - ls -la yoloe11s* - mv yoloe-11s-seg.pt yoloe11s/ - mv mobileclip_blt.ts yoloe11s/ - echo "Files in yoloe11s directory:" - ls -la yoloe11s/ - - - name: Build model image - run: | - cd yoloe11s - cog build - - - name: Test model - run: | - cd yoloe11s - 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 yoloe11s - cog push diff --git a/yolov8s-worldv2/README.md b/yolov8s-worldv2/README.md new file mode 100644 index 0000000..6ca8df1 --- /dev/null +++ b/yolov8s-worldv2/README.md @@ -0,0 +1,30 @@ +# YOLOv8s WorldV2 Demo Deployment + +Deploy the official YOLOv8s WorldV2 model to Replicate with PyTorch inference at https://replicate.com/ultralytics/yolov8s-worldv2. + +## Setup + +1. **Deploy to Replicate:** + + ```bash + cog push r8.im/ultralytics/yolov8s-worldv2 + ``` + +## Model Details + +- **Model**: YOLOv8s WorldV2 (Small) +- **Parameters**: 12.7M +- **Format**: PyTorch (.pt) +- **Use Case**: Demonstration of official Ultralytics model deployment + +## Model Files + +**Note:** The model weights (`yolov8s-worldv2.pt`) will be automatically downloaded by ultralytics when the container starts. + +## Configuration + +- **GPU**: Disabled by default (CPU inference) +- **Python**: 3.12 with PyTorch 2.3.1+ +- **Framework**: Ultralytics 8.3+ +- **Input**: Single image with configurable confidence/IoU thresholds +- **Output**: Annotated image with detected objects diff --git a/yolov8s-worldv2/cog.yaml b/yolov8s-worldv2/cog.yaml new file mode 100644 index 0000000..f01edbf --- /dev/null +++ b/yolov8s-worldv2/cog.yaml @@ -0,0 +1,15 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +build: + gpu: false + python_version: "3.12" + system_packages: + - "libgl1-mesa-glx" + - "libglib2.0-0" + - "ffmpeg" + python_packages: + - "ultralytics>=8.3.0" + - "clip @ git+https://github.com/ultralytics/CLIP.git@main#egg=clip" + +predict: predict.py:Predictor +image: r8.im/ultralytics/yolov8s-worldv2 diff --git a/yolov8s-worldv2/download.py b/yolov8s-worldv2/download.py new file mode 100644 index 0000000..eec4bc4 --- /dev/null +++ b/yolov8s-worldv2/download.py @@ -0,0 +1,20 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +from pathlib import Path + +from ultralytics import YOLOWorld + + +def main(): + """Download YOLOv8s-worldv2 weights and move to model directory.""" + current_dir = Path(__file__).parent + YOLOWorld(current_dir / "yolov8s-worldv2.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() diff --git a/yolov8s-worldv2/predict.py b/yolov8s-worldv2/predict.py new file mode 100644 index 0000000..3288bb8 --- /dev/null +++ b/yolov8s-worldv2/predict.py @@ -0,0 +1,50 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +from typing import Optional + +from cog import BaseModel, BasePredictor, Input, Path +from ultralytics import YOLOWorld + + +class Output(BaseModel): + """Output model for predictions.""" + + image: Optional[Path] = None + json_str: Optional[str] = None + + +class Predictor(BasePredictor): + """YOLOv8s WorldV2 model predictor for Replicate deployment.""" + + def setup(self) -> None: + """Load YOLOWorld model into memory.""" + self.model = YOLOWorld("yolov8s-worldv2.pt") + + def re_init_model(self, class_names: str) -> None: + """Re-Initialize model with class names.""" + self.model = YOLOWorld("yolov8s-worldv2.pt") + class_list = class_names.split(", ") + self.model.set_classes(class_list) + + def predict( + self, + image: Path = Input(description="Input image"), + conf: float = Input(description="Confidence threshold", default=0.25, ge=0.0, le=1.0), + iou: float = Input(description="IoU threshold for NMS", default=0.45, ge=0.0, le=1.0), + imgsz: int = Input(description="Image size", default=640, choices=[320, 416, 512, 640, 832, 1024, 1280]), + class_names: str = Input( + description="Comma-separated list of class names to filter results (e.g., 'person, bus, sign') You can also leave it empty to detect classes automatically.", + default="person, bus, sign", + ), + return_json: bool = Input(description="Return detection results as JSON", default=False), + ) -> Output: + """Run inference and return annotated image with optional JSON results.""" + self.re_init_model(class_names) + result = self.model(str(image), conf=conf, iou=iou, imgsz=imgsz)[0] + image_path = "output.png" + result.save(image_path) + + if return_json: + return Output(image=Path(image_path), json_str=result.to_json()) + else: + return Output(image=Path(image_path)) From a33d094213d91ccc2149b7af0b88c21c6a53e43d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 7 Aug 2025 18:44:30 +0200 Subject: [PATCH 7/8] Update cog.yaml Signed-off-by: Glenn Jocher --- yoloe11s/cog.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/yoloe11s/cog.yaml b/yoloe11s/cog.yaml index 22a28f3..38d4dc6 100644 --- a/yoloe11s/cog.yaml +++ b/yoloe11s/cog.yaml @@ -9,11 +9,6 @@ build: - "ffmpeg" python_packages: - "ultralytics>=8.3.0" - - "torch==2.3.1" - - "torchvision" - - "numpy>=1.24.0" - - "opencv-python" - - "pillow" - "clip @ git+https://github.com/ultralytics/CLIP.git@main#egg=clip" predict: predict.py:Predictor From d336b5848ba09090105545be94726d7be129e6c4 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Thu, 7 Aug 2025 19:49:51 +0300 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=F0=9F=90=9E=20update=20model=20matr?= =?UTF-8?q?ix=20to=20include=20yoloe11s=20in=20push=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b7281b0..407e5b1 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - model: [yolo11n,yolov8s-worldv2,yolov8s-worldv2] + model: [yolo11n,yolov8s-worldv2,yoloe11s] steps: - name: Checkout uses: actions/checkout@v4