将MetaGraphDef转移到GraphDef的简单方法?

时间:2018-09-24 07:09:44

标签: tensorflow

是否有一种简单的方法可以将SaveModel生成的MetaGraphDef原型传输到GraphDef?

tf.saved_model.builder.SavedModelBuilder

2 个答案:

答案 0 :(得分:0)

好吧,我在这里找到答案: https://github.com/tensorflow/tensorflow/issues/8854

基本上,

graph_def = meta_graph_def.graph_def

答案 1 :(得分:0)

您可以推断出答案

https://medium.com/google-cloud/optimizing-tensorflow-models-for-serving-959080e9ddbf

metagrapydef-> graphdef->优化-> metagraphdef

from tensorflow.python.tools import freeze_graph
def freeze_model(saved_model_dir, output_node_names, output_filename):
  output_graph_filename = os.path.join(saved_model_dir, output_filename)
  initializer_nodes = ''
  freeze_graph.freeze_graph(
      input_saved_model_dir=saved_model_dir,
      output_graph=output_graph_filename,
      saved_model_tags = tag_constants.SERVING,
      output_node_names=output_node_names,
      initializer_nodes=initializer_nodes,
      input_graph=None,
      input_saver=False,
      input_binary=False,
      input_checkpoint=None,
      restore_op_name=None,
      filename_tensor_name=None,
      clear_devices=False,
      input_meta_graph=False,
  )
  print('graph freezed!')

freeze_graph(saved_model_dir, “head/predictions/class_ids”)