Ii
commited on
Delete main.py.txt
Browse files- main.py.txt +0 -57
main.py.txt
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
|
3 |
-
import os
|
4 |
-
import os.path as osp
|
5 |
-
import argparse
|
6 |
-
import cv2
|
7 |
-
import numpy as np
|
8 |
-
import onnxruntime
|
9 |
-
from scrfd import SCRFD
|
10 |
-
from arcface_onnx import ArcFaceONNX
|
11 |
-
|
12 |
-
onnxruntime.set_default_logger_severity(5)
|
13 |
-
|
14 |
-
assets_dir = osp.expanduser('~/.insightface/models/buffalo_l')
|
15 |
-
|
16 |
-
detector = SCRFD(os.path.join(assets_dir, 'det_10g.onnx'))
|
17 |
-
detector.prepare(0)
|
18 |
-
model_path = os.path.join(assets_dir, 'w600k_r50.onnx')
|
19 |
-
rec = ArcFaceONNX(model_path)
|
20 |
-
rec.prepare(0)
|
21 |
-
|
22 |
-
def parse_args() -> argparse.Namespace:
|
23 |
-
parser = argparse.ArgumentParser()
|
24 |
-
parser.add_argument('img1', type=str)
|
25 |
-
parser.add_argument('img2', type=str)
|
26 |
-
return parser.parse_args()
|
27 |
-
|
28 |
-
|
29 |
-
def func(args):
|
30 |
-
image1 = cv2.imread(args.img1)
|
31 |
-
image2 = cv2.imread(args.img2)
|
32 |
-
bboxes1, kpss1 = detector.autodetect(image1, max_num=1)
|
33 |
-
if bboxes1.shape[0]==0:
|
34 |
-
return -1.0, "Face not found in Image-1"
|
35 |
-
bboxes2, kpss2 = detector.autodetect(image2, max_num=1)
|
36 |
-
if bboxes2.shape[0]==0:
|
37 |
-
return -1.0, "Face not found in Image-2"
|
38 |
-
kps1 = kpss1[0]
|
39 |
-
kps2 = kpss2[0]
|
40 |
-
feat1 = rec.get(image1, kps1)
|
41 |
-
feat2 = rec.get(image2, kps2)
|
42 |
-
sim = rec.compute_sim(feat1, feat2)
|
43 |
-
if sim<0.2:
|
44 |
-
conclu = 'They are NOT the same person'
|
45 |
-
elif sim>=0.2 and sim<0.28:
|
46 |
-
conclu = 'They are LIKELY TO be the same person'
|
47 |
-
else:
|
48 |
-
conclu = 'They ARE the same person'
|
49 |
-
return sim, conclu
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
if __name__ == '__main__':
|
54 |
-
args = parse_args()
|
55 |
-
output = func(args)
|
56 |
-
print('sim: %.4f, message: %s'%(output[0], output[1]))
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|