I've successfully trained and validated my TensorFlow model via the Experiment framework. I'm a little lost on how I can now make predictions on new samples from the saved model. My experiment code looks like with my feature columns defined in a previous cell:
def experiment_fn(output_dir):
return tflearn.Experiment(
tflearn.DNNClassifier(feature_columns=feature_cols,
hidden_units=[30, 2],
n_classes=2,
model_dir=output_dir),
train_input_fn=get_train(),
eval_input_fn=get_valid(),
eval_metrics = {
"accuracy":
tf.contrib.learn.MetricSpec(
metric_fn=tf.contrib.metrics.streaming_accuracy,
prediction_key=tf.contrib.learn.PredictionKey.CLASSES),
"precision":
tf.contrib.learn.MetricSpec(
metric_fn=tf.contrib.metrics.streaming_precision,
prediction_key=tf.contrib.learn.PredictionKey.CLASSES),
"recall":
tf.contrib.learn.MetricSpec(
metric_fn=tf.contrib.metrics.streaming_recall,
prediction_key=tf.contrib.learn.PredictionKey.CLASSES)
}
)
learn_runner.run(experiment_fn, 'model_trained')
Looking at this post on saving and restoring a model, I thought I may be able to retrieve the predict method on the DNNClassifier like this:
op_to_restore = graph.get_tensor_by_name("predict:0")
and then build a feed_dict with new samples and run:
print sess.run(op_to_restore,feed_dict)
However, after successfully restoring the model, TensorFlow complains it cannot find a 'predict' operation.
Any help here would be greatly appreciated. Thanks!