Files
insightface/attribute/gender_age/test.py

25 lines
626 B
Python
Raw Normal View History

2018-01-26 13:07:00 +08:00
import argparse
import cv2
import sys
2018-01-26 13:07:00 +08:00
import numpy as np
2021-05-04 16:17:50 +08:00
import insightface
from insightface.app import FaceAnalysis
2021-06-19 23:37:10 +08:00
from insightface.data import get_image as ins_get_image
2018-01-26 13:07:00 +08:00
2021-05-04 22:38:07 +08:00
2021-06-19 23:37:10 +08:00
parser = argparse.ArgumentParser(description='insightface gender-age test')
2018-01-26 13:07:00 +08:00
# general
2021-05-04 16:17:50 +08:00
parser.add_argument('--ctx', default=0, type=int, help='ctx id, <0 means using cpu')
2018-01-26 13:07:00 +08:00
args = parser.parse_args()
2021-06-19 23:37:10 +08:00
app = FaceAnalysis(allowed_modules=['detection', 'genderage'])
2021-05-04 22:38:07 +08:00
app.prepare(ctx_id=args.ctx, det_size=(640,640))
2020-11-07 13:22:05 +08:00
2021-06-19 23:37:10 +08:00
img = ins_get_image('t1')
2021-05-04 16:17:50 +08:00
faces = app.get(img)
2021-05-04 22:38:07 +08:00
assert len(faces)==6
2021-05-04 16:17:50 +08:00
for face in faces:
print(face.bbox)
2021-06-19 23:37:10 +08:00
print(face.sex, face.age)
2020-11-07 13:22:05 +08:00