A4_4410169_Turki / dummy.py
TurkiAM's picture
Upload 2 files
07b139d verified
import random
import numpy as np
import torch as tr
seed = 4410169 # <<<<<<<<<<<<<<<< Your UPM ID Goes Here
random.seed(seed)
np.random.seed(seed)
tr.manual_seed(seed)
class SimpleFeedForwardNet(tr.nn.Module):
def __init__(self):
super().__init__()
self.linear0 = tr.nn.Linear(784, 128) # 784 -> 128 - Layer 0 -- Affine Transformation (Linear with Bias)
self.linear1 = tr.nn.Linear(128, 32) # 128 -> 32 - Layer 1 -- Affine Transformation (Linear with Bias)
self.linear2 = tr.nn.Linear(32,10) # 32 -> 10 - Layer 2 -- Affine Transformation (Linear with Bias)
self.init_weights()
def init_weights(self):
tr.nn.init.zeros_(self.linear0.weight)
tr.nn.init.eye_(self.linear1.weight)
tr.nn.init.zeros_(self.linear0.bias)
tr.nn.init.zeros_(self.linear1.bias)
def forward(self, x):
x = self.linear0(x)
x = self.linear1(x)
x = self.linear2(x)
return x
model = SimpleFeedForwardNet() # Architecture
optimizer = tr.optim.SGD(model.parameters(), lr=0.01,weight_decay=1/3000,momentum=1/3000, maximize=False) # Optimizer
loss_fn = tr.nn.CrossEntropyLoss() # Objective Function [DO NOT CHANGE !]