Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type-error: fit_generator() got an unexpected keyword argument 'samples_per_epoch'

defining the samples per epoch = 233 and nb_val_samples = 62 and epochs =4 then in am getting the error

Type-error: fit_generator() got an unexpected keyword argument 'samples_per_epoch'

What caused this error and how to solve it?

history_object = model.fit_generator(train_generator, 
     samples_per_epoch=samples_per_epoch,
     validation_data=validation_generator,
     nb_val_samples=nb_val_samples, 
     nb_epoch=nb_epoch, verbose=1,
     callbacks=callbacks_list)

```

 
like image 807
Prasun Biswas Avatar asked Mar 02 '23 04:03

Prasun Biswas


2 Answers

Check the documentations for expected arguments to fit_generator. As for your current case, the following should work:

history_object = model.fit_generator(train_generator, 
                                     steps_per_epoch=samples_per_epoch,
                                      validation_data=validation_generator,
                                      validation_steps=nb_val_samples, 
                                     epochs=nb_epoch, verbose=1,
                                     callbacks=callbacks_list)
like image 136
Bashir Kazimi Avatar answered Mar 05 '23 18:03

Bashir Kazimi


in my case making the TensorFlow to the version of 1.14.0 and Keras to 2.3.1 works well with the above problem as model.fit_generator() is deprecated in the newest model scenario.

install these versions and it will work fine for the above example.

pip install keras==2.3.1 pip install tensorflow==1.14.0

like image 20
Prasun Biswas Avatar answered Mar 05 '23 17:03

Prasun Biswas