Ajay85/hackathon
0
1import torch2import torchvision3import torch.nn as nn4from torchvision import transforms5import torch.nn.functional as F6## Add more imports if required7 8####################################################################################################################9# Define your model and transform and all necessary helper functions here #10# They will be imported to the exp_recognition.py file #11####################################################################################################################12 13# Definition of classes as dictionary14classes = {0: 'ANGER', 1: 'DISGUST', 2: 'FEAR', 3: 'HAPPINESS', 4: 'NEUTRAL', 5: 'SADNESS', 6: 'SURPRISE'}15 16# Example Network17class facExpRec(torch.nn.Module):18 def __init__(self):19 super(facExpRec, self).__init__()20 21 22 self.conv1 = nn.Conv2d(in_channels=1, out_channels=16, kernel_size=3)23 self.conv2 = nn.Conv2d(in_channels=16, out_channels=64, kernel_size=3)24 self.conv3 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3)25 self.conv4 = nn.Conv2d(in_channels=128, out_channels=256, kernel_size=1) 26 self.conv5 = nn.Conv2d(in_channels=256, out_channels=512, kernel_size=1) 27 self.conv6 = nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=1) 28 self.fc1 = nn.Linear(1024 * 1 * 1, 256) 29 self.fc2 = nn.Linear(256, 128)30 self.fc3 = nn.Linear(128, 64)31 self.fc4 = nn.Linear(64, 7)32 33 self.pool = nn.MaxPool2d(kernel_size=2)34 #YOUR CODE HERE35 36 def forward(self, x):37 x = self.pool(F.elu(self.conv1(x)))38 x = self.pool(F.elu(self.conv2(x)))39 x = self.pool(F.elu(self.conv3(x)))40 x = self.pool(F.elu(self.conv4(x))) 41 x = self.pool(F.elu(self.conv5(x))) 42 x = self.pool(F.elu(self.conv6(x))) 43 x = x.view(-1, 1024 * 1 * 1) 44 x = F.elu(self.fc1(x))45 x = F.elu(self.fc2(x))46 x = F.elu(self.fc3(x))47 x = self.fc4(x)48 x = F.log_softmax(x, dim=1)49 return x50 51# Sample Helper function52def rgb2gray(image):53 return image.convert('L')54 55# Sample Transformation function56#YOUR CODE HERE for changing the Transformation values.57trnscm = transforms.Compose([rgb2gray, transforms.Resize((100,100)), transforms.ToTensor()])