Skip to content

Commit

Permalink
Fix bug in cv2 imwrite and try prevent mem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
timesler committed Feb 17, 2020
1 parent 1e16357 commit 12c7e7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions models/utils/detect_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def detect_face(imgs, minsize, pnet, rnet, onet, threshold, factor, device):
batch_points = []
for b_i in range(batch_size):
b_i_inds = np.where(image_inds == b_i)
batch_boxes.append(boxes[b_i_inds])
batch_points.append(points[b_i_inds])
batch_boxes.append(boxes[b_i_inds].copy())
batch_points.append(points[b_i_inds].copy())

batch_boxes, batch_points = np.array(batch_boxes), np.array(batch_points)

Expand Down Expand Up @@ -189,10 +189,10 @@ def nms_numpy(boxes, scores, threshold, method):
if boxes.size == 0:
return np.empty((0, 3))

x1 = boxes[:, 0]
y1 = boxes[:, 1]
x2 = boxes[:, 2]
y2 = boxes[:, 3]
x1 = boxes[:, 0].copy()
y1 = boxes[:, 1].copy()
x2 = boxes[:, 2].copy()
y2 = boxes[:, 3].copy()
s = scores
area = (x2 - x1 + 1) * (y2 - y1 + 1)

Expand All @@ -205,13 +205,13 @@ def nms_numpy(boxes, scores, threshold, method):
counter += 1
idx = I[0:-1]

xx1 = np.maximum(x1[i], x1[idx])
yy1 = np.maximum(y1[i], y1[idx])
xx2 = np.minimum(x2[i], x2[idx])
yy2 = np.minimum(y2[i], y2[idx])
xx1 = np.maximum(x1[i], x1[idx]).copy()
yy1 = np.maximum(y1[i], y1[idx]).copy()
xx2 = np.minimum(x2[i], x2[idx]).copy()
yy2 = np.minimum(y2[i], y2[idx]).copy()

w = np.maximum(0.0, xx2 - xx1 + 1)
h = np.maximum(0.0, yy2 - yy1 + 1)
w = np.maximum(0.0, xx2 - xx1 + 1).copy()
h = np.maximum(0.0, yy2 - yy1 + 1).copy()

inter = w * h
if method is "Min":
Expand All @@ -220,7 +220,7 @@ def nms_numpy(boxes, scores, threshold, method):
o = inter / (area[i] + area[idx] - inter)
I = I[np.where(o <= threshold)]

pick = pick[:counter]
pick = pick[:counter].copy()
return pick


Expand Down Expand Up @@ -278,8 +278,8 @@ def crop_resize(img, box, image_size):
out = cv2.resize(
img[box[1]:box[3], box[0]:box[2]],
(image_size, image_size),
cv2.INTER_LINEAR
)
interpolation=cv2.INTER_AREA
).copy()
else:
out = img.crop(box).resize((image_size, image_size), Image.BILINEAR)
return out
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools, os

PACKAGE_NAME = 'facenet-pytorch'
VERSION = '2.2.6'
VERSION = '2.2.7'
AUTHOR = 'Tim Esler'
EMAIL = '[email protected]'
DESCRIPTION = 'Pretrained Pytorch face detection and recognition models'
Expand Down

0 comments on commit 12c7e7c

Please sign in to comment.