-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_model.py
More file actions
30 lines (26 loc) · 983 Bytes
/
Copy pathsimple_model.py
File metadata and controls
30 lines (26 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import torch.nn as nn
class SimpleCNN(nn.Module):
"""Simple CNN for testing Conv2d and BatchNorm support"""
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(3, 16, kernel_size=3, padding=1)
self.bn1 = nn.BatchNorm2d(16)
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(16, 32, kernel_size=3, padding=1)
self.relu2 = nn.ReLU()
self.fc = nn.Linear(32 * 8 * 8, 10) # Assuming 8x8 after operations
def forward(self, x):
x = self.relu1(self.bn1(self.conv1(x)))
x = self.relu2(self.conv2(x))
x = x.view(x.size(0), -1) # Flatten
x = self.fc(x)
return x
class SimpleModel(nn.Module):
"""Original simple model for backward compatibility"""
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(4, 4)
self.relu = nn.ReLU()
self.fc2 = nn.Linear(4, 2)
def forward(self, x):
return self.fc2(self.relu(self.fc1(x)))