Noah Vriese
commited on
Commit
·
aac4532
1
Parent(s):
283dab4
Add output parsing
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
import onnxruntime as ort
|
4 |
|
@@ -22,6 +23,21 @@ object_detector = YOLOXDetector(
|
|
22 |
sess_options=sess_options,
|
23 |
)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def predict(input_img):
|
26 |
|
27 |
final_boxes, final_scores, final_cls = object_detector.predict(input_img)
|
@@ -54,8 +70,10 @@ def predict(input_img):
|
|
54 |
text_scale=0.6,
|
55 |
obfuscate_classes=[],
|
56 |
)
|
|
|
|
|
57 |
|
58 |
-
return input_img, {obj.display_name: obj.score for obj in detected_objects}
|
59 |
|
60 |
example_images = [
|
61 |
os.path.join("./examples", img) for img in os.listdir("./examples") if img.lower().endswith(('png', 'jpg', 'jpeg'))
|
@@ -64,7 +82,12 @@ example_images = [
|
|
64 |
gradio_app = gr.Interface(
|
65 |
predict,
|
66 |
inputs=gr.Image(label="Select image to process", sources=['upload', 'webcam'], type="numpy"),
|
67 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
68 |
title="License Plate Detection",
|
69 |
examples=example_images,
|
70 |
)
|
|
|
1 |
import os
|
2 |
+
import json
|
3 |
import gradio as gr
|
4 |
import onnxruntime as ort
|
5 |
|
|
|
23 |
sess_options=sess_options,
|
24 |
)
|
25 |
|
26 |
+
def generate_json(detected_objects):
|
27 |
+
detections_list = []
|
28 |
+
for obj in detected_objects:
|
29 |
+
detections_list.append({
|
30 |
+
"class_name": obj.display_name,
|
31 |
+
"score": obj.score,
|
32 |
+
"bbox_xyxy": obj.points_xyxy.tolist()
|
33 |
+
})
|
34 |
+
|
35 |
+
json_data = json.dumps(detections_list, indent=4)
|
36 |
+
with open("detections.json", "w") as f:
|
37 |
+
f.write(json_data)
|
38 |
+
|
39 |
+
return "detections.json", json_data
|
40 |
+
|
41 |
def predict(input_img):
|
42 |
|
43 |
final_boxes, final_scores, final_cls = object_detector.predict(input_img)
|
|
|
70 |
text_scale=0.6,
|
71 |
obfuscate_classes=[],
|
72 |
)
|
73 |
+
|
74 |
+
json_file, json_text = generate_json(detected_objects)
|
75 |
|
76 |
+
return input_img, {obj.display_name: obj.score for obj in detected_objects}, json_file, json_text
|
77 |
|
78 |
example_images = [
|
79 |
os.path.join("./examples", img) for img in os.listdir("./examples") if img.lower().endswith(('png', 'jpg', 'jpeg'))
|
|
|
82 |
gradio_app = gr.Interface(
|
83 |
predict,
|
84 |
inputs=gr.Image(label="Select image to process", sources=['upload', 'webcam'], type="numpy"),
|
85 |
+
outputs=[
|
86 |
+
gr.Image(label="Processed Image"),
|
87 |
+
gr.Label(label="Result", num_top_classes=2),
|
88 |
+
gr.File(label="Download JSON"),
|
89 |
+
gr.Textbox(label="Copy JSON Text", lines=10)
|
90 |
+
],
|
91 |
title="License Plate Detection",
|
92 |
examples=example_images,
|
93 |
)
|