Upload 6 files
Browse files- README.md +3 -0
- dummy-weights.bin +3 -0
- dummy.py +37 -0
- hubconf.py +28 -0
- vanilla-weight.bin +3 -0
- vanilla.py +36 -0
README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Assignment 4 - AI417
|
| 2 |
+
|
| 3 |
+
This repository contains my trained models (DummyNet and VanillaNet) for Assignment 4.
|
dummy-weights.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a832d7797004f5ea77e8f3d791cfbf9509253971ae731b3fbfb9d985a88a50b1
|
| 3 |
+
size 824029
|
dummy.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import numpy as np
|
| 3 |
+
import torch as tr
|
| 4 |
+
|
| 5 |
+
seed = 4320232 # <<<<<<<<<<<<<<<< Your UPM ID Goes Here
|
| 6 |
+
random.seed(seed)
|
| 7 |
+
np.random.seed(seed)
|
| 8 |
+
tr.manual_seed(seed)
|
| 9 |
+
|
| 10 |
+
class SimpleFeedForwardNet(tr.nn.Module):
|
| 11 |
+
|
| 12 |
+
def __init__(self):
|
| 13 |
+
super().__init__()
|
| 14 |
+
self.linear1 = tr.nn.Linear(784, 256, bias=True) # 784 -> 16 - Layer 1 -- Affine Transformation (Linear with Bias)
|
| 15 |
+
self.linear2 = tr.nn.Linear(256, 16, bias=True) # 16 -> 16 - Layer 2 -- Linear Transformation (no bias)
|
| 16 |
+
self.linear3 = tr.nn.Linear(16, 10, bias=True) # 16 -> 10 - Layer 3 -- Affine Transformation (Linear with Bias)
|
| 17 |
+
#self.init_weights()
|
| 18 |
+
|
| 19 |
+
def init_weights(self):
|
| 20 |
+
tr.nn.init.zeros_(self.linear1.weight)
|
| 21 |
+
tr.nn.init.zeros_(self.linear2.weight)
|
| 22 |
+
tr.nn.init.zeros_(self.linear3.weight)
|
| 23 |
+
tr.nn.init.zeros_(self.linear1.bias)
|
| 24 |
+
tr.nn.init.ones_(self.linear2.bias)
|
| 25 |
+
tr.nn.init.ones_(self.linear3.bias)
|
| 26 |
+
|
| 27 |
+
def forward(self, x):
|
| 28 |
+
x = self.linear1(x)
|
| 29 |
+
x = self.linear2(x)
|
| 30 |
+
x = self.linear3(x)
|
| 31 |
+
return x
|
| 32 |
+
|
| 33 |
+
model = SimpleFeedForwardNet() # Architecture
|
| 34 |
+
optimizer = tr.optim.SGD(model.parameters(), lr=0.02, maximize=False) # Optimizer
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
loss_fn = tr.nn.CrossEntropyLoss() # Objective Function [DO NOT CHANGE !]
|
hubconf.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dependencies = ['torch']
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def DummyNet(pretrained=True, **kwargs):
|
| 7 |
+
"""Entry point for the DummyNet model."""
|
| 8 |
+
from dummy import SimpleFeedForwardNet
|
| 9 |
+
model = SimpleFeedForwardNet(**kwargs)
|
| 10 |
+
|
| 11 |
+
if pretrained:
|
| 12 |
+
hub_dir = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
+
weight_path = os.path.join(hub_dir, 'dummy-weights.bin')
|
| 14 |
+
model.load_state_dict(torch.load(weight_path))
|
| 15 |
+
|
| 16 |
+
return model
|
| 17 |
+
|
| 18 |
+
def VanillaNet(pretrained=True, **kwargs):
|
| 19 |
+
"""Entry point for the VanillaNet model."""
|
| 20 |
+
from vanilla import SimpleFeedForwardNet
|
| 21 |
+
model = SimpleFeedForwardNet(**kwargs)
|
| 22 |
+
|
| 23 |
+
if pretrained:
|
| 24 |
+
hub_dir = os.path.dirname(os.path.abspath(__file__))
|
| 25 |
+
weight_path = os.path.join(hub_dir, 'vanilla-weight.bin')
|
| 26 |
+
model.load_state_dict(torch.load(weight_path))
|
| 27 |
+
|
| 28 |
+
return model
|
vanilla-weight.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ee546974cd4bc192ede04b3c0c36d7c783de5eb68c89813243a76eb055aae9fc
|
| 3 |
+
size 816675
|
vanilla.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
import numpy as np
|
| 3 |
+
import torch as tr
|
| 4 |
+
|
| 5 |
+
seed = 4320232 # <<<<<<<<<<<<<<<< Your UPM ID Goes Here
|
| 6 |
+
random.seed(seed)
|
| 7 |
+
np.random.seed(seed)
|
| 8 |
+
tr.manual_seed(seed)
|
| 9 |
+
|
| 10 |
+
class SimpleFeedForwardNet(tr.nn.Module):
|
| 11 |
+
|
| 12 |
+
def __init__(self):
|
| 13 |
+
super().__init__()
|
| 14 |
+
self.linear1 = tr.nn.Linear(784, 256)
|
| 15 |
+
self.activation1 = tr.nn.ReLU() # 784 -> 16 - Layer 1 -- Affine Transformation (Linear with Bias)
|
| 16 |
+
self.linear2 = tr.nn.Linear(256, 10) # 16 -> 16 - Layer 2 -- Linear Transformation (no bias)
|
| 17 |
+
# 16 -> 10 - Layer 3 -- Affine Transformation (Linear with Bias)
|
| 18 |
+
#self.init_weights()
|
| 19 |
+
|
| 20 |
+
def init_weights(self):
|
| 21 |
+
tr.nn.init.kaiming_uniform_(self.linear1.weight, nonlinearity='relu')
|
| 22 |
+
tr.nn.init.constant_(self.linear1.bias, 0)
|
| 23 |
+
tr.nn.init.kaiming_uniform_(self.linear2.weight, nonlinearity='relu')
|
| 24 |
+
tr.nn.init.constant_(self.linear2.bias, 0)
|
| 25 |
+
|
| 26 |
+
def forward(self, x):
|
| 27 |
+
x = self.linear1(x)
|
| 28 |
+
x = self.activation1(x)
|
| 29 |
+
x = self.linear2(x)
|
| 30 |
+
return x
|
| 31 |
+
|
| 32 |
+
model = SimpleFeedForwardNet() # Architecture
|
| 33 |
+
optimizer = tr.optim.Adam(model.parameters(), lr=0.001) # Optimizer
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
loss_fn = tr.nn.CrossEntropyLoss() # Objective Function [DO NOT CHANGE !]
|