句読点を予測するために tf.estimator API を使用しています。TFRecords と を使用して、前処理されたデータでトレーニングしましたtf.train.shuffle_batch
。今、私は予測をしたいと思います。静的な NumPy データを に送りtf.constant
、これを から返すことができますinput_fn
。
ただし、私はシーケンス データを扱っており、一度に 1 つの例をフィードする必要があり、次の入力は前の出力に依存しています。また、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()
ただし、次のエラーが発生します。
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.
input_fn
一度に 1 つずつ予測を取得するために、 を介して既存のグラフにデータを非同期的にプラグインするにはどうすればよいですか?