Code: Select all
@DESKTOP-HS1UL5Q:~/.nuclio/best-model$ nuctl deploy --project-name cvat --path . --platform local
Ich versuche, das Modell oben auszuführen, aber es kann Anforderungen nicht finden. Das Bild unten zeigt die Dateistruktur. />
Code: Select all
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
Code: Select all
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)
Code: Select all
ultralytics==8.1.24
opencv-python
numpy