Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,28 +24,28 @@ def detect_objects(frame, confidence_threshold=0.5):
|
|
24 |
inputs = {session.get_inputs()[0].name: image_input}
|
25 |
outputs = session.run(None, inputs)
|
26 |
|
27 |
-
# Assuming YOLO model outputs are in the form of [boxes, confidences, class_probs]
|
28 |
-
boxes, confidences, class_probs = outputs
|
29 |
|
30 |
-
# Post-processing: Filter boxes by confidence threshold
|
31 |
-
detections = []
|
32 |
-
for i, confidence in enumerate(confidences[0]):
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
# Draw bounding boxes and labels on the image
|
39 |
-
for (x1, y1, x2, y2, confidence, class_id) in detections:
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
-
# Convert the image back to BGR for displaying in Gradio
|
46 |
-
image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
47 |
|
48 |
-
return
|
49 |
|
50 |
# Gradio interface to use the webcam for real-time object detection
|
51 |
# Added a slider for the confidence threshold
|
|
|
24 |
inputs = {session.get_inputs()[0].name: image_input}
|
25 |
outputs = session.run(None, inputs)
|
26 |
|
27 |
+
# # Assuming YOLO model outputs are in the form of [boxes, confidences, class_probs]
|
28 |
+
# boxes, confidences, class_probs = outputs
|
29 |
|
30 |
+
# # Post-processing: Filter boxes by confidence threshold
|
31 |
+
# detections = []
|
32 |
+
# for i, confidence in enumerate(confidences[0]):
|
33 |
+
# if confidence >= confidence_threshold:
|
34 |
+
# x1, y1, x2, y2 = boxes[0][i]
|
35 |
+
# class_id = np.argmax(class_probs[0][i]) # Get class with highest probability
|
36 |
+
# detections.append((x1, y1, x2, y2, confidence, class_id))
|
37 |
|
38 |
+
# # Draw bounding boxes and labels on the image
|
39 |
+
# for (x1, y1, x2, y2, confidence, class_id) in detections:
|
40 |
+
# color = (0, 255, 0) # Green color for bounding boxes
|
41 |
+
# cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
|
42 |
+
# label = f"Class {class_id}: {confidence:.2f}"
|
43 |
+
# cv2.putText(image, label, (int(x1), int(y1)-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
|
44 |
|
45 |
+
# # Convert the image back to BGR for displaying in Gradio
|
46 |
+
# image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
47 |
|
48 |
+
return outputs
|
49 |
|
50 |
# Gradio interface to use the webcam for real-time object detection
|
51 |
# Added a slider for the confidence threshold
|