ONNX
Wanli commited on
Commit
ca93dd9
·
1 Parent(s): 6df937f

Fix a bug in yolox when there are no acceptable objects (#115)

Browse files

* Fix a bug when there is no object

* Add the minimum version requirement for opencv-python

Files changed (2) hide show
  1. README.md +2 -1
  2. yolox.py +3 -5
README.md CHANGED
@@ -22,6 +22,7 @@ python demo.py --input /path/to/image
22
  ```
23
  Note:
24
  - image result saved as "result.jpg"
 
25
 
26
 
27
  ## Results
@@ -56,7 +57,7 @@ The model is evaluated on [COCO 2017 val](https://cocodataset.org/#download). Re
56
 
57
  </td><td>
58
 
59
- area | IoU | Average Recall(AR) |
60
  |:-------|:------|:----------------|
61
  | all | 0.50:0.95 | 0.326 |
62
  | all | 0.50:0.95 | 0.531 |
 
22
  ```
23
  Note:
24
  - image result saved as "result.jpg"
25
+ - this model requires `opencv-python>=4.7.0`
26
 
27
 
28
  ## Results
 
57
 
58
  </td><td>
59
 
60
+ | area | IoU | Average Recall(AR) |
61
  |:-------|:------|:----------------|
62
  | all | 0.50:0.95 | 0.326 |
63
  | all | 0.50:0.95 | 0.531 |
yolox.py CHANGED
@@ -63,13 +63,11 @@ class YoloX:
63
  max_scores = np.amax(scores, axis=1)
64
  max_scores_idx = np.argmax(scores, axis=1)
65
 
66
- # batched-nms, TODO: replace with cv2.dnn.NMSBoxesBatched when OpenCV 4.7.0 is released
67
- max_coord = boxes_xyxy.max()
68
- offsets = max_scores_idx * (max_coord + 1)
69
- boxes_for_nms = boxes_xyxy + offsets[:, None]
70
- keep = cv2.dnn.NMSBoxes(boxes_for_nms.tolist(), max_scores.tolist(), self.confThreshold, self.nmsThreshold)
71
 
72
  candidates = np.concatenate([boxes_xyxy, max_scores[:, None], max_scores_idx[:, None]], axis=1)
 
 
73
  return candidates[keep]
74
 
75
  def generateAnchors(self):
 
63
  max_scores = np.amax(scores, axis=1)
64
  max_scores_idx = np.argmax(scores, axis=1)
65
 
66
+ keep = cv2.dnn.NMSBoxesBatched(boxes_xyxy.tolist(), max_scores.tolist(), max_scores_idx.tolist(), self.confThreshold, self.nmsThreshold)
 
 
 
 
67
 
68
  candidates = np.concatenate([boxes_xyxy, max_scores[:, None], max_scores_idx[:, None]], axis=1)
69
+ if len(keep) == 0:
70
+ return np.array([])
71
  return candidates[keep]
72
 
73
  def generateAnchors(self):