Giter Club home page Giter Club logo

dataset-utils's Introduction

Annotation format conversion

This module is designed to facilitate the conversion of various annotation formats for bounding box-based object detection.

  • Example to convert xml to txt:
from AnnotationFormatConverter import vocxml_to_yolotxt

# define class name to id dict
class_name_to_id_mapping = {"smoke": 0,
                            "fire": 1}

# get the annotations
annotation_dir = 'annotations_xml/'
saved_dir = 'annotations_txt/val/'
annotations = glob.glob(annotation_dir + '*.xml')
annotations.sort()

# convert and save the annotations
for ann in tqdm.tqdm(annotations):
    info_dict = vocxml_to_yolotxt.extract_info_from_xml(ann)
    vocxml_to_yolotxt.convert_to_yolo_txt(saved_dir, info_dict, class_name_to_id_mapping)
  • Example to convert txt to xml:

(script only work when image and correspondent annotation file are in a same folder).

from AnnotationFormatConverter import yolotxt_to_vocxml

# define id to class mapping dict
id_to_class_name_mapping = {0: "smoke",
                            1: "fire"}

# define dataset directory that contain images and labels in the same folder
data_dir = 'data_dir'
saved_dir = 'annotation_xml'

yolotxt_to_vocxml.convert_to_voc_xml(id_to_class_name_mapping, data_dir, 'saved_dir')

Image clustering

This module utilizes sentence transformer models to measure image similarity, enabling image clustering and dataset splitting based on those similarities.

from ImageClustering import image_similarity

# get list of images
images_dir = "data_neuroo/train/images/"
images_path = sorted(os.listdir(images_dir))

# do image clustering
image_clusters, image_centroids, images_duplicate = image_similarity.cluster(root=images_dir, images_list=images_path,, sim_threshold=0.93,  
                                                    min_community_size=1, emb_batch_size=64, cluster_batch_size=128, size=320)

Datatset statistic

You can utilize this module to display statistical information about your dataset.

from DatasetStatistic import dataset_stistics

# define class names
names = {0: '0',
        1: '1', 
        2: '2',
        3: '3'}

# get list of labels
labels_dir = "train/labels/"
labels_path = sorted(os.listdir(labels_dir))

labels = []

# read labels
for i, label_file in enumerate(labels_path):
    with open(labels_dir + label_file, 'r') as fl:
        lines = fl.readlines()
    fl.close()

    for line in lines:
        line = line.split(" ")
        line = [float(i) for i in line]
        labels.append(line)
    
labels = np.array(labels)

# plot labels statistic
plot_labels_statistic(labels, names)

Dataset split

This module facilitates the splitting of datasets for object detection while preserving the class proportions. It treats the problem as a multi-label split. However, it's worth noting that in object detection tasks, there might be multiple instances of the same object in one image (e.g., multiple persons in an image). Therefore, this approach is considered an "approximation" since it doesn't fully account for such multi-instance scenarios.

from DatasetSplit import approximation_multi_label_data_split

# list label files
labels_dir = "train/labels/"
labels_path = sorted(os.listdir(labels_dir))

# split train/test
train_index, test_index = approximation_multi_label_data_split.split(labels_path=labels_path, labels_dir=labels_dir, n_splits=7, shuffle=True, random_state=0)

TODO

  • convert yolo to coco
  • annotation sanity check
  • dataset statistic
  • go through dataset
  • boobs annotator
  • bbox clustering

dataset-utils's People

Contributors

hulkds avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.