【发布时间】:2016-05-10 18:29:03
【问题描述】:
如果我尝试使用
导入保存的TensorFlow 图形定义import tensorflow as tf
from tensorflow.python.platform import gfile
with gfile.FastGFile(FLAGS.model_save_dir.format(log_id) + '/graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
x, y, y_ = tf.import_graph_def(graph_def,
return_elements=['data/inputs',
'output/network_activation',
'data/correct_outputs'],
name='')
返回的值不是预期的Tensors,而是其他东西:例如,将x 获取为
Tensor("data/inputs:0", shape=(?, 784), dtype=float32)
我明白了
name: "data/inputs_1"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
attr {
key: "shape"
value {
shape {
}
}
}
也就是说,我得到的不是预期的张量x,而是x.op。这让我很困惑,因为documentation 似乎说我应该得到一个Tensor(尽管那里有一堆 or 让人难以理解)。
我如何让tf.import_graph_def 返回特定的Tensors,然后我可以使用(例如,在输入加载的模型或运行分析时)?
【问题讨论】:
-
第二行代码应该是
from tensorflow.python.platform import gfile。
标签: python machine-learning tensorflow restore