Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Yolo Export Support #1034

Open
NHodgesVFX opened this issue Dec 9, 2020 · 4 comments · May be fixed by #1047
Open

Yolo Export Support #1034

NHodgesVFX opened this issue Dec 9, 2020 · 4 comments · May be fixed by #1047

Comments

@NHodgesVFX
Copy link

Is your feature request related to a problem? Please describe.
I want to use vott to label images for a yolov5 model.
Instead of having to convert in an external program or service it would be nice if VOTT could export to the yolo format directly

Describe the solution you'd like
the ability to export to the yolo format.

Describe alternatives you've considered
python scripting or roboflow, python is fine but just an extra step, roboflow is paid and a extra step.

@tovi911
Copy link

tovi911 commented Jan 31, 2021

Make your own Python script to convert the CSV output to whatever you want.

@phaabe
Copy link

phaabe commented Mar 2, 2021

Licht-T added a commit to Licht-T/VoTT that referenced this issue Mar 27, 2021
@Licht-T Licht-T linked a pull request Mar 27, 2021 that will close this issue
@pullmyleg
Copy link

Here is a pyhton script to convert from VoTT CSV to Yolo label txt files.

from PIL import Image
from os import path, makedirs
import os
import re
import pandas as pd
import sys
import argparse


def get_parent_dir(n=1):
    """returns the n-th parent dicrectory of the current
    working directory"""
    current_path = os.path.dirname(os.path.abspath(__file__))
    for k in range(n):
        current_path = os.path.dirname(current_path)
    return current_path


sys.path.append(os.path.join(get_parent_dir(1), "Utils"))
from Convert_Format import convert_vott_csv_to_yolo

Data_Folder = os.path.join(get_parent_dir(1), "Data")
VoTT_Folder = os.path.join(
    Data_Folder, "Source_Images", "Training_Images", "vott-csv-export"
)
VoTT_csv = os.path.join(VoTT_Folder, "Annotations-export.csv")
YOLO_filename = os.path.join(VoTT_Folder, "data_train.txt")

model_folder = os.path.join(Data_Folder, "Model_Weights")
classes_filename = os.path.join(model_folder, "data_classes.txt")

if __name__ == "__main__":
    # surpress any inhereted default values
    parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
    """
    Command line options
    """
    parser.add_argument(
        "--VoTT_Folder",
        type=str,
        default=VoTT_Folder,
        help="Absolute path to the exported files from the image tagging step with VoTT. Default is "
        + VoTT_Folder,
    )

    parser.add_argument(
        "--VoTT_csv",
        type=str,
        default=VoTT_csv,
        help="Absolute path to the *.csv file exported from VoTT. Default is "
        + VoTT_csv,
    )
    parser.add_argument(
        "--YOLO_filename",
        type=str,
        default=YOLO_filename,
        help="Absolute path to the file where the annotations in YOLO format should be saved. Default is "
        + YOLO_filename,
    )

    FLAGS = parser.parse_args()

    # Prepare the dataset for YOLO
    multi_df = pd.read_csv(FLAGS.VoTT_csv)
    labels = multi_df["label"].unique()
    labeldict = dict(zip(labels, range(len(labels))))
    multi_df.drop_duplicates(subset=None, keep="first", inplace=True)
    train_path = FLAGS.VoTT_Folder
    convert_vott_csv_to_yolo(
        multi_df, labeldict, path=train_path, target_name=FLAGS.YOLO_filename
    )

    # Make classes file
    file = open(classes_filename, "w")

    # Sort Dict by Values
    SortedLabelDict = sorted(labeldict.items(), key=lambda x: x[1])
    for elem in SortedLabelDict:
        file.write(elem[0] + "\n")
    file.close()

@jeanbmar
Copy link

Here is an NPM module I've written to do the conversion: https://www.npmjs.com/package/vott2yolo
One-liner : vott2yolo /path/to/labeled-files/**/*.json /path/to/project.vott

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

Successfully merging a pull request may close this issue.

5 participants