I am currently using VGG-face-discriptor from https://github.com/AKSHAYUBHAT/TensorFace.
VGG-face-discriptor uses VGG16 and output vector 2622, a number of class of celebrities. What I really need is response of second last fully connected layer, which size is 4096. Using the code provided from the repository I mentioned above
import vggface
from pprint import pprint
import tensorflow as tf
input_placeholder = tf.placeholder(tf.float32, shape=(1, 224, 224, 3))
network = vggface.VGGFace()
ses = tf.InteractiveSession()
network.load(ses,input_placeholder)
output = network.eval(feed_dict={input_placeholder:vggface.load_image('test/ak.png')})[0]
pprint(sorted([(v,network.names[k]) for k,v in enumerate(output)],reverse=True)[:10])
Works very fine, giving me the closest celebrity face result.
result:
[(13.686731, 'Aamir_Khan'),
(8.4711819, 'Adam_Driver'),
(8.0207777, 'Manish_Dayal'),
(7.2776313, 'John_Abraham'),
(6.8999376, 'Jacob_Artist'),
(6.5390964, 'Adam_Copeland'),
(6.4980922, 'Adrian_Paul'),
(6.4170547, 'Akshay_Kumar'),
(6.3718734, 'D.B._Woodside'),
(6.0774565, 'Ajay_Devgn')]
Looking at the output
varaible, I see 2622 numpy ndarry.
But I actually want the 2nd last feature vector.. How can I achieve this?
I've looked around all the TensorFlow tutorial codes, but cannot find something like this. With Caffe, I just
out = net.forward()
v = net.blobs['fc7'].data[0].copy()
Simple was that. How can I see through 'blob' in TensorFlow? With numpy array feature vector?
You can use session.run to get the current values of elements in your computation graph.
layer7_values = session.run(layer7_tf, feed_dict={<your inputs>})
In this example session
is a tf.Session()
object. layer7_tf
is a reference to the Tensor
output of a layer in the TensorFlow model, and layer7_values
will contain the layer values for the given input as a numpy array.
To get a handle to layer7_tf
, you have a couple of options. You can either modify TensorFace/vggface/init.py
to return a reference to the appropriate layer; or you can explore the session.graph_def
structure to find the name
of the node that corresponds to that tensor, and pass the string name of the tensor (e.g. layer7_tf/foo/bar:0
, where the :0
corresponds to the 0th output of the op called layer7_tf/foo/bar
) to session.run()
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With