[Python] How do I deploy local model weights (best.pt) to CVAT for auto-annotation

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use CVAT locally with Docker for image bounding box labeling. To save time, I'd like to use auto-annotation with a partially trained model. However, when I try to deploy the model from WSL, I keep getting an error saying requirements.txt is missing. I'm not sure how to proceed. Any help would be greatly appreciated.

    @DESKTOP-HS1UL5Q:~/.nuclio/best-model$ nuctl deploy --project-name cvat --path . --platform local


    enter image description here

    I'm trying to deploy the model by running the code above, but it can't find requirements.txt. The image below shows the file structure.

    enter image description here

    Here are the contents of each file.

    function.yaml

    metadata:
    name: best-model
    namespace: cvat
    spec:
    runtime: python:3.9
    handler: handler:handler
    description: YOLOv8 object detector for CVAT
    env: []
    build:
    commands:
    - pip install -r requirements.txt
    artifacts:
    - target: best.pt
    - target: handler.py
    - target: requirements.txt
    triggers:
    http:
    kind: http
    maxWorkers: 1
    workerAvailabilityTimeoutMilliseconds: 10000
    attributes:
    maxRequestBodySize: 33554432


    handler.py

    import io
    import json
    import numpy as np
    import cv2
    from PIL import Image
    import base64
    from ultralytics import YOLO

    model = YOLO("best.pt")

    def handler(context, event):
    body = event.body
    img_bytes = np.asarray(bytearray(body), dtype=np.uint8)
    img = cv2.imdecode(img_bytes, cv2.IMREAD_COLOR)

    results = model(img)[0]
    predictions = []

    for box in results.boxes:
    cls = int(box.cls[0].item())
    conf = float(box.conf[0].item())
    x1, y1, x2, y2 = map(float, box.xyxy[0].tolist())

    predictions.append({
    "confidence": conf,
    "label": str(cls),
    "points": [[x1, y1], [x2, y2]],
    "type": "rectangle"
    })

    return context.Response(body=json.dumps(predictions), headers={},
    content_type='application/json', status_code=200)


    requirements.txt

    ultralytics==8.1.24
    opencv-python
    numpy

    Continue reading...

Compartilhe esta Página