Hi.

I am switching from the old scikeras wrappers to the newer keras.api.wrappers.SKLearnClassifier and have encountered an issue.

My workflow includes saving checkpoints:

    callbacks = None
    if saved_dir is not None and model_name is not None:
        model_path = f'./{saved_dir}/_{model_name}_model.keras'
        callbacks = [
            keras.callbacks.ModelCheckpoint(
                filepath=model_path,
                save_best_only=True,
                verbose=1 if verbose else 0,
            ),
            keras.callbacks.EarlyStopping(
                patience=patience,
                verbose=1 if verbose else 0,
            ),]

    model = keras.api.wrappers.SKLearnClassifier(model=nn_create(**kwargs),
                    fit_kwargs={'callbacks': callbacks, }
                    )

    model_with_learning_history = model.fit(
        X_train, y_train,
        validation_split=validation_split,
        epochs=epochs,
        batch_size=32,
    )

Later, I want to load one of these checkpoints, and make sure it is wrapped as a scikit-learn object. I do

    keras_native_model: keras.models.Model = keras.models.load_model(
        f'{saved_dir}/_{model_name}_model.keras'
    )
    model = keras.api.wrappers.SKLearnClassifier(keras_native_model)
    preds = model.predict(X_test)

However, the predict fails for the following reasons:

predict depends in its own code on a line raw_output = self.model_.predict(X) and on a line self._target_encoder.inverse_transform(y). But the attributes model_ and _target_encoder are set in fit() AFTER the checkpoints are saved.

I am currently setting these attributes manually to get things working. Have I missed something or is this a bug?

Thank you for the support.

Comment From: sonali-kumari1

Hi @giladpn -

Sorry for the delayed response. Could you please provide a minimal reproducible code and error traceback to replicate this issue. Thanks!

Comment From: github-actions[bot]

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

Comment From: github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.