Week 2 Ungraded lab TypeError in provided "lab_utils" Python Module

I try to run the Weeks 2 Ungraded Lab in the online version. However, when training the model for the first time, i get the following error:

Step:

# Create a model to use with the imbalanced dataset
imbalanced_model = lab_utils.create_model()

# Print the model's summary
print(imbalanced_model.summary())

Error:

TypeError                                 Traceback (most recent call last)
Cell In[17], line 2
      1 # Create a model to use with the imbalanced dataset
----> 2 imbalanced_model = lab_utils.create_model()
      4 # Print the model's summary
      5 print(imbalanced_model.summary())

File ~/work/lab_utils.py:67, in create_model()
     51 model = tf.keras.Sequential([
     52   tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(150, 150, 3)),
     53   tf.keras.layers.MaxPooling2D((2, 2)),
   (...)
     62   tf.keras.layers.Dense(3, activation='softmax')
     63 ])
     66 # Compile the model
---> 67 model.compile(
     68     loss='sparse_categorical_crossentropy',
     69     optidatamizer='adam',
     70     metrics=['sparse_categorical_accuracy']
     71 )
     73 return model

File /usr/local/lib/python3.11/dist-packages/keras/src/utils/traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     67     filtered_tb = _process_traceback_frames(e.__traceback__)
     68     # To get the full stack trace, call:
     69     # `tf.debugging.disable_traceback_filtering()`
---> 70     raise e.with_traceback(filtered_tb) from None
     71 finally:
     72     del filtered_tb

File /usr/local/lib/python3.11/dist-packages/keras/src/engine/training.py:3895, in Model._validate_compile(self, optimizer, metrics, **kwargs)
   3893 invalid_kwargs = set(kwargs) - {"sample_weight_mode"}
   3894 if invalid_kwargs:
-> 3895     raise TypeError(
   3896         "Invalid keyword argument(s) in `compile()`: "
   3897         f"{(invalid_kwargs,)}. Valid keyword arguments include "
   3898         '"cloning", "experimental_run_tf_function", "distribute",'
   3899         ' "target_tensors", or "sample_weight_mode".'
   3900     )
   3902 # Model must be created and compiled with the same DistStrat.
   3903 if self.built and tf.distribute.has_strategy():

TypeError: Invalid keyword argument(s) in `compile()`: ({'optidatamizer'},). Valid keyword arguments include "cloning", "experimental_run_tf_function", "distribute", "target_tensors", or "sample_weight_mode".

Can anyone give me any suggestions what to do about it? It sounds like Keras library doesn’t know the optimizer=‘adam’ keyword which is in the provided python script.

And other question: Is it possible to somehow reset the complete workspace, including the Files? Since I already executed the steps above, a additional Folder got created. I would like to restart with a “blank” workspace.

The error isn’t that Keras doesn’t recognize the ‘optimizer’ keyword; it’s that there is a typo in the lab_utils.py file.

If you look closely at your traceback: —> 69 optidatamizer=‘adam’,

The keyword being passed is 'optidatamizer’ instead of ‘optimizer’. Keras sees ‘optidatamizer’ and doesn’t know what that is, and throws a TypeError.

2 Likes

To reset your workspace, click on the three vertical dots in the right corner and select Restore Original Version. Lastly, refresh the page. This will fetch the original version of the file(s).

Thanks a lot @sanjaypsachdev ! I managed to fetch a new version and now the keyword also seems correct. I guess I somehow changed it :sweat_smile:

2 Likes

@Kerambad:
I’m curious as to the root cause.

Had you modified the lab_utils.py file?

I also was thinking about that. Definitely not on purpose. Maybe Accidentally. I did realize that the last change timestamp was very recent when I encountered the error, but I somehow pressed in Jupyter restore file to last checkpoint but nothing changed afterwards…

Thanks for the update.