You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the HUB issues and discussions and found no similar questions.
Question
I have conducted preliminary training on your platform and program to define the data set, and obtained some pictures of prediction results. However, I want to return the format of the annotation file from these results. What should I do?
Additional
There are categories for drawing borders and predictions in the test result picture.
The text was updated successfully, but these errors were encountered:
Thank you for reaching out with your question. It's great to hear that you've been working with the Ultralytics platform and achieving prediction results! 😊
To convert the YOLO test results back into the annotated .txt file format, you can follow these steps:
Run Inference and Get Results:
First, ensure you have the inference results in JSON format. You can use the Ultralytics HUB Inference API to get these results. Here's a quick Python example to get you started:
importrequests# API URL, use actual MODEL_IDurl="https://api.ultralytics.com/v1/predict/MODEL_ID"# Headers, use actual API_KEYheaders= {"x-api-key": "API_KEY"}
# Inference arguments (optional)data= {"size": 640, "confidence": 0.25, "iou": 0.45}
# Load image and send requestwithopen("path/to/image.jpg", "rb") asimage_file:
files= {"image": image_file}
response=requests.post(url, headers=headers, files=files, data=data)
results=response.json()
Extract and Convert Results:
Once you have the results, you can extract the necessary information and convert it into the YOLO annotation format. The YOLO format typically includes the class, center x, center y, width, and height of the bounding box, all normalized by the image dimensions.
Here's a sample code snippet to convert the results:
importjsondefconvert_to_yolo_format(results, image_width, image_height):
annotations= []
fordetectioninresults['data']:
class_id=detection['class']
x_center=detection['xcenter'] *image_widthy_center=detection['ycenter'] *image_heightwidth=detection['width'] *image_widthheight=detection['height'] *image_heightannotations.append(f"{class_id}{x_center}{y_center}{width}{height}")
returnannotations# Assuming you have the image dimensionsimage_width=640image_height=480yolo_annotations=convert_to_yolo_format(results, image_width, image_height)
# Save to a .txt filewithopen("path/to/annotations.txt", "w") asfile:
forannotationinyolo_annotations:
file.write(f"{annotation}\n")
Verify and Adjust:
Ensure that the image dimensions (image_width and image_height) are correctly set to match your input image. The annotations will be saved in the YOLO format in the specified .txt file.
If you encounter any issues or if the problem persists, please make sure you are using the latest versions of the Ultralytics packages and the YOLO model. Updates often include important bug fixes and improvements.
Search before asking
Question
I have conducted preliminary training on your platform and program to define the data set, and obtained some pictures of prediction results. However, I want to return the format of the annotation file from these results. What should I do?
Additional
There are categories for drawing borders and predictions in the test result picture.
The text was updated successfully, but these errors were encountered: