当我尝试编译使用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`.
这是我生成错误的代码片段,您可以注意到它确实为validation_steps指定了一个值。我无法找出问题所在:
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)
请注意:
conf = dict()
conf['batch_size'] = 16
答案 0 :(得分:4)
好的第二次尝试回答这个问题。
查看training.py的来源后,我只能看到一个情况,当len(valid_list)小于16(batch_size的值)时会发生这种情况。这将导致楼层划分返回0并导致如果传递并引发您看到的错误。