3

我正在尝试使用以下代码段导出先前训练的模型(pb)以用于服务

from tensorflow_serving.session_bundle import exporter
def create_graph():
        """Creates a graph from saved GraphDef file and returns a saver."""
        # Creates graph from saved graph_def.pb.
        with tf.gfile.FastGFile(modelFullPath, 'rb') as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())
            _ = tf.import_graph_def(graph_def, name='')

def export():
        print 'Exporting trained model to', export_path
        saver = tf.train.Saver(sharded=True)
        model_exporter = exporter.Exporter(saver)
        signature = exporter.classification_signature(input_tensor=x, scores_tensor=y)
        model_exporter.init(sess.graph.as_graph_def(),default_graph_signature=signature) 
        model_exporter.export(export_path, tf.constant(FLAGS.export_version), sess)
        print 'Done exporting!'

但是没有找到 exporter.py 中的 manifest_pb2。我在这种方法中是否遗漏了一些基本的东西?

4

1 回答 1

0

manifest_pb2.py是从manifest.proto使用 bazel 构建 session_bundle 时生成的。在 Mac 上,我使用 pip3 安装了 TensorFlow,文件位于/usr/local/lib/python3.5/site-packages/tensorflow/contrib/session_bundle/manifest_pb2.py.

按照https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html中的步骤操作您的平台,它应该可以解决问题。

于 2016-08-20T11:59:56.930 回答