Team Ai
Apppublic

adititewari/hackathon4

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
exp_recognition_model.py54 linesDownload Raw Back to Hackathon_setup
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        self.conv1 = nn.Conv2d(in_channels=1, out_channels=16, kernel_size=3)21        self.conv2 = nn.Conv2d(in_channels=16, out_channels=64, kernel_size=3)22        self.conv3 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3)23        self.conv4 = nn.Conv2d(in_channels=128, out_channels=256, kernel_size=1)  24        self.conv5 = nn.Conv2d(in_channels=256, out_channels=512, kernel_size=1)  25        self.conv6 = nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=1) 26        self.fc1 = nn.Linear(1024 * 1 * 1, 256)  27        self.fc2 = nn.Linear(256, 128)28        self.fc3 = nn.Linear(128, 64)29        self.fc4 = nn.Linear(64, 7)30 31        self.pool = nn.MaxPool2d(kernel_size=2)32 33    def forward(self, x):34        x = self.pool(F.elu(self.conv1(x)))35        x = self.pool(F.elu(self.conv2(x)))36        x = self.pool(F.elu(self.conv3(x)))37        x = self.pool(F.elu(self.conv4(x)))  38        x = self.pool(F.elu(self.conv5(x))) 39        x = self.pool(F.elu(self.conv6(x)))  40        x = x.view(-1, 1024 * 1 * 1)  41        x = F.elu(self.fc1(x))42        x = F.elu(self.fc2(x))43        x = F.elu(self.fc3(x))44        x = self.fc4(x)45        x = F.log_softmax(x, dim=1)46        return x47        48# Sample Helper function49def rgb2gray(image):50    return image.convert('L')51    52# Sample Transformation function53#YOUR CODE HERE for changing the Transformation values.54trnscm = transforms.Compose([rgb2gray, transforms.Resize((100,100)), transforms.ToTensor()])