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 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) pv.add_patch(patch[:,:,0], rescale=False)
""" 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) pv.add_patch(patch[:, :, 0], rescale=False)