Skip to content

Instantly share code, notes, and snippets.

View david-littlefield's full-sized avatar

david-littlefield

View GitHub Profile
# Line 68
def infer(net , img , transform , thresh , cuda , shrink):
if shrink != 1:
img = cv2.resize(img, None, None, fx=shrink, fy=shrink, interpolation=cv2.INTER_LINEAR)
x = torch.from_numpy(transform(img)[0]).permute(2, 0, 1)
with torch.no_grad(): # <----------
x = Variable(x.unsqueeze(0)) # <----------
if cuda:
x = x.cuda()
# Line 191
def init_priors(self ,cfg , min_size=cfg['min_sizes'], max_size=cfg['max_sizes']):
priorbox = PriorBox(cfg , min_size, max_size)
with torch.no_grad(): # <----------
prior = Variable( priorbox.forward()) # <----------
return prior
# Line 61
def detect_face(image, shrink):
x = image
if shrink != 1:
x = cv2.resize(image, None, None, fx=shrink, fy=shrink, interpolation=cv2.INTER_LINEAR)
#print('shrink:{}'.format(shrink))
width = x.shape[1]
height = x.shape[0]
x = x.astype(np.float32)
# Line 167
def test_oneimage():
torch.set_grad_enabled(False) # <----------
# load net
cfg = widerface_640
num_classes = len(WIDERFace_CLASSES) + 1 # +1 background
net = build_ssd('test', cfg['min_dim'], num_classes) # initialize SSD
# Line 25
WIDERFace_CLASSES = ['face'] # always index 0
# note: if you used our download scripts, this should be right
WIDERFace_ROOT = './data/ # <----------
# Line 13
from data import widerface_640
from ..box_utils import log_sum_exp, match, refine_match, sfd_match # <----------
# Line 83
while detections[0, i, j, 0] >= thresh:
score = detections[0, i, j, 0]
score = score.cpu().numpy() # <----------
#label_name = labelmap[i-1]
pt = (detections[0, i, j, 1:]*scale).cpu().numpy()
coords = (pt[0], pt[1], pt[2], pt[3])
det.append([pt[0], pt[1], pt[2], pt[3], score])
j += 1
# Line 207
def load(f, map_location="cpu", pickle_module=pickle): # <----------
# Line 75
def infer(net , img , transform , thresh , cuda , shrink):
if shrink != 1:
img = cv2.resize(img, None, None, fx=shrink, fy=shrink, interpolation=cv2.INTER_LINEAR)
x = torch.from_numpy(transform(img)[0]).permute(2, 0, 1)
with torch.no_grad():
x = Variable(x.unsqueeze(0))
#if cuda: # <----------
# x = x.cuda() # <----------
# Line 231
# load net
cfg = widerface_640
num_classes = len(WIDERFace_CLASSES) + 1 # +1 background
net = build_ssd('test', cfg['min_dim'], num_classes) # initialize SSD
net.load_state_dict(torch.load(args.trained_model))
#net.cuda() # <----------