1

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.

desertnaut's user avatar
desertnaut
60.8k32 gold badges155 silver badges183 bronze badges
askedOct 27, 2017 at 3:22
buydadip's user avatar

1 Answer1

8

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)
answeredOct 27, 2017 at 4:25
Avijit Dasgupta's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.