-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
56 lines (42 loc) · 1.72 KB
/
Copy pathtest.py
File metadata and controls
56 lines (42 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 19 10:45:24 2018
@author: shen1994
"""
import os
import cv2
import tensorflow as tf
import numpy as np
if __name__ == "__main__":
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
output_graph_def = tf.GraphDef()
output_graph_def.ParseFromString(open("model/pico_FaceProper_model.pb", "rb").read())
tensors = tf.import_graph_def(output_graph_def, name="")
sess = tf.Session()
sess.run(tf.global_variables_initializer())
opt = sess.graph.get_operations()
input_x = sess.graph.get_tensor_by_name("proper_input:0")
gender_y = sess.graph.get_tensor_by_name("pred_gender/Softmax:0")
age_y = sess.graph.get_tensor_by_name("pred_age/Softmax:0")
image_path = "timg.jpg"
image_size = 128
o_image = cv2.imread(image_path, 1)
image = cv2.resize(o_image, (image_size, image_size))
image = image.astype('float32')
gender_list, age_list = sess.run([gender_y, age_y], \
feed_dict={input_x: [image]})
g_gender_list = np.arange(0, 2).reshape(2,)
g_age_list = np.arange(0, 101).reshape(101,)
gender = gender_list.dot(g_gender_list)[0]
age = age_list.dot(g_age_list)[0]
cv2.namedWindow("test")
while(True):
age_text = 'Age: %.2f' % age
gender_text = 'Gender: %.2f' % gender
cv2.putText(o_image, age_text, (130, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.60, (0,255,0), 2)
cv2.putText(o_image, gender_text, (0, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.60, (0,255,0), 2)
cv2.imwrite("DeepFaceProper-female.jpg", o_image)
break
cv2.imshow("test", o_image)
if cv2.waitKey(1) & 0xFF == ord("q"):
break