Skip to content

Instantly share code, notes, and snippets.

@harveyslash
Created July 20, 2017 08:31
Show Gist options
  • Save harveyslash/473641633a9bcf75ca9cb7ca49f9034e to your computer and use it in GitHub Desktop.
Save harveyslash/473641633a9bcf75ca9cb7ca49f9034e to your computer and use it in GitHub Desktop.
net = SiameseNetwork().cuda()
criterion = ContrastiveLoss()
optimizer = optim.Adam(net.parameters(),lr = 0.0005 )
counter = []
loss_history = []
iteration_number= 0
for epoch in range(0,Config.train_number_epochs):
for i, data in enumerate(train_dataloader,0):
img0, img1 , label = data
img0, img1 , label = Variable(img0).cuda(), Variable(img1).cuda() , Variable(label).cuda()
output1,output2 = net(img0,img1)
optimizer.zero_grad()
loss_contrastive = criterion(output1,output2,label)
loss_contrastive.backward()
optimizer.step()
if i %10 == 0 :
print("Epoch number {}\n Current loss {}\n".format(epoch,loss_contrastive.data[0]))
iteration_number +=10
counter.append(iteration_number)
loss_history.append(loss_contrastive.data[0])
show_plot(counter,loss_history)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment