I'm trying to implement a RandomizedSearchCV using the ImageDataGenerators.
Here an example of the generator used for the train set:
train_datagen = ImageDataGenerator(rotation_range=20,
rescale=1./255,
shear_range=0.2,
zoom_range=0.25,
horizontal_flip=True,
width_shift_range=0.2,
height_shift_range=0.2)
train_generator = train_datagen.flow_from_directory(paths["train_path"],
batch_size=train_batch_size,
class_mode='binary',
target_size=(image_shape[0], image_shape[1]))
I've done the same for the validation_generator and finally the model has been fitted as:
model_history = model.fit(train_generator,
epochs=200,
steps_per_epoch=train_steps_per_epoch,
validation_data=validation_generator,
validation_steps=valdation_steps_per_epoch,
callbacks=[callbacks.EarlyStopping(patience=20)])
I would like to apply a grid search (using sklearn RandomizedSearchCV) to optimize my model, for that reason I used SciKeras:
rnd_search_cv = RandomizedSearchCV(keras_reg, param_distribs, n_iter=10, cv=3)
where keras_reg is the KerasClassifier which wraps the model for sklearn and param_distribs is the dictionary with the hyperparameters values.
Finally I fitted the RandomizedSearchCV object as follows:
rnd_search_cv.fit(train_generator,
epochs=200,
steps_per_epoch=train_steps_per_epoch,
validation_data=validation_generator,
validation_steps=valdation_steps_per_epoch,
callbacks=[callbacks.EarlyStopping(patience=20)])
I have the following error:
Traceback (most recent call last):
File "/home/docker_user/.local/lib/python3.8/site-packages/sklearn/model_selection/_validation.py", line 684, in _fit_and_score
estimator.fit(X_train, **fit_params)
TypeError: fit() missing 1 required positional argument: 'y'
Do you know how to integrate RandomizedSearchCV and ImageDataGenerator objects?