Commit d1fd6e5f authored by 葛梦颖's avatar 葛梦颖
parents 7216acd8 d093d870
# Created by https://www.gitignore.io/api/python,virtualenv,macos,linux,windows,visualstudiocode,vim,emacs,sublimetext,jetbrains,ansible
# Edit at https://www.gitignore.io/?templates=python,virtualenv,macos,linux,windows,visualstudiocode,vim,emacs,sublimetext,jetbrains,ansible
### Ansible ###
*.retry
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
### JetBrains ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### JetBrains Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/sonarlint
### Linux ###
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
### Python Patch ###
.venv/
### Python.VirtualEnv Stack ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json
### SublimeText ###
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# Workspace files are user-specific
*.sublime-workspace
# Project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using Sublime Text
# *.sublime-project
# SFTP configuration file
sftp-config.json
# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
### VirtualEnv ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/python,virtualenv,macos,linux,windows,visualstudiocode,vim,emacs,sublimetext,jetbrains,ansible
Metadata-Version: 1.1
Name: AgeGenderDist
Version: 0.1.0
Summary: A short description of the project
Home-page: https://github.com/rentingting/AgeGenderDist
Author: rentingting
Author-email: Your address email (eq. you@example.com)
License: BSD
Download-URL: https://github.com/rentingting/AgeGenderDist/tarball/0.1.0
Description: AgeGenderDist
===============================
version number: 0.1.0
author: rentingting
Overview
--------
A short description of the project
Installation / Usage
--------------------
To install use pip:
$ pip install AgeGenderDist
Or clone the repo:
$ git clone https://github.com/rentingting/AgeGenderDist.git
$ python setup.py install
Contributing
------------
TBD
Example
-------
TBD
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
MANIFEST.in
README.md
requirements.txt
setup.cfg
setup.py
AgeGenderDist/__init__.py
AgeGenderDist/face_image.py
AgeGenderDist/face_model.py
AgeGenderDist/face_preprocess.py
AgeGenderDist/gender.py
AgeGenderDist/helper.py
AgeGenderDist/mtcnn_detector.py
AgeGenderDist/noise_sgd.py
AgeGenderDist.egg-info/PKG-INFO
AgeGenderDist.egg-info/SOURCES.txt
AgeGenderDist.egg-info/dependency_links.txt
AgeGenderDist.egg-info/requires.txt
AgeGenderDist.egg-info/top_level.txt
AgeGenderDist/model/model-0000.params
AgeGenderDist/model/model-symbol.json
AgeGenderDist/mtcnn-model/det1-0001.params
AgeGenderDist/mtcnn-model/det1-symbol.json
AgeGenderDist/mtcnn-model/det1.caffemodel
AgeGenderDist/mtcnn-model/det1.prototxt
AgeGenderDist/mtcnn-model/det2-0001.params
AgeGenderDist/mtcnn-model/det2-symbol.json
AgeGenderDist/mtcnn-model/det2.caffemodel
AgeGenderDist/mtcnn-model/det2.prototxt
AgeGenderDist/mtcnn-model/det3-0001.params
AgeGenderDist/mtcnn-model/det3-symbol.json
AgeGenderDist/mtcnn-model/det3.caffemodel
AgeGenderDist/mtcnn-model/det3.prototxt
AgeGenderDist/mtcnn-model/det4-0001.params
AgeGenderDist/mtcnn-model/det4-symbol.json
AgeGenderDist/mtcnn-model/det4.caffemodel
AgeGenderDist/mtcnn-model/det4.prototxt
\ No newline at end of file
mxnet-cu100==1.4.1
scipy==1.2.2
scikit-learn==0.20.3
opencv-python==4.1.0.25
easydict==1.9
scikit-image==0.14.3
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
from scipy import misc
import sys
import os
import argparse
#import tensorflow as tf
import numpy as np
import mxnet as mx
import random
......@@ -18,8 +17,12 @@ from easydict import EasyDict as edict
from AgeGenderDist.mtcnn_detector import MtcnnDetector
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src', 'common'))
import AgeGenderDist.face_image
import AgeGenderDist.face_preprocess
from AgeGenderDist import face_image
from AgeGenderDist import face_preprocess
from pkg_resources import resource_filename
MODEL_STR = resource_filename(__name__, "model/model")
......@@ -27,21 +30,27 @@ def do_flip(data):
for idx in range(data.shape[0]):
data[idx,:,:] = np.fliplr(data[idx,:,:])
def get_model(ctx, image_size, model_str, layer):
_vec = model_str.split(',')
assert len(_vec)==2
prefix = _vec[0]
epoch = int(_vec[1])
print('loading',prefix, epoch)
def get_model(ctx, image_size, layer):
epoch = 0
prefix = MODEL_STR
sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)
all_layers = sym.get_internals()
sym = all_layers[layer+'_output']
model = mx.mod.Module(symbol=sym, context=ctx, label_names = None)
#model.bind(data_shapes=[('data', (args.batch_size, 3, image_size[0], image_size[1]))], label_shapes=[('softmax_label', (args.batch_size,))])
model.bind(data_shapes=[('data', (1, 3, image_size[0], image_size[1]))])
model.set_params(arg_params, aux_params)
return model
class FaceModelArgs:
def __init__(self, image_size='112,112', gpu=0, det=0, flip=0, threshold=1.24):
self.image_size = image_size
self.gpu = gpu
self.det = det
self.flip = flip
self.threshold = threshold
class FaceModel:
def __init__(self, args):
self.args = args
......@@ -53,8 +62,7 @@ class FaceModel:
assert len(_vec)==2
image_size = (int(_vec[0]), int(_vec[1]))
self.model = None
if len(args.model)>0:
self.model = get_model(ctx, image_size, args.model, 'fc1')
self.model = get_model(ctx, image_size, 'fc1')
self.det_minsize = 50
self.det_threshold = [0.6,0.7,0.8]
......@@ -70,7 +78,6 @@ class FaceModel:
def get_input(self, face_img):
ret = self.detector.detect_face(face_img, det_type = self.args.det)
#print('ret',ret)
if ret is None:
return None
bbox, points = ret
......@@ -78,16 +85,13 @@ class FaceModel:
return None
bbox = bbox[0,0:4]
points = points[0,:].reshape((2,5)).T
#print(bbox)
#print(points)
nimg = face_preprocess.preprocess(face_img, bbox, points, image_size='112,112')
nimg = cv2.cvtColor(nimg, cv2.COLOR_BGR2RGB)
aligned = np.transpose(nimg, (2,0,1))
input_blob = np.expand_dims(aligned, axis=0)
data = mx.nd.array(input_blob)
db = mx.io.DataBatch(data=(data,))
return db
return db, ret
def get_ga(self, data):
self.model.forward(data, is_train=False)
......@@ -100,3 +104,18 @@ class FaceModel:
return gender, age
def get_age_gender_dist(self, img_src):
img, ret =self.get_input(img_src)
if ret is None:
print('ret is none')
return 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])
gender,age=self.get_ga(img)
return age,gender,dist
import AgeGenderDist.face_model
from AgeGenderDist import face_model
import argparse
import cv2
import sys
......
......@@ -6,9 +6,11 @@ import math
import cv2
from multiprocessing import Pool
from itertools import repeat
#from itertools import zip_longest as zip
from itertools import izip
from helper import nms, adjust_input, generate_bbox, detect_first_stage_warpper
try:
from itertools import izip
except ImportError:
izip = zip
from AgeGenderDist.helper import nms, adjust_input, generate_bbox, detect_first_stage_warpper
class MtcnnDetector(object):
"""
......
AgeGenderDist
===============================
# AgeGenderDist
version number: 0.1.0
author: rentingting
人脸尺寸测量库
Overview
--------
## 安装
A short description of the project
1. pip 安装
Installation / Usage
--------------------
```shell
pip install git@git.wanmeizhensuo.com:ai/AgeGenderDist.git#egg=AgeGenderDist
```
To install use pip:
## 使用方式
$ pip install AgeGenderDist
```python
from AgeGenderDist.face_model import FaceModel, FaceModelArgs
import cv2
args = FaceModelArgs()
model = FaceModel(args)
Or clone the repo:
$ git clone https://github.com/rentingting/AgeGenderDist.git
$ python setup.py install
Contributing
------------
TBD
Example
-------
TBD
\ No newline at end of file
img = cv2.imread('./lihaonan.jpg')
age, gender, dist = model.get_age_gender_dist(img)
print(age) # 年龄
print(gender) # 性别 0: 女 1: 男
print(dist) # 瞳距 单位 px
```
# Dev/Deployment
mxnet-cu100==1.4.1
mxnet
scipy==1.2.2
scikit-learn==0.20.3
opencv-python==4.1.0.25
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment