TensorFlow: How do I release a model without sourc

2020-02-15 03:29发布

I am using Tensorflow + Python.

I am curious if I can release a saved Tensorflow model (architecture + trained variables) without detailed source code. I'm aware of tf.train.Saver(), but it looks to save only variables, and in order to restore/run them, a user needs to "define" the same architecture.

For the testing/running purpose only, is there a way to release a saved {architecture+trained variables} without source code, so that a user can just cast a query and get a result?

2条回答
霸刀☆藐视天下
2楼-- · 2020-02-15 03:31

You can build a Saver from the MetaGraphDef (saved with checkpoints by default: those .meta files). and then use that Saver to restore your model. So users don't have to re-define your graph in their code. But then they still need to figure out the model signature (input, output variables). I solve this using tf.Collection (but i am interested to find better ways to do it as well).

You can take a look at my example implementation (the eval.py evaluate a model without re-defining a model):

查看更多
够拽才男人
3楼-- · 2020-02-15 03:37

The TensorFlow Serving project is intended to make this use case straightforward (assuming that the end user is only using the model for inference, not training). TensorFlow Serving includes an Exporter class that takes your tf.train.Saver, the tf.GraphDef that defines your overall model, and a "signature" that describes the inputs to and output from your model.

The basics tutorial has a good introduction to exporting your model.

查看更多
登录 后发表回答