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

AP loss Backpropagation #21

Open
Zenobia7 opened this issue Aug 20, 2020 · 0 comments
Open

AP loss Backpropagation #21

Zenobia7 opened this issue Aug 20, 2020 · 0 comments

Comments

@Zenobia7
Copy link

Zenobia7 commented Aug 20, 2020

@almazan
How do you calculate the derivative of the similarity matrix S and matrix D?I calculated it automatically through pytorch, but the parameter update seems to be a bit problematic.
'''
desc_db = Variable(torch.cuda.FloatTensor(desc_db),requires_grad=True)
scores = torch.matmul(desc_db,desc_db.t())
vaild_index = np.arange(batch_sizeindex,batch_size(index+1),1)
Y = np.array(Y_all)[vaild_index][:,vaild_index]
Y = torch.cuda.FloatTensor(np.array(Y))
rank_loss = criterion(scores, Y)
rank_loss.backward()
loss += rank_loss.item()
net.train()
for i,img in enumerate(imgs):
img = Variable(img.cuda(),requires_grad=True)
desc = net(img.unsqueeze(dim=0))
one_grad = desc_db.grad[i].unsqueeze(0)
desc.unsqueeze(0).backward(one_grad)
optimizer.step()
scheduler_mul.step()
optimizer.zero_grad()
lr = scheduler_mul.get_lr()[0]
'''

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

1 participant