3 # svrt is the ``Synthetic Visual Reasoning Test'', an image
4 # generator for evaluating classification performance of machine
5 # learning systems, humans and primates.
7 # Copyright (c) 2017 Idiap Research Institute, http://www.idiap.ch/
8 # Written by Francois Fleuret <francois.fleuret@idiap.ch>
10 # This file is part of svrt.
12 # svrt is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License version 3 as
14 # published by the Free Software Foundation.
16 # svrt is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with svrt. If not, see <http://www.gnu.org/licenses/>.
29 from torch import optim
30 from torch import FloatTensor as Tensor
31 from torch.autograd import Variable
33 from torch.nn import functional as fn
35 from torchvision import datasets, transforms, utils
39 labels = torch.LongTensor(12).zero_()
40 labels.narrow(0, 0, labels.size(0)//2).fill_(1)
42 x = svrt.generate_vignettes(4, labels)
44 print('compression factor {:f}'.format(x.storage().size() / svrt.compress(x.storage()).size()))
46 x = x.view(x.size(0), 1, x.size(1), x.size(2))
50 torchvision.utils.save_image(x, 'example.png')
52 print('Wrote example.png')