Tensorflow:如何将.meta,.data和.index模型文件转换为一个graph.pb文件

前端之家收集整理的这篇文章主要介绍了Tensorflow:如何将.meta,.data和.index模型文件转换为一个graph.pb文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在tensorflow中,从头开始训练产生以下6个文件
  1. events.out.tfevents.1503494436.06L7-BRM738
  2. model.ckpt-22480.Meta
  3. checkpoint
  4. model.ckpt-22480.data-00000-of-00001
  5. model.ckpt-22480.index
  6. graph.pbtxt

我想将它们(或仅需要的)转换为一个文件graph.pb,以便能够将其转移到我的Android应用程序.

我尝试了脚本freeze_graph.py但它需要输入我还没有的input.pb文件. (我之前只提到过这6个文件).如何获得这个freezed_graph.pb文件?我看到几个线程,但没有一个为我工作.

解决方法

@H_502_25@ 您可以使用此简单脚本来执行此操作.但是您必须指定输出节点的名称.
import tensorflow as tf

Meta_path = 'model.ckpt-22480.Meta' # Your .Meta file

with tf.Session() as sess:

    # Restore the graph
    saver = tf.train.import_Meta_graph(Meta_path)

    # Load weights
    saver.restore(sess,tf.train.latest_checkpoint('.'))

    # Output nodes
    output_node_names =[n.name for n in tf.get_default_graph().as_graph_def().node]

    # Freeze the graph
    frozen_graph_def = tf.graph_util.convert_variables_to_constants(
        sess,sess.graph_def,output_node_names)

    # Save the frozen graph
    with open('output_graph.pb','wb') as f:
      f.write(frozen_graph_def.SerializeToString())
原文链接:https://www.f2er.com/html5/168509.html

猜你在找的HTML5相关文章