0
votes

I'm using tensorflow in python for building a simple neural network for regression and I would like to extract the weights and the bias in order to use them in another program. Can somebody maybe point out how to extract the weights from the tf neural network and compute the prediction from the same weights, with simple matrix multiplication and addition once the tensorflow NN is trained. Also will this computation improve the prediction time(since tf.predict does some additional computations)?

1
this was what I could find relevant to your query - github.com/google/prettytensor/issues/6gireesh4manu
My guess is that it's not likely to improve prediction time, substantially at least. Numpy might get you there, but may not be worth it. Not sure about the inner workings of tf.predict, I've only been working with Keras.Felix

1 Answers

0
votes

You can use the tf.train.Saver class to save your model as a ckpt file and use it later:

saver = tf.train.Saver()
 with tf.Session() as sess:
    #your code here
    save_path = saver.save(sess, "/model_path/model.ckpt")

To restore the variables:

saver.restore(sess, "/your_path/model.ckpt") 

Complete documentation: https://www.tensorflow.org/guide/saved_model