Skip to content

Convert a YOLOv8 seg model detection result to YOLOv8 label #16658

Answered by johnlockejrr
johnlockejrr asked this question in Q&A
Discussion options

You must be logged in to vote

I changed the second script like this as you suggested, I'm not sure the polygons are sorted top down:

import torch
import cv2
import numpy as np
from ultralytics import YOLO
from pathlib import Path

# Load YOLOv8 segmentation model
model = YOLO("./runs/segment/train2/weights/best.pt")

# Run inference on an image
results = model('./3_page-0018.jpg')

# Directory to save YOLOv8 labels
output_directory = Path("./output_yolo_labels/")
output_directory.mkdir(parents=True, exist_ok=True)

# Get the first result (assuming one image for simplicity)
result = results[0]
image_height, image_width = result.orig_img.shape[:2]

# Open file to save YOLOv8 format multipoint polygons
txt_file_path = ou…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@glenn-jocher
Comment options

Answer selected by johnlockejrr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested segment Instance Segmentation issues, PR's detect Object Detection issues, PR's
3 participants