Skip to content

Commit d8f7fa6

Browse files
committed
Simplify pad function
1 parent ed66b36 commit d8f7fa6

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

models/utils/detect_face.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def detect_face(imgs, minsize, pnet, rnet, onet, threshold, factor, device):
6060
total_boxes = np.transpose(np.vstack([qq1, qq2, qq3, qq4, total_boxes[:, 4]]))
6161
total_boxes = rerec(total_boxes)
6262
total_boxes[:, 0:4] = np.fix(total_boxes[:, 0:4]).astype(np.int32)
63-
dy, edy, dx, edx, y, ey, x, ex, tmpw, tmph = pad(total_boxes, w, h)
63+
y, ey, x, ex = pad(total_boxes, w, h)
6464

6565
numbox = total_boxes.shape[0]
6666
if numbox > 0:
@@ -92,7 +92,7 @@ def detect_face(imgs, minsize, pnet, rnet, onet, threshold, factor, device):
9292
if numbox > 0:
9393
# third stage
9494
total_boxes = np.fix(total_boxes).astype(np.int32)
95-
dy, edy, dx, edx, y, ey, x, ex, tmpw, tmph = pad(total_boxes.copy(), w, h)
95+
y, ey, x, ex = pad(total_boxes.copy(), w, h)
9696
im_data = []
9797
for k in range(0, numbox):
9898
if ey[k] > (y[k] - 1) and ex[k] > (x[k] - 1):
@@ -197,37 +197,17 @@ def nms(boxes, threshold, method):
197197

198198

199199
def pad(total_boxes, w, h):
200-
tmpw = (total_boxes[:, 2] - total_boxes[:, 0] + 1).astype(np.int32)
201-
tmph = (total_boxes[:, 3] - total_boxes[:, 1] + 1).astype(np.int32)
202-
numbox = total_boxes.shape[0]
203-
204-
dx = np.ones((numbox), dtype=np.int32)
205-
dy = np.ones((numbox), dtype=np.int32)
206-
edx = tmpw.copy().astype(np.int32)
207-
edy = tmph.copy().astype(np.int32)
208-
209200
x = total_boxes[:, 0].copy().astype(np.int32)
210201
y = total_boxes[:, 1].copy().astype(np.int32)
211202
ex = total_boxes[:, 2].copy().astype(np.int32)
212203
ey = total_boxes[:, 3].copy().astype(np.int32)
213204

214-
tmp = np.where(ex > w)
215-
edx.flat[tmp] = np.expand_dims(-ex[tmp] + w + tmpw[tmp], 1)
216-
ex[tmp] = w
217-
218-
tmp = np.where(ey > h)
219-
edy.flat[tmp] = np.expand_dims(-ey[tmp] + h + tmph[tmp], 1)
220-
ey[tmp] = h
221-
222-
tmp = np.where(x < 1)
223-
dx.flat[tmp] = np.expand_dims(2 - x[tmp], 1)
224-
x[tmp] = 1
225-
226-
tmp = np.where(y < 1)
227-
dy.flat[tmp] = np.expand_dims(2 - y[tmp], 1)
228-
y[tmp] = 1
205+
x[np.where(x < 1)] = 1
206+
y[np.where(y < 1)] = 1
207+
ex[np.where(ex > w)] = w
208+
ey[np.where(ey > h)] = h
229209

230-
return dy, edy, dx, edx, y, ey, x, ex, tmpw, tmph
210+
return y, ey, x, ex
231211

232212

233213
def rerec(bboxA):

0 commit comments

Comments
 (0)