Skip to content

Commit e823b6d

Browse files
author
dafu
committed
Need to improve and perfect. Don't run in this version.
0 parents  commit e823b6d

30 files changed

+3659
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.so
2+
*.pyc
3+
configs
4+
evaluation
5+
logdir
6+
models
7+
tfrecords
8+
.idea

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## JDAP(**J**oint **D**etection and **A**ilgnment and Head **P**ose)
2+
A face detection algorithm joint multi-task using cascade structure in CNN. This repository containtraining code and testing code using Tensorflow architecture.
3+
4+
### Results
5+
6+
### Requirement
7+
8+
### Preparation Data
9+
10+
### Training PNet
11+
12+
### Training RNet
13+
14+
### Training ONet
15+
16+
### Demo
17+
18+
### FAQ
19+
20+
21+
### References
22+
1. K. Zhang, Z. Zhang, Z. Li and Y. Qiao. Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks. Signal Processing Letters, 23(10):1499–1503, 2016.
23+
2. K. Zhang, Z. Zhang, Z. Li and Y. Qiao. Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks. Signal Processing Letters, 23(10):1499–1503, 2016.
24+
3. V. Jain and E. Learned-Miller. FDDB: A benchmark for face detection in unconstrained settings. In Technical Report UMCS-2010-009, 2010.
25+
4. S. Yang, P. Luo, C.-C. Loy, and X. Tang. Wider face: A face detection benchmark. In Conference on Computer Vision and Pattern Recognition (CVPR), 2016.

demo/Detector.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import tensorflow as tf
2+
import numpy as np
3+
from configs.config import config
4+
5+
6+
class Detector(object):
7+
def __init__(self, net_factory, data_size, batch_size, model_path, aux_idx=0):
8+
self._aux_idx = aux_idx
9+
graph = tf.Graph()
10+
with graph.as_default():
11+
#self.image_op = tf.placeholder(tf.float32, shape=[batch_size, data_size, data_size, 3], name='input_image')
12+
self.image_op = tf.placeholder(tf.float32, shape=[None, data_size, data_size, 3], name='input_image')
13+
if self._aux_idx == 0:
14+
self.cls_prob, self.bbox_pred = net_factory(self.image_op, is_training=False)
15+
# Only face landmark aux
16+
if self._aux_idx == 1:
17+
self.cls_prob, self.bbox_pred, self.land_pred = net_factory(self.image_op, is_training=False)
18+
# Only head pose aux
19+
elif self._aux_idx == 2:
20+
self.cls_prob, self.bbox_pred, self.pose_pred = net_factory(self.image_op, is_training=False)
21+
# face landmark and head pose aux together
22+
elif self._aux_idx == 3:
23+
self.cls_prob, self.bbox_pred, self.land_pred, self.pose_pred = net_factory(self.image_op, is_training=False)
24+
# Using early reject classifier
25+
elif self._aux_idx == 4:
26+
self.cls_prob, self.bbox_pred, self.DR1_index, self.DR2_index = net_factory(self.image_op, is_training=False)
27+
self.sess = tf.Session(
28+
config=tf.ConfigProto(allow_soft_placement=True, gpu_options=tf.GPUOptions(allow_growth=True)))
29+
saver = tf.train.Saver()
30+
saver.restore(self.sess, model_path)
31+
32+
self.data_size = data_size
33+
self.batch_size = batch_size
34+
35+
def predict(self, databatch):
36+
# access data
37+
# databatch: N x 3 x data_size x data_size
38+
scores = []
39+
batch_size = self.batch_size
40+
41+
minibatch = []
42+
cur = 0
43+
n = databatch.shape[0]
44+
while cur < n:
45+
minibatch.append(databatch[cur:min(cur+batch_size, n), :, :, :])
46+
cur += batch_size
47+
cls_prob_list = []
48+
bbox_pred_list = []
49+
land_pred_list = []
50+
pose_pred_list = []
51+
DR_index_list = []
52+
if self._aux_idx == 4:
53+
cls_prob, bbox_pred, DR1_index, DR2_index = \
54+
self.sess.run([self.cls_prob, self.bbox_pred, self.DR1_index, self.DR2_index], feed_dict={self.image_op: databatch})
55+
last_index = DR1_index[DR2_index]
56+
return cls_prob, bbox_pred, last_index
57+
else:
58+
for idx, data in enumerate(minibatch):
59+
m = data.shape[0]
60+
real_size = self.batch_size
61+
if m < batch_size:
62+
keep_inds = np.arange(m)
63+
gap = self.batch_size - m
64+
while gap >= len(keep_inds):
65+
gap -= len(keep_inds)
66+
keep_inds = np.concatenate((keep_inds, keep_inds))
67+
if gap != 0:
68+
keep_inds = np.concatenate((keep_inds, keep_inds[:gap]))
69+
data = data[keep_inds]
70+
real_size = m
71+
if self._aux_idx == 0:
72+
cls_prob, bbox_pred = self.sess.run([self.cls_prob, self.bbox_pred], feed_dict={self.image_op: data})
73+
elif self._aux_idx == 1:
74+
pass
75+
elif self._aux_idx == 2:
76+
pass
77+
elif self._aux_idx == 3:
78+
cls_prob, bbox_pred, land_pred, pose_pred = \
79+
self.sess.run([self.cls_prob, self.bbox_pred, self.land_pred, self.pose_pred], feed_dict={self.image_op: data})
80+
land_pred_list.append(land_pred[:real_size])
81+
pose_pred_list.append(pose_pred[:real_size])
82+
# elif self._aux_idx == 4:
83+
# cls_prob, bbox_pred, DR1_index, DR2_index = \
84+
# self.sess.run([self.cls_prob, self.bbox_pred, self.DR1_index, self.DR2_index], feed_dict={self.image_op: data})
85+
# index_1 = np.where(DR1_index < real_size)
86+
# filter_num_1 = np.size(index_1, axis=1)
87+
# #DR1_index_list.append(DR1_index[:filter_num_1])
88+
# valid_base_index = DR1_index[:filter_num_1]
89+
# index_2 = np.where(DR2_index < filter_num_1)
90+
# filter_num_2 = np.size(index_2, axis=1)
91+
# #DR2_index_list.append(DR2_index[:filter_num_2])
92+
# short_index = DR2_index[:filter_num_2]
93+
# last_index = valid_base_index[short_index]
94+
# mask = np.zeros(batch_size, dtype=np.int32)
95+
# mask[last_index] = 1
96+
# cls_prob_list.append(cls_prob[short_index])
97+
# bbox_pred_list.append(bbox_pred[short_index])
98+
# DR_index_list.append(mask[:real_size])
99+
100+
cls_prob_list.append(cls_prob[:real_size])
101+
bbox_pred_list.append(bbox_pred[:real_size])
102+
cls_result = np.concatenate(cls_prob_list, axis=0)
103+
bbox_result = np.concatenate(bbox_pred_list, axis=0)
104+
105+
if self._aux_idx == 0:
106+
return cls_result, bbox_result
107+
elif self._aux_idx == 1:
108+
return []
109+
elif self._aux_idx == 2:
110+
return []
111+
elif self._aux_idx == 3:
112+
land_result = np.concatenate(land_pred_list, axis=0)
113+
pose_result = np.concatenate(pose_pred_list, axis=0)
114+
return cls_result, bbox_result, land_result, pose_result
115+
# elif self._aux_idx == 4:
116+
# # DR1_index_list = np.concatenate(DR1_index_list, axis=0)
117+
# # DR2_index_list = np.concatenate(DR2_index_list, axis=0)
118+
# # return cls_result, bbox_result, DR1_index_list, DR2_index_list
119+
# reserve_mask = np.concatenate(DR_index_list, axis=0)
120+
# return cls_result, bbox_result, reserve_mask

demo/FcnDetector.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
import tensorflow as tf
3+
from configs.config import config
4+
5+
6+
class FcnDetector(object):
7+
def __init__(self, net_factory, model_path):
8+
with tf.Graph().as_default():
9+
self.image_op = tf.placeholder(tf.float32, name='input_image')
10+
self.width_op = tf.placeholder(tf.int32, name='image_width')
11+
self.height_op = tf.placeholder(tf.int32, name='image_height')
12+
image_reshape = tf.reshape(self.image_op, [1, self.height_op, self.width_op, 3])
13+
self.cls_prob, self.bbox_pred = net_factory(image_reshape, is_training=False)
14+
self.sess = tf.Session(
15+
config=tf.ConfigProto(allow_soft_placement=True, gpu_options=tf.GPUOptions(allow_growth=True)))
16+
saver = tf.train.Saver()
17+
saver.restore(self.sess, model_path)
18+
19+
def predict(self, databatch):
20+
height, width, _ = databatch.shape
21+
cls_prob, bbox_pred = self.sess.run([self.cls_prob, self.bbox_pred],
22+
feed_dict={self.image_op: databatch, self.width_op: width,
23+
self.height_op: height})
24+
return cls_prob, bbox_pred

0 commit comments

Comments
 (0)