我正在使用tf.estimator API来预测标点符号。我使用TFRecords和tf.train.shuffle_batch
用预处理数据训练了它。现在我想做出预测。我可以将静态NumPy数据填入tf.constant
,并从input_fn
返回。如何使用TensorFlow Estimator API运行异步预测?
但是我正在处理序列数据,我需要一次提供一个示例,下一个输入取决于先前的输出。我也希望能够通过HTTP请求处理数据输入。
每次调用estimator.predict
时,都会重新加载检查点并重新创建整个图形。这是缓慢和昂贵的。所以我需要能够动态地向input_fn
提供数据。
我当前的尝试大致是这样的:
feature_input = tf.placeholder(tf.int32, shape=[1, MAX_SUBSEQUENCE_LEN])
q = tf.FIFOQueue(1, tf.int32, shapes=[[1, MAX_SUBSEQUENCE_LEN]])
enqueue_op = q.enqueue(feature_input)
def input_fn():
return q.dequeue()
estimator = tf.estimator.Estimator(model_fn, model_dir=model_file)
predictor = estimator.predict(input_fn=input_fn)
sess = tf.Session()
output = None
while True:
x = get_numpy_data(x, output)
if x is None:
break
sess.run(enqueue_op, {feature_input: x})
output = predictor.next()
save_to_file(output)
sess.close()
但是我收到以下错误:通过input_fn
ValueError: Input graph and Layer graph are not the same: Tensor("EmbedSequence/embedding_lookup:0", shape=(1, 200, 128), dtype=float32) is not from the passed-in graph.
我如何可以异步插入数据到我现有的图形得到的预测一个在一次?