HienK64BKHN commited on
Commit
2fd2924
·
verified ·
1 Parent(s): 7a99d40

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +4 -4
utils.py CHANGED
@@ -17,11 +17,11 @@ THRESHOLD = 0.8
17
  mtcnn = MTCNN(
18
  image_size=160, margin=0, min_face_size=20,
19
  thresholds=[0.6, 0.7, 0.7], factor=0.709, post_process=True,
20
- device=device,
21
  keep_all=True
22
  )
23
 
24
- resnet = InceptionResnetV1(pretrained='vggface2').eval().to(device)
25
 
26
  def extract_face(box, img, margin=20):
27
  img_size = (len(img), len(img[0]))
@@ -52,9 +52,9 @@ def trans(img):
52
 
53
  def find_and_compare(model, face):
54
  face = trans(face)
55
- face_embedded = model(face.unsqueeze(dim=0).to(device))
56
  for usr in os.listdir(SINGLE_FACE_PATH):
57
- usr_embedding = torch.load(SINGLE_FACE_PATH + "/" + usr + "/" + usr + ".pt").to(device)
58
  if (face_embedded - usr_embedding).norm().item() < THRESHOLD:
59
  print("Found " + usr + " in the image!")
60
  return usr
 
17
  mtcnn = MTCNN(
18
  image_size=160, margin=0, min_face_size=20,
19
  thresholds=[0.6, 0.7, 0.7], factor=0.709, post_process=True,
20
+ device='cpu',
21
  keep_all=True
22
  )
23
 
24
+ resnet = InceptionResnetV1(pretrained='vggface2').eval().to('cpu')
25
 
26
  def extract_face(box, img, margin=20):
27
  img_size = (len(img), len(img[0]))
 
52
 
53
  def find_and_compare(model, face):
54
  face = trans(face)
55
+ face_embedded = model(face.unsqueeze(dim=0).to('cpu'))
56
  for usr in os.listdir(SINGLE_FACE_PATH):
57
+ usr_embedding = torch.load(SINGLE_FACE_PATH + "/" + usr + "/" + usr + ".pt").to('cpu')
58
  if (face_embedded - usr_embedding).norm().item() < THRESHOLD:
59
  print("Found " + usr + " in the image!")
60
  return usr