FisayoF's picture
Update model.py
6cbd405 verified
Raw History Blame Contribute Delete
811 Bytes
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
class CnnNet(nn.Module):
def __init__(self):
super(CnnNet, self).__init__()
# Spectrogram is single channel, so use 1 input rather than 3 (RGB)
self.conv1 = nn.Conv2d(1, 64, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1)
self.pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)
self.fc1 = nn.Linear(128 * 120 * 160, 3)
def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.pool(x)
x = self.conv2(x)
x = F.relu(x)
x = self.pool(x)
x = x.view(-1, 128 * 120 * 160)
x = self.fc1(x)
x = F.log_softmax(x, dim=1)
return x