Reputation: 4901
In tensorflow, I can use Session.run
to map my inputs to my outputs. Suppose I do:
b = sess.run(B, {A:a})
Is the tensor associated with b
reallocated every time I make this call? Could I just store a pointer to b
and expect it to be updated every time I run sess.run(B, {A:a})
?
Upvotes: 1
Views: 388
Reputation: 126154
The result tensor is allocated each time you call sess.run()
, as a NumPy array. There's no way in the current API to share storage between Python and the TensorFlow backend, but if you want to allocate storage once and update it, you might be able to use a tf.Variable
:
A = ...
B = tf.Variable()
assign_op = B.assign(some_function(A))
# ...
sess.run(assign_op.op, {A: a})
Then, when you want to inspect B
, you can call:
b = sess.run(B)
...to get its current value.
Upvotes: 4