Skip to main content

Modal-Schnellstartanleitung für Ultralytics

Dieser Leitfaden bietet eine umfassende Einführung in die Ausführung von Ultralytics YOLO26 auf Modal, und deckt serverlose GPU-Inferenz sowie Modelltraining ab.

Was ist Modal?

Modal ist eine serverlose Cloud-Computing Plattform für KI- und Machine Learning Workloads. Sie kümmert sich automatisch um die Bereitstellung, Skalierung und Ausführung – du schreibst Python-Code lokal und Modal führt ihn in der Cloud mit GPU-Zugriff aus. Das macht es ideal für die Ausführung von Deep Learning Modellen wie YOLO26, ohne dass du dich um die Infrastruktur kümmern musst.

Was du lernen wirst

  • Modal einrichten und authentifizieren
  • YOLO26-Inferenz auf Modal ausführen
  • GPUs für schnellere Inferenz verwenden
  • YOLO26-Modelle auf Modal trainieren

Voraussetzungen

  • Ein Modal-Konto (kostenlos registrieren unter modal.com)
  • Python 3.9 oder neuer auf deinem lokalen Rechner installiert

Installation

Installiere das Modal Python-Paket und authentifiziere dich:

pip install modal
modal token new
Authentifizierung

Die modal token new Der Befehl öffnet ein Browserfenster zur Authentifizierung deines Modal-Kontos. Nach der Authentifizierung kannst du Modal-Befehle vom Terminal ausführen.

YOLO26-Inferenz ausführen

Erstelle eine neue Python-Datei namens modal_yolo.py mit dem folgenden Code:

"""
Modal + Ultralytics YOLO26 Quickstart
Run: modal run modal_yolo.py.
"""

import modal

app = modal.App("ultralytics-yolo")

image = modal.Image.debian_slim(python_version="3.11").apt_install("libgl1", "libglib2.0-0").pip_install("ultralytics")

@app.function(image=image)
def predict(image_url: str):
    """Run YOLO26 inference on an image URL."""
    from ultralytics import YOLO

    model = YOLO("yolo26n.pt")
    results = model(image_url)

    for r in results:
        print(f"Detected {len(r.boxes)} objects:")
        for box in r.boxes:
            print(f"  - {model.names[int(box.cls)]}: {float(box.conf):.2f}")

@app.local_entrypoint()
def main():
    """Test inference with sample image."""
    predict.remote("https://ultralytics.com/images/bus.jpg")

Führe die Inferenz aus:

modal run modal_yolo.py

Erwartete Ausgabe:

✓ Initialized. View run at https://modal.com/apps/your-username/main/ap-xxxxxxxx
✓ Created objects.
├── 🔨 Created mount modal_yolo.py
└── 🔨 Created function predict.
Downloading https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26n.pt to 'yolo26n.pt'...
Downloading https://ultralytics.com/images/bus.jpg to 'bus.jpg'...
image 1/1 /root/bus.jpg: 640x480 4 persons, 1 bus, 377.8ms
Speed: 5.8ms preprocess, 377.8ms inference, 0.3ms postprocess per image at shape (1, 3, 640, 480)

Detected 5 objects:
  - bus: 0.92
  - person: 0.91
  - person: 0.91
  - person: 0.87
  - person: 0.53
✓ App completed.

Du kannst deine Funktionsausführung im Modal-Dashboard überwachen:

Modal Dashboard Function Calls

GPU für schnellere Inferenz nutzen

Füge deiner Funktion eine GPU hinzu, indem du die gpu verwenden:

@app.function(image=image, gpu="T4")  # Options: "T4", "A10G", "A100", "H100"
def predict_gpu(image_url: str):
    """Run YOLO26 inference on GPU."""
    from ultralytics import YOLO

    model = YOLO("yolo26n.pt")
    results = model(image_url)
    print(results[0].boxes)
GPUMemoryBestens geeignet für
T416 GBInferenz, Training kleiner Modelle
A10G24 GBMittlere Trainingsaufträge
A10040 GBGroßskaliges Training
H10080 GBMaximale Performance

YOLO26 auf Modal trainieren

Nutze für das Training eine GPU und Modal Volumes für persistenten Speicher. Erstelle eine neue Python-Datei namens train_yolo.py:

import modal

app = modal.App("ultralytics-training")

volume = modal.Volume.from_name("yolo-training-vol", create_if_missing=True)

image = modal.Image.debian_slim(python_version="3.11").apt_install("libgl1", "libglib2.0-0").pip_install("ultralytics")

@app.function(image=image, gpu="T4", timeout=3600, volumes={"/data": volume})
def train():
    """Train YOLO26 model on Modal."""
    from ultralytics import YOLO

    model = YOLO("yolo26n.pt")
    model.train(data="coco8.yaml", epochs=3, imgsz=640, project="/data/runs")

@app.local_entrypoint()
def main():
    train.remote()

Führe das Training aus:

modal run train_yolo.py
Volume-Persistenz

Modal Volumes speichern Daten dauerhaft zwischen Funktionsaufrufen. Trainierte Gewichte werden gespeichert in /data/runs/detect/train/weights/.

Herzlichen Glückwunsch! Du hast Ultralytics YOLO26 erfolgreich auf Modal eingerichtet. Zum weiteren Lernen:

FAQ

Wie wähle ich die richtige GPU für meinen YOLO26-Workload aus?

Für Inferenz ist eine NVIDIA T4 (16 GB) in der Regel ausreichend und kosteneffizient. Für Training oder größere Modelle wie YOLO26x, ziehe A10G oder A100 GPUs in Betracht.

Was kostet es, YOLO26 auf Modal auszuführen?

Modal nutzt eine sekundengenaue Abrechnung. Ungefähre Preise: CPU ~0,05 $/Std., T4 ~0,59 $/Std., A10G ~1,10 $/Std., A100 ~2,10 $/Std. Prüfe Modal-Preise für aktuelle Tarife.

Kann ich mein eigenes, benutzerdefiniertes YOLO-Modell verwenden?

Ja! Lade benutzerdefinierte Modelle von einem Modal Volume:

model = YOLO("/data/my_custom_model.pt")

Für weitere Informationen zum Training benutzerdefinierter Modelle, siehe die Trainingsleitfaden.

Kommentare