简体   繁体   English

在Tensorflow中如何冻结已保存的模型

[英]In Tensorflow how to freeze saved model

This is probably a very basic question... 这可能是一个非常基本的问题......

But how do I convert checkpoint files into a single .pb file. 但是如何将检查点文件转换为单个.pb文件。 My goal is to serve the model using probably C++ 我的目标是使用C ++来提供模型

These are the files that I'm trying to convert. 这些是我试图转换的文件。

检查点

As a side note I'm using tflearn with tensorflow. 作为旁注,我正在使用带有tensorflow的tflearn。

Edit 1: I found an article that explains how to do this: https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc 编辑1:我发现了一篇解释如何执行此操作的文章: https//blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api- d4f3596b3adc

The problem is that I'm stuck with the following error 问题是我遇到了以下错误

KeyError: "The name 'Adam' refers to an Operation not in the graph."

How do I fix this? 我该如何解决?

Edit 2: Maybe this will shed some light on the problem. 编辑2:也许这会对问题有所了解。

回归层

The error that I get comes from the regression layer, if I use: sgd . 我得到的错误来自回归层,如果我使用: sgd I'll get 我去拿

KeyError: "The name 'SGD' refers to an Operation not in the graph."

The tutorial on https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc works just fine . https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc上的教程工作正常

The problem was that I was loading the model using tensorflow instead of using tflearn. 问题是我使用tensorflow而不是使用tflearn加载模型。

So... instead of: 所以...而不是:

tf.train.import_meta_graph(...)

We do: 我们的确是:

model.load(...)

TFLearn knows how to parse the graph properly. TFLearn知道如何正确地解析图表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM