Skip to content

Bug: ResNet18 final layer hardcoded to 1000 classes instead of using num_classes argument #91

@abhiram123467

Description

@abhiram123467

Bug Description

In the ResNet18 model definition, num_classes is accepted
as an argument in __init__ but is completely ignored.
The final fully connected layer is hardcoded to output
1000 classes (ImageNet default), which causes silent
wrong behavior when the model is used for Renaissance OCR
classification tasks.

Location

File: [paste exact file path here]

Current Broken Code

class ResNet18(nn.Module):
    def __init__(self, num_classes):  # accepted but ignored!
        super().__init__()
        self.fc = nn.Linear(512, 1000)  # hardcoded 1000 — BUG!

Fixed Code

class ResNet18(nn.Module):
    def __init__(self, num_classes):
        super().__init__()
        self.fc = nn.Linear(512, num_classes)  # uses argument correctly

Impact

  • Model silently outputs wrong number of classes
  • Will crash or give wrong results for any dataset
    with classes ≠ 1000
  • Renaissance OCR tasks have far fewer than 1000 classes

Proposed Fix

Replace hardcoded 1000 with num_classes in the
Linear layer definition.

I would like to submit a PR to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions