def russ_features(which_set, restrict_instances): raw = FoveatedNORB(which_set=which_set, restrict_instances=None, one_hot=True) X = np.load("/data/lisa/data/norb_small/ruslan_binarized/%s_X.npy" % which_set) assert raw.X.shape[0] == X.shape[0], (raw.X.shape[0], X.shape[0]) raw.X = X y = np.load("/data/lisa/data/norb_small/ruslan_binarized/%s_Y.npy" % which_set) print y[0:5, :] print raw.y[0:5, :] assert np.allclose(y, raw.y) if restrict_instances is not None: raw.restrict_instances(restrict_instances) rval = BinarizerDataset(raw) rval.X = raw.X return rval
def setUp(self): try: self.train = FoveatedNORB(which_set='train') self.test = FoveatedNORB(which_set='test') self.train_one_hot = self.train.convert_to_one_hot() self.test_one_hot = self.test.convert_to_one_hot() except (NoDataPathError, NotInstalledError): raise SkipTest()
def test_foveated_norb(self): # Test that the FoveatedNORB class can be instantiated norb_train = FoveatedNORB(which_set="train", scale=1, restrict_instances=[4, 6, 7, 8], one_hot=1)
class TestFoveatedNORB(unittest.TestCase): def setUp(self): try: self.train = FoveatedNORB(which_set='train') self.test = FoveatedNORB(which_set='test') self.train_one_hot = self.train.convert_to_one_hot() self.test_one_hot = self.test.convert_to_one_hot() except (NoDataPathError, NotInstalledError): raise SkipTest() def test_one_hot(self): train_non_zeros = numpy.transpose(numpy.nonzeros(self.train_one_hot)) test_non_zeros = numpy.transpose(numpy.nonzeros(self.test_one_hot)) self.assertEquals(len(train_non_zeros), 1) self.assertEquals(len(test_non_zeros), 1) self.assertEquals(self.train_one_hot[train_non_zeros[0]], 1) self.assertEquals(self.test_one_hot[test_non_zeros[0]], 1) def test_restrict_instances(self): pass
__author__ = "Ian Goodfellow" """ A script for sequentially stepping through FoveatedNORB, viewing each image and its label. """ import numpy as np from pylearn2.datasets.norb_small import FoveatedNORB from pylearn2.gui.patch_viewer import PatchViewer from pylearn2.utils import get_choice print('Use test set?') choices = {'y': 'test', 'n': 'train'} which_set = choices[get_choice(choices)] dataset = FoveatedNORB(which_set=which_set, center=True) topo = dataset.get_topological_view() b, r, c, ch = topo.shape assert ch == 2 pv = PatchViewer((1, 2), (r, c), is_color=False) i = 0 while True: patch = topo[i, :, :, :] patch = patch / np.abs(patch).max() pv.add_patch(patch[:,:,1], rescale=False)
def test_FoveatedNORB(): """ This function tests the FoveatedNORB class. In addition to the shape and datatype of X and y member of the returned object, it also checks the scale of data while passing different parameters to the constructor. """ skip_if_no_data() data = FoveatedNORB('train') datamin = data.X.min() datamax = data.X.max() assert data.X.shape == (24300, 8976) assert data.X.dtype == 'float32' assert data.y.shape == (24300, ) assert data.y_labels == 5 assert data.get_topological_view().shape == (24300, 96, 96, 2) data = FoveatedNORB('train', center=True) assert data.X.min() == datamin - 127.5 assert data.X.max() == datamax - 127.5 data = FoveatedNORB('train', center=True, scale=True) assert numpy.all(data.X <= 1.) assert numpy.all(data.X >= -1.) data = FoveatedNORB('train', scale=True) assert numpy.all(data.X <= 1.) assert numpy.all(data.X >= 0.) data = FoveatedNORB('test') assert data.X.shape == (24300, 8976) assert data.X.dtype == 'float32' assert data.y.shape == (24300, ) assert data.y_labels == 5 assert data.get_topological_view().shape == (24300, 96, 96, 2)
A script for sequentially stepping through FoveatedNORB, viewing each image and its label. """ import numpy as np from six.moves import input from pylearn2.datasets.norb_small import FoveatedNORB from pylearn2.gui.patch_viewer import PatchViewer from pylearn2.utils import get_choice print('Use test set?') choices = {'y': 'test', 'n': 'train'} which_set = choices[get_choice(choices)] dataset = FoveatedNORB(which_set=which_set, center=True) topo = dataset.get_topological_view() b, r, c, ch = topo.shape assert ch == 2 pv = PatchViewer((1, 2), (r, c), is_color=False) i = 0 while True: patch = topo[i, :, :, :] patch = patch / np.abs(patch).max() pv.add_patch(patch[:, :, 1], rescale=False)
from pylearn2.datasets.norb_small import FoveatedNORB dataset = FoveatedNORB(which_set='train') from pylearn2.datasets.preprocessing import Standardize standardize = Standardize(global_mean=True, global_std=True) standardize.apply(dataset, can_fit=True) from pylearn2.utils import serial serial.save("norb_prepro_global.pkl", standardize)