Skip to content

Implement dynamic num_classes and resolve dimension mismatch in ResNet18 #91#136

Open
alimohmedelsaid26-cell wants to merge 3 commits intohumanai-foundation:mainfrom
alimohmedelsaid26-cell:main
Open

Implement dynamic num_classes and resolve dimension mismatch in ResNet18 #91#136
alimohmedelsaid26-cell wants to merge 3 commits intohumanai-foundation:mainfrom
alimohmedelsaid26-cell:main

Conversation

@alimohmedelsaid26-cell
Copy link
Copy Markdown

I have addressed Issue #91 by making the following improvements to the ResNet models:

  1. Added missing FC layer: Implemented the final Fully Connected layer in ResNet18 and ResNet34.
  2. Dynamic num_classes: Linked the FC layer to the num_classes parameter to ensure the model adapts to different label sets.
  3. Fixed Dimension Mismatch: Set the input features to 512 * 32 to correctly match the output of AdaptiveAvgPool2d((1, 32)).
  4. Forward Pass Update: Added torch.flatten to ensure correct tensor shapes before passing data to the linear layer.

Testing

Verified the fix with a test script. The model now correctly outputs the specified tensor shape without the previous dimension mismatch error.

@alimohmedelsaid26-cell
Copy link
Copy Markdown
Author

I've verified the fix locally and it resolves the dimension mismatch error. Ready for review!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant