根据this answer,我可以从MetaGraph中提取SavedModel,然后卡住MetaGraphGraphDef,然后在该freeze_graph.py上运行GraphDef脚本以获得可在Android中使用的.pb。我的问题:如何准确地提取MetaGraph(然后提取其GraphDef)?因为tf.saved_model.loader.load(sess, [tag_constants.SERVING], <model_path>)返回MetaGraphDef而不是MetaGraph

最佳答案

我知道了原来,删除从conda获得的Tensorflow版本并将其替换为pip的版本后,我可以这样做:

from tensorflow.python.tools import freeze_graph
from tensorflow.python.saved_model import tag_constants

input_saved_model_dir = "F:/python_machine_learning_codes/estimator_exported_model/1509418513"
output_node_names = "softmax_tensor"
input_binary = False
input_saver_def_path = False
restore_op_name = None
filename_tensor_name = None
clear_devices = False
input_meta_graph = False
checkpoint_path = None
input_graph_filename = None
saved_model_tags = tag_constants.SERVING

freeze_graph.freeze_graph(input_graph_filename, input_saver_def_path,
                            input_binary, checkpoint_path, output_node_names,
                              restore_op_name, filename_tensor_name,
                              output_graph_filename, clear_devices, "", "", "",
                              input_meta_graph, input_saved_model_dir,
                            saved_model_tags)
conda-forge中的一个不完整,即使安装了pip,我也必须从freeze_graph.py中复制saved_model_utilstensorflow-master。同样,上面的代码大部分是从freeze_graph_test.py复制的。

10-06 03:25