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 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
tf.predict
, I've only been working with Keras. – Felix