|
import torch |
|
import torch.nn as nn |
|
import torch.nn.functional as F |
|
|
|
|
|
class NumberIdentityModel(nn.Module): |
|
def __init__(self): |
|
super(NumberIdentityModel, self).__init__() |
|
self.conv1 = nn.Conv2d(1, 32, kernel_size=3, padding=1) |
|
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1) |
|
self.pool = nn.MaxPool2d(2, 2) |
|
self.fc1 = nn.Linear(64 * 7 * 7, 128) |
|
self.fc2 = nn.Linear(128, 10) |
|
|
|
def forward(self, x): |
|
x = self.pool(F.relu(self.conv1(x))) |
|
x = self.pool(F.relu(self.conv2(x))) |
|
x = x.view(-1, 64 * 7 * 7) |
|
x = F.relu(self.fc1(x)) |
|
x = self.fc2(x) |
|
return x |
|
|
|
|
|
model = NumberIdentityModel() |
|
|
|
|
|
|
|
|
|
|
|
dummy_input = torch.randn(1, 1, 28, 28) |
|
output = model(dummy_input) |
|
|
|
|
|
model_path = "number-identity-model.pth" |
|
torch.save(model.state_dict(), model_path) |
|
|
|
print(f"Model saved to {model_path}") |
|
|