I'm trying to reproduce some neural transfer tutorial which previously based on TensorFlow v1.x but using TensorFlow v2.0.
For some reason, I can't apply gradients with Adam optimizer due to, I believe, some data format.
The source is quite large so I tried to give just most relevant lines, but if someone asks about full code I will add it here.
Here is the optimizer
opt = tf.optimizers.Adam(learning_rate = 5, beta_1 = 0.99, epsilon = 1e-1)
And when I'm trying to apply gradients to initial variables using
opt.apply_gradients(zip(grads, init_image))
I'm getting error
!opt.apply_gradients(zip(grads, init_image))
*** TypeError: zip argument #2 must support iteration
These are the zip arguments:
init_image
<tf.Variable 'Variable:0' shape=(1, 345, 512, 3) dtype=float32, numpy=
array([[[[...]]]], dtype=float32)>
grads
<tf.Tensor: shape=(1, 345, 512, 3), dtype=float32, numpy=
array([[[[...]]]], dtype=float32)>
As you can see, the shape is the same as it should be, values inside numpy are some real values, not nans or something like that.
The gradients are calculated with:
with tf.GradientTape() as tape:
...computing all_loss...
total_loss = all_loss[0]
grads = tape.gradient(total_loss, init_image)
Any suggestions please.