aimliiith / app /Hackathon_setup /exp_recognition_model.py
sid-reddy-krishna's picture
exp rec code
87fac06
import torch
import torchvision
import torch.nn as nn
from torchvision import transforms
## Add more imports if required
####################################################################################################################
# Define your model and transform and all necessary helper functions here #
# They will be imported to the exp_recognition.py file #
####################################################################################################################
# Definition of classes as dictionary
classes = {0: 'ANGER', 1: 'DISGUST', 2: 'FEAR', 3: 'HAPPINESS', 4: 'NEUTRAL', 5: 'SADNESS', 6: 'SURPRISE'}
# Example Network
class facExpRec(torch.nn.Module):
def __init__(self):
pass # remove 'pass' once you have written your code
#YOUR CODE HERE
def forward(self, x):
pass # remove 'pass' once you have written your code
#YOUR CODE HERE
class ExpressionRecognitionCNN(nn.Module):
def __init__(self, num_classes = 7):
super(ExpressionRecognitionCNN, self).__init__()
self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
self.fc1 = nn.Linear(64 * 25 * 25, 128)
self.fc2 = nn.Linear(128, num_classes)
def forward(self, x):
x = self.pool(torch.relu(self.conv1(x)))
x = self.pool(torch.relu(self.conv2(x)))
x = x.view(-1, 64 * 25 * 25)
x = torch.relu(self.fc1(x))
x = self.fc2(x)
return x
# Sample Helper function
def rgb2gray(image):
return image.convert('L')
# Sample Transformation function
#YOUR CODE HERE for changing the Transformation values.
trnscm = transforms.Compose([transforms.Grayscale(num_output_channels=1),
transforms.Resize((100, 100)),
transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,)),])