Note: I have read the TensorFlow guide for Save and Restore
I have a function which requires a constant SparseTensor
as input and it takes a while to run:
sparse = coo_matrix(dense)
sparse_indicies = list(zip(
sparse.row.astype(np.int64).tolist(),
sparse.col.astype(np.int64).tolist()
))
input_tensor = tf.SparseTensor(
indices = sparse_indicies,
values = (sparse.data).astype(np.float32),
dense_shape = sparse.shape
)
I just want to be able to save input_tensor
and load it later when needed. I am not running in eager execution.
Does that mean I have to do this:
file = 'tensor_{}_{}.ckpt'.format(*sparse.shape)
# save
init_op = tf.global_variables_initializer()
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(init_op)
save_path = saver.save(sess, file)
and then
# reload
tf.reset_default_graph()
junk, n_rows, n_cols = file.split('.')[0].split('_')
please_work = tf.get_variable("input_tensor", shape=[n_rows, n_cols])
saver = tf.train.Saver()
with tf.Session() as sess:
# Restore variables from disk.
saver.restore(sess, "i_just_want_one_tensor.ckpt")