Tensorflow: How to use a trained model in a application?

I have trained a Tensorflow Model, and now I want to export the "function" to use it in my python program. Is that possible, and if yes, how? Any help would be nice, could not find much in the documentation. (I dont want to save a session!)

I have now stored the session as you suggested. I am loading it now like this:

f = open('batches/batch_9.pkl', 'rb')
input = pickle.load(f)
f.close()
sess = tf.Session()

saver = tf.train.Saver()
saver.restore(sess, 'trained_network.ckpt')
y_pred = []

sess.run(y_pred, feed_dict={x: input})

print(y_pred)

However, I get the error "no Variables to save" when I try to initialize the saver.

What I want to do is this: I am writing a bot for a board game, and the input is the situation on the board formatted into a tensor. Now I want to return a tensor which gives me the best position to play next, ie a tensor with 0 everywhere and a 1 at one position.


I don't know if there is any other way to do it, but you can use your model in another Python program by saving your session:

Your training code:

# build your model

sess = tf.Session()
# train your model
saver = tf.train.Saver()
saver.save(sess, 'model/model.ckpt')

In your application:

# build your model (same as training)
sess = tf.Session()
saver = tf.train.Saver()
saver.restore(sess, 'model/model.ckpt')

You can then evaluate any tensor in your model using a feed_dict. This obviously depends on your model. For example:

session.run(y_pred, feed_dict={x: input_data})
链接地址: http://www.djcxy.com/p/94750.html

上一篇: 这种分割近似算法如何工作?

下一篇: Tensorflow:如何在应用程序中使用训练有素的模型?