File size: 1,996 Bytes
30555e7
 
 
 
0190e78
30555e7
 
 
 
 
 
 
 
 
 
 
 
 
0190e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30555e7
 
0190e78
30555e7
 
 
 
 
 
 
094f908
 
0190e78
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import torch
import torchvision
import torch.nn as nn
from torchvision import transforms
import torchvision.models as models
## 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):

        super().__init__()
        self.model = models.vgg16(pretrained=True)
        for params in self.model.parameters():
            params.requires_grad = False
        input_shape = self.model.classifier[6].in_features

        self.model.classifier[6] = nn.Sequential(nn.Linear(input_shape, 1024),nn.ReLU(), nn.Dropout(0.2),
                                                 nn.Linear(1024,256), nn.ReLU(),nn.Dropout(0.2),
                                                 nn.Linear(256,7), nn.LogSoftmax(dim=1))
        self.model.classifier[6].requires_grad = True
        print("New Layers Added:")
        for params in self.model.parameters():
            if params.requires_grad:
                print(params.shape)

        
    def forward(self, x):
        return self.model(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([rgb2gray, transforms.Resize((48,48)), transforms.ToTensor()])
trnscm = transforms.Compose([transforms.Resize((100,100)),transforms.ToTensor()])