wrapping `yolov5/train.py`

We're building towards generating a model with a single call.

Trainer is a fairly bare-bones wrapper built around train.py.

AutoWeights is a more robust wrapper and allows for custom naming/placement of the results folder.

class Trainer[source]

Trainer(yaml_data, name, yaml_file='models/custom_yolov5s.yaml')

A wrapper for Ultralytic's test.py

Write the backbone of the model to file and then run YOLOv5's train file.

class AutoWeights[source]

AutoWeights(name='AutoWeight <name>', out_dir='.', MAX_SIZE=5, custom_split=None, data_yaml=None, verbose=True, train_path='yolov5/runs/train')

Given a bag of images (.jpg) and labels (.txt) in YOLOv5 format in a repository, initialize the ROOT directory with a train-valid-test split and a file needed by the Ultralytics repository. Pairs are identified via having a common filename.

Then call generate_weights to run train.py. The resultant file will try to be moved to the out_dir and if a conflict exists, a new name will be made.

aw = AutoWeights(name="<AutoWeight>", out_dir="ipynb_tests/02_train_datadump", MAX_SIZE=10)
aw.initialize_images_from_zip("ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-24 17-23-14.zip")
mv 'unzipped/ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-24 17-23-14/train' .
mv 'unzipped/ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-24 17-23-14/valid' .
mv 'unzipped/ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-24 17-23-14/test' .
mv 'unzipped/ipynb_tests/01_split_datadump/Final Roboflow Export (841)<01_split_all> 21-03-24 17-23-14/data.yaml' .
['train', 'valid', 'test', 'data.yaml']
	 > 231 files
	 > 231 files
	 > 169 files
	 > 169 files
	 > 83 files
	 > 83 files
File:  data.yaml
from ModelAssistedLabel.config import Defaults

current = aw.generate_weights(1, Defaults().trainer_template, rm_local_files=True)
Removing:  train
Removing:  valid
Removing:  test
Removing:  data.yaml
CPU times: user 188 ms, sys: 42.7 ms, total: 230 ms
Wall time: 53.4 s
!ls "{current}"
confusion_matrix.png				   results.txt
events.out.tfevents.1616819427.d2b6878b276d.635.0  test_batch0_labels.jpg
F1_curve.png					   test_batch0_pred.jpg
hyp.yaml					   test_batch1_labels.jpg
labels_correlogram.jpg				   test_batch1_pred.jpg
labels.jpg					   test_batch2_labels.jpg
opt.yaml					   test_batch2_pred.jpg
P_curve.png					   train_batch0.jpg
PR_curve.png					   train_batch1.jpg
R_curve.png					   train_batch2.jpg
results.png					   weights