Upload predictions
Upload YOLOv5 predictions
from trainyolo.client import Client, Project
from trainyolo.utils.yolov5 import format_boxes
from urllib.request import urlretrieve
import torch
import os
# initialize client
APIKEY = "YOUR_API_KEY"
client = Client(APIKEY)
# load unlabeled samples
PROJECT_NAME = "YOUR_PROJECT"
project = Project.get_by_name(client, PROJECT_NAME)
samples = project.get_samples(filter='UNLABELED')
# initialize YOLOv5 model
MODEL_PATH = "PATH_TO_YOLOV8_MODEL.pt"
SIZE, CONF, IOU = 640, 0.5, 0.45
model = torch.hub.load('ultralytics/yolov5', 'custom', path=model_path)
model.conf = CONF
model.iou = IOU
# create a temporary image location
image_loc = './images'
os.makedirs(image_loc, exist_ok=True)
for sample in samples:
# download image
image_path = os.path.join(image_loc, sample.name)
if not os.path.exists(image_path):
urlretrieve(sample.asset['url'], image_path)
# forward image
detections = model(image_path, size=SIZE)
# upload detections
boxes = detections.xyxy[0].cpu().numpy()
sample.prediction = format_boxes(boxes)Last updated