Views
No views yet
| File | Variant | Training data |
|---|---|---|
siamese_standard_model.pth | Standard | Original input order |
siamese_flip_model.pth | Flip-augmented | Input-swapped pairs included |
SiameseNetwork(input_channels=1, embedding_dim=128)
├── feature_extractor # shared CNN branch
│ Conv2d(1→32, 5×5) + BN + ReLU + MaxPool → 128×128
│ Conv2d(32→64, 5×5) + BN + ReLU + MaxPool → 64×64
│ Conv2d(64→128, 3×3)+ BN + ReLU + MaxPool → 32×32
│ Conv2d(128→256,3×3)+ BN + ReLU + MaxPool → 16×16
│ Conv2d(256→512,3×3)+ BN + ReLU + MaxPool → 8×8
├── embedding_net # 32768 → 512 → 256 → 128
└── classifier # 256 → 64 → 32 → 1 (Sigmoid)1import torch
2import numpy as np
3from model import SiameseNetwork
4
5device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6
7model = SiameseNetwork(input_channels=1, embedding_dim=128)
8model.load_state_dict(torch.load("siamese_standard_model.pth", map_location=device))
9model.eval()
10model.to(device)
11
12def heatmap_to_tensor(heatmap: np.ndarray) -> torch.Tensor:
13 """Convert a (256, 256) int array to a normalised (1, 1, 256, 256) tensor."""
14 x = heatmap.astype(np.float32)
15 x = (x - x.mean()) / (x.std() + 1e-8)
16 return torch.from_numpy(x).unsqueeze(0).unsqueeze(0) # (1, 1, 256, 256)
17
18# feat1 / feat2 are (256, 256) numpy arrays from the dataset
19img1 = heatmap_to_tensor(feat1).to(device)
20img2 = heatmap_to_tensor(feat2).to(device)
21
22with torch.no_grad():
23 score = model(img1, img2).item() # float in [0, 1]
24
25print("Derived (IP theft):", score > 0.5)1from torch.utils.data import DataLoader
2from dataset import get_np_dataset
3
4test_dataset = get_np_dataset("data/test_data.npz")
5test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False, num_workers=4)
6
7model.eval()
8correct = total = 0
9with torch.no_grad():
10 for img1, img2, labels in test_loader:
11 img1, img2, labels = img1.to(device), img2.to(device), labels.to(device)
12 outputs = model(img1, img2)
13 predicted = (outputs > 0.5).float()
14 correct += (predicted == labels).sum().item()
15 total += labels.size(0)
16
17print(f"Accuracy: {100 * correct / total:.2f}%")nn.BCELoss)03_train.py04_eval.py script reports accuracy, sensitivity (recall on same=1), and specificity (recall on same=0) for every model × dataset combination:python 04_eval.py # writes eval_results.txt (JSON lines)1@inproceedings{sekanina2026obfax,
2 author = {Lukas Sekanina and Vojtech Mrazek},
3 title = {{ObfAx}: Obfuscation and {IP} Piracy Detection in Approximate Circuits},
4 booktitle = {Proceedings of the Great Lakes Symposium on VLSI (GLSVLSI)},
5 year = {2026},
6 doi = {10.1145/3787109.3815215}
7}