简体   繁体   English

卷积神经网络训练

[英]Convolutional Neural Network Training

I have a question regarding convolutional neural network ( CNN ) training. 我有一个关于卷积神经网络( CNN )培训的问题。

I have managed to train a network using tensorflow that takes an input image (1600 pixels) and output one of three classes that matches it. 我设法使用张量tensorflow训练网络,该张量流将输入图像(1600像素)并输出与其匹配的三个类别之一。

Testing the network with variations of the trained classes is giving good results. 用训练有素的课程的变化来测试网络会产生良好的结果。 However; 然而; when I give it a different -fourth- image (does not contain any of the trained 3 image), it always returns a random match to one of the classes. 当我给它不同的第四张图像(不包含任何经过训练的3张图像)时,它总是向其中一个类返回随机匹配。

My question is, how can I train a network to classify that the image does not belong to either of the three trained images? 我的问题是,如何训练网络以将图像分类为不属于三个训练图像中的任何一个? A similar example, if i trained a network against the mnist database and then a gave it the character "A" or "B". 一个类似的例子,如果我针对mnist数据库训练了一个网络,然后给了它一个字符“ A”或“ B”。 Is there a way to discriminate that the input does not belong to either of the classes? 有没有一种方法可以区分输入不属于任何一个类?

Thank you 谢谢

Your model will always make predictions like your labels, so for example if you train your model with MNIST data, when you will make predictions, prediction will always be 0-9 just like MNIST labels. 您的模型将始终像标签一样进行预测,因此,例如,如果使用MNIST数据训练模型,则在进行预测时,就像MNIST标签一样,预测将始终为0-9。

What you can do is train a different model first with 2 classes in which you will predict if an image belongs to data set A or BEx for MNIST data you label all data as 1 and add data from other sources that are different (not 0-9) and label them as 0. Then train a model to find if image belongs to MNIST or not. 您可以做的是首先使用2个类别训练不同的模型,其中您将预测图像是否属于MNIST数据的数据集A或BEx,将所有数据标记为1并添加来自其他来源(不是0- 9)并将其标记为0。然后训练模型以查找图像是否属于MNIST。

Convolutional Neural Network (CNN) predicts the result from the defined classes after training. 卷积神经网络(CNN)在训练后根据定义的类预测结果。 CNN always return from one of the classes regardless of accuracy. 不管准确性如何,CNN总是从其中一个类别返回。 I have faced similar problem, what you can do is to check for accuracy value. 我也遇到过类似的问题,您可以做的是检查准确性值。 If the accuracy is below some threshold value then it's belong to none category. 如果精度低于某个阈值,则它不属于任何类别。 Hope this helps. 希望这可以帮助。

You probably have three output nodes, and choose the maximum value (one-hot encoding). 您可能有三个输出节点,然后选择最大值(单热编码)。 That's a bit unfortunate as it's a low number of outputs. 这有点不幸,因为它的输出数量很少。 Non-recognized inputs tend to cause pretty random outputs. 无法识别的输入往往会导致相当随机的输出。

Now, with 3 outputs, roughly speaking you can get 7 outcomes. 现在,有了3个输出,粗略地说您可以获得7个结果。 You might get a single high value (3 possibilities) but non-recognized input can also cause 2 high outputs (also 3 possibilities) or approximately equal output (also 3 possibilities). 您可能会得到一个高值(3种可能性),但是无法识别的输入也会导致2种​​高输出(也有3种可能性)或近似相等的输出(也有3种可能性)。 So there's a decent chance (~ 3/7) of random inputs producing a pattern on the output nodes which you'd only expect for a recognized input. 因此,随机输入很有可能(〜3/7)在输出节点上产生模式,您只希望获得可识别的输入。

Now, if you had 15 classes and thus 15 output nodes, you'd be looking at roughly 32767 possible outcomes for unrecognized inputs, only 15 of which correspond to expected one-hot outcomes. 现在,如果您有15个类,因此有15个输出节点,那么您将查看未识别的输入的大约32767个可能的结果,其中只有15个对应于预期的一次性结果。

Underlying this is a lack of training data. 根本原因是缺乏培训数据。 If your training set has examples outside the 3 classes, you can just dump this in a 4th "other" category and train with that. 如果您的训练集中有3个班级以外的示例,则可以将其转储到第4个“其他”类别中并进行训练。 This by itself isn't a reliable indication, as usually the theoretical "other" set is huge, but you now have 2 complementary ways of detecting other inputs: either by the "other" output node or by one of the 11 ambiguous outputs. 这本身并不是一个可靠的指示,因为通常理论上的“其他”集合很大,但是您现在有两种互补的方式来检测其他输入:通过“其他”输出节点或11个歧义输出之一。

Another solution would be to check what outcome your CNN usually gives when given something else. 另一个解决方案是检查您的CNN通常在得到其他结果时会产生什么结果。 I believe the last layer must be softmax and your CNN should return probabilities of the three given classes. 我相信最后一层必须是softmax,而您的CNN应该返回三个给定类的概率。 If none of these probabilities is close to 1 this might be a sign that this is something else assuming your CNN is well trained (it must be fined for overconfidence when predicting wrong labels). 如果这些概率中的任何一个都不接近1,则这可能意味着如果您的CNN受过良好的训练,这可能是另一回事(预测错误的标签时,必须对它的过度自信加以罚款)。

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

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