I am having problems using the Defun decorator in a tensor stream. Namely, Defun cannot close any TF ops created outside. The following is a separate example showing what I would like to do. Note that the tensor x belongs to different graphs inside and outside the call to custom_op. Defun code creates a timeline, converts the schedule into a proto function, and then combines it into a source graph. The code is reset in the first step, since the tensors that we close are not in the new time graph. Is there any way around this? Being able to close things would be very helpful.
import tensorflow as tf
from tensorflow.python.framework import function
w = tf.Variable(1.0)
function_factory = lambda x: x*w
@function.Defun(x=tf.float32)
def custom_op(x):
print('graph for x inside custom_op: ', x.graph)
return function_factory(x)
x = tf.constant(2.0)
print('graph for x outside custom_op: ', x.graph)
y = custom_op(x)
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
sess.run(y)
source
share