Exception in C4W3 Assignment: Optimizer must have a "lr" attribute

When trying to set solve the part of the C4W3 assignment where the learning rate is adjusted, I’m getting an exception:

Optimizer must have a “lr” attribute.

It’s apparently a known issue (see keras#15299). In my case, manually setting the lr attribute in the optimizer made it work:

optimizer = tf.keras.optimizers.Adam(learning_rate = 1e-6)
# I had to add this
optimizer.lr = learning_rate

Is that a common error? Am I missing something?

1 Like

Can you share the image you are getting without sharing the code in the image.

2 Likes

Hi Deepti,

I tried to reproduce the issue by re-running the assignment without the “optimizer.lr” line but I couldn’t reproduce it. This time all the code was executed without any problem.

I also tried downloading the notebook file and running it locally and it also did work smoothly without the “optimizer.lr” line.

I guess it was just a temporary thing.

Thanks!

1 Like