InsectModelZoo / yolo_utils.py
Martin Tomov
@spaces.GPU yolo_utils.py
302e52c verified
raw
history blame
504 Bytes
from ultralytics import YOLO
import torch
import numpy as np
import cv2
from huggingface_hub import hf_hub_download
import spaces
REPO_ID = "idml/Yolov8_InsectDetect"
FILENAME = "insectYolo.pt"
# Ensure you have the model file
model = YOLO(hf_hub_download(repo_id=REPO_ID, filename=FILENAME))
@spaces.GPU
def yolo_processimage(image):
results = model(source=image,
conf=0.2, device='cpu')
rgb_image = cv2.cvtColor(results[0].plot(), cv2.COLOR_BGR2RGB)
return rgb_image