From a8a58a078c5019fc92f5a4309aad8edb9e4d1937 Mon Sep 17 00:00:00 2001 From: niten Date: Tue, 10 Jan 2023 23:05:42 -0800 Subject: [PATCH] Try forcing labels to strings... --- src/objectifier.py | 28 ++-------------------------- yolo-cli.nix | 8 ++++---- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/objectifier.py b/src/objectifier.py index 27724ac..b8741b4 100644 --- a/src/objectifier.py +++ b/src/objectifier.py @@ -73,7 +73,7 @@ cleanup_thread.start() def detection_to_dict(d): return { - "label": d.label, + "label": str(d.label), "confidence": d.confidence, "box": { "x": d.box[0], @@ -85,34 +85,13 @@ def detection_to_dict(d): def result_to_dict(res, base_url): return { - "labels": list(map(lambda d: d.label, res.detections)), + "labels": list(map(lambda d: str(d.label), res.detections)), "detections": list(map(detection_to_dict, res.detections)), "output": base_url + basename(res.outfile), } -# @app.put("/images") -# def analyze_image(file: UploadFile(), request: Request): -# print("Initiating file receipt, url: " + str(request.url)) -# base_url = re.sub(r'\/images\/$', '/analyzed_images/', str(request.url)) -# infile = open(incoming_dir / file.filename) -# file_hash = hashlib.sha256() -# with open(infile, mode="wb") as f: -# chunk = f.read(buffer_size) -# while chunk: -# print("writing chunk") -# file_hash.update(chunk) -# infile.write(chunk) -# chunk=f.read(buffer_size) -# print("saving complete") -# print("analyzing image") -# result = detector.detect_objects(infile, file_hash.hexdigest() + ".png") -# print("image analyzed") -# remove(infile) -# return result_to_dict(result, base_url) - @app.post("/images") def analyze_image(request: Request, image: UploadFile): - print("Initiating file receipt, url: " + str(request.url)) base_url = re.sub(r'\/images\/?$', '/analyzed_images/', str(request.url)) infile = incoming_dir / image.filename file_hash = hashlib.sha256() @@ -123,12 +102,9 @@ def analyze_image(request: Request, image: UploadFile): print ("writing " + str(buffer_size) + " bytes") f.write(chunk) chunk = image.file.read(buffer_size) - print("save complete") - print("analyzing image") result = detector.detect_objects( infile, str(outgoing_dir / (file_hash.hexdigest() + ".png"))) - print("image analyzed") remove(infile) return result_to_dict(result, base_url) diff --git a/yolo-cli.nix b/yolo-cli.nix index 63a6560..ab1f5ef 100644 --- a/yolo-cli.nix +++ b/yolo-cli.nix @@ -1,4 +1,4 @@ -{ pkgs, yolo-data, ... }: +{ pkgs, yolov3-data, ... }: let name = "yolo-cli"; @@ -20,9 +20,9 @@ in pkgs.writeShellApplication { runtimeInputs = [ pythonYolo ]; text = pkgs.lib.concatStringsSep " " [ "${yoloCliFiles}/yolo-cli.py" - "--yolo_weights=${yolo-data}/yolov3.weights" - "--yolo_config=${yolo-data}/yolov3.cfg" - "--yolo_labels=${yolo-data}/labels" + "--yolo_weights=${yolov3-data}/yolov3.weights" + "--yolo_config=${yolov3-data}/yolov3.cfg" + "--yolo_labels=${yolov3-data}/labels" ''"$@"'' ]; }