验证数据batch_size为1? (凯拉斯) [英] Validation data batch_size of size one? (Keras)

查看:713
本文介绍了验证数据batch_size为1? (凯拉斯)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Keras中,有一个选项可以将验证集批次的大小设置为一个:

In Keras there is an option to set the size of the validation set batches to one:

valid_batches = ImageDataGenerator().flow_from_directory(valid_path, ... batch_size=1)

在每个训练数据时期之后,模型仅使用验证数据中的一个对象来验证模型是否正确?如果是这种情况,那么我的模型应该不会获得很好的验证分数.但是,当我运行模型时,它运行起来没有任何问题,并且不断改进,并且似乎正在使用许多验证对象进行评估.有人可以解释一下吗?谢谢你.

Is it correct that the model then just uses one object from the validation data to validate the model after each training data epoch? If that is the case then my model should not get a very good validation score. But when I run the model it runs without any problems, keeps improving and seems to be using many validation objects for evaluation. Can someone explain this please? Thank you.

推荐答案

您确实在这里给我们提供了很少的信息,所以我会尽力为您提供所需的信息,以便您自己理解并自行解决.

You really give us little information there so I'll try to give you the information that you need in order to understand and maybe fix it by yourself.

valid_batches = ImageDataGenerator().flow_from_directory(valid_path, ... batch_size=1)

这为您提供了一个生成器.它将执行python生成器的工作:生成一批验证数据,在您的情况下,这些批的大小将为1.

This gives you a generator. It'll do what python generators do : yield batches of validation data, those batches will be of size 1 in your case.

但是,当您这样做时:

model.fit_generator(train_batches, validation_data=valid_batches, ... )

keras要做的是使用您的生成器来获取一些验证数据.但是调用一次valid_batches后它不会停止,它将进行多次设置.批次不是您的整个验证集,keras假设您将按批次将其验证数据集提供给它.因此,它会根据要求在您的validate_data生成器上进行多次迭代.

What keras does is to use your generator to get some validation data. But it will not stop after one call to valid_batches, it will make several setps. A batch isn't your whole validation set, keras assumes that you will give it its validation data set by batches. So it iterates on your validation_data generator as many times as asked.

指定要在一个验证步骤中生成批处理的次数的方法是使用validation_steps参数,如下所示:

The way to specify how many times you want to generate batches in one validation step is to use the validation_steps argument like this :

model.fit_generator(train_batches, validation_data=valid_batches,  validation_steps=10... )

这样,您的验证将对每个执行的验证使用validation_steps * batch_size = 10 * 1 = 10个示例.

That way, your validation will be using validation_steps * batch_size = 10 * 1 = 10 samples for each validation executed.

希望对您有所帮助:-)如果没有,请更详细地说明您的代码.一个好的堆栈溢出问题应包含一个可重现的代码,以减少错误.

I hope it helps a bit :-) If not, please be more specific about your code. A good stack overflow question should contain a minimal reproducible code for your error.

这篇关于验证数据batch_size为1? (凯拉斯)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆