Try forcing labels to strings...
This commit is contained in:
parent
6bf366b68a
commit
a8a58a078c
|
@ -73,7 +73,7 @@ cleanup_thread.start()
|
||||||
|
|
||||||
def detection_to_dict(d):
|
def detection_to_dict(d):
|
||||||
return {
|
return {
|
||||||
"label": d.label,
|
"label": str(d.label),
|
||||||
"confidence": d.confidence,
|
"confidence": d.confidence,
|
||||||
"box": {
|
"box": {
|
||||||
"x": d.box[0],
|
"x": d.box[0],
|
||||||
|
@ -85,34 +85,13 @@ 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: d.label, res.detections)),
|
"labels": list(map(lambda d: str(d.label), res.detections)),
|
||||||
"detections": list(map(detection_to_dict, res.detections)),
|
"detections": list(map(detection_to_dict, res.detections)),
|
||||||
"output": base_url + basename(res.outfile),
|
"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")
|
@app.post("/images")
|
||||||
def analyze_image(request: Request, image: UploadFile):
|
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))
|
base_url = re.sub(r'\/images\/?$', '/analyzed_images/', str(request.url))
|
||||||
infile = incoming_dir / image.filename
|
infile = incoming_dir / image.filename
|
||||||
file_hash = hashlib.sha256()
|
file_hash = hashlib.sha256()
|
||||||
|
@ -123,12 +102,9 @@ def analyze_image(request: Request, image: UploadFile):
|
||||||
print ("writing " + str(buffer_size) + " bytes")
|
print ("writing " + str(buffer_size) + " bytes")
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
chunk = image.file.read(buffer_size)
|
chunk = image.file.read(buffer_size)
|
||||||
print("save complete")
|
|
||||||
print("analyzing image")
|
|
||||||
result = detector.detect_objects(
|
result = detector.detect_objects(
|
||||||
infile,
|
infile,
|
||||||
str(outgoing_dir / (file_hash.hexdigest() + ".png")))
|
str(outgoing_dir / (file_hash.hexdigest() + ".png")))
|
||||||
print("image analyzed")
|
|
||||||
remove(infile)
|
remove(infile)
|
||||||
return result_to_dict(result, base_url)
|
return result_to_dict(result, base_url)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{ pkgs, yolo-data, ... }:
|
{ pkgs, yolov3-data, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
name = "yolo-cli";
|
name = "yolo-cli";
|
||||||
|
@ -20,9 +20,9 @@ in pkgs.writeShellApplication {
|
||||||
runtimeInputs = [ pythonYolo ];
|
runtimeInputs = [ pythonYolo ];
|
||||||
text = pkgs.lib.concatStringsSep " " [
|
text = pkgs.lib.concatStringsSep " " [
|
||||||
"${yoloCliFiles}/yolo-cli.py"
|
"${yoloCliFiles}/yolo-cli.py"
|
||||||
"--yolo_weights=${yolo-data}/yolov3.weights"
|
"--yolo_weights=${yolov3-data}/yolov3.weights"
|
||||||
"--yolo_config=${yolo-data}/yolov3.cfg"
|
"--yolo_config=${yolov3-data}/yolov3.cfg"
|
||||||
"--yolo_labels=${yolo-data}/labels"
|
"--yolo_labels=${yolov3-data}/labels"
|
||||||
''"$@"''
|
''"$@"''
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue