2016-09-11 6 views
0

学習プロセス中にいくつかのランダムサンプルの出力を予測するようモデルに頼んでみたいです。現在、私はtf.contrib.learn.monitors.EveryNから派生したクラスを構築し、次のようにevery_n_step_endを上書き:モデルのトレーニング中に予測結果のサンプルを印刷するにはどうすればよいですか?

def every_n_step_end(self, step, outputs): 
    # evaluate the model on the validation set 
    self._estimator.evaluate(
     input_fn=input_fn_eval, 
     metrics=validation_metrics, 
     steps=None) 
    # generate some random samples 
    for _ in range(FLAGS.num_samples): 
    input_sample, output_sample, label = random.choice(validation_set) 
    prob = self._estimator.predict(input_fn=lambda: get_features(input_sample, output_sample)) 
    print("{}:{}:{}:{}".format(input_sample, output_sample, prob[0, 0], label)) 

問題は、それが各反復である、predict関数は、チェックポイントとなどからモデルを読み込むには、適切な方法か?

答えて

0

predictメソッドは、入力関数(input_fn)を使用して、モデルにデータを前処理し、フィードします。したがって、入力関数を作成してからそれをpredictメソッドに渡して、予測される確率のリストを取得するのは簡単です。 input_fn関数の記述の詳細については、Building Input Functions with tf.contrib.learnを参照してください。

関連する問題