diff --git a/src/pytorch/data/MNIST/raw/t10k-images-idx3-ubyte b/src/pytorch/data/MNIST/raw/t10k-images-idx3-ubyte new file mode 100644 index 0000000..1170b2c Binary files /dev/null and b/src/pytorch/data/MNIST/raw/t10k-images-idx3-ubyte differ diff --git a/src/pytorch/data/MNIST/raw/t10k-images-idx3-ubyte.gz b/src/pytorch/data/MNIST/raw/t10k-images-idx3-ubyte.gz new file mode 100644 index 0000000..5ace8ea Binary files /dev/null and b/src/pytorch/data/MNIST/raw/t10k-images-idx3-ubyte.gz differ diff --git a/src/pytorch/data/MNIST/raw/t10k-labels-idx1-ubyte b/src/pytorch/data/MNIST/raw/t10k-labels-idx1-ubyte new file mode 100644 index 0000000..d1c3a97 Binary files /dev/null and b/src/pytorch/data/MNIST/raw/t10k-labels-idx1-ubyte differ diff --git a/src/pytorch/data/MNIST/raw/t10k-labels-idx1-ubyte.gz b/src/pytorch/data/MNIST/raw/t10k-labels-idx1-ubyte.gz new file mode 100644 index 0000000..a7e1415 Binary files /dev/null and b/src/pytorch/data/MNIST/raw/t10k-labels-idx1-ubyte.gz differ diff --git a/src/pytorch/data/MNIST/raw/train-images-idx3-ubyte b/src/pytorch/data/MNIST/raw/train-images-idx3-ubyte new file mode 100644 index 0000000..bbce276 Binary files /dev/null and b/src/pytorch/data/MNIST/raw/train-images-idx3-ubyte differ diff --git a/src/pytorch/data/MNIST/raw/train-images-idx3-ubyte.gz b/src/pytorch/data/MNIST/raw/train-images-idx3-ubyte.gz new file mode 100644 index 0000000..b50e4b6 Binary files /dev/null and b/src/pytorch/data/MNIST/raw/train-images-idx3-ubyte.gz differ diff --git a/src/pytorch/data/MNIST/raw/train-labels-idx1-ubyte b/src/pytorch/data/MNIST/raw/train-labels-idx1-ubyte new file mode 100644 index 0000000..d6b4c5d Binary files /dev/null and b/src/pytorch/data/MNIST/raw/train-labels-idx1-ubyte differ diff --git a/src/pytorch/data/MNIST/raw/train-labels-idx1-ubyte.gz b/src/pytorch/data/MNIST/raw/train-labels-idx1-ubyte.gz new file mode 100644 index 0000000..707a576 Binary files /dev/null and b/src/pytorch/data/MNIST/raw/train-labels-idx1-ubyte.gz differ diff --git a/src/pytorch/functions.py b/src/pytorch/functions.py index e005810..a89c989 100644 --- a/src/pytorch/functions.py +++ b/src/pytorch/functions.py @@ -18,7 +18,7 @@ def __init__(self, k): ''' super(linearUnified, self).__init__() self.k = k - + @staticmethod def forward(self, x, w, b): ''' forward propagation @@ -36,7 +36,7 @@ def forward(self, x, w, b): self.add_buffer = x.new(x.size(0)).fill_(1) y.addr_(self.add_buffer, b) return y - + @staticmethod def backward(self, dy): ''' backprop with meprop diff --git a/src/pytorch/modules.py b/src/pytorch/modules.py index 06a6ac7..45cf883 100644 --- a/src/pytorch/modules.py +++ b/src/pytorch/modules.py @@ -36,9 +36,9 @@ def reset_parameters(self): def forward(self, x): if self.unified: - return linearUnified(self.k)(x, self.w, self.b) + return linearUnified.apply(x, self.w, self.b)#add apply else: - return linear(self.k)(x, self.w, self.b) + return linear.apply(x, self.w, self.b)#add apply def __repr__(self): return '{} ({} -> {} <- {}{})'.format(self.__class__.__name__, diff --git a/src/pytorch/util.py b/src/pytorch/util.py index 632ca41..90f2554 100644 --- a/src/pytorch/util.py +++ b/src/pytorch/util.py @@ -10,7 +10,7 @@ import torch.nn.functional as F import torch.optim as optim import torch.utils.data -from torch.autograd import Variable +from torch.autograd import Variable#deprecated- no longer supported from model import NetLayer @@ -102,8 +102,7 @@ def _train(self, model, opt): utime = 0 tloss = 0 for bid, (data, target) in enumerate(self.trainloader): - data, target = Variable(data).cuda(), Variable( - target.view(-1)).cuda() + data, target = Variable(data).cuda(), Variable(target.view(-1)).cuda()#Deprecated- need to replace start = torch.cuda.Event(True) end = torch.cuda.Event(True) @@ -145,8 +144,7 @@ def _evaluate(self, model, loader, name='test'): test_loss = 0 correct = 0 for data, target in loader: - data, target = Variable( - data, volatile=True).cuda(), Variable(target).cuda() + data, target = Variable(data, volatile=True).cuda(), Variable(target).cuda()# Deprecated- need to update output = model(data) test_loss += F.nll_loss(output, target).data[0] pred = output.data.max(1)[ @@ -204,7 +202,7 @@ def run(self, k=None, epoch=None): start = torch.cuda.Event(True) end = torch.cuda.Event(True) start.record() - loss, ft, bt, ut = self._train(model, opt) + loss, ft, bt, ut = self._train(model, opt)#model is trained here end.record() end.synchronize() ttime = start.elapsed_time(end) @@ -215,7 +213,7 @@ def run(self, k=None, epoch=None): btime.append(bt) utime.append(ut) # predict - curacc = self._evaluate(model, self.devloader, 'dev') + curacc = self._evaluate(model, self.devloader, 'dev')#evaluation here if curacc > acc: e = t acc = curacc