Ejemplo n.º 1
0
    def test_get_topological_view(self):

        def test_impl(norb):
            # Get a topological view as a single "(b, s, 0 1, c)" tensor.
            topo_tensor = norb.get_topological_view(single_tensor=True)
            shape = ((norb.X.shape[0], 2) +
                     SmallNORB.original_image_shape +
                     (1, ))
            expected_topo_tensor = norb.X.reshape(shape)
            # We loop to lower the peak memory usage
            for i in range(topo_tensor.shape[0]):
                assert numpy.all(topo_tensor[i] == expected_topo_tensor[i])

            # Get a topological view as two "(b, 0, 1, c)" tensors
            topo_tensors = norb.get_topological_view(single_tensor=False)
            expected_topo_tensors = tuple(expected_topo_tensor[:, i, ...]
                                          for i in range(2))

            for topo_tensor, expected_topo_tensor in safe_zip(
                    topo_tensors, expected_topo_tensors):
                assert numpy.all(topo_tensor == expected_topo_tensor)

        # Use stop parameter for SmallNORB; otherwise the buildbot uses close
        # to 10G of RAM.
        for norb in (SmallNORB('train', stop=1000),
                     NORB(which_norb='small', which_set='train')):
            test_impl(norb)
Ejemplo n.º 2
0
    def test_get_topological_view(self):
        norb = SmallNORB('train')

        # Get a topological view as a single "(b, s, 0 1, c)" tensor.
        topo_tensor = norb.get_topological_view(single_tensor=True)
        shape = (norb.X.shape[0], 2) + SmallNORB.original_image_shape + (1, )
        expected_topo_tensor = norb.X.reshape(shape)
        assert numpy.all(topo_tensor == expected_topo_tensor)

        # Get a topological view as two "(b, 0, 1, c)" tensors
        topo_tensors = norb.get_topological_view(single_tensor=False)
        expected_topo_tensors = tuple(expected_topo_tensor[:, i, ...]
                                      for i in range(2))

        for topo_tensor, expected_topo_tensor in \
            safe_zip(topo_tensors, expected_topo_tensors):
            assert numpy.all(topo_tensor == expected_topo_tensor)
Ejemplo n.º 3
0
    def test_get_topological_view(self):
        norb = SmallNORB('train')

        # Get a topological view as a single "(b, s, 0 1, c)" tensor.
        topo_tensor = norb.get_topological_view(single_tensor=True)
        shape = (norb.X.shape[0], 2) + SmallNORB.original_image_shape + (1, )
        expected_topo_tensor = norb.X.reshape(shape)
        assert numpy.all(topo_tensor == expected_topo_tensor)

        # Get a topological view as two "(b, 0, 1, c)" tensors
        topo_tensors = norb.get_topological_view(single_tensor=False)
        expected_topo_tensors = tuple(expected_topo_tensor[:, i, ...]
                                      for i in range(2))

        for topo_tensor, expected_topo_tensor in \
            safe_zip(topo_tensors, expected_topo_tensors):
            assert numpy.all(topo_tensor == expected_topo_tensor)
Ejemplo n.º 4
0
    def test_get_topological_view(self):
        # This is just to lower the memory usage. Otherwise, the
        # buildbot use close to 10G of ram.
        norb = SmallNORB('train', stop=1000)

        # Get a topological view as a single "(b, s, 0 1, c)" tensor.
        topo_tensor = norb.get_topological_view(single_tensor=True)
        shape = (norb.X.shape[0], 2) + SmallNORB.original_image_shape + (1, )
        expected_topo_tensor = norb.X.reshape(shape)
        # We loop to lower the peak memory usage
        for i in range(topo_tensor.shape[0]):
            assert numpy.all(topo_tensor[i] == expected_topo_tensor[i])

        # Get a topological view as two "(b, 0, 1, c)" tensors
        topo_tensors = norb.get_topological_view(single_tensor=False)
        expected_topo_tensors = tuple(expected_topo_tensor[:, i, ...]
                                      for i in range(2))

        for topo_tensor, expected_topo_tensor in safe_zip(
                topo_tensors, expected_topo_tensors):
            assert numpy.all(topo_tensor == expected_topo_tensor)
Ejemplo n.º 5
0
 def load_norb(args):
     if args.which_set in ('test', 'train'):
         return SmallNORB(args.which_set, True)
     else:
         norb_file = open(args.which_set)
         return pickle.load(norb_file)