Spaces:
Runtime error
Runtime error
danielcd99
commited on
Commit
•
1b8bd99
1
Parent(s):
1b96396
Added a Model file
Browse files
Model.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch import nn
|
3 |
+
|
4 |
+
# Neural Network
|
5 |
+
class LeNet(nn.Module):
|
6 |
+
def __init__(self):
|
7 |
+
super(LeNet, self).__init__()
|
8 |
+
|
9 |
+
self.convs = nn.Sequential(
|
10 |
+
nn.Conv2d(in_channels=1, out_channels=4, kernel_size=(5, 5)),
|
11 |
+
nn.Tanh(),
|
12 |
+
nn.AvgPool2d(2, 2),
|
13 |
+
|
14 |
+
nn.Conv2d(in_channels=4, out_channels=12, kernel_size=(5, 5)),
|
15 |
+
nn.Tanh(),
|
16 |
+
nn.AvgPool2d(2, 2)
|
17 |
+
)
|
18 |
+
|
19 |
+
self.linear = nn.Sequential(
|
20 |
+
nn.Linear(4*4*12,10)
|
21 |
+
)
|
22 |
+
|
23 |
+
def forward(self, x):
|
24 |
+
x = self.convs(x)
|
25 |
+
x = torch.flatten(x, 1)
|
26 |
+
|
27 |
+
return self.linear(x)
|
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from
|
4 |
|
5 |
labels = ['Zero','Um','Dois','Três','Quatro','Cinco','Seis','Sete','Oito', 'Nove']
|
6 |
|
@@ -13,30 +13,6 @@ else:
|
|
13 |
print("CPU")
|
14 |
|
15 |
|
16 |
-
# Neural Network
|
17 |
-
class LeNet(nn.Module):
|
18 |
-
def __init__(self):
|
19 |
-
super(LeNet, self).__init__()
|
20 |
-
|
21 |
-
self.convs = nn.Sequential(
|
22 |
-
nn.Conv2d(in_channels=1, out_channels=4, kernel_size=(5, 5)),
|
23 |
-
nn.Tanh(),
|
24 |
-
nn.AvgPool2d(2, 2),
|
25 |
-
|
26 |
-
nn.Conv2d(in_channels=4, out_channels=12, kernel_size=(5, 5)),
|
27 |
-
nn.Tanh(),
|
28 |
-
nn.AvgPool2d(2, 2)
|
29 |
-
)
|
30 |
-
|
31 |
-
self.linear = nn.Sequential(
|
32 |
-
nn.Linear(4*4*12,10)
|
33 |
-
)
|
34 |
-
|
35 |
-
def forward(self, x):
|
36 |
-
x = self.convs(x)
|
37 |
-
x = torch.flatten(x, 1)
|
38 |
-
|
39 |
-
return self.linear(x)
|
40 |
|
41 |
# Loading model
|
42 |
model = LeNet().to(device)
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from Model import LeNet
|
4 |
|
5 |
labels = ['Zero','Um','Dois','Três','Quatro','Cinco','Seis','Sete','Oito', 'Nove']
|
6 |
|
|
|
13 |
print("CPU")
|
14 |
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Loading model
|
18 |
model = LeNet().to(device)
|