Update app.py
Browse files
app.py
CHANGED
@@ -30,12 +30,16 @@ def apply_nms(predictions, iou_threshold=0.5):
|
|
30 |
# Perform NMS using OpenCV
|
31 |
indices = cv2.dnn.NMSBoxes(boxes.tolist(), scores.tolist(), score_threshold=0.25, nms_threshold=iou_threshold)
|
32 |
|
33 |
-
#
|
34 |
-
if isinstance(indices, tuple):
|
35 |
-
|
|
|
36 |
|
37 |
-
#
|
38 |
-
indices = indices
|
|
|
|
|
|
|
39 |
|
40 |
nms_predictions = []
|
41 |
|
|
|
30 |
# Perform NMS using OpenCV
|
31 |
indices = cv2.dnn.NMSBoxes(boxes.tolist(), scores.tolist(), score_threshold=0.25, nms_threshold=iou_threshold)
|
32 |
|
33 |
+
# Check if indices is empty or invalid
|
34 |
+
if not indices or not isinstance(indices, tuple) or len(indices) == 0:
|
35 |
+
print("No valid indices returned from NMS.")
|
36 |
+
return [] # Return an empty list if no valid indices are found
|
37 |
|
38 |
+
# Extract the indices if they are valid
|
39 |
+
indices = indices[0] # Extracting the first element which contains the indices
|
40 |
+
|
41 |
+
# Flatten indices array (if returned as a tuple)
|
42 |
+
indices = indices.flatten() if isinstance(indices, np.ndarray) else np.array(indices).flatten()
|
43 |
|
44 |
nms_predictions = []
|
45 |
|