-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathKANConvs_MLP_2.py
88 lines (67 loc) · 2.13 KB
/
KANConvs_MLP_2.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from torch import nn
import sys
import torch.nn.functional as F
# sys.path.append('../kan_convolutional')
from kan_convolutional.KANConv import KAN_Convolutional_Layer
class KANC_MLP_2(nn.Module):
def __init__(self,grid_size= 5):
super().__init__()
self.conv1 = KAN_Convolutional_Layer(
n_convs = 5,
kernel_size= (3,3),
grid_size = grid_size
)
self.conv2 = KAN_Convolutional_Layer(
n_convs = 5,
kernel_size = (3,3),
dinamic_grid=True,
grid_size= grid_size
)
self.pool1 = nn.MaxPool2d(
kernel_size=(2, 2)
)
self.flat = nn.Flatten()
self.linear1 = nn.Linear(625, 256)
self.linear2 = nn.Linear(256, 10)
self.name = "KAN Conv Grid updated & 2 Layer MLP"
def forward(self, x):
x = self.conv1(x)
x = self.pool1(x)
x = self.conv2(x)
x = self.pool1(x)
x = self.flat(x)
x = self.linear1(x)
x = self.linear2(x)
x = F.log_softmax(x, dim=1)
return x
class KANC_MLP_sin_grid_2(nn.Module):
def __init__(self,grid_size= 5):
super().__init__()
self.conv1 = KAN_Convolutional_Layer(
n_convs = 5,
kernel_size= (3,3),
grid_size= grid_size
)
self.conv2 = KAN_Convolutional_Layer(
n_convs = 5,
kernel_size = (3,3),
dinamic_grid=False,
grid_size= grid_size
)
self.pool1 = nn.MaxPool2d(
kernel_size=(2, 2)
)
self.flat = nn.Flatten()
self.linear1 = nn.Linear(625, 256)
self.linear2 = nn.Linear(256, 10)
self.name = "KAN Conv & 2 Layer MLP"
def forward(self, x):
x = self.conv1(x)
x = self.pool1(x)
x = self.conv2(x)
x = self.pool1(x)
x = self.flat(x)
x = self.linear1(x)
x = self.linear2(x)
x = F.log_softmax(x, dim=1)
return x