I am implementing simple RNN. In it I want to return outputs of each timestep in list which later I can feed it to optimizer. I have built working rnn without @tf.function. But after adding @tf.function it gives problem
def basic_rnn_cell(self,x,s):#Note :These function are defined in class
s=self.U*x+self.W*s+self.b #U,W,b and all are tf.Variable
y=self.V*s+self.c
return y,s
@tf.function
def rnn(self,X):
outputs=[]
state=self.state
for x in X:
output,state=self.basic_rnn_cell(x,state)
outputs.append(output)
return outputs
This is how I call :
x=np.array([0.01,0.02,0.03],dtype=np.float32)
o.rnn(x)
The error I get :
raise errors.InaccessibleTensorError(
tensorflow.python.framework.errors_impl.InaccessibleTensorError: The tensor 'Tensor("while/add_2:0", shape=(), dtype=float32)' cannot be accessed here: it is defined in another function or code block.
Use return values, explicit Python locals or TensorFlow collections to access it. Defined in: FuncGraph(name=while_body_44, id=2538759416224); accessed from: FuncGraph(name=rnn, id=2538758824096).