Spaces:
Runtime error
Runtime error
Update app/Hackathon_setup/exp_recognition_model.py
Browse files
app/Hackathon_setup/exp_recognition_model.py
CHANGED
|
@@ -20,43 +20,41 @@ classes = {0: 'ANGER', 1: 'DISGUST', 2: 'FEAR', 3: 'HAPPINESS', 4: 'NEUTRAL', 5:
|
|
| 20 |
# Example Network
|
| 21 |
class facExpRec(torch.nn.Module):
|
| 22 |
def __init__(self, out_features=7):
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
nn.ReLU(),
|
| 38 |
-
# nn.Dropout2d(),
|
| 39 |
-
nn.MaxPool2d(kernel_size=max_pool),
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
def fclayer(self, in_features, out_features):
|
| 43 |
-
return nn.Sequential(
|
| 44 |
-
nn.Linear(in_features, out_features),
|
| 45 |
-
nn.BatchNorm1d(out_features),
|
| 46 |
-
# nn.Dropout1d(0.4),
|
| 47 |
-
nn.ReLU(),
|
| 48 |
-
)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
return x
|
| 60 |
|
| 61 |
# Sample Helper function
|
| 62 |
def rgb2gray(image):
|
|
|
|
| 20 |
# Example Network
|
| 21 |
class facExpRec(torch.nn.Module):
|
| 22 |
def __init__(self, out_features=7):
|
| 23 |
+
super().__init__()
|
| 24 |
|
| 25 |
+
self.conv1 = self.convlayer(in_channels=1, out_channels=64, kernel_size=3, max_pool=2)
|
| 26 |
+
self.conv2 = self.convlayer(in_channels=64, out_channels=128, kernel_size=3, max_pool=2)
|
| 27 |
+
self.conv3 = self.convlayer(in_channels=128, out_channels=512, kernel_size=3, max_pool=2)
|
| 28 |
+
self.conv4 = self.convlayer(in_channels=512, out_channels=512, kernel_size=3, max_pool=1)
|
| 29 |
+
self.fc1 = self.fclayer(2048, 512)
|
| 30 |
+
self.fc2 = nn.Linear(512, 7)
|
| 31 |
+
|
| 32 |
+
def convlayer(self, in_channels, out_channels, kernel_size, max_pool=2):
|
| 33 |
+
return nn.Sequential(
|
| 34 |
+
nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=1),
|
| 35 |
+
nn.BatchNorm2d(out_channels),
|
| 36 |
+
nn.ReLU(),
|
| 37 |
+
# nn.Dropout2d(),
|
| 38 |
+
nn.MaxPool2d(kernel_size=max_pool),
|
| 39 |
+
)
|
| 40 |
|
| 41 |
+
def fclayer(self, in_features, out_features):
|
| 42 |
+
return nn.Sequential(
|
| 43 |
+
nn.Linear(in_features, out_features),
|
| 44 |
+
nn.BatchNorm1d(out_features),
|
| 45 |
+
# nn.Dropout1d(0.4),
|
| 46 |
+
nn.ReLU(),
|
| 47 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
def forward(self, x):
|
| 50 |
+
x = self.conv1(x)
|
| 51 |
+
x = self.conv2(x)
|
| 52 |
+
x = self.conv3(x)
|
| 53 |
+
x = self.conv4(x)
|
| 54 |
+
x = x.view(-1, 2048)
|
| 55 |
+
x = self.fc1(x)
|
| 56 |
+
x = self.fc2(x)
|
| 57 |
+
return x
|
|
|
|
| 58 |
|
| 59 |
# Sample Helper function
|
| 60 |
def rgb2gray(image):
|