-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/luxonis dataset integration (#50)
* feature: add dataset convertets (coco, yolo, ldf) * feature: add dataset utils * feature: add raw dataset merge * docs: update examples * feature: add LuxonisDataset, COCO, YOLO formats * fix: remove old yolo conversion script * format: fix formatting * chore: update .gitignore * [Automated] Updated coverage badge * fix: import from utils * fix: not removing dir when --annotate_only * [Automated] Updated coverage badge * docs: fix docstrings in converters * refactor: remove file with a typo in name * chore: set the minimum required version of luxonis-ml * fix: remove redundant function * refactor: rename ldf to luxonis-dataset * format: black and ruff * [Automated] Updated coverage badge * feature: add reproducibility with a random seed to converters * test: add converter tests * format: black * [Automated] Updated coverage badge --------- Co-authored-by: GitHub Actions <actions@github.com>
- Loading branch information
1 parent
bb16db9
commit 77811c9
Showing
17 changed files
with
1,017 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,5 +153,6 @@ Thumbs.db | |
# Others | ||
node_modules/ | ||
**generated_dataset*/ | ||
**gen_dataset*/ | ||
**runs/ | ||
**wandb/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from .base_converter import BaseConverter | ||
from .coco_converter import COCOConverter | ||
from .luxonis_dataset_converter import LuxonisDatasetConverter | ||
from .yolo_converter import YOLOConverter | ||
|
||
__all__ = [ | ||
"BaseConverter", | ||
"COCOConverter", | ||
"LuxonisDatasetConverter", | ||
"YOLOConverter", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from abc import ABC, abstractmethod | ||
|
||
import numpy as np | ||
|
||
|
||
class BaseConverter(ABC): | ||
"""Abstract base class for converter.""" | ||
|
||
def __init__(self, seed=42): | ||
np.random.seed(seed) | ||
|
||
@abstractmethod | ||
def convert(self, dataset_dir, output_dir, split_ratios, copy_files=True): | ||
"""Converts a dataset into another format. | ||
Args: | ||
- dataset_dir (str): The directory where the source dataset is located. | ||
- output_dir (str): The directory where the processed dataset should be saved. | ||
- split_ratios (list of float): The ratios to split the data into training, validation, and test sets. | ||
- copy_files (bool, optional): Whether to copy the source files to the output directory, otherwise move them. Defaults to True. | ||
No return value. | ||
""" | ||
pass | ||
|
||
@staticmethod | ||
def read_annotations(annotation_path): | ||
"""Reads annotations from a JSON file located at the specified path. | ||
Args: | ||
- annotation_path (str): The path to the JSON file containing annotations. | ||
Returns: | ||
- dict: A dictionary containing the data loaded from the JSON file. | ||
""" | ||
with open(annotation_path) as f: | ||
data = json.load(f) | ||
return data | ||
|
||
@staticmethod | ||
def make_splits(images, split_ratios, shuffle=True): | ||
"""Splits the list of images into training, validation, and test sets. | ||
Args: | ||
- images (list of str): A list of image paths. | ||
- split_ratios (list of float): The ratios to split the data into training, validation, and test sets. | ||
- shuffle (bool, optional): Whether to shuffle the list of images. Defaults to True. | ||
Returns: | ||
- list of str: A list of image paths for the training set. | ||
- list of str: A list of image paths for the validation set. | ||
- list of str: A list of image paths for the test set. | ||
""" | ||
if shuffle: | ||
np.random.shuffle(images) | ||
|
||
train_images = images[: int(len(images) * split_ratios[0])] | ||
val_images = images[ | ||
int(len(images) * split_ratios[0]) : int( | ||
len(images) * (split_ratios[0] + split_ratios[1]) | ||
) | ||
] | ||
test_images = images[int(len(images) * (split_ratios[0] + split_ratios[1])) :] | ||
|
||
return train_images, val_images, test_images |
Oops, something went wrong.