I need to compute the gradient wrt a loss for the variables of a defined neural network, the loss is computed correctly but the gradients are None. The code is the following:
variables = self.model.trainable_variables
for var in variables:
print("{}".format(var.name)
with tf.GradientTape() as tape:
y = self.model.predict(states[t])
y = tf.reshape(y, constants.NUM_ACTIONS)
loss = y[actions[t]]
grads = tape.gradient(loss, variables)
print("Information about gradients")
for var, g in zip(variables, grads):
print(f'{var.name}, shape: {g.shape}')
I get the following error:
AttributeError: 'NoneType' object has no attribute 'shape'
How can I fix this problem?