from colorama import Fore, Back, Style
+# Pytorch
+
import torch
from torch import optim
from torch.nn import functional as fn
from torchvision import datasets, transforms, utils
+# SVRT
+
from vignette_set import VignetteSet, CompressedVignetteSet
######################################################################
for problem_number in range(1, 24):
if args.compress_vignettes:
- train_set = CompressedVignetteSet(problem_number, args.nb_train_batches, args.batch_size)
- test_set = CompressedVignetteSet(problem_number, args.nb_test_batches, args.batch_size)
+ train_set = CompressedVignetteSet(problem_number, args.nb_train_batches, args.batch_size,
+ cuda=torch.cuda.is_available())
+ test_set = CompressedVignetteSet(problem_number, args.nb_test_batches, args.batch_size,
+ cuda=torch.cuda.is_available())
else:
- train_set = VignetteSet(problem_number, args.nb_train_batches, args.batch_size)
- test_set = VignetteSet(problem_number, args.nb_test_batches, args.batch_size)
+ train_set = VignetteSet(problem_number, args.nb_train_batches, args.batch_size,
+ cuda=torch.cuda.is_available())
+ test_set = VignetteSet(problem_number, args.nb_test_batches, args.batch_size,
+ cuda=torch.cuda.is_available())
model = AfrozeShallowNet()
######################################################################
class VignetteSet:
- def __init__(self, problem_number, nb_batches, batch_size):
+ def __init__(self, problem_number, nb_batches, batch_size, cuda = False):
+ self.cuda = cuda
self.batch_size = batch_size
self.problem_number = problem_number
self.nb_batches = nb_batches
target = torch.LongTensor(self.batch_size).bernoulli_(0.5)
input = svrt.generate_vignettes(problem_number, target)
input = input.float().view(input.size(0), 1, input.size(1), input.size(2))
- if torch.cuda.is_available():
+ if self.cuda:
input = input.cuda()
target = target.cuda()
acc += input.sum() / input.numel()
######################################################################
class CompressedVignetteSet:
- def __init__(self, problem_number, nb_batches, batch_size):
+ def __init__(self, problem_number, nb_batches, batch_size, cuda = False):
+ self.cuda = cuda
self.batch_size = batch_size
self.problem_number = problem_number
self.nb_batches = nb_batches
input = input.view(self.batch_size, 1, 128, 128).sub_(self.mean).div_(self.std)
target = self.targets[b]
- if torch.cuda.is_available():
+ if self.cuda:
input = input.cuda()
target = target.cuda()