Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
AgeGenderDist
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
人工智能
AgeGenderDist
Commits
4ca14e9c
Commit
4ca14e9c
authored
Jul 19, 2019
by
葛梦颖
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gender accurate improved
parent
bbc0557a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2 additions
and
69 deletions
+2
-69
:wq
AgeGenderDist/:wq
+0
-68
face_model.py
AgeGenderDist/face_model.py
+1
-0
mtcnn_detector.py
AgeGenderDist/mtcnn_detector.py
+1
-1
No files found.
AgeGenderDist/:wq
deleted
100644 → 0
View file @
bbc0557a
import AgeGenderDist.face_model
import argparse
import cv2
import sys
import numpy as np
import datetime
from AgeGenderDist.mtcnn_detector import MtcnnDetector
import os
import mxnet as mx
import math
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src', 'common'))
parser = argparse.ArgumentParser(description='face model test')
# general
parser.add_argument('--image-size', default='112,112', help='')
parser.add_argument('--image', default='Tom_Hanks_54745.png', help='')
parser.add_argument('--model', default='model/model,0', help='path to load model.')
parser.add_argument('--gpu', default=0, type=int, help='gpu id')
parser.add_argument('--det', default=0, type=int, help='mtcnn option, 1 means using R+O, 0 means detect from begining')
args = parser.parse_args()
def get_age_gender_dist(img_src):
if args.gpu>=0:
ctx = mx.gpu(args.gpu)
else:
ctx = mx.cpu()
det_threshold = [0.6,0.7,0.8]
mtcnn_path = os.path.join(os.path.dirname(__file__), 'mtcnn-model')
if args.det==0:
detector = MtcnnDetector(model_folder=mtcnn_path, ctx=ctx, num_worker=1, accurate_landmark = True, threshold=det_threshold)
else:
detector = MtcnnDetector(model_folder=mtcnn_path, ctx=ctx, num_worker=1, accurate_landmark = True, threshold=[0.0,0.0,0.2])
ret = detector.detect_face(img_src, det_type = args.det)
if ret is None:
print('ret is none')
bbox, points = ret
points = points[0,:].reshape((2,5)).T
im=img_src.copy()
lf_eye=points[0]
rt_eye=points[1]
tmp=rt_eye-lf_eye
dist=math.hypot(tmp[0],tmp[1])
model=face_model.FaceModel(args)
img=model.get_input(img_src)
gender,age=model.get_ga(img)
return age,gender,dist
def get_gender_age(img):
model=face_model.FaceModel(args)
img=model.get_input(img)
gender,age=model.get_ga(img)
return gender,age
if __name__=='__main__':
dirs= os.listdir(args.image)
for file in dirs:
print('file',file)
imgdir=os.path.join('testimg',file)
img_src = cv2.imread(imgdir)
gender,age=get_gender_age(img_src)
age,gender,dist=get_age_gender_dist(img_src)
print(age,gender,dist)
#print('gender:',gender)
AgeGenderDist/face_model.py
View file @
4ca14e9c
...
@@ -21,6 +21,7 @@ import AgeGenderDist.face_image
...
@@ -21,6 +21,7 @@ import AgeGenderDist.face_image
import
AgeGenderDist.face_preprocess
import
AgeGenderDist.face_preprocess
def
do_flip
(
data
):
def
do_flip
(
data
):
for
idx
in
range
(
data
.
shape
[
0
]):
for
idx
in
range
(
data
.
shape
[
0
]):
data
[
idx
,:,:]
=
np
.
fliplr
(
data
[
idx
,:,:])
data
[
idx
,:,:]
=
np
.
fliplr
(
data
[
idx
,:,:])
...
...
AgeGenderDist/mtcnn_detector.py
View file @
4ca14e9c
...
@@ -319,7 +319,7 @@ class MtcnnDetector(object):
...
@@ -319,7 +319,7 @@ class MtcnnDetector(object):
# check input
# check input
height
,
width
,
_
=
img
.
shape
height
,
width
,
_
=
img
.
shape
if
det_type
==
0
:
if
det_type
==
0
:
MIN_DET_SIZE
=
12
MIN_DET_SIZE
=
1
0
#1
2
if
img
is
None
:
if
img
is
None
:
return
None
return
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment