6
$\begingroup$

I am using Tensorflow Object detection API to detect 2 objects. I need negative samples because it sometimes detects something random as one of the images . How should I annotate an image to be a 'negative sample'? I am using LabelImg to annotate the images. Do I draw the bounding box around the whole image and label it as 'none'?

$\endgroup$

3 Answers 3

6
$\begingroup$

Short answer:

You don't need negative samples to train your model. Focus on improving your model.

Long answer:

Ideally your detector after being trained on your 2 objects would detect them and place a bounding box around them. When you test it and get wrong results this could be caused by a variety of reasons:

  1. A wrong object is being detected if your detector just misinterpreted as belonging to one of the 2 objects you trained it on.
  2. When an image of your 2 objects is being thrown to the detector but it's not detected, then this also means your detector failed to detect your object.

Both cases could of course happen in the same image and also occur more than once.

As far as I know images with no bounding box in them which would be your "negative examples" cannot be processed by the current model because tfrecord reader just fails.

Negative samples do exist implicitly though. All region of your images that do not correspond to a bounding box is a "negative sample". Defining explicitly "negative samples" by selecting them in a bounding box will create a new class with name 'none'. You will have 3 classes then.

So, to make it simpler focus on your positive examples. If your model fails greatly then something is wrong. Check if:

  • Your test images differ significantly from the trained ones. If so, try to find images similar to your test images and use them along your previous images to retrain your model.
  • Examine that you have enough training samples to train your model. Enough is not defined strictly but may mean at least a few hundred images.
  • Examine that your train model contains enough samples from both objects. If not the misrepresented class will be detected poorly compared to the other one.
  • Examine that you don't have implicit negative examples of your object that could hinder training process. This means if you detect cars make sure at least all visually qualitative appearances in your image are being labels as cars. If you only label 1 car and also left 2 unlabeled ones then those two cars will hamper your training.
$\endgroup$
2
  • 2
    $\begingroup$ I agree with you!! but Consider this example!! I have trained an object detection model to detect dogs with bounding box!! If I pass the cat picture it should say that its a dog and put bounding around it!! Instead, it should learn that its a cat (-ve image) and should not put a bounding box around it!! $\endgroup$ Commented Aug 21, 2018 at 6:22
  • $\begingroup$ If your model is trained to detect dogs then only dogs can be detected. In the best case scenario it will ignore cat pictures being thrown at it and in the worse case it will label them as cats. $\endgroup$
    – Eypros
    Commented Aug 21, 2018 at 13:04
6
$\begingroup$

You can simply use the verify feature in LabelImg and it will create a file without annotations you can run through your process. Reading through this article it seems negative images are indeed needed.

$\endgroup$
2
  • 2
    $\begingroup$ If the link goes dead this is not going to be very helpful can you summarise the key points and also expand on why your answer is different from the current one? $\endgroup$
    – mdewey
    Commented Sep 11, 2018 at 13:29
  • $\begingroup$ That article is not about the object detection api so is not addressing op's question. Plus, better to give answer rather than link. $\endgroup$
    – neuronet
    Commented Sep 18, 2019 at 23:03
-2
$\begingroup$

The OP asked about negative samples in Tensorflow Object detection API. I agree that we do not specific images for negative samples in NNs-based Object Detection. All negatives samples are implicitly available when some areas of the images are not labelled (no bounding box on it).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.