akuratikaustiki/hackathon4a
0
1import math2import torch3import torchvision4import torch.nn as nn5import torch.nn.functional as F6from torchvision import transforms7# Add more imports if required8 9# Sample Transformation function10# YOUR CODE HERE for changing the Transformation values.11trnscm = transforms.Compose([transforms.Resize((100,100)), transforms.ToTensor()])12 13##Example Network14class Siamese(torch.nn.Module):15 def __init__(self):16 super(Siamese, self).__init__()17 #YOUR CODE HERE18 self.cnn1 = nn.Sequential(19 nn.ReflectionPad2d(1), #Pads the input tensor using the reflection of the input boundary, it similar to the padding.20 nn.Conv2d(1, 4, kernel_size=3),21 nn.ReLU(inplace=True),22 nn.BatchNorm2d(4),23 24 nn.ReflectionPad2d(1),25 nn.Conv2d(4, 8, kernel_size=3),26 nn.ReLU(inplace=True),27 nn.BatchNorm2d(8),28 29 30 nn.ReflectionPad2d(1),31 nn.Conv2d(8, 8, kernel_size=3),32 nn.ReLU(inplace=True),33 nn.BatchNorm2d(8),34 )35 36 self.fc1 = nn.Sequential(37 nn.Linear(8*100*100, 500),38 nn.ReLU(inplace=True),39 40 nn.Linear(500, 500),41 nn.ReLU(inplace=True),42 43 nn.Linear(500, 10))44 45 # forward_once is for one image. This can be used while classifying the face images46 def forward_once(self, x):47 output = self.cnn1(x)48 output = output.view(output.size()[0], -1)49 output = self.fc1(output)50 return output51 52 def forward(self, input1, input2):53 output1 = self.forward_once(input1)54 output2 = self.forward_once(input2)55 return output1, output256 57##########################################################################################################58## Sample classification network (Specify if you are using a pytorch classifier during the training) ##59## classifier = nn.Sequential(nn.Linear(64, 64), nn.BatchNorm1d(64), nn.ReLU(), nn.Linear...) ##60##########################################################################################################61 62# YOUR CODE HERE for pytorch classifier63classifier=nn.Sequential(nn.Linear(8*100*100, 500),nn.ReLU(inplace=True),nn.Linear(500, 500),nn.ReLU(inplace=True), nn.Linear(500, 10))64# Definition of classes as dictionary65person_labels=["Aparna","Kaustiki","Gouthami","Venkatesh"]