Reputation: 21
model = tf.estimator.DNNClassifier(feature_columns=feat_cols, hidden_units=[1024, 512, 256])
model.train(input_fn=input_func,steps=5000)
This create check point
I comeback day 2; now I need my model from check point; how to restore?
sess=tf.Session()
saver = tf.train.import_meta_graph(file_path + "/" + "model.ckpt-1000.meta")
saver.restore(sess,tf.train.latest_checkpoint(file_path))
model = ????? -- how do I get my model back?
Upvotes: 0
Views: 984
Reputation: 21
Not sure why I struggled. Answer to be rather simple. Read Article on Checkpoints: https://www.tensorflow.org/get_started/checkpoints
Very simple code to reload your model:
model_load = tf.estimator.DNNClassifier(feature_columns=feat_cols, hidden_units=[10, 10, 10, 10], model_dir="C:/Users/AI101~1/AppData/Local/Temp/tmpm2ndcvf_")
Upvotes: 1
Reputation: 43
I was also stuck at the same problem for a whole day, on How to run inference from saved checkpoints and graphs. Almost all of the suggestions are to load the graph using .meta file, and freeze it to some .pb file. I tried those approaches, they were working in the examples but were failing in my case for one reason or another. Also, being new to TF, couldn't make much sense out of it.
So, I just did some hit and trials(after4-5 hours web sniffing) to load the model same way as during training, and to my surprise it worked. You will need your training script/Estimator or Model Function to load the model.
test_data = tf.estimator.inputs.numpy_input_fn(<input_feed_dict/x=np.array(something)>, num_epochs=1, shuffle=False)
model = tf.estimator.Estimator(model_fn=<Your_Estimator_Function>, model_dir="<model_dir>")
predictions = model.predict(input_fn=test_data)
On a side note, After going through so many links I can say that there is no proper documentation available(especially for beginners) for high level tensorflow APIs. All Saving and Restoration a Tensorflow model tutorials make use of Low-level Tensorflow APIs, which support all these functionalities and many more (Sessions/Graphs/Summary etc. gracefully)
Just saw the comment after saving the answer, which also I think suggests similar thing, so not sure whether to keep mine or not. Still keeping it incase
Upvotes: 0