-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Change the classifier input from 2048 to 1000. #5232
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5232 +/- ##
======================================
Coverage 93% 93%
======================================
Files 134 134
Lines 9976 9976
======================================
Hits 9294 9294
Misses 682 682 |
class ImagenetTransferLearning(LightningModule):
def __init__(self):
super().__init__()
# init a pretrained resnet
backbone = models.resnet50(pretrained=True)
num_filters = backbone.fc.in_features
_layers = list(backbone.children())[:-1]
self.feature_extractor = torch.nn.Sequential(*_layers)
# use the pretrained model to classify cifar-10 (10 image classes)
num_target_classes = 10
self.classifier = nn.Linear(num_filters, num_target_classes)
def forward(self, x):
self.feature_extractor.eval()
batch_size = x.size(0)
with torch.no_grad():
representations = self.feature_extractor(x).view(batch_size, -1)
x = self.classifier(representations)
...I think it should be like this.
|
|
@rohitgr7 Thank you ! This is my source code. Google Colab Can you give me a solution? |
|
@LaserBit fixed it. should be working now. |
|
@rohitgr7 Thanks! |
Borda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
SkafteNicki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Change the classifier input from 2048 to 1000. * Update docs for Imagenet example Thanks @rohitgr7 * Apply suggestions from code review Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com> Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com> (cherry picked from commit a40e3a3)
What does this PR do?
Fixes #5231
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃