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

Viewed 12182

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)

```

 
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)

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

Related