Meet YOLO26: next-gen vision AI.

Link to this sectionHướng dẫn Bắt đầu Nhanh Modal cho Ultralytics#

Hướng dẫn này cung cấp phần giới thiệu toàn diện về cách chạy Ultralytics YOLO26 trên Modal, bao gồm suy luận GPU serverless và huấn luyện mô hình.

Modal là một nền tảng cloud computing serverless dành cho các khối lượng công việc AI và machine learning. Nó tự động xử lý việc cấp phát, mở rộng và thực thi — bạn viết mã Python cục bộ và Modal chạy nó trên đám mây với quyền truy cập GPU. Điều này làm cho nó trở nên lý tưởng để chạy các mô hình deep learning như YOLO26 mà không cần quản lý hạ tầng.

Link to this sectionNhững gì bạn sẽ học#

  • Thiết lập và xác thực Modal
  • Chạy suy luận YOLO26 trên Modal
  • Sử dụng GPU để tăng tốc suy luận
  • Huấn luyện các mô hình YOLO26 trên Modal

Link to this sectionĐiều kiện tiên quyết#

  • Một tài khoản Modal (đăng ký miễn phí tại modal.com)
  • Python 3.9 trở lên đã được cài đặt trên máy cục bộ của bạn

Link to this sectionCài đặt#

Cài đặt gói Python của Modal:

pip install modal

Sau đó xác thực CLI với tài khoản Modal của bạn:

modal token new
Xác thực

Lệnh modal token new sẽ mở một cửa sổ trình duyệt để xác thực tài khoản Modal của bạn. Sau khi xác thực, bạn có thể chạy các lệnh Modal từ terminal.

Link to this sectionChạy suy luận YOLO26#

Tạo một tệp Python mới có tên modal_yolo.py để chạy inference với mã sau:

"""
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")

Chạy suy luận:

modal run modal_yolo.py

Kết quả dự kiến:

✓ 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.

Bạn có thể theo dõi quá trình thực thi hàm của mình trong bảng điều khiển Modal:

Modal Dashboard Function Calls

Link to this sectionSử dụng GPU để tăng tốc suy luận#

Thêm GPU vào hàm của bạn bằng cách chỉ định tham số gpu:

@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)
GPUBộ nhớPhù hợp nhất cho
T416 GBSuy luận, huấn luyện mô hình nhỏ
A10G24 GBCác tác vụ huấn luyện quy mô trung bình
A10040 GBHuấn luyện quy mô lớn
H10080 GBHiệu suất tối đa

Link to this sectionHuấn luyện YOLO26 trên Modal#

Để huấn luyện, hãy sử dụng GPU và Modal Volumes để lưu trữ bền bỉ. Tạo một tệp Python mới có tên 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()

Chạy huấn luyện:

modal run train_yolo.py
Volume Persistence (Lưu trữ bền bỉ)

Modal Volumes lưu trữ dữ liệu giữa các lần chạy hàm. Các trọng số đã huấn luyện được lưu vào /data/runs/train/weights/.

Chúc mừng! Bạn đã thiết lập thành công Ultralytics YOLO26 trên Modal. Để tìm hiểu thêm:

Link to this sectionCâu hỏi thường gặp#

Link to this sectionLàm thế nào để tôi chọn GPU phù hợp cho khối lượng công việc YOLO26 của mình?#

Đối với suy luận, NVIDIA T4 (16 GB) thường là đủ và tiết kiệm chi phí. Đối với huấn luyện hoặc các mô hình lớn hơn như YOLO26x, hãy cân nhắc sử dụng GPU A10G hoặc A100.

Link to this sectionChi phí để chạy YOLO26 trên Modal là bao nhiêu?#

Modal sử dụng hình thức thanh toán theo giây. Mức giá xấp xỉ: CPU ~0,05 USD/giờ, T4 ~0,59 USD/giờ, A10G ~1,10 USD/giờ, A100 ~2,10 USD/giờ. Kiểm tra bảng giá Modal để biết giá hiện tại.

Link to this sectionTôi có thể sử dụng mô hình YOLO tùy chỉnh của riêng mình không?#

Có, bạn có thể chạy mô hình YOLO tùy chỉnh của riêng mình trên Modal bằng cách tải tệp trọng số từ một Modal Volume:

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

Để biết thêm thông tin về việc huấn luyện các mô hình tùy chỉnh, hãy xem hướng dẫn huấn luyện.

Người đóng góp

Bình luận