Spaces:
Runtime error
Runtime error
Download model.py from Moremoholo2/datasets-switch-ai: direct link, hf CLI and curl.
- Browser
- Download file 815 Bytes
-
https://huggingface.co/spaces/Moremoholo2/datasets-switch-ai/resolve/main/model.py
- Command line
-
hf download hf://spaces/Moremoholo2/datasets-switch-ai/model.py
-
curl -L -o model.py https://huggingface.co/spaces/Moremoholo2/datasets-switch-ai/resolve/main/model.py
815 Bytes
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class AudioCNN(nn.Module): | |
| def __init__(self, num_classes): | |
| super(AudioCNN, self).__init__() | |
| # 1D conv layers | |
| self.conv1 = nn.Conv1d(1, 16, kernel_size=3, stride=1, padding=1) | |
| self.pool1 = nn.MaxPool1d(2) | |
| self.conv2 = nn.Conv1d(16, 32, kernel_size=3, stride=1, padding=1) | |
| self.pool2 = nn.AdaptiveMaxPool1d(64) # output length fixed at 64 | |
| # Fully connected layers | |
| self.fc1 = nn.Linear(32 * 64, 128) | |
| self.fc2 = nn.Linear(128, num_classes) | |
| def forward(self, x): | |
| x = self.pool1(F.relu(self.conv1(x))) | |
| x = self.pool2(F.relu(self.conv2(x))) | |
| x = x.view(x.size(0), -1) | |
| x = F.relu(self.fc1(x)) | |
| x = self.fc2(x) | |
| return x | |