Do i need 'no object' example when i train a single class object detection model?

4bach: <p>Hi everyone,</p>
<p>I am trying to set up a single class detection model. My goal is to detect drones. The only annotated images I have are images where a drone appears. Otherwise I have images without drone, but without annotations either.</p>
<p>I tried to train my network with two classes, 0 → background and 1-&gt; drone.<br>
But the pytorch model can’t take empty bbox in the case of background class, i can set the bbox as the size of the image but i don’t think that is a good solution.</p>
<p>My question is, is it good to only train my model with drone images and test/ evaluate with background/<br>
no drone images ?<br>
Can my model learn good features of it if I only train with one class ? I’m afraid that  in inference my model confuse a drone with any flying object (bird,helicopter…)</p>
<p>It’s more a theorical question but i’m just a beginner i’m trying to understand what is best for this case.</p>
<p>Thanks a lot</p>

KFrank: <p>Hi 4bach!</p>
<aside class="quote no-group" data-username="4bach" data-post="1" data-topic="118448" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/4/e9c0ed/48.png" class="avatar"> 4bach:</div>
<blockquote>
<p>My question is, is it good to only train my model with drone images and test/ evaluate with background/<br>
no drone images ?</p>
</blockquote>
</aside>
<p>No.  As a general rule it is important to train your model with data that<br>
is fully representative of the real-world data you will be feeding to your<br>
model for inference.</p>
<p>To me, “detection” means (and I think this is the conventional usage)<br>
locating zero, one, or more instances of an object of a given type within<br>
the image being analyzed (or locate and identify objects of multiple<br>
types if you are doing multi-class detection).</p>
<p>If you train your network on images that have exactly one drone, then<br>
your model will likely misidentify any little wisp of cloud as a drone when<br>
you analyze images with no drones.  Similarly, it will likely miss a drone<br>
when you analyze images with two drones.</p>
<p>(This is less likely to be the case if your detector is built with the older<br>
sliding-window / binary-classifier architecture.)</p>
<p>If your model “detects” drones in images without any, you want to<br>
penalize it for doing so – during training – so you want to have images<br>
without drones in your training set.</p>
<aside class="quote no-group">
<blockquote>
<p>Can my model learn good features of it if I only train with one class ? I’m afraid that  in inference my model confuse a drone with any flying object (bird,helicopter…)</p>
</blockquote>
</aside>
<p>If you only train on drones, your model will likely learn good features for<br>
identifying flying “stuff” and misidentify birds and helicopters as drones.<br>
So, ideally, you will want to train on images that have nothing, just birds,<br>
just drones (sometimes more than one), birds and drones, etc.</p>
<p>That way, your model will learn good features that not only detect<br>
flying stuff but also distinguish drones from other flying stuff (such<br>
as birds and helicopters).</p>
<aside class="quote no-group">
<blockquote>
<p>But the pytorch model can’t take empty bbox in the case of background class, i can set the bbox as the size of the image but i don’t think that is a good solution.</p>
</blockquote>
</aside>
<p>This seems like a problem with the model.</p>
<p>For example, pytorch’s torchvision <a href="https://pytorch.org/vision/0.8/models.html#faster-r-cnn" rel="noopener nofollow ugc">Faster R-CNN</a> model takes as its<br>
training targets (annotations) a list of object instances in the image.<br>
I would <em>expect</em> (but I haven’t checked) that this list can be empty.</p>
<p>Best.</p>
<p>K. Frank</p>

4bach: <p>I understand the need to train my model with images that do not contain my ‘drone’ class as well as to try to have a dataset as close to the real world as possible.</p>
<p>However, I think my problem lies in the model, since unfortunately a detection model trains with a loss function for classification AND a regression loss function for bounding boxes. So for the examples without class (with only background),  I have to generate a bounding box.  For me the most intuitive way is to put a bbox the size of my image… It’s not ideal, but I don’t see how to train my detection model well without a regression loss function for my background examples.</p>
<p>Thanks again for your answer</p>

Aditya_Sule: <p>Hey, a bit late for this post but is it possible if you can share your detection model somehow needed it</p>