Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: dump fails on keras models with RecursionError: maximum recursion depth exceeded, after calling fit #388

Open
blaisethom opened this issue Aug 29, 2023 · 1 comment · May be fixed by #394

Comments

@blaisethom
Copy link

skops io seems to work fine with scikeras models when they haven't been fit, but not when they've been fit. The error message (and potentially underlying cause) is the same as #184

Example code (this works):

from tensorflow import keras
from sklearn.pipeline import Pipeline
from skops.io import dump
from scikeras.wrappers import KerasClassifier

# This simplifies the basic usage tutorial from https://adriangb.com/scikeras/stable/notebooks/Basic_Usage.html

def get_clf(meta):
    n_features_in_ = meta["n_features_in_"]
    model = keras.models.Sequential()
    model.add(keras.layers.Input(shape=(n_features_in_,)))
    model.add(keras.layers.Dense(1, activation="sigmoid"))
    return model
    
clf = KerasClassifier(
    model=get_clf,
    loss="binary_crossentropy"
)

pipeline = Pipeline(
    [("classifier", clf)]
)

# These both work
dump(clf, 'keras-test.skops') 
dump(pipeline, 'keras-test.skops')

However, running the following then gives a "RecursionError: maximum recursion depth exceeded" on the last line:

import numpy as np
from sklearn.datasets import make_classification
X, y = make_classification(1000, 20, n_informative=10, random_state=0)
clf.fit(X, y)
dump(clf, 'keras-test.skops') 
@lazarust
Copy link
Contributor

@blaisethom What version of scikeras are you using?

@lazarust lazarust linked a pull request Oct 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants