Skip to content

Commit 9c116f1

Browse files
authored
Fix a bug in yolox when there are no acceptable objects (#115)
* Fix a bug when there is no object * Add the minimum version requirement for opencv-python
1 parent df8b973 commit 9c116f1

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

models/object_detection_yolox/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ python demo.py --input /path/to/image
2222
```
2323
Note:
2424
- image result saved as "result.jpg"
25+
- this model requires `opencv-python>=4.7.0`
2526

2627

2728
## Results
@@ -56,7 +57,7 @@ The model is evaluated on [COCO 2017 val](https://cocodataset.org/#download). Re
5657

5758
</td><td>
5859

59-
area | IoU | Average Recall(AR) |
60+
| area | IoU | Average Recall(AR) |
6061
|:-------|:------|:----------------|
6162
| all | 0.50:0.95 | 0.326 |
6263
| all | 0.50:0.95 | 0.531 |

models/object_detection_yolox/yolox.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ def postprocess(self, outputs):
6363
max_scores = np.amax(scores, axis=1)
6464
max_scores_idx = np.argmax(scores, axis=1)
6565

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)
66+
keep = cv2.dnn.NMSBoxesBatched(boxes_xyxy.tolist(), max_scores.tolist(), max_scores_idx.tolist(), self.confThreshold, self.nmsThreshold)
7167

7268
candidates = np.concatenate([boxes_xyxy, max_scores[:, None], max_scores_idx[:, None]], axis=1)
69+
if len(keep) == 0:
70+
return np.array([])
7371
return candidates[keep]
7472

7573
def generateAnchors(self):

0 commit comments

Comments
 (0)