harveyslash / Facial-Similarity-with-Siamese-Networks-in-Pytorch

Implementing Siamese networks with a contrastive loss for similarity learning
https://hackernoon.com/one-shot-learning-with-siamese-networks-in-pytorch-8ddaab10340e
MIT License
972 stars 274 forks source link

Where the trained result saved in ? #45

Open ikouhaha opened 2 years ago

ikouhaha commented 2 years ago

Sorry, I am a beginner. I could not find the results after training. It makes me feel that actually testing and training are two different things. Thank you very much

1191658517 commented 2 years ago

add those code by your self: for epoch in range(0, Config.train_number_epochs): for i, data in enumerate(train_dataloader, 0): img0, img1, label = data img0, img1, label = img0.cuda(), img1.cuda(), label.cuda() optimizer.zero_grad() output1, output2 = net(img0, img1) 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.item())) iteration_number += 10 counter.append(iteration_number) loss_history.append(loss_contrastive.item())

show_plot(counter, loss_history)

save the training res

PATH = "./net.pt" torch.save(net.state_dict(),PATH)