Make package
@glenn-jocher Added setup.py to convert this into into a package. Can be imported in yolov5 to convert datasets on the fly while training.
Usage
from json2yolo import convert_coco_json
convert_coco_json(...)
Potential improvement:
The function creates a new_dir by default. Instead we can just create the labels/ folder in the coco dataset dir along with the yaml file needed for subsequent loading of data.
🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
📊 Key Changes
- Created a new Python package structure by moving existing scripts under a new
json2yolodirectory. - Removed
requirements.txtand added asetup.pyscript to manage package installation. - Refactored utility functions by moving them from individual scripts into
json2yolo/utils.py. - Removed redundant code related to merging multi-segments within the JSON conversion script.
🎯 Purpose & Impact
- The change to a package structure 📦 streamlines the use and distribution of JSON to YOLO conversion tools.
- By moving dependencies to
setup.py🛠, installation becomes more conventional and manageable using Python's packaging tools. - Centralizing utility functions 🧰 reduces code duplication and eases maintenance, making it easier for developers to use and contribute to the project.
🌟 Summary
Converted JSON2YOLO tools into a maintainable and easily installable Python package 🎁.
Hi @AyushExel,
Thank you for your contribution! 🎉 Your effort to convert the JSON2YOLO tools into a maintainable and easily installable Python package is much appreciated. This will certainly streamline the usage and distribution of these tools.
Regarding your suggestion to create the labels/ folder within the COCO dataset directory along with the YAML file, that sounds like a practical improvement. It would indeed simplify the directory structure and make it more intuitive for users.
If you haven't already, please ensure that this change is compatible with the latest version of the YOLOv5 repository. This will help us avoid any potential integration issues.
Here's a quick example of how you might modify the function to create the labels/ folder within the COCO dataset directory:
import os
def convert_coco_json(json_path, output_dir=None):
if output_dir is None:
output_dir = os.path.join(os.path.dirname(json_path), 'labels')
os.makedirs(output_dir, exist_ok=True)
# Conversion logic here
# ...
# Save YAML file
yaml_path = os.path.join(output_dir, 'dataset.yaml')
with open(yaml_path, 'w') as f:
f.write('...') # YAML content here
Feel free to adjust the implementation as needed. Once again, thank you for your valuable contribution to the YOLO community and the Ultralytics team. If you have any further questions or need assistance, please don't hesitate to ask!