I'm trying to do what these lines of code used to do with an older version of Tensorflow (seen on a ML online course)
optimizer = tf.train.AdamOptimizer(learning_rate)
train_step = optimiser.minimize(loss)
and checking previously answered questions and documentation, I found out that var_list is now a required parameter, and in case loss is provided as a Tensor the tape that computed the loss must be provided. So I got to write the following code:
optimizer = tf.optimizers.Adam(learning_rate=learning_rate)
params = [w1, b1, w2, b2, w3, b3]
gradients = optimizer.get_gradients(loss=loss, params=params)
train_step = optimizer.minimize(loss=loss, var_list=params, tape=tf.GradientTape(), grad_loss=gradients)
but I'm still getting the error:
ValueError: No gradients provided for any variable: (['Variable:0', 'Variable_1:0',
'Variable_8:0', 'Variable_9:0', 'Variable_12:0', 'Variable_13:0'],). Provided
`grads_and_vars` is ((None, <tf.Variable 'Variable:0' shape=(784, 512) dtype=float32>),
(None, <tf.Variable 'Variable_1:0' shape=(512,) dtype=float32>), (None, <tf.Variable
'Variable_8:0' shape=(512, 64) dtype=float32>), (None, <tf.Variable 'Variable_9:0'
shape=(64,) dtype=float32>), (None, <tf.Variable 'Variable_12:0' shape=(64, 10)
dtype=float32>), (None, <tf.Variable 'Variable_13:0' shape=(10,) dtype=float32>)).
I thought I'd solve the problem computing the gradients with the get_gradients method and providing it as a grad_loss parameter, but it still doesn't work.
I'm not even completely sure I should provide all those six parameters, but the architecture of the neural network I'm working with is actually made of two hidden layers and an output layer, with weights and bias each.
Thank you so much in advance