-
Notifications
You must be signed in to change notification settings - Fork 66
/
net.py
29 lines (24 loc) · 859 Bytes
/
net.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- encoding: utf-8 -*-
import torch.nn as nn
class SiameseNetwork(nn.Module):
def __init__(self):
super(SiameseNetwork, self).__init__()
self.cnn1 = nn.Sequential(
nn.Conv2d(1, 20, kernel_size=5),
nn.MaxPool2d(2, stride=2),
nn.Conv2d(20, 50, kernel_size=5),
nn.MaxPool2d(2, stride=2))
self.fc1 = nn.Sequential(
nn.Linear(50 * 4 * 4, 500),
nn.ReLU(inplace=True),
nn.Linear(500, 10),
nn.Linear(10, 2))
def forward_once(self, x):
output = self.cnn1(x)
output = output.view(output.size()[0], -1)
output = self.fc1(output)
return output
def forward(self, input1, input2):
output1 = self.forward_once(input1)
output2 = self.forward_once(input2)
return output1, output2