Upload 5 files
Browse files- Dummy.py +37 -0
- Vanilla.py +78 -0
- dummy_weights.bin +3 -0
- hubconf.py +20 -0
- vanilla_weights.bin +3 -0
Dummy.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import numpy as np
|
| 3 |
+
import torch as tr
|
| 4 |
+
|
| 5 |
+
seed = 4310220 # <<<<<<<<<<<<<<<< Your UPM ID Goes Here
|
| 6 |
+
random.seed(seed)
|
| 7 |
+
np.random.seed(seed)
|
| 8 |
+
tr.manual_seed(seed)
|
| 9 |
+
|
| 10 |
+
class DummyNet(tr.nn.Module):
|
| 11 |
+
|
| 12 |
+
def __init__(self):
|
| 13 |
+
super().__init__()
|
| 14 |
+
self.flatten = tr.nn.Flatten()
|
| 15 |
+
self.linear1 = tr.nn.Linear(784, 228, bias=True) # 784 -> 16 - Layer 1 -- Affine Transformation (Linear with Bias)
|
| 16 |
+
self.linear2 = tr.nn.Linear(228, 228, bias=False)
|
| 17 |
+
#self.linear3 = tr.nn.Linear(128, 128, bias=False) # 16 -> 16 - Layer 2 -- Linear Transformation (no bias)
|
| 18 |
+
self.linear4 = tr.nn.Linear(228, 10, bias=True) # 16 -> 10 - Layer 3 -- Affine Transformation (Linear with Bias)
|
| 19 |
+
self.init_weights()
|
| 20 |
+
|
| 21 |
+
def init_weights(self):
|
| 22 |
+
tr.nn.init.normal_(self.linear1.weight)
|
| 23 |
+
tr.nn.init.normal_(self.linear2.weight)
|
| 24 |
+
#tr.nn.init.normal_(self.linear3.weight)
|
| 25 |
+
tr.nn.init.normal_(self.linear4.weight)
|
| 26 |
+
tr.nn.init.normal_(self.linear1.bias)
|
| 27 |
+
tr.nn.init.normal_(self.linear4.bias)
|
| 28 |
+
|
| 29 |
+
def forward(self, x):
|
| 30 |
+
x = self.flatten(x)
|
| 31 |
+
x = self.linear1(x)
|
| 32 |
+
x = self.linear2(x)
|
| 33 |
+
#x = self.linear3(x)
|
| 34 |
+
x = self.linear4(x)
|
| 35 |
+
return x
|
| 36 |
+
|
| 37 |
+
# Objective Function [DO NOT CHANGE !]
|
Vanilla.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import numpy as np
|
| 3 |
+
import torch as tr
|
| 4 |
+
|
| 5 |
+
seed = 4310220 # <<<<<<<<<<<<<<<< Your UPM ID Goes Here
|
| 6 |
+
random.seed(seed)
|
| 7 |
+
np.random.seed(seed)
|
| 8 |
+
tr.manual_seed(seed)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class VanillaNet(tr.nn.Module):
|
| 12 |
+
|
| 13 |
+
def __init__(self):
|
| 14 |
+
super().__init__()
|
| 15 |
+
self.flatten = tr.nn.Flatten()
|
| 16 |
+
|
| 17 |
+
self.linear1 = tr.nn.Linear(784, 324, bias=True)
|
| 18 |
+
self.tanh1 = tr.nn.LeakyReLU()
|
| 19 |
+
|
| 20 |
+
self.linear2 = tr.nn.Linear(324, 324, bias=True)
|
| 21 |
+
self.tanh2 = tr.nn.LeakyReLU()
|
| 22 |
+
|
| 23 |
+
self.linear3 = tr.nn.Linear(324, 324, bias=True)
|
| 24 |
+
self.tanh3 = tr.nn.LeakyReLU()
|
| 25 |
+
|
| 26 |
+
self.linear4 = tr.nn.Linear(324, 324, bias=True)
|
| 27 |
+
self.tanh4 = tr.nn.LeakyReLU()
|
| 28 |
+
|
| 29 |
+
self.linear5 = tr.nn.Linear(324, 324, bias=True)
|
| 30 |
+
self.tanh5 = tr.nn.LeakyReLU()
|
| 31 |
+
|
| 32 |
+
self.linear6 = tr.nn.Linear(324, 10, bias=True)
|
| 33 |
+
#self.soft6 = tr.nn.Softmax(dim=1)
|
| 34 |
+
|
| 35 |
+
#self.init_weights()
|
| 36 |
+
self.init_weights()
|
| 37 |
+
|
| 38 |
+
def init_weights(self):
|
| 39 |
+
tr.nn.init.xavier_uniform_(self.linear1.weight)
|
| 40 |
+
tr.nn.init.xavier_uniform_(self.linear2.weight)
|
| 41 |
+
tr.nn.init.xavier_uniform_(self.linear3.weight)
|
| 42 |
+
tr.nn.init.xavier_uniform_(self.linear4.weight)
|
| 43 |
+
tr.nn.init.xavier_uniform_(self.linear5.weight)
|
| 44 |
+
tr.nn.init.xavier_uniform_(self.linear6.weight)
|
| 45 |
+
|
| 46 |
+
tr.nn.init.zeros_(self.linear1.bias)
|
| 47 |
+
tr.nn.init.zeros_(self.linear2.bias)
|
| 48 |
+
tr.nn.init.zeros_(self.linear3.bias)
|
| 49 |
+
tr.nn.init.zeros_(self.linear4.bias)
|
| 50 |
+
tr.nn.init.zeros_(self.linear5.bias)
|
| 51 |
+
tr.nn.init.zeros_(self.linear6.bias)
|
| 52 |
+
|
| 53 |
+
def forward(self, x):
|
| 54 |
+
x = self.flatten(x)
|
| 55 |
+
|
| 56 |
+
x = self.linear1(x)
|
| 57 |
+
x = self.tanh1(x)
|
| 58 |
+
|
| 59 |
+
x = self.linear2(x)
|
| 60 |
+
x = self.tanh2(x)
|
| 61 |
+
|
| 62 |
+
x = self.linear3(x)
|
| 63 |
+
x = self.tanh3(x)
|
| 64 |
+
|
| 65 |
+
x = self.linear4(x)
|
| 66 |
+
x = self.tanh4(x)
|
| 67 |
+
|
| 68 |
+
x = self.linear5(x)
|
| 69 |
+
x = self.tanh5(x)
|
| 70 |
+
|
| 71 |
+
x = self.linear6(x)
|
| 72 |
+
#x = self.soft6(x)
|
| 73 |
+
return x
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
dummy_weights.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f96697cbdd4b977a259dbb57b25771b54a30903c72d5de696c637d880da7537e
|
| 3 |
+
size 935771
|
hubconf.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from Dummy import DummyNet as _DummyNet
|
| 3 |
+
from Vanilla import VanillaNet as _VanillaNet
|
| 4 |
+
|
| 5 |
+
def DummyNet(pretrained=False):
|
| 6 |
+
model = _DummyNet()
|
| 7 |
+
if pretrained:
|
| 8 |
+
model.load_state_dict(
|
| 9 |
+
torch.load("dummy_weights.bin", map_location="cpu")
|
| 10 |
+
)
|
| 11 |
+
return model
|
| 12 |
+
|
| 13 |
+
def VanillaNet(pretrained=False):
|
| 14 |
+
model = _VanillaNet()
|
| 15 |
+
if pretrained:
|
| 16 |
+
model.load_state_dict(
|
| 17 |
+
torch.load("vanilla_weights.bin", map_location="cpu")
|
| 18 |
+
)
|
| 19 |
+
return model
|
| 20 |
+
|
vanilla_weights.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:222e98611e247ad028e349566a0390203d452e88e991a1d85b07d5b0046a3e88
|
| 3 |
+
size 2719951
|