Try forcing labels to strings...

This commit is contained in:
niten 2023-01-10 23:05:42 -08:00
parent 6bf366b68a
commit a8a58a078c
2 changed files with 6 additions and 30 deletions

View File

@ -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)

View File

@ -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"
''"$@"''
];
}