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

查看:85
本文介绍了如何在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替换为S型来做到这一点(因此,损失将是S型交叉熵而不是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天全站免登陆