Update app.py
Browse files
app.py
CHANGED
|
@@ -9,9 +9,9 @@ import requests
|
|
| 9 |
from io import BytesIO
|
| 10 |
import os
|
| 11 |
|
| 12 |
-
model = YOLO('
|
| 13 |
model2 = pipeline('image-classification','Kaludi/csgo-weapon-classification')
|
| 14 |
-
name = ['grenade','knife','pistol','rifle']
|
| 15 |
image_directory = "/home/user/app/image"
|
| 16 |
video_directory = "/home/user/app/video"
|
| 17 |
|
|
@@ -57,10 +57,10 @@ def response2(image: gr.Image = None,image_size: gr.Slider = 640, conf_threshold
|
|
| 57 |
|
| 58 |
|
| 59 |
for r in results:
|
| 60 |
-
conf = np.array(r.boxes.conf)
|
| 61 |
-
cls = np.array(r.boxes.cls)
|
| 62 |
cls = cls.astype(int)
|
| 63 |
-
xywh = np.array(r.boxes.xywh)
|
| 64 |
xywh = xywh.astype(int)
|
| 65 |
|
| 66 |
for con, cl, xy in zip(conf, cls, xywh):
|
|
@@ -74,9 +74,11 @@ def response2(image: gr.Image = None,image_size: gr.Slider = 640, conf_threshold
|
|
| 74 |
elif cl == 1:
|
| 75 |
name_weap += name[cl] + '\n'
|
| 76 |
elif cl == 2:
|
|
|
|
|
|
|
| 77 |
out = model2(image)
|
| 78 |
name_weap += out[0]["label"] + '\n'
|
| 79 |
-
elif cl ==
|
| 80 |
out = model2(image)
|
| 81 |
name_weap += out[0]["label"] + '\n'
|
| 82 |
|
|
@@ -106,7 +108,8 @@ outputs = [gr.Image( type="pil", label="Output Image"),
|
|
| 106 |
examples = [[os.path.join(image_directory, "th (5).jpg"),640, 0.3, 0.6],
|
| 107 |
[os.path.join(image_directory, "th (8).jpg"),640, 0.3, 0.6],
|
| 108 |
[os.path.join(image_directory, "th (11).jpg"),640, 0.3, 0.6],
|
| 109 |
-
[os.path.join(image_directory, "th (3).jpg"),640, 0.3, 0.6]
|
|
|
|
| 110 |
]
|
| 111 |
title = 'Weapon Detection Finetuned YOLOv8'
|
| 112 |
description = 'Image Size: Defines the image size for inference.\nConfidence Treshold: Sets the minimum confidence threshold for detections.\nIOU Treshold: Intersection Over Union (IoU) threshold for Non-Maximum Suppression (NMS). Useful for reducing duplicates.'
|
|
|
|
| 9 |
from io import BytesIO
|
| 10 |
import os
|
| 11 |
|
| 12 |
+
model = YOLO('50epoch-new-weapon.pt')
|
| 13 |
model2 = pipeline('image-classification','Kaludi/csgo-weapon-classification')
|
| 14 |
+
name = ['grenade','knife','missile','pistol','rifle']
|
| 15 |
image_directory = "/home/user/app/image"
|
| 16 |
video_directory = "/home/user/app/video"
|
| 17 |
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
for r in results:
|
| 60 |
+
conf = np.array(r.boxes.conf.cpu())
|
| 61 |
+
cls = np.array(r.boxes.cls.cpu())
|
| 62 |
cls = cls.astype(int)
|
| 63 |
+
xywh = np.array(r.boxes.xywh.cpu())
|
| 64 |
xywh = xywh.astype(int)
|
| 65 |
|
| 66 |
for con, cl, xy in zip(conf, cls, xywh):
|
|
|
|
| 74 |
elif cl == 1:
|
| 75 |
name_weap += name[cl] + '\n'
|
| 76 |
elif cl == 2:
|
| 77 |
+
name_weap += name[cl] + '\n'
|
| 78 |
+
elif cl == 3:
|
| 79 |
out = model2(image)
|
| 80 |
name_weap += out[0]["label"] + '\n'
|
| 81 |
+
elif cl == 4:
|
| 82 |
out = model2(image)
|
| 83 |
name_weap += out[0]["label"] + '\n'
|
| 84 |
|
|
|
|
| 108 |
examples = [[os.path.join(image_directory, "th (5).jpg"),640, 0.3, 0.6],
|
| 109 |
[os.path.join(image_directory, "th (8).jpg"),640, 0.3, 0.6],
|
| 110 |
[os.path.join(image_directory, "th (11).jpg"),640, 0.3, 0.6],
|
| 111 |
+
[os.path.join(image_directory, "th (3).jpg"),640, 0.3, 0.6],
|
| 112 |
+
[os.path.join(image_directory, "th.jpg"),640, 0.3, 0.6]
|
| 113 |
]
|
| 114 |
title = 'Weapon Detection Finetuned YOLOv8'
|
| 115 |
description = 'Image Size: Defines the image size for inference.\nConfidence Treshold: Sets the minimum confidence threshold for detections.\nIOU Treshold: Intersection Over Union (IoU) threshold for Non-Maximum Suppression (NMS). Useful for reducing duplicates.'
|