@@ -76,10 +76,11 @@ def detect_faces(image, min_face_size=20.0,
7676 # STAGE 2
7777
7878 img_boxes = get_image_boxes (bounding_boxes , image , size = 24 )
79- img_boxes = Variable (torch .FloatTensor (img_boxes ), volatile = True )
80- output = rnet (img_boxes )
81- offsets = output [0 ].data .numpy () # shape [n_boxes, 4]
82- probs = output [1 ].data .numpy () # shape [n_boxes, 2]
79+ with torch .no_grad ():
80+ img_boxes = Variable (torch .FloatTensor (img_boxes ))
81+ output = rnet (img_boxes )
82+ offsets = output [0 ].data .numpy () # shape [n_boxes, 4]
83+ probs = output [1 ].data .numpy () # shape [n_boxes, 2]
8384
8485 keep = np .where (probs [:, 1 ] > thresholds [1 ])[0 ]
8586 bounding_boxes = bounding_boxes [keep ]
@@ -97,11 +98,13 @@ def detect_faces(image, min_face_size=20.0,
9798 img_boxes = get_image_boxes (bounding_boxes , image , size = 48 )
9899 if len (img_boxes ) == 0 :
99100 return [], []
100- img_boxes = Variable (torch .FloatTensor (img_boxes ), volatile = True )
101- output = onet (img_boxes )
102- landmarks = output [0 ].data .numpy () # shape [n_boxes, 10]
103- offsets = output [1 ].data .numpy () # shape [n_boxes, 4]
104- probs = output [2 ].data .numpy () # shape [n_boxes, 2]
101+
102+ with torch .no_grad ():
103+ img_boxes = Variable (torch .FloatTensor (img_boxes ))
104+ output = onet (img_boxes )
105+ landmarks = output [0 ].data .numpy () # shape [n_boxes, 10]
106+ offsets = output [1 ].data .numpy () # shape [n_boxes, 4]
107+ probs = output [2 ].data .numpy () # shape [n_boxes, 2]
105108
106109 keep = np .where (probs [:, 1 ] > thresholds [2 ])[0 ]
107110 bounding_boxes = bounding_boxes [keep ]
0 commit comments