Upload 3 files
Browse files- cnn_letters.safetensors +3 -0
- dowload.py +47 -0
- training_loss30.png +0 -0
cnn_letters.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5fb7a8a2aa2b31911683753a2c1ec8ec9e2654b5d022d91bd6f096a2bead31ed
|
| 3 |
+
size 428216
|
dowload.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
import torch.nn.functional as F
|
| 4 |
+
from safetensors.torch import load_file
|
| 5 |
+
|
| 6 |
+
class CNN(nn.Module):
|
| 7 |
+
def __init__(self):
|
| 8 |
+
super(CNN, self).__init__()
|
| 9 |
+
self.conv1 = nn.Conv2d(1, 16, kernel_size=3, padding=1)
|
| 10 |
+
self.conv2 = nn.Conv2d(16, 32, kernel_size=3, padding=1)
|
| 11 |
+
self.fc1 = nn.Linear(32*7*7, 64)
|
| 12 |
+
self.fc2 = nn.Linear(64, 26)
|
| 13 |
+
|
| 14 |
+
def forward(self, x):
|
| 15 |
+
x = F.relu(self.conv1(x))
|
| 16 |
+
x = F.max_pool2d(x, 2)
|
| 17 |
+
x = F.relu(self.conv2(x))
|
| 18 |
+
x = F.max_pool2d(x, 2)
|
| 19 |
+
x = x.view(x.size(0), -1)
|
| 20 |
+
x = F.relu(self.fc1(x))
|
| 21 |
+
x = self.fc2(x)
|
| 22 |
+
return x
|
| 23 |
+
|
| 24 |
+
model = CNN()
|
| 25 |
+
weights_dict = load_file("cnn_letters.safetensors")
|
| 26 |
+
model.load_state_dict(weights_dict)
|
| 27 |
+
model.eval()
|
| 28 |
+
|
| 29 |
+
#using
|
| 30 |
+
|
| 31 |
+
#from PIL import Image
|
| 32 |
+
#from torchvision import transforms
|
| 33 |
+
#get you image
|
| 34 |
+
#img = Image.open("my_letter.png").convert("L")
|
| 35 |
+
|
| 36 |
+
#transform = transforms.Compose([
|
| 37 |
+
# transforms.Resize((28,28)),
|
| 38 |
+
# transforms.ToTensor(),
|
| 39 |
+
# transforms.Normalize((0.5,), (0.5,))
|
| 40 |
+
#])
|
| 41 |
+
|
| 42 |
+
#x = transform(img).unsqueeze(0)
|
| 43 |
+
|
| 44 |
+
#with torch.no_grad():
|
| 45 |
+
# output = model(x)
|
| 46 |
+
# pred = output.argmax(dim=1)
|
| 47 |
+
#print(f"Predicted class: {pred.item() + 1}")
|
training_loss30.png
ADDED
|