Skip to content

Instantly share code, notes, and snippets.

@thunderInfy
Created August 6, 2020 22:15
Show Gist options
  • Select an option

  • Save thunderInfy/4bacc0afff37e60a09539c76f8164520 to your computer and use it in GitHub Desktop.

Select an option

Save thunderInfy/4bacc0afff37e60a09539c76f8164520 to your computer and use it in GitHub Desktop.
# zero out grads
optimizer.zero_grad()
# retrieve xq and xk the two image batches
xq = sample_batched['image1']
xk = sample_batched['image2']
# move them to the device
xq = xq.to(device)
xk = xk.to(device)
# get their outputs
q = resnetq(xq)
k = resnetk(xk)
k = k.detach()
# normalize the ouptuts, make them unit vectors
q = torch.div(q,torch.norm(q,dim=1).reshape(-1,1))
k = torch.div(k,torch.norm(k,dim=1).reshape(-1,1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment