adriangb / scikeras

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

Keras 3 support #315

Closed jamesmyatt closed 5 months ago

jamesmyatt commented 6 months ago

Does SciKeras work with Keras 3, which was released recently? https://keras.io/keras_3/

Are there any changes that might need to be made to SciKeras? https://keras.io/guides/migrating_to_keras_3/

Martin-Molinero commented 5 months ago

Don't think it's working with keras 3, getting the following error with keras==3.0.5 scikeras==0.12.0 scikit-learn==1.4.1.post1 tensorflow==2.16.1

Expected: No Exception to be thrown
  But was:  <Python.Runtime.PythonException: Could not interpret metric identifier: loss
  File "/opt/miniconda3/lib/python3.11/site-packages/keras/src/metrics/__init__.py", line 204, in get
    raise ValueError(f"Could not interpret metric identifier: {identifier}")
  File "/opt/miniconda3/lib/python3.11/site-packages/scikeras/utils/__init__.py", line 111, in metric_name
    fn_or_cls = keras_metric_get(metric)
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/scikeras/wrappers.py", line 531, in _fit_keras_model
    key = metric_name(key)
          ^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/lib/python3.11/site-packages/scikeras/wrappers.py", line 536, in _fit_keras_model
    raise e
  File "/opt/miniconda3/lib/python3.11/site-packages/scikeras/wrappers.py", line 928, in _fit
    self._fit_keras_model(
  File "/opt/miniconda3/lib/python3.11/site-packages/scikeras/wrappers.py", line 760, in fit
    self._fit(
  File "/opt/miniconda3/lib/python3.11/site-packages/scikeras/wrappers.py", line 1491, in fit
    super().fit(X=X, y=y, sample_weight=sample_weight, **kwargs)
adriangb commented 5 months ago

It is not compatible right now but I think getting it compatible with Keras v3 (and doing cleanup along the way) would be a good milestone.

jamesmyatt commented 5 months ago

That would be great. Keras 3 should increase interest in Keras again, so it would be a great help to have this.

adriangb commented 5 months ago

I started working on this: https://github.com/keras-team/keras/pull/19352

adriangb commented 5 months ago

Could you please try #317 (pip install -U 'git+https://github.com/adriangb/scikeras.git@keras-3') and see if it fixes your problem? Thanks!

adriangb commented 5 months ago

This should be fixed now. Please let me know if this is still not fixed with SciKeras 0.13.0. Thanks!