| import torch |
| import torch.nn as nn |
| import torch.nn.functional as F |
| from safetensors.torch import load_file |
|
|
| class CNN(nn.Module): |
| def __init__(self): |
| super(CNN, self).__init__() |
| self.conv1 = nn.Conv2d(1, 16, kernel_size=3, padding=1) |
| self.conv2 = nn.Conv2d(16, 32, kernel_size=3, padding=1) |
| self.fc1 = nn.Linear(32*7*7, 64) |
| self.fc2 = nn.Linear(64, 26) |
|
|
| def forward(self, x): |
| x = F.relu(self.conv1(x)) |
| x = F.max_pool2d(x, 2) |
| x = F.relu(self.conv2(x)) |
| x = F.max_pool2d(x, 2) |
| x = x.view(x.size(0), -1) |
| x = F.relu(self.fc1(x)) |
| x = self.fc2(x) |
| return x |
|
|
| model = CNN() |
| weights_dict = load_file("cnn_letters.safetensors") |
| model.load_state_dict(weights_dict) |
| model.eval() |
|
|
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
|
|
| |
|
|
| |
| |
| |
| |