Skip to content
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

Make package #26

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Make package #26

wants to merge 6 commits into from

Conversation

AyushExel
Copy link

@AyushExel AyushExel commented Aug 25, 2022

@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(...)

Screenshot 2022-08-25 at 3 29 34 PM

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 json2yolo directory.
  • Removed requirements.txt and added a setup.py script 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 🎁.

@glenn-jocher
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants