在张量流中导出和导入预制估计量

时间:2019-05-07 10:32:59

标签: python tensorflow machine-learning

我有一个数据集,该数据集包含35个要素,约有10000行。 另外,我使用来自tensorflow教程(https://www.tensorflow.org/api_docs/python/tf/contrib/factorization/KMeansClustering)的预制kmeansClustering。

对于导出,我的serve_input_fn()函数看起来像

def serving_input_fn():
    feature_placeholders = {
        'feature1' : tf.placeholder(tf.float32, [None]),
        'feature2' : tf.placeholder(tf.float32, [None]),
        ...

    }
    features = {
        key: tf.expand_dims(tensor, -1)
        for key, tensor in feature_placeholders.items()
    }
    return tf.estimator.export.ServingInputReceiver(features, feature_placeholders)

kmeans.export_savedmodel(
        export_dir_base=path_to_export,
        serving_input_receiver_fn=serving_input_fn)

我将得到一个pb文件和两个变量文件。如何导入此模型并通过数据进行预测?我的导入功能看起来像

import tensorflow as tf
from tensorflow.python.platform import gfile
from tensorflow.contrib import predictor
from tensorflow.python.util import compat
from tensorflow.core.protobuf import saved_model_pb2

GRAPH_PB_PATH = 'path_to_model/saved_model.pb'

with tf.gfile.FastGFile(GRAPH_PB_PATH, "rb") as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    g_in = tf.import_graph_def(graph_def, name="")
sess = tf.Session(graph=g_in)

但崩溃并显示错误消息“错误分析消息”。

怎么了?

0 个答案:

没有答案