-
-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use this repo ? #98
Comments
I am in the same boat, looking for any tutorial in how to use this repo and convert the JSON(VGG Image Annotator)/COCO format into YOLO (.pt). Unfortunately no one put any tutorial about how to use this repository and what should we run to convert |
@VictorGimenez hello! Thank you for reaching out. To convert JSON (VGG Image Annotator/COCO) format annotations to YOLO format, you can follow these steps:
If you encounter any issues or if the script does not work as expected, please ensure you are using the latest version of the repository. You can update your local copy by running: git pull origin master Feel free to ask if you have any more questions or need further assistance. The YOLO community and the Ultralytics team are here to help! 😊 |
Hi @pderrenger! Thanks for the feedback! Where is the I would like to know the format of the desired input JSON file so that the script works! Thanks again for the response! |
Hi @VictorGimenez! Thanks for your patience and for reaching out. It looks like the import json
import os
def convert_coco_to_yolo(json_path, output_path):
with open(json_path) as f:
data = json.load(f)
if not os.path.exists(output_path):
os.makedirs(output_path)
for image in data['images']:
image_id = image['id']
file_name = image['file_name']
width = image['width']
height = image['height']
annotations = [ann for ann in data['annotations'] if ann['image_id'] == image_id]
with open(os.path.join(output_path, f"{os.path.splitext(file_name)[0]}.txt"), 'w') as f:
for ann in annotations:
category_id = ann['category_id']
bbox = ann['bbox']
x_center = (bbox[0] + bbox[2] / 2) / width
y_center = (bbox[1] + bbox[3] / 2) / height
w = bbox[2] / width
h = bbox[3] / height
f.write(f"{category_id} {x_center} {y_center} {w} {h}\n")
json_path = 'path/to/your/coco_annotations.json'
output_path = 'path/to/output_directory'
convert_coco_to_yolo(json_path, output_path) Steps to Use the Script:
Input JSON Format:The input JSON file should follow the COCO format, which typically includes:
If you encounter any issues, please ensure you are using the latest version of the Ultralytics package. You can update it by running: pip install --upgrade ultralytics Feel free to reach out if you have any more questions or need further assistance. The YOLO community and the Ultralytics team are here to help! 😊 |
Greeat!! Many thanks for the help!!! I am gonna give a test on it and come back here after to say the results ;) |
You're welcome! 😊 I'm glad I could help. Please go ahead and test the script with your dataset. If you encounter any issues or have further questions, feel free to come back and share your results or any challenges you face. Also, make sure you are using the latest version of the Ultralytics package to avoid any compatibility issues. You can update it by running: pip install --upgrade ultralytics Looking forward to hearing how it goes! 🚀 |
|
HI @glenn-jocher I have downloaded the requirements.txt file but nowhere in the description can I see how to use or run this repo what code I have to use to change my JSON files to txt files so please help regarding this
The text was updated successfully, but these errors were encountered: