python - Tensorflow: Can't extract the feature vector from the penultimate layer -


i want extract feature vector image pre-trained network penultimate layer.

when ran:

from neural_network import net   x = tf.placeholder(tf.float32, shape=[1, 144, 144, 3])  net = net({'data': x}) sess = tf.interactivesession() sess.run(tf.initialize_all_variables()) net.load('inference.npy', sess)  feature = sess.graph.get_tensor_by_name('fc7:0') 

i received error message:

keyerror: "the name 'fc7:0' refers tensor not exist. operation, 'fc7', not exist in graph." 

on other hand, if replace last line with:

 feature = sess.graph.get_tensor_by_name('global_pool:0') 

then works.

the end of neural_network.py file is:

    (self.feed('inception_3b_pool',                'inception_3b_3x3',                'inception_3b_double_3x3_2')          .concat(3, name='inception_3b_output')          .avg_pool(9, 4, 1, 1, padding='valid', name='global_pool')           .fc(256, relu=false, name='fc7')) 

and definition of fc layer is:

def fc(self, input, num_out, name, relu=true):     tf.variable_scope(name) scope:         input_shape = input.get_shape()         if input_shape.ndims == 4:             # input spatial. vectorize first.             dim = 1             d in input_shape[1:].as_list():                 dim *= d             feed_in = tf.reshape(input, [-1, dim])         else:             feed_in, dim = (input, input_shape[-1].value)         weights = self.make_var('weights', shape=[dim, num_out])         biases = self.make_var('biases', [num_out])         op = tf.nn.relu_layer if relu else tf.nn.xw_plus_b         fc = op(feed_in, weights, biases, name=scope.name)         return fc 

usually output of fc layers biasadd node , output tensor name fc7/biasadd:0. though depends on implementation of fc method.

i think makes sense load graph in tensorboard , output node name.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -