-
Notifications
You must be signed in to change notification settings - Fork 18
/
get_fc7.py
72 lines (57 loc) · 2.24 KB
/
get_fc7.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import tensorflow as tf
import utils
import numpy as np
import path
def load_graph(frozen_graph_filename):
with tf.gfile.GFile(frozen_graph_filename, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
# We load the graph_def in the default graph
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def,
input_map=None,
return_elements=None,
name='prefix',
op_dict=None,
producer_op_list=None)
return graph
def get_fc7(graph_filename,load_filename):
graph = load_graph(graph_filename)
#for op in graph.get_operations():
# print(op.name, op.values())
input = graph.get_tensor_by_name('prefix/input:0')
prob = graph.get_tensor_by_name('prefix/test/prob:0')
fc7 = graph.get_tensor_by_name('prefix/fc7/fc7:0')
keep_prob = graph.get_tensor_by_name('prefix/Placeholder_1:0')
paths, labels = utils.load_paths(load_filename, './')
features = []
with tf.Session(graph=graph) as sess:
# with tf.device('gpu:/0'):
for i in range(len(paths)):
path.DataDir.percent_bar(i+1,len(paths))
#print(paths[i])
images = utils.load_inputs(paths[i])
#print(images)
images = np.asarray(images, dtype=np.float32)
out = sess.run(fc7, feed_dict={
input: images,
keep_prob: 1.
})
features.append(out)
#print('Gain %d utterance feature' % i)
return features,labels
def get_dcnn_out(graph_filename,pic_path):
graph = load_graph(graph_filename)
input = graph.get_tensor_by_name('prefix/input:0')
prob = graph.get_tensor_by_name('prefix/test/prob:0')
fc7 = graph.get_tensor_by_name('prefix/fc7/fc7:0')
keep_prob = graph.get_tensor_by_name('prefix/Placeholder_1:0')
with tf.Session(graph=graph) as sess:
images = utils.load_inputs(pic_path)
images = np.asarray(images, dtype=np.float32)
out = sess.run(fc7, feed_dict={input: images,keep_prob: 1.})
print(out.shape)
return out
if __name__ == '__main__':
print('test')