Move to idiomatic python instead of map

...And strip newline from labels.
This commit is contained in:
niten 2023-01-11 16:32:22 -08:00
parent 4302d1d706
commit 686cfefc06
1 changed files with 4 additions and 4 deletions

View File

@ -39,7 +39,7 @@ file_cleanup_delay = to_int(get_envvar('OBJECTIFIER_CLEANUP_DELAY'))
yolo_labels = [] yolo_labels = []
with open(yolo_labels_file, "r") as f: with open(yolo_labels_file, "r") as f:
yolo_labels = f.readlines() yolo_labels = [line.strip() for line in f.readlines()]
incoming_dir = Path(get_envvar_or_fail('CACHE_DIRECTORY')) incoming_dir = Path(get_envvar_or_fail('CACHE_DIRECTORY'))
outgoing_dir = Path(get_envvar_or_fail('STATE_DIRECTORY')) outgoing_dir = Path(get_envvar_or_fail('STATE_DIRECTORY'))
@ -77,7 +77,7 @@ cleanup_thread.start()
def detection_to_dict(d): def detection_to_dict(d):
return { return {
"label": str(d.label), "label": d.label,
"confidence": d.confidence, "confidence": d.confidence,
"box": { "box": {
"x": d.box[0], "x": d.box[0],
@ -89,8 +89,8 @@ def detection_to_dict(d):
def result_to_dict(res, base_url): def result_to_dict(res, base_url):
return { return {
"labels": list(map(lambda d: str(d.label), res.detections)), "labels": [detection.label for detection in res.dectections],
"detections": list(map(detection_to_dict, res.detections)), "detections": [detection_to_dict(dectection) for detection in res.detections],
"output": base_url + basename(res.outfile), "output": base_url + basename(res.outfile),
} }