Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
face_recognition
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lu Manh Hung
face_recognition
Commits
d7b11a94
Commit
d7b11a94
authored
Dec 24, 2019
by
banglv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prediction
parent
83d65319
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
205 additions
and
0 deletions
+205
-0
options.py
options.py
+139
-0
prediction_dual.py
prediction_dual.py
+66
-0
No files found.
options.py
0 → 100644
View file @
d7b11a94
import
argparse
import
os
saved_model
=
'/media/banglv/DATA/CORE_Quality_Preprocess_GUI_backup/data_files/svm_models/occlusion_detection'
BASED_PATH
=
'/media/banglv/DATA/CORE_Quality_Preprocess_GUI_backup/data_files'
BASED_PATH_YOLO
=
os
.
path
.
join
(
BASED_PATH
,
'face_detection_yolo_weight'
)
BASED_PATH_INFERENCE
=
os
.
path
.
join
(
BASED_PATH
,
'face_insight_pretrained'
)
def
get_yolo_args
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--model'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH_YOLO
,
'model-weights/model-weights/YOLO_Face.h5'
),
help
=
'path to model weights file'
)
parser
.
add_argument
(
'--anchors'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH_YOLO
,
'cfg/yolo_anchors.txt'
),
help
=
'path to anchor definitions'
)
parser
.
add_argument
(
'--classes'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH_YOLO
,
'cfg/face_classes.txt'
),
help
=
'path to class definitions'
)
parser
.
add_argument
(
'--score'
,
type
=
float
,
default
=
0.35
,
help
=
'the score threshold'
)
parser
.
add_argument
(
'--iou'
,
type
=
float
,
default
=
0.45
,
help
=
'the iou threshold'
)
parser
.
add_argument
(
'--img-size'
,
type
=
list
,
action
=
'store'
,
default
=
(
416
,
416
),
help
=
'input image size'
)
parser
.
add_argument
(
'--image'
,
default
=
True
,
action
=
"store_true"
,
help
=
'image detection mode'
)
parser
.
add_argument
(
'--video'
,
type
=
str
,
default
=
'samples/subway.mp4'
,
help
=
'path to the video'
)
parser
.
add_argument
(
'--output'
,
type
=
str
,
default
=
'outputs/'
,
help
=
'image/video output path'
)
args
=
parser
.
parse_args
()
return
args
def
get_YOLO_tiny_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'YOLO tiny parameters'
)
parser
.
add_argument
(
'--saved_weight'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH_YOLO
,
'model-weights/model-weights/yolov2_tiny-face.h5'
))
parser
.
add_argument
(
'--image_size'
,
type
=
int
,
default
=
416
)
parser
.
add_argument
(
'--obj_threshold'
,
type
=
float
,
default
=
0.30
)
parser
.
add_argument
(
'--nms_threshold'
,
type
=
float
,
default
=
0.30
)
parser
.
add_argument
(
'--anchors'
,
type
=
list
,
default
=
[
0.57273
,
0.677385
,
1.87446
,
2.06253
,
3.33843
,
5.47434
,
7.88282
,
3.52778
,
9.77052
,
9.16828
])
parser
.
add_argument
(
'--nb_box'
,
type
=
int
,
default
=
5
)
parser
.
add_argument
(
'--nb_class'
,
type
=
int
,
default
=
1
)
parser
.
add_argument
(
'--crop_ratio'
,
type
=
float
,
default
=
1.0
)
args
=
parser
.
parse_args
()
return
args
def
get_landmark_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Landmark detection options'
)
parser
.
add_argument
(
'--landmark_model'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH
,
'landmark_models/facial_landmark_SqueezeNet.pb'
))
parser
.
add_argument
(
'--CNN_size'
,
type
=
int
,
default
=
64
)
args
=
parser
.
parse_args
()
return
args
def
get_system_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'VHT Face recognition system option parameters'
)
parser
.
add_argument
(
'--dlib_predictor'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH
,
'dlib_predictor/shape_predictor_68_face_landmarks.dat'
))
parser
.
add_argument
(
'--is_url'
,
default
=
True
,
help
=
'Use url or not'
)
parser
.
add_argument
(
'--url_link'
,
type
=
str
,
default
=
'/home/banglv/Videos/ex4.mp4'
,
help
=
'url link to open stream video'
)
# rtsp://admin:123456a@@192.168.0.205:554/cam/realmonitor?channel=1&subtype=0
# /home/banglv/Videos/ex4.mp4
# #rtsp://root:123456a@@192.168.0.204/axis-media/media.amp
parser
.
add_argument
(
'--detect_method'
,
type
=
str
,
default
=
'yolo'
,
help
=
'Face detection method: YOLO/SSD/MTCNN'
)
parser
.
add_argument
(
'--detect_mode'
,
type
=
str
,
default
=
'center'
)
parser
.
add_argument
(
'--detect_weight_ssd'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH
,
'face_detection_ssd_weight/graph_mobilenet_v2_all_180627.pb'
))
parser
.
add_argument
(
'--detect_haar_xml'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH
,
'haar_xml_set/haarcascade_frontalface_default.xml'
))
parser
.
add_argument
(
'--detect_select_mode'
,
type
=
str
,
default
=
'tiny'
,
help
=
'Choice face detection method: yolo/ssd'
)
parser
.
add_argument
(
'--used_feature_main'
,
type
=
str
,
default
=
'arcface'
,
help
=
'Choice image feature type'
)
parser
.
add_argument
(
'--image_feature'
,
type
=
str
,
default
=
'arcface'
,
help
=
'Feature type for face classification'
)
parser
.
add_argument
(
'--path_to_training_feature'
,
type
=
str
,
default
=
''
,
help
=
'Path to classifiers training feature set'
)
parser
.
add_argument
(
'--thr_location_jitter'
,
type
=
int
,
default
=
20
)
parser
.
add_argument
(
'--thr_size_jitter'
,
type
=
int
,
default
=
20
)
parser
.
add_argument
(
'--thr_bright'
,
type
=
float
,
default
=
0.15
,
help
=
'IQA: brightness threshold'
)
parser
.
add_argument
(
'--thr_contrast'
,
type
=
float
,
default
=
30
,
help
=
'IQA: contrast threshold'
)
parser
.
add_argument
(
'--thr_sharpness'
,
type
=
float
,
default
=
5
,
help
=
'IQA: sharpness threshold'
)
parser
.
add_argument
(
'--thr_noise'
,
type
=
float
,
default
=
10
,
help
=
'IQA: noise threshold'
)
parser
.
add_argument
(
'--thr_roll'
,
type
=
float
,
default
=
20
,
help
=
'IQA: roll angle threshold'
)
parser
.
add_argument
(
'--thr_pitch'
,
type
=
float
,
default
=
20
,
help
=
'IQA: pitch angle threshold'
)
parser
.
add_argument
(
'--thr_yaw'
,
type
=
float
,
default
=
20
,
help
=
'IQA: yaw angle threshold'
)
parser
.
add_argument
(
'--thr_eye_distance'
,
type
=
float
,
default
=
10
,
help
=
'Minimal eye to eye distance (pixels)'
)
parser
.
add_argument
(
'--thr_minimal_size'
,
type
=
float
,
default
=
20
,
help
=
'Minimal passed cropped face image size'
)
parser
.
add_argument
(
'--thr_decision_detect'
,
type
=
float
,
default
=
.75
,
help
=
'Threshold for detector'
)
parser
.
add_argument
(
'--thr_decision_classify'
,
type
=
float
,
default
=
.5
,
help
=
'Threshold for classifier'
)
parser
.
add_argument
(
'--is_remove_occlusion'
,
default
=
True
,
help
=
'Is remove the occluded sample or not'
)
parser
.
add_argument
(
'--path_to_occlusion_scaler'
,
type
=
str
,
default
=
saved_model
+
'/occlusion_detect_scaler.sav'
,
help
=
'Occluded face detection (SVM) model'
)
parser
.
add_argument
(
'--path_to_occlusion_model'
,
type
=
str
,
default
=
saved_model
+
'/occlusion_detect_svm.sav'
)
parser
.
add_argument
(
'--is_align'
,
default
=
True
,
help
=
'Face alignment'
)
parser
.
add_argument
(
'--align_method'
,
type
=
str
,
default
=
''
,
help
=
'Choice face alignment method'
)
parser
.
add_argument
(
'--is_brighten'
,
default
=
True
)
parser
.
add_argument
(
'--is_contrast'
,
default
=
False
)
parser
.
add_argument
(
'--is_sharpen'
,
default
=
False
)
parser
.
add_argument
(
'--is_denoise'
,
default
=
True
)
parser
.
add_argument
(
'--is_apply_shape'
,
default
=
False
,
help
=
'Use landmark features or not'
)
parser
.
add_argument
(
'--is_assist'
,
default
=
True
,
help
=
'Use the second feature or not'
)
parser
.
add_argument
(
'--used_feature_assist'
,
type
=
str
,
default
=
'lbp'
,
help
=
'The second feature to face classification'
)
parser
.
add_argument
(
'--is_multi_classifiers'
,
default
=
False
)
parser
.
add_argument
(
'--path_to_svm_model'
,
type
=
str
,
default
=
'/media/banglv/DATA/CORE_Quality_Preprocess_GUI_backup/data_files/svm_models/vht_llq_svm_model/backbone_res101_model_minmax.sav'
)
parser
.
add_argument
(
'--path_to_svm_scaler'
,
type
=
str
,
default
=
'/media/banglv/DATA/CORE_Quality_Preprocess_GUI_backup/data_files/svm_models/vht_llq_svm_model/backbone_res101_scaler_minmax.sav'
)
parser
.
add_argument
(
'--data_sample_names'
,
type
=
str
,
default
=
'/media/banglv/DATA/CORE_Quality_Preprocess_GUI_backup/data_files/features/VHT_LLQ/backbone_res101/res101_names.pkl'
)
parser
.
add_argument
(
'--path_to_rf_model'
,
type
=
str
,
default
=
''
)
parser
.
add_argument
(
'--path_to_rf_scaler'
,
type
=
str
,
default
=
''
)
sys_args
=
parser
.
parse_args
()
return
sys_args
def
get_reference_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Arcface parameters'
)
parser
.
add_argument
(
'--face_describer_input_tensor_names'
,
type
=
list
,
default
=
[
'img_inputs:0'
,
'dropout_rate:0'
])
parser
.
add_argument
(
'--face_describer_output_tensor_names'
,
type
=
list
,
default
=
[
'resnet_v1_50/E_BN2/Identity:0'
])
parser
.
add_argument
(
'--face_describer_device'
,
type
=
str
,
default
=
'/gpu:0'
)
parser
.
add_argument
(
'--face_describer_model_fp'
,
type
=
str
,
default
=
'{}/insightface_res50.pb'
.
format
(
BASED_PATH_INFERENCE
))
parser
.
add_argument
(
'--face_describer_tensor_shape'
,
default
=
(
112
,
112
))
parser
.
add_argument
(
'--face_describer_drop_out_rate'
,
type
=
float
,
default
=
0.1
)
parser
.
add_argument
(
'--face_similarity_threshold'
,
type
=
int
,
default
=
800
)
inference_opts
=
parser
.
parse_args
()
return
inference_opts
def
get_dual_network_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Dual network training parameters'
)
des
=
'dual_kid_inV3'
parser
.
add_argument
(
'--path_to_save'
,
type
=
str
,
default
=
os
.
path
.
join
(
BASED_PATH
,
'classification_weights'
,
des
))
parser
.
add_argument
(
'--path_to_dataset'
,
type
=
str
,
default
=
'/media/banglv/DATA/Data/child_alignn'
)
parser
.
add_argument
(
'--path_to_load'
,
type
=
str
,
default
=
BASED_PATH
)
parser
.
add_argument
(
'--batch_size'
,
type
=
int
,
default
=
64
)
parser
.
add_argument
(
'--model_name'
,
type
=
str
,
default
=
'dual_inception_celebA_l2.h5'
)
dual_opts
=
parser
.
parse_args
()
return
dual_opts
\ No newline at end of file
prediction_dual.py
0 → 100644
View file @
d7b11a94
import
numpy
as
np
from
keras
import
Input
from
DualTraining.dual_network
import
DualNetwork
from
keras.models
import
Model
from
PIL
import
Image
import
os
from
FaceRecognitionVHT.options
import
get_dual_network_args
import
matplotlib.pyplot
as
plt
from
keras.models
import
model_from_json
opts
=
get_dual_network_args
()
class
FacePredict
():
def
__init__
(
self
,
base_net
=
'resnet101'
):
path_to_weights
=
opts
.
path_to_save
load_target_h5
=
os
.
path
.
join
(
path_to_weights
,
os
.
path
.
split
(
path_to_weights
)[
1
]
+
'_celebA.h5'
)
load_target_json
=
os
.
path
.
join
(
path_to_weights
,
os
.
path
.
split
(
path_to_weights
)[
1
]
+
'_celebA.json'
)
json_file
=
open
(
load_target_json
,
'r'
)
loaded_model_json
=
json_file
.
read
()
json_file
.
close
()
self
.
model
=
model_from_json
(
loaded_model_json
)
self
.
model
.
load_weights
(
load_target_h5
)
# todo: load the trained weights
# self.dual_network.model.load_weights(load_target)
# input_tensor = Input(shape=(224, 224, 3))
core
=
self
.
model
.
get_layer
(
name
=
'model_1'
)
#
self
.
extractor
=
Model
(
core
.
get_input_at
(
0
),
core
.
get_layer
(
name
=
'dense5'
)
.
output
)
def
image_loader
(
self
,
path
):
image
=
Image
.
open
(
path
)
image
=
image
.
resize
((
112
,
112
))
image
=
np
.
asarray
(
image
)
.
astype
(
np
.
float64
)
if
np
.
min
(
image
)
<=
0
:
image
=
image
-
np
.
min
(
image
)
image
/=
127.5
image
-=
1.
# image = image / 255
return
image
def
images_similarity
(
self
,
image1
,
image2
):
pairs
=
[
np
.
zeros
((
1
,
112
,
112
,
3
))
for
i
in
range
(
2
)]
pairs
[
0
][
0
,
:,
:,
0
]
=
image1
pairs
[
1
][
0
,
:,
:,
0
]
=
image2
sim
=
self
.
model
.
model
.
predict
(
pairs
)
return
sim
def
feature_extraction
(
self
,
path
):
image
=
self
.
image_loader
(
path
)
image
=
image
.
astype
(
np
.
float
)
image
=
image
-
np
.
mean
(
image
)
expanded
=
np
.
zeros
((
1
,
224
,
224
,
3
))
expanded
[
0
,
:,
:,
:]
=
image
f
=
self
.
extractor
.
predict
(
expanded
)[
0
]
# f = f / np .linalg.norm(f)
return
f
# if __name__ == '__main__':
# path = '/media/banglv/DATA/Data/celebA_sorted/images_training/1004/cropped_173474.jpg'
# extractor = FacePredict()
# f = extractor.feature_extraction(path)
# plt.figure()
# plt.plot(f)
# plt.show()
\ No newline at end of file
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