Skip to content

Bug training CNNs with num_classes < 5 #62

@oke-aditya

Description

@oke-aditya

🐛 Bug

Describe the bug

I 'm training model with 2 class. Error appears at line 61 in metrics/accuracy.py. By default, maxk always equal 5 because topk is fixed (1,5) in train_step and val_step function. output variable shape is 32x4 so result in error RuntimeError: invalid argument 5: k not in range for dimension

     59     maxk = max(topk)
     60     batch_size = target.size(0)
     61     _, pred = output.topk(maxk, 1, True, True)
     62     pred = pred.t()
     63     correct = pred.eq(target.view(1, -1).expand_as(pred))

To Reproduce
Steps to reproduce the behavior:
Just train model using engine.fit with 2 classes

Expected behavior
training process works with arbitrary number of output class

Screenshots
image

Desktop (please complete the following information):

  • OS: ubuntu 20.04

Additional context

@vpeopleonatank

Metadata

Metadata

Assignees

No one assigned

    Labels

    Medium PriorityShould be addressed in few daysbugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions