muhammadsalmanalfaridzi commited on
Commit
1ea7f62
·
verified ·
1 Parent(s): cb1e9a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
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
- # Ensure indices are a numpy array (if returned as a tuple)
34
- if isinstance(indices, tuple):
35
- indices = indices[0] # Extracting the first element which contains the indices
 
36
 
37
- # Now indices is a numpy array, we can safely call .flatten()
38
- indices = indices.flatten()
 
 
 
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