diff options
| author | Tanner Robison <[email protected]> | 2026-06-17 18:14:20 -0700 |
|---|---|---|
| committer | Tanner Robison <[email protected]> | 2026-06-17 22:05:02 -0700 |
| commit | 3b87b8bd271ade1622149516ae14f94b7ff20dd5 (patch) | |
| tree | a715ff83c167238b6152fd380cdfa5cf1086d70f /neurobench_testing/examples/gsc/ANN.py | |
| parent | 190b63c9e25770a52f9b93f4a6267c2bc21c3cfc (diff) | |
neurobench & memtorch
Diffstat (limited to 'neurobench_testing/examples/gsc/ANN.py')
| -rw-r--r-- | neurobench_testing/examples/gsc/ANN.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/neurobench_testing/examples/gsc/ANN.py b/neurobench_testing/examples/gsc/ANN.py new file mode 100644 index 0000000..7607833 --- /dev/null +++ b/neurobench_testing/examples/gsc/ANN.py @@ -0,0 +1,49 @@ +import torch +import torch.nn as nn +import torch.nn.functional as F +import torch.optim as optim +import torchaudio +import sys + +from tqdm import tqdm + +class M5(nn.Module): + def __init__(self, n_input=1, n_output=35, stride=16, n_channel=32): + super().__init__() + self.conv1 = nn.Conv1d(n_input, n_channel, kernel_size=80, stride=stride) + self.bn1 = nn.BatchNorm1d(n_channel) + self.pool1 = nn.MaxPool1d(4) + self.conv2 = nn.Conv1d(n_channel, n_channel, kernel_size=3) + self.bn2 = nn.BatchNorm1d(n_channel) + self.pool2 = nn.MaxPool1d(4) + self.conv3 = nn.Conv1d(n_channel, 2 * n_channel, kernel_size=3) + self.bn3 = nn.BatchNorm1d(2 * n_channel) + self.pool3 = nn.MaxPool1d(4) + self.conv4 = nn.Conv1d(2 * n_channel, 2 * n_channel, kernel_size=3) + self.bn4 = nn.BatchNorm1d(2 * n_channel) + self.pool4 = nn.MaxPool1d(4) + self.fc1 = nn.Linear(2 * n_channel, n_output) + + # these need to be different ReLU objects so that they can be individually hooked + self.act1 = nn.ReLU() + self.act2 = nn.ReLU() + self.act3 = nn.ReLU() + self.act4 = nn.ReLU() + + def forward(self, x): + x = self.conv1(x) + x = self.act1(self.bn1(x)) + x = self.pool1(x) + x = self.conv2(x) + x = self.act2(self.bn2(x)) + x = self.pool2(x) + x = self.conv3(x) + x = self.act3(self.bn3(x)) + x = self.pool3(x) + x = self.conv4(x) + x = self.act4(self.bn4(x)) + x = self.pool4(x) + x = F.avg_pool1d(x, x.shape[-1]) + x = x.permute(0, 2, 1) + x = self.fc1(x) + return F.log_softmax(x, dim=2)
\ No newline at end of file |
