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

Dont know how to apply centerloss to my own project #12

Open
1653091 opened this issue Aug 30, 2019 · 2 comments
Open

Dont know how to apply centerloss to my own project #12

1653091 opened this issue Aug 30, 2019 · 2 comments

Comments

@1653091
Copy link

1653091 commented Aug 30, 2019

I want to use ResNet50 as my model and change Fully Connection layer to classify images.

#Create model:
model = models.resnet50(pretrained=True)
fc_inputs = model.fc.in_features
class FClayer(nn.Module):
def init(self):
super(FClayer, self).init()
self.fc1 = nn.Linear(fc_inputs, 2)
self.relu1 = nn.ReLU()
self.fc2 = nn.Linear(2, num_classes)
def forward(self, x):
x = self.relu1(self.fc1(x))
y = self.fc2(x)
return x, y
model.fc = FClayer()
...
#In train function:
features, outputs = model(inputs)
alpha = 1
loss = loss_criterion(outputs, labels) + (loss_criterion_cent(features, labels) * alpha)
optimizer.zero_grad()
optimizer_cent.zero_grad()
loss.backward()
optimizer.step()
for param in loss_criterion_cent.parameters():
param.grad.data *= (1./alpha)
optimizer_cent.step()

I dont know why when i was training, at the very first epochs, the accuracy had increased, but soon later, nothing happended. Here is my accuracy plot curve chart:
Sign_accuracy_curve

Do I have something wrong?

@shijianjian
Copy link

Your question is quite ambiguous. But I think it was probably caused by a high LR or a high loss weight which makes gradient descent optimization failed.

@RaduFilip16
Copy link

Have you found a solution to your problem?

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

No branches or pull requests

3 participants