C3W2 Zombie Assignment Exercise 10 training loop

Hi everyone,

I hope anyone can help me with the Zombie assignment. I’m stuck at exercise 10 when trying ot execute the training loop I get the following error:

ValueError: in user code:

File "<ipython-input-152-d49021fc563a>", line 62, in train_step_fn  *
    optimizer.apply_gradients(zip(gradients, vars_to_fine_tune))
File "/usr/local/lib/python3.9/dist-packages/keras/optimizer_v2/optimizer_v2.py", line 633, in apply_gradients  **
    grads_and_vars = optimizer_utils.filter_empty_gradients(grads_and_vars)
File "/usr/local/lib/python3.9/dist-packages/keras/optimizer_v2/utils.py", line 73, in filter_empty_gradients
    raise ValueError(f"No gradients provided for any variable: {variable}. "

ValueError: No gradients provided for any variable: (['WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalBoxHead/BoxPredictor/kernel:0', 'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalBoxHead/BoxPredictor/bias:0', 'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalClassHead/ClassPredictor/kernel:0', 'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalClassHead/ClassPredictor/bias:0'],). Provided `grads_and_vars` is ((None, <tf.Variable 'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalBoxHead/BoxPredictor/kernel:0' shape=(3, 3, 256, 24) dtype=float32>), (None, <tf.Variable 'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalBoxHead/BoxPredictor/bias:0' shape=(24,) dtype=float32>), (None, <tf.Variable 'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalClassHead/ClassPredictor/kernel:0' shape=(3, 3, 256, 12) dtype=float32>), (None, <tf.Variable 'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalClassHead/ClassPredictor/bias:0' shape=(12,) dtype=float32>)).

I appreciate any help.

Thank you

José Luis.

Hi Jose,

As long as you choosing the right top layer heads (which I think you are doing here), you are probably getting this error because you are not implementing the train_step_fn() correctly. Many learners I see do not follow the instructions properly.

I would suggest going it through it again.

Hi I have the same issue. I’ve been trying to fix train_step_fn for some time now. Can’t seem to figure it out.

Hello Aditya,

in case you have same error, then that means you have not written codes for gradient. Check if you have missed any part of the codes related to gradient.

Regards
DP