在 Tensorflow 中如何冻结保存的模型 [英] In Tensorflow how to freeze saved model
问题描述
这可能是一个非常基本的问题...
但是如何将检查点文件转换为单个 .pb 文件.我的目标是使用 C++ 为模型提供服务
这些是我要转换的文件.
附带说明,我将 tflearn 与 tensorflow 一起使用.
编辑 1:我找到了一篇解释如何做到这一点的文章:
我得到的错误来自回归层,如果我使用:sgd
.我会得到
KeyError:名称‘SGD’指的是不在图中的操作."
问题是我使用 tensorflow 而不是使用 tflearn 加载模型.
所以...而不是:
tf.train.import_meta_graph(...)
我们这样做:
model.load(...)
TFLearn 知道如何正确解析图.
This is probably a very basic question...
But how do I convert checkpoint files into a single .pb file. My goal is to serve the model using probably C++
These are the files that I'm trying to convert.
As a side note I'm using tflearn with tensorflow.
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
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.
The error that I get comes from the regression layer, if I use: 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.
The problem was that I was loading the model using tensorflow instead of using tflearn.
So... instead of:
tf.train.import_meta_graph(...)
We do:
model.load(...)
TFLearn knows how to parse the graph properly.
这篇关于在 Tensorflow 中如何冻结保存的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!