我已经训练了一个DCGAN模型,现在想将它加载到一个库中,通过图像空间优化将神经元激活的驱动程序可视化。从metagraph文件导入张量流模型时配置input_map
下面的代码有效,但是在进行后续图像分析时,强制我使用(1,宽度,高度,通道)图像进行处理,这是一种痛苦(图书馆对网络输入形状的假设)。
# 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, './')
我想改变input_map,读取源后,我预计这个代码工作:
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, './')
但得到了一个错误:
ValueError: tf.import_graph_def() requires a non-empty
name
ifinput_map
is used.
当堆栈得到下来tf.import_graph_def()
名称字段设置为import_scope,所以我尝试了以下内容:
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, './')
这使我获得以下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."
如果我设置“import_scope”,我得到了同样的错误是否我设置“input_map”。
我不确定该从哪里出发。
如果你有一个独立的例子,我很高兴看到它。你可以在[test](https://www.github.com/tensorflow/tensorflow/blob/master/tensorflow/python/framework/meta_graph_test.py#L262)中看到如何使用'input_map'。我会尽量接近测试,看看它在哪里分歧。 – drpng
@drpng在我打开的github问题中有一个完整的示例(https://github.com/tensorflow/tensorflow/issues/7634)。感谢您推荐查看测试。我会尝试为低层功能设计的方法。 – Sevenless