0

I know one can use the statement x.assign(1) followed by a call to Operation.run() or Session.run() to assign the value 1 to the TensorFlow variable x.

However, this solution stores 1 twice in the memory. This can be an issue when the value to assign is large (e.g., word embeddings).

How to assign a value from a file to a TensorFlow variable without storing 2 copies of the value in memory?

Community
  • 1
  • 1
Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501

1 Answers1

1

You can avoid storing the value in Python memory by using TensorFlow readers. IE, something like

filename_queue = tf.train.string_input_producer("myfile")
x.assign(reader.read(filename_queue))

You want to assign something than string you may have to have to combine reader.read with an op that produces the desired type, ie, TextLineReader + tf.decode_csv

https://www.tensorflow.org/programmers_guide/reading_data

Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197