Skip to content

Commit

Permalink
Add docstrings (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher authored Feb 22, 2024
1 parent 2767187 commit 5013314
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions general_json2yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Convert INFOLKS JSON file into YOLO-format labels ----------------------------
def convert_infolks_json(name, files, img_path):
# Create folders
"""Converts INFOLKS JSON annotations to YOLO-format labels."""
path = make_dirs()

# Import json
Expand Down Expand Up @@ -68,7 +68,7 @@ def convert_infolks_json(name, files, img_path):

# Convert vott JSON file into YOLO-format labels -------------------------------
def convert_vott_json(name, files, img_path):
# Create folders
"""Converts VoTT JSON files to YOLO-format labels and organizes dataset structure."""
path = make_dirs()
name = path + os.sep + name

Expand Down Expand Up @@ -254,6 +254,7 @@ def convert_ath_json(json_dir): # dir contains json annotations and images


def convert_coco_json(json_dir="../coco/annotations/", use_segments=False, cls91to80=False):
"""Converts COCO JSON format to YOLO label format, with options for segments and class mapping."""
save_dir = make_dirs() # output directory
coco80 = coco91_to_coco80_class()

Expand Down Expand Up @@ -376,7 +377,7 @@ def merge_multi_segment(segments):


def delete_dsstore(path="../datasets"):
# Delete apple .DS_store files
"""Deletes Apple .DS_Store files recursively from a specified directory."""
from pathlib import Path

files = list(Path(path).rglob(".DS_store"))
Expand Down
2 changes: 1 addition & 1 deletion labelbox_json2yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def convert(file, zip=True):
# Convert Labelbox JSON labels to YOLO labels
"""Converts Labelbox JSON labels to YOLO format and saves them, with optional zipping."""
names = [] # class names
file = Path(file)
save_dir = make_dirs(file.stem)
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def exif_size(img):
# Returns exif-corrected PIL size
"""Returns the EXIF-corrected PIL image size as a tuple (width, height)."""
s = img.size # (width, height)
try:
rotation = dict(img._getexif().items())[orientation]
Expand Down Expand Up @@ -70,7 +70,7 @@ def split_indices(x, train=0.9, test=0.1, validate=0.0, shuffle=True): # split


def make_dirs(dir="new_dir/"):
# Create folders
"""Creates a directory with subdirectories 'labels' and 'images', removing existing ones."""
dir = Path(dir)
if dir.exists():
shutil.rmtree(dir) # delete dir
Expand All @@ -80,7 +80,7 @@ def make_dirs(dir="new_dir/"):


def write_data_data(fname="data.data", nc=80):
# write darknet *.data file
"""Writes a Darknet-style .data file with dataset and training configuration."""
lines = [
"classes = %g\n" % nc,
"train =../out/data_train.txt\n",
Expand Down

0 comments on commit 5013314

Please sign in to comment.