diff options
Diffstat (limited to 'megapixels/commands/demo/face_age_gender.py')
| -rw-r--r-- | megapixels/commands/demo/face_age_gender.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/megapixels/commands/demo/face_age_gender.py b/megapixels/commands/demo/face_age_gender.py index c74f1e45..c4f09c13 100644 --- a/megapixels/commands/demo/face_age_gender.py +++ b/megapixels/commands/demo/face_age_gender.py @@ -17,7 +17,7 @@ from app.settings import app_cfg as cfg help='GPU index') @click.option('-f', '--force', 'opt_force', is_flag=True, help='Force overwrite file') -@click.option('--display/--no-display', 'opt_display', is_flag=True, default=False, +@click.option('--display/--no-display', 'opt_display', is_flag=True, default=True, help='Display detections to debug') @click.pass_context def cli(ctx, opt_fp_in, opt_fp_out, opt_gpu, opt_size, opt_force, opt_display): @@ -52,12 +52,12 @@ def cli(ctx, opt_fp_in, opt_fp_out, opt_gpu, opt_size, opt_force, opt_display): # ---------------------------------------------------------------------------- # detect face - face_detector = face_detector.DetectorDLIBCNN(gpu=opt_gpu) # -1 for CPU + face_detector = face_detector.DetectorCVDNN() bboxes = face_detector.detect(im_resized, largest=True) - bbox = bboxes[0] + bbox_norm = bboxes[0] dim = im_resized.shape[:2][::-1] - bbox_dim = bbox.to_dim(dim) - if not bbox: + bbox_dim = bbox_norm.to_dim(dim) + if not bbox_norm: log.error('no face detected') return else: @@ -70,21 +70,24 @@ def cli(ctx, opt_fp_in, opt_fp_out, opt_gpu, opt_size, opt_force, opt_display): # real age_real_predictor = face_age_gender.FaceAgeReal() st = time.time() - age_real = age_real_predictor.predict(im_resized, bbox_dim) + age_real = age_real_predictor.predict(im_resized, bbox_norm) log.info(f'age real took: {(time.time()-st)/1000:.5f}s') # apparent age_apparent_predictor = face_age_gender.FaceAgeApparent() st = time.time() - age_apparent = age_apparent_predictor.predict(im_resized, bbox_dim) + age_apparent = age_apparent_predictor.predict(im_resized, bbox_norm) log.info(f'age apparent took: {(time.time()-st)/1000:.5f}s') # gender gender_predictor = face_age_gender.FaceGender() st = time.time() - gender = gender_predictor.predict(im_resized, bbox_dim) + gender = gender_predictor.predict(im_resized, bbox_norm) log.info(f'gender took: {(time.time()-st)/1000:.5f}s') + # ethnicity + # TODO + # ---------------------------------------------------------------------------- # output @@ -99,21 +102,21 @@ def cli(ctx, opt_fp_in, opt_fp_out, opt_gpu, opt_size, opt_force, opt_display): # draw real age im_age_real = im_resized.copy() - draw_utils.draw_bbox(im_age_real, bbox_dim) + im_age_real = draw_utils.draw_bbox(im_age_real, bbox_norm) txt = f'{(age_real):.2f}' - draw_utils.draw_text(im_age_real, bbox_dim.pt_tl, txt) + im_age_real = draw_utils.draw_text(im_age_real, bbox_norm.pt_tl, txt) # apparent age im_age_apparent = im_resized.copy() - draw_utils.draw_bbox(im_age_apparent, bbox_dim) + im_age_apparent = draw_utils.draw_bbox(im_age_apparent, bbox_norm) txt = f'{(age_apparent):.2f}' - draw_utils.draw_text(im_age_apparent, bbox_dim.pt_tl, txt) + im_age_apparent = draw_utils.draw_text(im_age_apparent, bbox_norm.pt_tl, txt) # gender im_gender = im_resized.copy() - draw_utils.draw_bbox(im_age_apparent, bbox_dim) + im_gender = draw_utils.draw_bbox(im_gender, bbox_norm) txt = f"M: {gender['m']:.2f}, F: {gender['f']:.2f}" - draw_utils.draw_text(im_gender, (10, dim[1]-20), txt) + im_gender = draw_utils.draw_text(im_gender, (.1, .9), txt) # ---------------------------------------------------------------------------- |
