From 686cfefc062bfda888bcb12ad97b3f21511fd6b5 Mon Sep 17 00:00:00 2001 From: niten Date: Wed, 11 Jan 2023 16:32:22 -0800 Subject: [PATCH] Move to idiomatic python instead of map ...And strip newline from labels. --- src/objectifier.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/objectifier.py b/src/objectifier.py index 67a796d..4e5003a 100644 --- a/src/objectifier.py +++ b/src/objectifier.py @@ -39,7 +39,7 @@ file_cleanup_delay = to_int(get_envvar('OBJECTIFIER_CLEANUP_DELAY')) yolo_labels = [] 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')) outgoing_dir = Path(get_envvar_or_fail('STATE_DIRECTORY')) @@ -77,7 +77,7 @@ cleanup_thread.start() def detection_to_dict(d): return { - "label": str(d.label), + "label": d.label, "confidence": d.confidence, "box": { "x": d.box[0], @@ -89,8 +89,8 @@ def detection_to_dict(d): def result_to_dict(res, base_url): return { - "labels": list(map(lambda d: str(d.label), res.detections)), - "detections": list(map(detection_to_dict, res.detections)), + "labels": [detection.label for detection in res.dectections], + "detections": [detection_to_dict(dectection) for detection in res.detections], "output": base_url + basename(res.outfile), }