Trying to solve a multi label image classification problem,an 8 class multi label problem . My labels look like this
[0. 1. 0. 0. 1. 0. 0. 0.]
[0. 1. 0. 0. 0. 0. 0. 0.]
[0. 1. 0. 1. 0. 0. 0. 0.]
The code looks like this
model = models.resnet50(pretrained=True)
num_ftrs = model.fc.in_features
model.fc = nn.Linear(num_ftrs, 8)
model = model.cuda()
# Decay LR by a factor of 0.1 every 7 epochs
# exp_lr_scheduler = lr_scheduler.StepLR(optimizer_ft, step_size=7, gamma=0.1)
optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.5)
loss_fn = torch.nn.BCELoss()
# def train(epoch):
for epoch in range(15):
model.train()
for batch_idx, (data, target) in enumerate(train_loader):
# import pdb;pdb.set_trace()
data, target = data.cuda(), target.float().cuda()
optimizer.zero_grad()
output = model(data)
output = torch.sigmoid(output)
loss = loss_fn(output, target)
loss.backward()
optimizer.step()
For now the results are not good, am i doing something wrong?
Any suggestions would be really helpful.Thanks in advance.