如何在 tensorflow 中为非分类对象创建一个类? [英] How to create a class for non classified object in tensorflow?

查看:25
本文介绍了如何在 tensorflow 中为非分类对象创建一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用狗和猫这两个类构建了我的 CNN,我已经训练了它,现在我可以对狗和猫图像进行分类.但是如果我想为新的未分类对象引入一个类呢?例如,如果我用花卉图像输入我的网络,网络会给我错误的分类.我想用第三个类为新的未分类对象构建我的网络.但是我怎样才能建立这个第三类.我必须使用哪些图像来获取与狗或猫不同的新对象的类?实际上在我的网络末尾我使用 Softmax,我的代码是使用 tensorflow 开发的.有人可以给我一些建议吗?谢谢

Hi i have build my CNN with two classes dogs and cats, i have trained this and now i am able to classify dog and cat image. But what about if i want to introduce a class for new unclassified object? For example if i feed my network with a flower image's the network give me a wrong classification. I want to build my network with a third class for new unclassified object. But how can i build this third class. Which images i have to use to get class for new object that are different from dogs or cats? Actually at the end of my network i use Softmax and my code is developed by using tensorflow. Could someone provide me some suggestion? Thanks

推荐答案

您需要向您的网络添加第三个其他"类.有几种方法可以解决这个问题.一般来说,如果您有一个要检测的类,则应该有该类的示例,因此您可以将没有猫或狗的图像添加到用新类标记的训练数据中.然而,这有点棘手,因为根据定义,新类是宇宙中除狗和猫之外的所有事物,因此您不可能期望有足够的数据来训练它.但是,在实践中,如果您有足够多的示例,网络可能会了解到,只要前两个类没有触发,就会触发第三个类.

You need to add a third "something else" class to your network. There are several ways you can go about it. In general, if you have a class that you want to detect you should have examples for that class, so you could add images without cats or dogs to your training data labelled with the new class. However, this is a bit tricky, because the new class is, by definition, everything in the universe but dogs and cats, so you cannot possibly expect to have enough data to train for it. In practice, though, if you have enough examples the network will probably learn that the third class is triggered whenever the first two are not.

我过去使用的另一个选项是将默认"类建模为与常规类略有不同.因此,与其尝试真正了解什么是非猫或狗"图像,您可以明确地说它只是不会激活猫或狗神经元的任何东西.我通过将最后一层从 softmax 替换为 sigmoids(因此损失将是 sigmoid 交叉熵而不是 softmax 交叉熵,并且输出不再是分类概率分布,但老实说它并没有太大作用)在我的情况下,性能方面的差异),然后将默认"类表示为 1 减去每个其他类的最大激活值.因此,如果没有类的激活值为 0.5 或更大(即该类的估计概率为 50%),则默认"类将是得分最高的类.您可以探索其他类似的方案.

Another option that I have used in the past is to model the "default" class slightly different from the regular ones. So, instead of trying to actually learn what is a "not cat or dog" image, you can just explicitly say that it is just whatever does not activates the cat or dog neurons. I did this by replacing the last layer from softmax to a sigmoids (so the loss would be sigmoid cross-entropy instead of softmax cross-entropy, and the output would not be a categorical probability distribution anymore, but honestly it didn't make much difference performance-wise in my case), then express the "default" class as 1 minus the maximum activation value from every other class. So, if no class had an activation of 0.5 of greater (i.e. 50% estimated probability of being that class), the "default" class would be the highest scoring one. You can explore this an other similar schemes.

这篇关于如何在 tensorflow 中为非分类对象创建一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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