Yes, the frozen_layer and last_layer are just placeholder names for your layer names.
Did you train the “frozen” layers before and forgot to zero out the gradients?
If not, could you post a code snippet which represents your training routine and how and where you are freezing the layers?
Your initial code snippet looks like it has some indentation issues, as your “layer loop” would be used for each training iteration.
Is this a copy-paste error or are you using this code in your script as shown here?