Reputation: 2320
I am getting this error when I try to compile a python script that uses Keras
ValueError Traceback (most recent call last)
/home/cse/abdelrahmanML/project/cervix/cervixXception.py in <module>()
160 validation_steps=len(valid_list)//conf['batch_size'],
161 verbose=1,
--> 162 callbacks=myCallbacks)
163
164
/home/cse/venv/local/lib/python2.7/site-packages/keras/legacy/interfaces.pyc in wrapper(*args, **kwargs)
85 warnings.warn('Update your `' + object_name +
86 '` call to the Keras 2 API: ' + signature)
---> 87 return func(*args, **kwargs)
88 return wrapper
89 return legacy_support
/home/cse/venv/local/lib/python2.7/site-packages/keras/engine/training.pyc in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_q_size, workers, pickle_safe, initial_epoch)
1781 hasattr(validation_data, '__next__'))
1782 if val_gen and not validation_steps:
-> 1783 raise ValueError('When using a generator for validation data, '
1784 'you must specify a value for '
1785 '`validation_steps`.')
ValueError: When using a generator for validation data, you must specify a value for `validation_steps`.
Here is my piece of code that generates the error, as you can notice it does specify a value for validation_steps. I can't find out what is wrong:
fit = model.fit_generator(generator=batch_generator_train(train_list, conf['batch_size']),
steps_per_epoch=len(train_list)//conf['batch_size'],
nb_epoch=conf['nb_epoch'],
validation_data=batch_generator_train(valid_list, conf['batch_size']),
validation_steps=len(valid_list)//conf['batch_size'],
verbose=1,
callbacks=myCallbacks)
Note that:
conf = dict()
conf['batch_size'] = 16
Upvotes: 2
Views: 2572
Reputation: 2685
Okay second attempt at answering this.
After looking at the source for training.py I can only see one scenario when this will occur when len(valid_list) is less than 16 (the value of batch_size). This will cause the floor division to return 0 and cause that if to pass and raise that error you are seeing.
Upvotes: 4