C3W3 Exercise10: apply_gradients() missing 1 required positional argument: 'grads_and_vars'

optimizer.apply_gradients(zip(gradients, vars_to_fine_tune))

TypeError: apply_gradients() missing 1 required positional argument: 'grads_and_vars'

I tried several different things, I have no idea why this is not working

This line looks fine but check that gradients are calculated correctly above it (check all the steps above) . Also the vars_to_fine_tune when you choose them have a look are you choosing the right layers.

1 Like

Thank you for the answer!
I show you what I did, I do not see anything weird, although I in exercise 9 says 4 variables to fine tune and I just can see these two:

No need to show solutions here, its against the rules.

When you choose the layers I would suggest to use layer indexing. For the train-step_fn function I would check the whole function if something is not right. From those lines you posted here it seems ok.

1 Like

Maybe it does not have anything to do with it, but just in case. And I hope this is not considered a solution. When loading the checkpoint, at ex6.2, I don’t get the exact expected value the task says:

what I get:
‘_box_predictor’: <tensorflow.python.training.tracking.util.Checkpoint at 0x7f4820653850>,
‘_feature_extractor’: object_detection.models.ssd_resnet_v1_fpn_keras_feature_extractor.SSDResNet50V1FpnKerasFeatureExtractor at 0x7f48204b78d0>

Expected:

'_box_predictor': <tensorflow.python.training.tracking.util.Checkpoint at 0x7fefac044a20>, 
'_feature_extractor': <object_detection.models.ssd_resnet_v1_fpn_keras_feature_extractor.SSDResNet50V1FpnKerasFeatureExtractor at 0x7fefac0240b8>'

You know this is the most complex lab of the entire specialization. Its quite hard to debug it. I would think that given these checkpoints representing layers that we want to take ouputs from, I think that those values should be as expected.

So you should check the creation of the checkpoint, however thats a long way to the optimizer but it could be dependant on it. I would also suggest the rest of the train_step_fn function. Especially the provide model groundtruth part.

If you cannot fix the issue you could message me the notebook on private I will have a look on it when I have time, hopefully I find some problem with it.

1 Like

Thank you so much for your attention. I just solved it!!

Interestingly, I just solved it by setting up momentum in the Ex8, and setting the hyperparameters, I forgot to do it before, and somehow that was causing some trouble, no idea why.

2 Likes

It was a hard day.
The problem for me was indeed with the optimizer in ex 8. I didn’t set it properly, and received no error msgs, so I couldn’t find what I was doing wrong. Thank you guys for the help

1 Like