I am doing some calculation, and I want to store the resulting matrix as a Variable that I can restore and re-use it elsewhere. Here is my calculation...
# Initializing the variables.init = tf.global_variables_initializer()saver = tf.train.Saver()with tf.Session() as sess: sess.run(init) total_batch = int(features.train.num_examples/100) train_images = [] for i in range(total_batch): batch_xs, batch_ys = features.train.next_batch(100) batch_xs = sess.run(tf.reshape(batch_xs, [100, 28, 28, 1])) train_images.append(batch_xs) train_images = np.array(train_images) # save model save_path = saver.save(sess, "/tmp/parsed_data.ckpt")train_images is anumpy array. I want to be able to store this into a Tensorflow Variable and then save the model so that I can use the Variable in another Tensorflow script. How can I do this? An extra note, the shape of thenumpy array is(550, 100, 28, 28, 1).
I found this tutorialhttps://learningtensorflow.com/lesson4/ but it is not very useful becauseplace_holders cannot be saved.
1 Answer1
You save the numpy arraytrain_images as numpy first. Use the following code:
np.save('train_image.npy', train_images)When you are loading the numpy array in another script, use thetf.stack function. An example given below -
import tensorflow as tfimport numpy as nparray = np.load('train_images.npy')tensor = tf.stack(array)Comments
Explore related questions
See similar questions with these tags.