Tensorflow freeze_graph script failing on model defined with Keras

前端 未结 2 1409
小鲜肉
小鲜肉 2021-01-01 02:02

I\'m attempting to export a model built and trained with Keras to a protobuffer that I can load in a C++ script (as in this example). I\'ve generated a .pb file containing t

2条回答
  •  渐次进展
    2021-01-01 02:32

    The problem is the order of these two lines in your original program:

    tf.train.write_graph(graph_def=sess.graph.as_graph_def(), logdir='.',     name='simple_as_binary.pb', as_text=False)
    tf.train.Saver().save(sess, 'simple.ckpt')
    

    Calling tf.train.Saver() adds a set of nodes to the graph, including one called "save/restore_all". However, this program calls it after writing out the graph, so the file you pass to freeze_graph.py doesn't contain those nodes, which are necessary for doing the rewriting.

    Reversing the two lines should make the script work as intended:

    tf.train.Saver().save(sess, 'simple.ckpt')
    tf.train.write_graph(graph_def=sess.graph.as_graph_def(), logdir='.',     name='simple_as_binary.pb', as_text=False)
    

提交回复
热议问题