Reputation: 420
I have trained a cnn model using tf.estimator
and tf.data.TFRecordDataset
, which define a model in model_fn
funcition and input in input_fn
function. Also using an one-shot iterator to get one batch examples at a time.
Now I have trained model files(ckpt, meta, index) in a directory. What I want to do is predicting a image's label based on the trained model without training and evaluation again. The image can be numpy array but not possible a TFRecords file(which used when traing).
I can't find an effictive solution after trying all day. I only can get the value of weights and biases and don't know how to make my predicting image and model compatible.
FYI, my training code is here.
The similar question is Prediction from model saved with tf.estimator.Estimator
in Tensorflow
, but no accepted answer and my model input is using the dataset api.
So reaaally need help. Thanks.
Upvotes: 1
Views: 1071
Reputation: 28198
I have answered a similar question here.
To make predictions using a custom input, you need to use the built-in predict
method of Estimators:
estimator = tf.estimator.Estimator(model_fn, ...)
predict_input_fn = ... # define this using tf.data
predict_results = estimator.predict(predict_input_fn)
for idx, prediction in enumerate(predict_results):
print(idx)
for key in prediction:
print("...{}: {}".format(key, prediction[key]))
Upvotes: 1