我已經訓練了一個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