adriangb / scikeras

Scikit-Learn API wrapper for Keras.
https://www.adriangb.com/scikeras/
MIT License
239 stars 47 forks source link

Can't serialize a KerasClassifier object after fitting #325

Closed CAW9 closed 4 months ago

CAW9 commented 4 months ago

Hello,

I am trying to serialize a trained KerasClassifier. There seems to be no issue serializing and deserializing a model before fitting, but after .fit() is called, things seem to break down for me. I am using python 3.12 and scikeras 0.13.

Here is a very simple example, following the outline of the https://adriangb.com/scikeras/stable/advanced.html page:

https://colab.research.google.com/drive/162oDiHwSHXf_TwtCaqDglS5-hy7fPJkU?usp=sharing

There are several errors, but they are all of a similar flavor to this one:

TypeError: <class 'keras.src.models.sequential.Sequential'> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by get_config() are explicitly deserialized in the model's from_config() method.

Is there additional customization of a KerasClassifier model that has to be done before or after fitting to make it serializable again?

With gratitude, CAW9

CAW9 commented 4 months ago

After further investigation, I believe this is not a scikeras specific issue. I apologize.