Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -32,35 +32,35 @@ def yolov8_img_inference(
|
|
32 |
model = YOLO(model_path)
|
33 |
model.conf = conf_threshold
|
34 |
model.iou = iou_threshold
|
35 |
-
|
36 |
-
results = model.predict(image)
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
render = render_result(model=model, image=image, result=results[0])
|
64 |
|
65 |
return render
|
66 |
|
@@ -83,7 +83,7 @@ interface_image = gr.Interface(
|
|
83 |
outputs=outputs_image,
|
84 |
title=title,
|
85 |
examples=image_path,
|
86 |
-
cache_examples=
|
87 |
theme='huggingface'
|
88 |
)
|
89 |
|
@@ -92,4 +92,4 @@ gr.TabbedInterface(
|
|
92 |
tab_names=['Image inference']
|
93 |
).queue().launch()
|
94 |
|
95 |
-
|
|
|
32 |
model = YOLO(model_path)
|
33 |
model.conf = conf_threshold
|
34 |
model.iou = iou_threshold
|
35 |
+
results = model.predict(image, imgsz=image_size, return_outputs=True)
|
36 |
+
# results = model.predict(image)
|
37 |
+
object_prediction_list = []
|
38 |
+
for _, image_results in enumerate(results):
|
39 |
+
if len(image_results)!=0:
|
40 |
+
image_predictions_in_xyxy_format = image_results['det']
|
41 |
+
for pred in image_predictions_in_xyxy_format:
|
42 |
+
x1, y1, x2, y2 = (
|
43 |
+
int(pred[0]),
|
44 |
+
int(pred[1]),
|
45 |
+
int(pred[2]),
|
46 |
+
int(pred[3]),
|
47 |
+
)
|
48 |
+
bbox = [x1, y1, x2, y2]
|
49 |
+
score = pred[4]
|
50 |
+
category_name = model.model.names[int(pred[5])]
|
51 |
+
category_id = pred[5]
|
52 |
+
object_prediction = ObjectPrediction(
|
53 |
+
bbox=bbox,
|
54 |
+
category_id=int(category_id),
|
55 |
+
score=score,
|
56 |
+
category_name=category_name,
|
57 |
+
)
|
58 |
+
object_prediction_list.append(object_prediction)
|
59 |
|
60 |
+
image = read_image(image)
|
61 |
+
output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
|
62 |
+
return output_image['image']
|
63 |
+
# render = render_result(model=model, image=image, result=results[0])
|
64 |
|
65 |
return render
|
66 |
|
|
|
83 |
outputs=outputs_image,
|
84 |
title=title,
|
85 |
examples=image_path,
|
86 |
+
cache_examples=True,
|
87 |
theme='huggingface'
|
88 |
)
|
89 |
|
|
|
92 |
tab_names=['Image inference']
|
93 |
).queue().launch()
|
94 |
|
95 |
+
interface_image.launch(debug=True, enable_queue=True)
|