简体   繁体   English

训练神经网络的好方法

[英]Good approach for training a neural network

I am training a neural network model to differentiate the orange and pomegranate. 我正在训练一个神经网络模型来区分橙和石榴。 In the training dataset, the background of the object (for both orange and pomegranate) is same and constant. 在训练数据集中,对象的背景(橙色和石榴)相同且恒定。 But while testing, the background of the object is different than what I trained with. 但是在测试时,对象的背景与我训练的背景不同。

So my first doubt is, 所以我的第一个疑问是

Is it good approach to train a model with one background (suppose white background) and test with another background (suppose grey background)?. 一个背景 (假设白色背景) 训练模型并在另一背景 (假设灰色背景) 测试模型是一种好方法吗?

Second, I trained the object with different position and the same background. 其次,我训练了具有不同位置和相同背景的对象。 Since the theory says that position doesn't matter for convolution, it has ability to recognise the object placed at anywhere, because anyhow, after convolution, the dimension of the activation map decreases and the depth increases. 由于该理论说位置对卷积无关紧要,因此它具有识别放置在任何位置的对象的能力,因为无论如何,在卷积后,激活图的尺寸会减小,深度会增加。

So my second doubt is, 所以我的第二个疑问是

Is it necessary or good approach to keep the object at different position while training the model? 在训练模型时是否有必要或好的方法将对象保持在不同的位置

Is it good approach to train a model with one background (suppose white background) and test with another background (suppose grey background)?. 一个背景 (假设白色背景) 训练模型并在另一背景 (假设灰色背景) 测试模型是一种好方法吗?

When training a neural network, it is important to shuffle the dataset you are using and split the dataset to training and testing sets. 训练神经网络时,重要的是洗牌您正在使用的数据集并将数据集拆分为训练和测试集。 The reason why you need to shuffle the data, is in order for your model to see all types of samples in the training set so the moment it is exposed to new unseen data, it can reflect it over the previously seen data. 之所以需要对数据进行混洗,是为了使模型能够看到训练集中的所有类型的样本,因此,当模型暴露于新的看不见的数据时,就可以在以前看到的数据上反映出来。 In the example you mentioned above, it is important to shuffle the data due to the fact that there are different background colors which can effect the prediction of the model. 在上面提到的示例中,由于存在不同的背景颜色会影响模型的预测,因此对数据进行混洗很重要。 Therefore both the training and the testing set need to have both background colors in order for your model to give good predictions. 因此,训练集和测试集都必须同时具有两种背景色,以便模型能够提供良好的预测。

Is it necessary or good approach to keep the object at different position while training the model? 在训练模型时是否有必要或好的方法将对象保持在不同的位置

It is indeed better to train your model with objects in different positions due to the fact it can bring your model to predict more types of oranges or pomegranates. 确实,将模型与不同位置的对象一起训练确实更好,因为它可以使模型预测更多类型的橙子或石榴。 Note that if you are using different positions for the object you are trying to predict, it is important to have a sufficient amount of data in order for the model to give you good predictions over the testing set. 请注意,如果要对要预测的对象使用不同的位置,则重要的是要有足够的数据量,以便模型可以对测试集进行良好的预测。

I hope this short explanation helped, if something isn't clear please let me know and I'll edit the post. 希望这个简短的说明对您有所帮助,如果有不清楚的地方,请告诉我,我将对其进行编辑。

Is it good approach to train a model with one background (suppose white background) and test with another background (suppose grey background)?. 一个背景 (假设白色背景) 训练模型并在另一背景 (假设灰色背景) 测试模型是一种好方法吗?

Background is a property of an image that is not required for distinguishing the object. 背景是区分对象不需要的图像属性。 You want your network to learn this behavior. 您希望您的网络学习这种行为。 Consider two cases now: 现在考虑两种情况:

  1. You give your network images with one background. 您给网络图像提供一个背景。 Lets see what can go possibly wrong here. 让我们看看这里可能出什么问题。
    1. Assume that your background is completely black. 假设您的背景是完全黑色的。 This means that there will be 0 output for a feature map (kernel) when it was put into the background. 这意味着将要素地图(内核)置于后台时将有0个输出。 Your network will learn that it can put any high weights for these features and it will do a good job during training as long as those weights can successfully extract feature of the classes. 您的网络将了解它可以为这些功能赋予很高的权重,并且在训练过程中会做得很好,只要这些权重可以成功提取类的特征即可。
    2. Now during testing, the background color is white. 现在,在测试期间,背景色为白色。 The same feature maps with high weight now will have very high output. 现在,具有相同权重的相同特征地图将具有非常高的输出。 These high output can saturate the non-linear unit and all categories may be classified as one category. 这些高输出可以使非线性单元饱和,并且所有类别都可以分类为一个类别。
  2. The second case where during training you shows images with different background. 第二种情况是在训练期间您显示具有不同背景的图像。
    1. In this case, neural network has to learn that the feature maps corresponding to background and need to subtract the bias based on the background. 在这种情况下,神经网络必须学习特征映射对应于背景,并且需要减去基于背景的偏差。

In short, there is an extra information that you need to learn that is background is not important for deciding the category. When you provide only one color background, your neural network cannot learn this behavior and can give garbage result on test dataset.

Is it necessary or good approach to keep the object at different position while training the model? 在训练模型时是否有必要或好的方法将对象保持在不同的位置?

You are right, Convolutional Neural Network are translational-equivariant. 没错,卷积神经网络是平移等变的。 But for building a classifier, you pass the output of CNN-layer through a fully-connected layer. 但是,要构建分类器,您需要将CNN层的输出通过一个完全连接的层。 If you put image at different positions, different input will go to the fully-connected layer but output for all these images is the same category. 如果将图像放置在不同的位置,则不同的输入将进入完全连接的图层,但是所有这些图像的输出都属于同一类别。 So you are forcing your neural network to learn that the position of the object is not required for classifying its category.

Regarding your first doubt, It is not much of an issue as long as the target object is present in the images. 关于您的第一个疑问,只要目标对象存在于图像中,这不是什么大问题。 Shuffle the data before feeding it to the network. 在将数据馈送到网络之前先对其进行随机排序。

For second doubt, Yes it is always a good idea have target object at different positions. 对于第二个疑问,是的,将目标对象放置在不同的位置总是一个好主意。 Also one more thing to take care is that the source of your data is same and mostly of same quality. 另外还要注意的一件事是,您的数据源是相同的,并且大多数是相同质量的。 Otherwise performance issue will arise. 否则会出现性能问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM