Feature extraction together with data augmentation example from chapter 8 of the book "deep learning with python, second edition" fails during model serialization

30 views
Skip to first unread message

pmot01

unread,
Apr 24, 2024, 4:23:35 AMApr 24
to Keras-users
I am trying to follow the books examples and run into an error with the "Feature extraction together with data augmentation" example. The error occurs during serialization of the model after the first epoch:

TypeError: Cannot serialize object Ellipsis of type <class 'ellipsis'>. To be serializable, a class must implement the `get_config()` method

In the course of analyzing the cause of the error I tried removing different layers of the model to see which one causes the error. If I remove this line everything can be serialized:

layer_stack = keras.applications.vgg16.preprocess_input(layer_stack)

You can try it yourself with the attached code.

So what´s wrong here? What needs to be changed/fixed to serialize the model?

Thanks for your help
feature_extracted_model_with_augmentation_error_demo.py

Σωτήρης Γκούζιας

unread,
Apr 24, 2024, 5:44:10 AMApr 24
to Keras-users
It is a bug of TensorFlow version<2.16.1.  If you use h5 format for your model checkpoint file it will work. If you install TensorFlow version 2.16.1 the keras format will cause no trouble.

callbacks = [
    keras.callbacks.ModelCheckpoint(
        filepath="feature_extraction_with_data_augmentation.h5",
        save_best_only=True,
        monitor="val_loss")

pmot01

unread,
Apr 24, 2024, 11:59:55 AMApr 24
to Keras-users
After upgrading to  TensorFlow version 2.16.1 it worked. Thanks a lot!

Σωτήρης Γκούζιας

unread,
Apr 24, 2024, 1:23:29 PMApr 24
to Keras-users
Actually  the solution in order to use keras format with TensorFlow version 2.16.1 is implied here 

More specifically, it is stated by @t-kalinowski that:
"...users writing new code today should not need to use a separatepreprocess_input() function, the preprocessing steps should be managed as part of the model..."

Thus, you can simply comment out or remove the specific line of code:

x = keras.applications.vgg16.preprocess_input(x) # Apply input value scaling.





Reply all
Reply to author
Forward
0 new messages