class FileUtilities[source]

FileUtilities()

Set of utility functions for managing the requirements of the Ultralytics repo

class Generation[source]

Generation(repo, out_dir, data_yaml=None, verbose=True, resource_dirs=['train', 'valid', 'test'])

Container and organizer of photos for a given repository. This class "softly" organizes the files upon the setting of the split attribute via set_split.

The split can then be written to disk by calling write_split_to_disk. The relevant data will be zipped in out_dir

There is a two-step confirmation before making any changes to disk. First, crawl through the repo and collect all images and collect all labels. Labels must be in YOLOv5 format.

datadump = "ipynb_tests/01_split_datadump"

g = Generation(repo="./Image Repo/labeled/Final Roboflow Export (841)", 
               out_dir=datadump,
               verbose=True)

Apply a custom split or use only a maximum number of annotated images:

custom_split = {"train": .5, "valid": .3, "test": .2}
g.set_split(split_ratio=custom_split, MAX_SIZE=20)
g.get_split()
[{'train': 10}, {'valid': 6}, {'test': 4}]

Or split the entire repository on the default 70%/20%/10% of train/valid/test:

g.set_split()
g.get_split()
[{'train': 589}, {'valid': 169}, {'test': 83}]

Send the desired split to a zip folder that is sent to the out_dir

zipped = g.write_split_to_disk(descriptor="<01_split_all>")
dirs ['./train', './valid', './test']
yaml ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-27 04-28-42/data.yaml
subdir train
	outdir ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-27 04-28-42
subdir valid
	outdir ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-27 04-28-42
subdir test
	outdir ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-27 04-28-42
os.listdir ['train', 'valid', 'test', 'data.yaml']
print("Complete: ", zipped)
Complete:  ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-27 04-28-42.zip