我已经训练了一个DCGAN模型,现在想把它加载到一个库中,通过图像空间优化可视化神经元激活的驱动程序.
以下代码有效,但在进行后续图像分析时,迫使我使用(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, './')
Run Code Online (Sandbox Code Playgroud)
我想更改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, './')
Run Code Online (Sandbox Code Playgroud)
但是得到了一个错误:
ValueError:tf.import_graph_def()要求使用非空
nameifinput_map.
当堆栈到达tf.import_graph_def()name字段时设置为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': …Run Code Online (Sandbox Code Playgroud) tensorflow ×1