Tuesday, March 21, 2017

Configure input_map when importing a tensorflow model from metagraph file

Leave a Comment

I've trained a DCGAN model and would now like to load it into a library that visualizes the drivers of neuron activation through image space optimization.

The following code works, but forces me to work with (1, width, height, channels) images when doing subsequent image analysis, which is a pain (the library assumptions about the shape of network input).

# creating TensorFlow session and loading the model graph = tf.Graph() sess = tf.InteractiveSession(graph=graph)  new_saver = tf.train.import_meta_graph(model_fn) new_saver.restore(sess, './') 

I'd like to change the input_map, After reading the source, I expected this code to work:

graph = tf.Graph() sess = tf.InteractiveSession(graph=graph)  t_input = tf.placeholder(np.float32, name='images') # define the input tensor t_preprocessed = tf.expand_dims(t_input, 0)  new_saver = tf.train.import_meta_graph(model_fn, input_map={'images': t_input}) new_saver.restore(sess, './') 

But got an error:

ValueError: tf.import_graph_def() requires a non-empty `name` if `input_map` is used. 

When the stack gets down to tf.import_graph_def() the name field is set to import_scope, so I tried the following:

graph = tf.Graph() sess = tf.InteractiveSession(graph=graph)  t_input = tf.placeholder(np.float32, name='images') # define the input tensor t_preprocessed = tf.expand_dims(t_input, 0)  new_saver = tf.train.import_meta_graph(model_fn, input_map={'images': t_input}, import_scope='import') new_saver.restore(sess, './') 

Which netted me the following KeyError:

KeyError: "The name 'gradients/discriminator/minibatch/map/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayReadV3/RefEnter:0' refers to a Tensor which does not exist. The operation, 'gradients/discriminator/minibatch/map/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayReadV3/RefEnter', does not exist in the graph." 

If I set 'import_scope', I get the same error whether or not I set 'input_map'.

I'm not sure where to go from here.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment