Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
douglasrizzo opened this issue Jun 24, 2021 · 6 comments · Fixed by #4132
Closed

Comments

@douglasrizzo
Copy link

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.

num_classes (int): number of output classes of the model (excluding the background).

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).

model = SSD(backbone, anchor_generator, (300, 300), num_classes, **kwargs)

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

num_classes (int): number of output classes of the model (including the background)

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).

@datumbox
Copy link
Contributor

@douglasrizzo Thanks for reporting.

Blame me for copy-pasting the doc string of RetinaNet which had exactly the same issue. The num_classes should include the background. I've issued a PR that fixes the problem.

@douglasrizzo
Copy link
Author

@datumbox Thanks for the reply. I actually believe the RetinaNet documentation suffers from a similar problem.

The documentation for the RetinaNet class tells us to exclude the background as an object class:

num_classes (int): number of output classes of the model (excluding the background).

The function retinanet_resnet50_fpn tells us to include the background as an object class:

num_classes (int): number of output classes of the model (including the background)

But when a RetinaNet object is created inside of retinanet_resnet50_fpn, the number of classes passed to retinanet_resnet50_fpn (which counts the background) is not decremented by 1 before being used in RetinaNet:

model = RetinaNet(backbone, num_classes, **kwargs)

Since num_classes is only used inside retinanet_resnet50_fpn to instantiate a RetinaNet object, my bet is that the documentation for retinanet_resnet50_fpn is wrong.

@douglasrizzo douglasrizzo changed the title Documentation confusing on whether SSD counts background as class object Documentation confusing on whether SSD and RetinaNet count background as class object Jun 28, 2021
@douglasrizzo
Copy link
Author

I just saw your PR fixes both documents.

@WZMIAOMIAO
Copy link
Contributor

@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.

@Xonxt
Copy link

Xonxt commented Jun 8, 2022

Sorry to reopen the issue, but the other question was not answered:
how should the labels be numbered during training (for custom datasets) - starting from 0 or from 1?
And then during inference, does the model return the labels starting from 0 or from 1?

@datumbox
Copy link
Contributor

datumbox commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants