gpt4 book ai didi

python - 模型.fit : when you are using validation_generator you must specify a value for validation_steps

转载 作者:行者123 更新时间:2023-11-28 22:27:52 25 4
gpt4 key购买 nike

当我尝试编译使用 Keras

的 python 脚本时出现此错误
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

最佳答案

好的,第二次尝试回答这个问题。

查看 training.py 的源代码后当 len(valid_list) 小于 16(batch_size 的值)时,我只能看到一种情况。这将导致楼层划分返回 0 并导致 if 通过并引发您看到的错误。

关于python - 模型.fit : when you are using validation_generator you must specify a value for validation_steps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43915243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com