Using EfficientNetB0 and save model will result `Unable to serialize [2.0896919 2.1128857 2.1081853] to JSON. Unrecognized type <class 'tensorflow.python.framework.ops.EagerTensor'>.`

If you want to use EfficientNetB0orB4 backbone in tensorflow=2.10.0, you can use V2 version like the following code.
efficientnet = tf.keras.applications.efficientnet_v2.EfficientNetV2B0(include_top=False, weights=‘imagenet’, input_tensor=inputs). That solve the error you are facing. “TypeError: Unable to serialize [2.0896919 2.1128857 2.1081853] to JSON. Unrecognized type <class ‘tensorflow.python.framework.ops.EagerTensor’>.”

1 Like

2.12 has same problem.

(Pdb) model.save(‘model.h5’)
*** TypeError: Unable to serialize [[0. 0. 0.14285715 0.14285715]
[0.14285715 0. 0.2857143 0.14285715]

[0.71428573 0.85714287 0.85714287 1. ]
[0.85714287 0.85714287 1. 1. ]] to JSON. Unrecognized type <class ‘tensorflow.python.framework.ops.EagerTensor’>.

Is there any work around method? Otherwise, I should totally redesign my model.

This shift from EfficientNetB0 to EfficientNetV2B0 worked for me I didn’t need to downgrade my version…Thanks for the comment.

For me I just downgrade to tensorflow-metal version 0.5.0 and tensorflow-macos version 2.9.0

I’m getting the same error with 2.9.1:
TypeError: Unable to serialize [2.0896919 2.1128857 2.1081853] to JSON. Unrecognized type <class ‘tensorflow.python.framework.ops.EagerTensor’>.

The code :
history = model.fit(train_data, epochs=7, validation_data=valid_data, verbose=1, callbacks=[checkpoint, earlystop])

The error occurred after the 7th epoch, when the model was to be saved. I’m using EfficientnetB1