question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation confusing on whether SSD and RetinaNet count background as class object

See original GitHub issue

The documentation for the SSD class mentions that we should not count the background as an object class when passing the number of classes as a parameter to instantiate an SSD object.

https://github.com/pytorch/vision/blob/959666891589c35e6d225943253f523cffbae4cc/torchvision/models/detection/ssd.py#L144

However, further down in the same file, an SSD object is instantiated in a function that explicitly says that the background should be counted as an object class, but this is not taken into account in the code (i.e. I did not see num_classes be decremented by one when creating the SSD object).

https://github.com/pytorch/vision/blob/959666891589c35e6d225943253f523cffbae4cc/torchvision/models/detection/ssd.py#L589

Here is the documentation for this function, which says we should include the background in the number of classes.

https://github.com/pytorch/vision/blob/959666891589c35e6d225943253f523cffbae4cc/torchvision/models/detection/ssd.py#L563

This is confusing. Should we or should we not count the background as an object class when instantiating the SSD? In either case, how should object classes be ID’d during training?

As an example, with Faster RCNN, the background is counted as an object class (with ID 0 reserved for it) and actual object classes are identified during training starting from ID 1. What should be the procedure for SSD?

I have also opened a topic in the forums, since this is both a personal question of mine as well as a possible issue in the docs (or the code).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
WZMIAOMIAOcommented, Jun 30, 2021

@datumbox hi, I think num_classes in retinanet should exclude the background. because in classification loss using binary_cross_entropy_with_logits, don’t need to consider background.

1reaction
datumboxcommented, Jun 8, 2022

@Xonxt The documentation was improved to reflect on he situation. To answer your question, the num_classes should include the background which is encoded with 0. During inference the model predicts labels starting from 1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Do we have to count the background as an object class for ...
The documentation for the SSD class mentions that we should not count the background as an object class when passing the number of...
Read more >
How RetinaNet Fixes The Shortcomings Of SSD With Focal Loss
One-stage detectors generate a large set of object locations that densely cover few areas of the image. This creates a class imbalance as...
Read more >
(PDF) Comparison of RetinaNet, SSD, and YOLO v3 for real ...
Methods In this paper, we introduce the basic principles of three object detection models. We trained each algorithm on a pill image dataset...
Read more >
Object detection with deep learning and OpenCV
Learn how to apply object detection using deep learning, Python, and OpenCV with pre-trained Convolutional Neural Networks.
Read more >
Changelog — MMDetection 2.21.0 documentation
Allow to customize colors of different classes during visualization (#6716). Support CPU training (#7016). Add download script of COCO, LVIS, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found