| |
| import torch |
| from model import SiameseNet |
| from loss import ContrastiveLoss |
|
|
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
|
| model = SiameseNet(embedding_dim=128).to(device) |
| criterion = ContrastiveLoss(margin=1.0) |
|
|
| |
| img1 = torch.randn(32, 1, 105, 105).to(device) |
| img2 = torch.randn(32, 1, 105, 105).to(device) |
| labels = torch.randint(0, 2, (32,)).float().to(device) |
|
|
| emb1, emb2 = model(img1, img2) |
| loss, dist = criterion(emb1, emb2, labels) |
|
|
| print(f"emb1 shape : {emb1.shape}") |
| print(f"emb2 shape : {emb2.shape}") |
| print(f"emb1 norm : {emb1.norm(dim=1).mean():.4f}") |
| print(f"loss : {loss.item():.4f}") |
| print(f"dist range : {dist.min():.3f} – {dist.max():.3f}") |
| print("Sanity check passed") |