Adal Abilbekov
finall commit 2
fd98460
import torch
import torchaudio
import numpy as np
from torch import nn
# from torchsummary import summary
class CNNEmotinoalClassifier(nn.Module):
def __init__(self):
super(CNNEmotinoalClassifier, self).__init__()
# conv : 4, flatten, linear, softmax
self.conv1 = nn.Sequential(
nn.Conv2d(in_channels=1, out_channels=16, kernel_size=3, stride=1, padding=1),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2)
)
self.conv2 = nn.Sequential(
nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3, stride=1, padding=1),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2)
)
self.conv3 = nn.Sequential(
nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, stride=1, padding=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2)
)
self.conv4 = nn.Sequential(
nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=1, padding=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2)
)
self.flatten = nn.Flatten()
self.fully_connected = nn.Sequential(
nn.Linear(128 * 5 * 50, 128),
nn.ReLU(),
nn.Linear(128, 64),
nn.ReLU(),
nn.Linear(64, 32),
nn.ReLU(),
nn.Linear(32, 16),
nn.ReLU(),
nn.Linear(16, 6)
)
self.softmax = nn.Softmax(dim=1)
def forward(self, x):
x = self.conv1(x)
x = self.conv2(x)
x = self.conv3(x)
x = self.conv4(x)
x = self.flatten(x)
logits = self.fully_connected(x)
probs = self.softmax(logits)
return probs
if __name__ == '__main__':
device = ('cuda' if torch.cuda.is_available() else 'cpu')
model = CNNEmotinoalClassifier().to(device)
summary(model, (1, 64, 783))