wrapping `yolov5/detect.py`
weight_path = 'ipynb_tests/02_train_datadump/<AutoWeight> - 1/weights/best.pt'
repos = []
repos.append("Image Repo/unlabeled/21-3-18 rowing 8-12 /")
repos.append("Image Repo/unlabeled/21-3-22 rowing (200) 1:53-7:00")
repos.append("Image Repo/unlabeled/21-3-22 rowing (200) 7:50-12:50")
dirs = []
for repo in repos:
files = os.listdir(repo)
absolute_paths = [os.path.join(repo, file) for file in files]
dirs.append(absolute_paths)
detector = Detector(weight_path=weight_path)
samples = dirs[0][3:7] + dirs[1][3:7] + dirs[2][3:7]
for i in range(len(samples)):
res = detector.process_image(samples[i])
print(i, "|", res)
Human-readable information about the class indentities is stored in the data.yaml folder. By default, the data.yaml file is created from the Defaults
class. Let's take a look:
from ModelAssistedLabel.core import Defaults
print(Defaults().data_yaml)
To convert the "names" variable to a python-friendly format, we do the following manipulation:
import ast, re
# needs to be wrapped in quotes to parse as dict
substitute = "names"
#select last line
classlist = Defaults().data_yaml.split("\n")[-1]
#add quotes around `names` ONLY around the start of a string
classlist = re.sub('^%s' % substitute, f"'{substitute}'", classlist)
#surround the string in curly braces to tell python it's a dict
classlist = f"{{{classlist}}}"
# parse string as dict
classlist = ast.literal_eval(classlist)
And now here is the value of the classes as used by yolov5
classlist
Set up a Viewer
object to investigate the behavior of a model
v = Viewer([weight_path], classlist['names'])
%matplotlib inline
results = []
for image in samples:
result = v.plot_for(image)
results.append(result)