Let’s say I give you a bunch of images that contain one or more people, and I give you bounding boxes for each one. Your classifier will need both positive training examples (person) and negative training examples (not person).
For each person, you create a positive training example by looking inside that bounding box. But how do you create useful negative examples?
A good way to start is to generate a bunch of random bounding boxes, and for each that doesn’t overlap with any of your positives, keep that new box as a negative.
Ok, so you have positives and negatives, so you train a classifier, and to test it out, you run it on your training images again with a sliding window. But it turns out that your classifier isn’t very good, because it throws a bunch of false positives (people detected where there aren’t actually people).
A hard negative is when you take that falsely detected patch, and explicitly create a negative example out of that patch, and add that negative to your training set. When you retrain your classifier, it should perform better with this extra knowledge, and not make as many false positives.
参考:https://www.reddit.com/r/computervision/comments/2ggc5l/what_is_hard_negative_mining_and_how_is_it/
最近一直在看关于CNN的目标检测和跟踪的文章,在这中间会经常看到hard negative mining这个名词,把这个大概解释一下:
假设给你一堆包含一个或多个人物的图片,并且每一个人都给你一个bounding box做标记,如果要训练一个分类器去做分类的话,你的分类器需要既包含正训练样本(人)和负训练样本(背景)。
你通过观察bounding box去创建一个有用的正训练样本,那么怎么做才能创建一个有用的负训练样本呢?
一个很好的方式就是去在开始时随机创建一堆的bounding box候选框,并且不能与你的正样本有任何的重叠,把这些未与正样本重叠的新的bounding box作为你的负样本。
好了,这样你的正负样本都有了,可以训练可以用的分类器了,你用滑动窗口在你的训练图片上进行运行,但是你会发现你的分类器并不是很好用,分类的效果并不是很好,因为它会抛出一堆的错误的正样本(当检测到人时实际上却并不是实际的人),这就问题来了,你训练了一个用于分类的分类器,然而这个分类器却并不能达到你想要的效果,那么应该怎么办呢?
这个时候就要用的hard negative了,hard negative就是当你得到错误的检测patch时,会明确的从这个patch中创建一个负样本,并把这个负样本添加到你的训练集中去。当你重新训练你的分类器后,分类器会表现的更好,并且不会像之前那样产生多的错误的正样本。