X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=vignette_set.py;h=0b6de7e17d7db8fc4897f844c889acf549cda562;hb=c5660d2adc37f116088867ae71f66a89b34c94f1;hp=72880bab74b2041a013f3bb2048ca50d8e54488c;hpb=605697b42bdf62c0d8a6715d43ab40b7446e9af2;p=pysvrt.git diff --git a/vignette_set.py b/vignette_set.py index 72880ba..0b6de7e 100755 --- a/vignette_set.py +++ b/vignette_set.py @@ -22,7 +22,7 @@ import torch from math import sqrt -from multiprocessing import Pool, cpu_count +from torch import multiprocessing from torch import Tensor from torch.autograd import Variable @@ -32,13 +32,11 @@ import svrt ###################################################################### def generate_one_batch(s): - svrt.seed(s) - target = torch.LongTensor(self.batch_size).bernoulli_(0.5) + problem_number, batch_size, random_seed = s + svrt.seed(random_seed) + target = torch.LongTensor(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 self.cuda: - input = input.cuda() - target = target.cuda() return [ input, target ] class VignetteSet: @@ -50,13 +48,19 @@ class VignetteSet: self.nb_batches = nb_batches self.nb_samples = self.nb_batches * self.batch_size - seed_list = torch.LongTensor(self.nb_batches).random_().tolist() + seeds = torch.LongTensor(self.nb_batches).random_() + mp_args = [] + for b in range(0, self.nb_batches): + mp_args.append( [ problem_number, batch_size, seeds[b] ]) + + self.data = [] + for b in range(0, self.nb_batches): + self.data.append(generate_one_batch(mp_args[b])) - # self.data = [] - # for b in range(0, self.nb_batches): - # self.data.append(generate_one_batch(seed_list[b])) + # Weird thing going on with the multi-processing, waiting for more info - self.data = Pool(cpu_count()).map(generate_one_batch, seed_list) + # pool = multiprocessing.Pool(multiprocessing.cpu_count()) + # self.data = pool.map(generate_one_batch, mp_args) acc = 0.0 acc_sq = 0.0 @@ -69,6 +73,9 @@ class VignetteSet: std = sqrt(acc_sq / self.nb_batches - mean * mean) for b in range(0, self.nb_batches): self.data[b][0].sub_(mean).div_(std) + if cuda: + self.data[b][0] = self.data[b][0].cuda() + self.data[b][1] = self.data[b][1].cuda() def get_batch(self, b): return self.data[b]