DRY conviences

class Defaults[source]

Defaults(config_file='ModelAssistedLabel config.json')

Makes certain variables are very accessible across the repository. The names of the variables and their respective values are stored in JSON format in ./ModelAssistedLabel config.json

Functions defined here are also available across this project.

make sure that autonaming works

datadump = "ipynb_tests/00_config_datadump"
extension = ".text"
Defaults.__hard_reset_test_dir__(datadump, keep_folder=True)

for i in range(3):
  next_filename = Defaults._itername(pre = f"{datadump}/Defaults (", 
                                     post = f"){extension}")
  with open(next_filename, "w") as outfile:
    outfile.writelines("<data>")

for i in range(3):
  next_filename = Defaults._itername(pre = f"{datadump}/Version - ", 
                                     post = "")
  with open(next_filename, "w") as outfile:
    outfile.writelines("<data>")

files = os.listdir(datadump)
assert len(files) == 6
files
deleted `ipynb_tests/00_config_datadump`
making `ipynb_tests/00_config_datadump`
['Defaults (1).text',
 'Defaults (2).text',
 'Defaults (3).text',
 'Version - 1',
 'Version - 2',
 'Version - 3']

Default Values are stored in "ModelAssistedLabel config.json"

Every time the class is called, the config file is re-read for changes.

Currently, the following attributes are then dynamically assigned to the newly-created Default object.

  • root (parent folder of YOLOv5 repo)
  • resource_map (defines images as ".jpg" and labels as ".txt")
  • split_ratio (by default, 70/20/10 split of train/valid/test.)
  • data_yaml (from YOLOv5 repo)
  • trainer template (from YOLOv5 repo)

This data is generated dynamically.

import json
d = Defaults()
data = d.read_json()
for k,v in data.items():
  print("Attribute:", k, "\n\t- Type:", type(v))
reading defaults from: ModelAssistedLabel config.json
Attribute: config_file 
	- Type: <class 'str'>
Attribute: root 
	- Type: <class 'str'>
Attribute: split_ratio 
	- Type: <class 'dict'>
Attribute: data_yaml 
	- Type: <class 'str'>
Attribute: resource_map 
	- Type: <class 'dict'>
Attribute: trainer_template 
	- Type: <class 'str'>