C4W3 Assignment Error when compiling the final model

I am getting the following error when I am trying to compile the model:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-42-c0ff0189b972> in <module>
      1 # Save an instance of the model
----> 2 model = create_model()
      3 
      4 # Train it
      5 history = model.fit(dataset, epochs=50)

<ipython-input-41-25e19cbe7b0f> in create_model()
      9     #optimizer = tf.keras.optimizers.SGD(learning_rate=learning_rate, momentum=0.9)
     10 
---> 11     model.compile(tf.keras.losses.Huber(),
     12                   optimizer=tf.keras.optimizers.SGD(learning_rate=learning_rate, momentum=0.9),
     13                   metrics=["mae"])  

/opt/conda/lib/python3.8/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

/opt/conda/lib/python3.8/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     62     filtered_tb = None
     63     try:
---> 64       return fn(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)

TypeError: compile() got multiple values for argument 'optimizer'

I am following all the correct steps. I don’t know why am I getting this?

This is MODEL COMPILE how you place the parameters inside compile. The compile is thinking that you are giving it 2 optimizers since its the first argument. Either you place a loss =, ifront of it or use the arangement as shown in the link.

1 Like

Thanks that helped a lot, I was stuck on it for at least 3 hours.

1 Like