giuseppegrieco / keras-tuner-cv

Extension for keras tuner that adds a set of classes to implement cross validation techniques.
GNU General Public License v3.0
5 stars 5 forks source link

Type error when running inner cross-validation #3

Closed VZoche-Golob closed 1 year ago

VZoche-Golob commented 1 year ago

When trying the examples/inner_cv, I got a type error after calling tuner.search(...) in lines 52-60:

INFO:tensorflow:
------------------------------
Inner Cross-Validation 5/5
------------------------------

Epoch 1/2
1/1 [==============================] - 1s 1s/step - loss: 2.3470 - accuracy: 0.1125 - val_loss: 2.1534 - val_accuracy: 0.2590
Epoch 2/2
1/1 [==============================] - 0s 260ms/step - loss: 2.1707 - accuracy: 0.2352 - val_loss: 2.0040 - val_accuracy: 0.4114
1/1 [==============================] - 0s 219ms/step
1/1 [==============================] - 0s 82ms/step
1/1 [==============================] - 0s 305ms/step - loss: 2.0043 - accuracy: 0.4132
1/1 [==============================] - 0s 184ms/step - loss: 2.0040 - accuracy: 0.4114
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [20], line 1
----> 1 tuner.search(
      2     x_train,
      3     y_train,
      4     validation_split=0.2,
      5     batch_size="full-batch",
      6     validation_batch_size="full-batch",
      7     epochs=2,
      8     verbose=True,
      9 )

File ~/miniconda3/envs/tf/lib/python3.9/site-packages/keras_tuner_cv/inner_cv.py:78, in inner_cv.<locals>.InnerCV.search(self, *fit_args, **fit_kwargs)
     68     warnings.warn(
     69         "`Tuner.run_trial()` returned None. It should return one of "
     70         "float, dict, keras.callbacks.History, or a list of one "
   (...)
     75         stacklevel=2,
     76     )
     77 else:
---> 78     metrics = tuner_utils.convert_to_metrics_dict(
     79         results, self.oracle.objective, "Tuner.run_trial()"
     80     )
     81     metrics.update(get_metrics_std_dict(results))
     82     self.oracle.update_trial(
     83         trial.trial_id,
     84         metrics,
     85     )

TypeError: convert_to_metrics_dict() takes 2 positional arguments but 3 were given
VZoche-Golob commented 1 year ago

Would be fixed here: https://github.com/giuseppegrieco/keras-tuner-cv/pull/1

giuseppegrieco commented 1 year ago

Thank you @VZoche-Golob for this further report, I will apply the mentioned fix this week. The error is due to the fact that this package was developed for an earlier version of keras-tuner, which did not maintain backward compatibility.