Python 如何导出VocabularyProcessor并在TF服务加载后使用它?
我的代码有两部分:Python 如何导出VocabularyProcessor并在TF服务加载后使用它?,python,tensorflow,classification,Python,Tensorflow,Classification,我的代码有两部分: 用于训练数据的脚本(python+tf+bag_of_words) 任何字符串的predict类的脚本(现在是python,但后来是golang) 生产) 我将在python上训练我的模型,并通过GolangAPI在生产中使用模型 培训步骤: Fittf.contrib.learn.preprocessing.VocabularyProcessor 用BOW算法训练 添加输出tf.estimator.export.ClassificationOutput 添加输入tf.e
- 用于训练数据的脚本(python+tf+bag_of_words)
- 任何字符串的predict类的脚本(现在是python,但后来是golang) 生产)
tf.contrib.learn.preprocessing.VocabularyProcessor
tf.estimator.export.ClassificationOutput
tf.estimator.export.servicingInputReceiver
tf.estimator.estimator
string
。这个字符串
应该通过词汇处理器转换成向量。但词汇处理器不是张量,我不能用它作为图形节点。我不能对它进行pickle,因为我不会使用golang客户端实现来恢复它
有可能解决我的问题吗
def preprocess_for_prediction(n_words):
def serving_input_fn():
words = tf.placeholder(dtype=tf.string)
receiver_inputs = {"raw_words": words}
# Now use const by needed to convert raw_words to vector
vector = tf.constant([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], shape=(1, 10), dtype=tf.int32)
features = {WORDS_FEATURE: vector}
return tf.estimator.export.ServingInputReceiver(features, receiver_inputs)
return serving_input_fn
UPD:
我刚读到关于张量流变换的书。我想它会对我有用,试过之后我会把答案写在这里