Skip to content

Commit c18bfc9

Browse files
benhoffChris Lee-Messer
authored and
Chris Lee-Messer
committed
Fix Yolo: swap width, height; Change box coord order; parsing fix (cvat-ai#802)
1 parent db62c3a commit c18bfc9

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

utils/open_model_zoo/yolov3/interp.py

+10-16
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,25 @@ def parse_yolo_region(self, blob: 'np.ndarray', original_shape: list, params: di
7373
for n in range(num):
7474
# -----entry index calcs------
7575
obj_index = self.entry_index(params['side'], coords, classes, n * side_square + i, coords)
76-
# -----entry index calcs------
7776
scale = predictions[obj_index]
7877
if scale < self.PROB_THRESHOLD:
7978
continue
8079
box_index = self.entry_index(params['side'], coords, classes, n * side_square + i, 0)
8180

8281
# Network produces location predictions in absolute coordinates of feature maps.
8382
# Scale it to relative coordinates.
84-
x = (col + predictions[box_index + 0 * side_square]) / params['side']
85-
y = (row + predictions[box_index + 1 * side_square]) / params['side']
83+
x = (col + predictions[box_index + 0 * side_square]) / params['side'] * 416
84+
y = (row + predictions[box_index + 1 * side_square]) / params['side'] * 416
8685
# Value for exp is very big number in some cases so following construction is using here
8786
try:
88-
w_exp = exp(predictions[box_index + 2 * side_square])
8987
h_exp = exp(predictions[box_index + 3 * side_square])
88+
w_exp = exp(predictions[box_index + 2 * side_square])
9089
except OverflowError:
9190
continue
9291

93-
w = w_exp * params['anchors'][2 * n] / 416
94-
h = h_exp * params['anchors'][2 * n + 1] / 416
92+
w = w_exp * params['anchors'][2 * n]
93+
h = h_exp * params['anchors'][2 * n + 1]
94+
9595
for j in range(classes):
9696
class_index = self.entry_index(params['side'], coords, classes, n * side_square + i,
9797
coords + 1 + j)
@@ -105,8 +105,8 @@ def parse_yolo_region(self, blob: 'np.ndarray', original_shape: list, params: di
105105
w=w,
106106
class_id=j,
107107
confidence=confidence,
108-
h_scale=orig_im_h,
109-
w_scale=orig_im_w))
108+
h_scale=(orig_im_h/416),
109+
w_scale=(orig_im_w/416)))
110110

111111

112112
for detection in detections:
@@ -115,12 +115,7 @@ def parse_yolo_region(self, blob: 'np.ndarray', original_shape: list, params: di
115115
width = detection['frame_width']
116116
detection = detection['detections']
117117

118-
original_shape = (width, height)
119-
120-
resized_width = width / 416
121-
resized_height = height / 416
122-
123-
resized_shape = (resized_width, resized_height)
118+
original_shape = (height, width)
124119

125120
# https://github.com/opencv/open_model_zoo/blob/master/demos/python_demos/object_detection_demo_yolov3_async/object_detection_demo_yolov3_async.py#L72
126121
anchors = [10,13,16,30,33,23,30,61,62,45,59,119,116,90,156,198,373,326]
@@ -148,7 +143,6 @@ def parse_yolo_region(self, blob: 'np.ndarray', original_shape: list, params: di
148143
parser.sort_objects()
149144

150145
objects = []
151-
152146
for obj in parser.objects:
153147
if obj['confidence'] >= parser.PROB_THRESHOLD:
154148
label = obj['class_id']
@@ -157,4 +151,4 @@ def parse_yolo_region(self, blob: 'np.ndarray', original_shape: list, params: di
157151
ymin = obj['ymin']
158152
ymax = obj['ymax']
159153

160-
results.add_box(xmax, ymax, xmin, ymin, label, frame_number)
154+
results.add_box(xmin, ymin, xmax, ymax, label, frame_number)

0 commit comments

Comments
 (0)