Cleaning up the strings
Browse files
app.py
CHANGED
@@ -20,6 +20,8 @@ COLORS = [
|
|
20 |
[0.301, 0.745, 0.933]
|
21 |
]
|
22 |
|
|
|
|
|
23 |
def make_prediction(img, feature_extractor, model):
|
24 |
inputs = feature_extractor(img, return_tensors="pt")
|
25 |
outputs = model(**inputs)
|
@@ -64,8 +66,8 @@ def detect_objects(model_name,url_input,image_input,threshold):
|
|
64 |
|
65 |
model = YOLO(model_name)
|
66 |
# set model parameters
|
67 |
-
model.overrides['conf'] = 0.
|
68 |
-
model.overrides['iou'] = 0.
|
69 |
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
70 |
model.overrides['max_det'] = 1000 # maximum number of detections per image
|
71 |
|
@@ -81,11 +83,14 @@ def detect_objects(model_name,url_input,image_input,threshold):
|
|
81 |
boxes = result.boxes.cpu().numpy()
|
82 |
for i, box in enumerate(boxes):
|
83 |
# r = box.xyxy[0].astype(int)
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
89 |
|
90 |
final_str = "{:*^50}\n".format("ABOVE THRESHOLD OR EQUAL") + final_str_abv + "\n{:*^50}\n".format("BELOW THRESHOLD")+final_str_else
|
91 |
|
|
|
20 |
[0.301, 0.745, 0.933]
|
21 |
]
|
22 |
|
23 |
+
YOLOV8_LABELS = ['pedestrian', 'people', 'bicycle', 'car', 'van', 'truck', 'tricycle', 'awning-tricycle', 'bus', 'motor']
|
24 |
+
|
25 |
def make_prediction(img, feature_extractor, model):
|
26 |
inputs = feature_extractor(img, return_tensors="pt")
|
27 |
outputs = model(**inputs)
|
|
|
66 |
|
67 |
model = YOLO(model_name)
|
68 |
# set model parameters
|
69 |
+
model.overrides['conf'] = 0.15 # NMS confidence threshold
|
70 |
+
model.overrides['iou'] = 0.05 # NMS IoU threshold https://www.google.com/search?client=firefox-b-1-d&q=intersection+over+union+meaning
|
71 |
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
72 |
model.overrides['max_det'] = 1000 # maximum number of detections per image
|
73 |
|
|
|
83 |
boxes = result.boxes.cpu().numpy()
|
84 |
for i, box in enumerate(boxes):
|
85 |
# r = box.xyxy[0].astype(int)
|
86 |
+
coordinates = box.xyxy[0].astype(int)
|
87 |
+
label = YOLOV8_LABELS[box.cls]
|
88 |
+
confi = box.conf
|
89 |
+
# final_str_abv += str() + "__" + str(box.cls) + "__" + str(box.conf) + "__" + str(box) + "\n"
|
90 |
+
if confi >= threshold:
|
91 |
+
final_str_abv += f"Detected `{label}` with confidence `{round(confi, 3)}` at location `{coordinates}`\n"
|
92 |
+
else:
|
93 |
+
final_str_else += f"Detected `{label}` with confidence `{round(confi, 3)}` at location `{coordinates}`\n"
|
94 |
|
95 |
final_str = "{:*^50}\n".format("ABOVE THRESHOLD OR EQUAL") + final_str_abv + "\n{:*^50}\n".format("BELOW THRESHOLD")+final_str_else
|
96 |
|