Spaces:
Runtime error
Runtime error
Commit
·
03d7b11
1
Parent(s):
00a50b3
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ from ultralyticsplus import YOLO
|
|
8 |
torch.hub.download_url_to_file('https://raw.githubusercontent.com/Owaiskhan9654/test_test/main/20.jpeg', '20.jpeg')
|
9 |
torch.hub.download_url_to_file('https://raw.githubusercontent.com/Owaiskhan9654/test_test/main/30.jpeg', '30.jpeg')
|
10 |
torch.hub.download_url_to_file('https://raw.githubusercontent.com/Owaiskhan9654/test_test/main/17.jpeg', '17.jpeg')
|
11 |
-
|
12 |
def yolov8_inference(
|
13 |
image: gr.inputs.Image = None,
|
14 |
model_path: gr.inputs.Dropdown = None,
|
@@ -31,35 +30,35 @@ def yolov8_inference(
|
|
31 |
model.conf = conf_threshold
|
32 |
model.iou = iou_threshold
|
33 |
results = model.predict(image, imgsz=image_size, )#return_outputs=True)
|
34 |
-
print(results)
|
|
|
|
|
35 |
object_prediction_list = []
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
image = read_image(image)
|
60 |
output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
|
61 |
-
return output_image['image']
|
62 |
-
|
63 |
|
64 |
inputs = [
|
65 |
gr.inputs.Image(type="filepath", label="Input Image"),
|
@@ -71,7 +70,7 @@ inputs = [
|
|
71 |
]
|
72 |
|
73 |
outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
74 |
-
title = "
|
75 |
|
76 |
examples = [['20.jpeg', 'owaiskha9654/yolov8-custom_objects', 224, 0.25, 0.45], ['30.jpeg', 'owaiskha9654/yolov8-custom_objects', 224, 0.25, 0.45],]# ['17.jpeg', 'owaiskha9654/yolov8-custom_objects', 1280, 0.25, 0.45]]
|
77 |
demo_app = gr.Interface(
|
|
|
8 |
torch.hub.download_url_to_file('https://raw.githubusercontent.com/Owaiskhan9654/test_test/main/20.jpeg', '20.jpeg')
|
9 |
torch.hub.download_url_to_file('https://raw.githubusercontent.com/Owaiskhan9654/test_test/main/30.jpeg', '30.jpeg')
|
10 |
torch.hub.download_url_to_file('https://raw.githubusercontent.com/Owaiskhan9654/test_test/main/17.jpeg', '17.jpeg')
|
|
|
11 |
def yolov8_inference(
|
12 |
image: gr.inputs.Image = None,
|
13 |
model_path: gr.inputs.Dropdown = None,
|
|
|
30 |
model.conf = conf_threshold
|
31 |
model.iou = iou_threshold
|
32 |
results = model.predict(image, imgsz=image_size, )#return_outputs=True)
|
33 |
+
print("Outputs", results[0].numpy())
|
34 |
+
# data = np.array(results[0].numpy(), dtype=np.float32)
|
35 |
+
print("Boxexes",results[0].boxes.boxes)
|
36 |
object_prediction_list = []
|
37 |
+
outputs = results[0].boxes.boxes.numpy()
|
38 |
+
if len(outputs)!=0
|
39 |
+
for pred in outputs:
|
40 |
+
print(type(pred),pred)
|
41 |
+
x1, y1, x2, y2 = (
|
42 |
+
int(pred[0]),
|
43 |
+
int(pred[1]),
|
44 |
+
int(pred[2]),
|
45 |
+
int(pred[3]),
|
46 |
+
)
|
47 |
+
bbox = [x1, y1, x2, y2]
|
48 |
+
score = pred[4]
|
49 |
+
category_name = model.model.names[int(pred[5])]
|
50 |
+
category_id = pred[5]
|
51 |
+
object_prediction = ObjectPrediction(
|
52 |
+
bbox=bbox,
|
53 |
+
category_id=int(category_id),
|
54 |
+
score=score,
|
55 |
+
category_name=category_name,
|
56 |
+
)
|
57 |
+
object_prediction_list.append(object_prediction)
|
58 |
+
|
|
|
59 |
image = read_image(image)
|
60 |
output_image = visualize_object_predictions(image=image, object_prediction_list=object_prediction_list)
|
61 |
+
return output_image['image']
|
|
|
62 |
|
63 |
inputs = [
|
64 |
gr.inputs.Image(type="filepath", label="Input Image"),
|
|
|
70 |
]
|
71 |
|
72 |
outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
73 |
+
title = "Custom YOLOv8: Trained on Industrial Equipments predictions"
|
74 |
|
75 |
examples = [['20.jpeg', 'owaiskha9654/yolov8-custom_objects', 224, 0.25, 0.45], ['30.jpeg', 'owaiskha9654/yolov8-custom_objects', 224, 0.25, 0.45],]# ['17.jpeg', 'owaiskha9654/yolov8-custom_objects', 1280, 0.25, 0.45]]
|
76 |
demo_app = gr.Interface(
|