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

前端 未结 1 1515
[愿得一人]
[愿得一人] 2020-12-30 06:07

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

相关标签:
1条回答
  • 2020-12-30 06:47

    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:

    #evaluate tensor
    sess.run(y_pred, feed_dict={x: input_data})
    
    0 讨论(0)
提交回复
热议问题