예제 #1
0
 def test_simple(self):
     channels = 12
     height = 3
     width = 5
     bottom = Array.zeros((5, channels, height, width), np.int32)
     for n in range(5):
         for c in range(channels):
             bottom[n, c] = Array.array([[1, 2, 5, 2, 3], [9, 4, 1, 4, 8],
                                         [1, 2, 5, 2, 3]]).astype(np.int32)
     param = self.layer[5]
     param.pooling_param.kernel_size = 2
     param.pooling_param.stride = 1
     layer = PoolingLayer(param)
     actual_shape = layer.get_top_shape(bottom)
     actual = Array.zeros(actual_shape, np.int32)
     layer.setup(bottom, actual)
     layer.forward(bottom, actual)
     for n in range(5):
         for c in range(channels):
             np.testing.assert_array_equal(
                 actual[n, c],
                 np.array([[9, 5, 5, 8], [9, 5, 5, 8]]).astype(np.int32))
     bottom = Array.zeros_like(bottom)
     for n in range(5):
         for c in range(channels):
             actual[n, c] = Array.array([[1, 1, 1, 1],
                                         [1, 1, 1, 1]]).astype(np.int32)
     layer.backward(bottom, actual)
     for n in range(5):
         for c in range(channels):
             np.testing.assert_array_equal(
                 bottom[n, c],
                 np.array([[0, 0, 2, 0, 0], [2, 0, 0, 0, 2],
                           [0, 0, 2, 0, 0]]).astype(np.int32))
예제 #2
0
        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            C = dot(A.transpose(), B.transpose())

            return C
예제 #3
0
        def matrix_mult_sample():

            B = Array.array([[10, 3], [7, 4]])

            # transposition
            A = Array.array([[1, 2], [3, 4]])
            A = Array.transpose(A)
            C = dot(B, A)
            return C
예제 #4
0
        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            M = Array.transpose(A)

            M = Array.array([[1, 1], [3, 0]])

            C = dot(M, B)
            return C
예제 #5
0
        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            # double transposition
            A = Array.transpose(A)
            B = Array.transpose(B)

            C = dot(A, B)
            return C
예제 #6
0
        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            A = Array.transpose(A)
            B = Array.transpose(B)

            C = dot(A, B)

            # the double transpose in place after the dot call
            A = Array.transpose(A)
            B = Array.transpose(B)

            return C
예제 #7
0
        def matrix_mult_sample():

            A = Array.array([[1, 2], [3, 4]])
            B = Array.array([[10, 3], [7, 4]])

            M = Array.transpose(A)
            N = Array.transpose(B)

            C = dot(M, N)

            # the double assignment after the dot call
            M = Array.array([[1, 1], [3, 0]])
            N = Array.array([[1, 0], [7, 0]])

            return C
예제 #8
0
 def test_gradient(self):
     for kernel_h in range(3, 5):
         for kernel_w in range(3, 5):
             channels = 12
             height = 3
             width = 5
             bottom = Array.zeros((5, channels, height, width), np.int32)
             bottom_diff = Array.zeros_like(bottom)
             for n in range(5):
                 for c in range(channels):
                     bottom[n, c] = Array.array([[1, 2, 5, 2, 3],
                                                 [9, 4, 1, 4, 8],
                                                 [1, 2, 5, 2,
                                                  3]]).astype(np.int32)
             param = self.layer[5]
             param.pooling_param.kernel_h = kernel_h
             param.pooling_param.kernel_w = kernel_w
             param.pooling_param.stride = 2
             param.pooling_param.pad = 1
             layer = PoolingLayer(param)
             top_shape = layer.get_top_shape(bottom)
             top = Array.zeros(top_shape, np.int32)
             top_diff = Array.zeros_like(top)
             checker = GradientChecker(1e-4, 1e-2)
             checker.check_gradient_exhaustive(layer, bottom, bottom_diff,
                                               top, top_diff)
예제 #9
0
 def test_gradient(self):
     for kernel_h in range(3, 5):
         for kernel_w in range(3, 5):
             channels = 12
             height = 3
             width = 5
             bottom = Array.zeros((5, channels, height, width), np.int32)
             bottom_diff = Array.zeros_like(bottom)
             for n in range(5):
                 for c in range(channels):
                     bottom[n, c] = Array.array(
                         [[1, 2, 5, 2, 3],
                          [9, 4, 1, 4, 8],
                          [1, 2, 5, 2, 3]]).astype(np.int32)
             param = self.layer[5]
             param.pooling_param.kernel_h = kernel_h
             param.pooling_param.kernel_w = kernel_w
             param.pooling_param.stride = 2
             param.pooling_param.pad = 1
             layer = PoolingLayer(param)
             top_shape = layer.get_top_shape(bottom)
             top = Array.zeros(top_shape, np.int32)
             top_diff = Array.zeros_like(top)
             checker = GradientChecker(1e-4, 1e-2)
             checker.check_gradient_exhaustive(layer, bottom, bottom_diff,
                                               top, top_diff)
    def test_range_of_fifty(self):

        TOTAL_SIZE = 50
        height = 25             # height: (number of rows, or column length)
        width = 2               # width: (number of columns, or row length)
        pfov_length = 5

        # Creating a sample dataset for the SEJITS tests
        sejits_block_set = Array.array(list(range(TOTAL_SIZE)))
        sejits_block_set = sejits_block_set.reshape(height, width)
        sejits_block_set = sejits_block_set.astype(np.float32)

        # Creating a sample dataset for the Python tests
        pyop_block_set = np.array(list(range(TOTAL_SIZE)))
        pyop_block_set = pyop_block_set.reshape(height, width)
        pyop_block_set = pyop_block_set.astype(np.float32)

        python_result = dcRemPython(pyop_block_set.flatten(1), height, pfov_length).astype(
            np.float32).reshape((height, width), order='F').astype(np.int32)
        sejits_result = np.array(
            dcRemSejits(sejits_block_set.flatten(), pfov_length, height)).astype(
            np.float32).reshape((height, width)).astype(np.int32)

        print sejits_result

        self._check(python_result, sejits_result)
def main():

    # Smaller Dataset
    h = 1200  # height (number of rows, or column length)
    w = 1000  # width (number of columns, or row length)
    TOTAL_SIZE = h * w
    length = 100

    # Larger Dataset
    # TOTAL_SIZE = 500000000
    # h = 500000             # height (number of rows, or column length)
    # w = 1000               # width (number of columns, or row length)
    # length = 5000

    block_set = Array.array(list(range(TOTAL_SIZE)))  # sample dataset
    block_set = block_set.reshape(h, w)
    block_set = block_set.astype(np.float32)

    start_time = time.time()
    result = np.array(dcRemoval(block_set.flatten(), length, h).reshape(h, w))
    time_total = time.time() - start_time

    print "SEJITS dcRemoval Time: ", time_total, " seconds"
    print "RESULT: ", result
    return result
예제 #12
0
 def test_simple(self):
     channels = 12
     height = 3
     width = 5
     bottom = Array.zeros((5, channels, height, width), np.int32)
     for n in range(5):
         for c in range(channels):
             bottom[n, c] = Array.array(
                 [[1, 2, 5, 2, 3],
                  [9, 4, 1, 4, 8],
                  [1, 2, 5, 2, 3]]).astype(np.int32)
     param = self.layer[5]
     param.pooling_param.kernel_size = 2
     param.pooling_param.stride = 1
     layer = PoolingLayer(param)
     actual_shape = layer.get_top_shape(bottom)
     actual = Array.zeros(actual_shape, np.int32)
     layer.setup(bottom, actual)
     layer.forward(bottom, actual)
     for n in range(5):
         for c in range(channels):
             np.testing.assert_array_equal(
                 actual[n, c],
                 np.array([
                     [9, 5, 5, 8],
                     [9, 5, 5, 8]
                 ]).astype(np.int32))
     bottom = Array.zeros_like(bottom)
     for n in range(5):
         for c in range(channels):
             actual[n, c] = Array.array(
                 [[1, 1, 1, 1],
                  [1, 1, 1, 1]]).astype(np.int32)
     layer.backward(bottom, actual)
     for n in range(5):
         for c in range(channels):
             np.testing.assert_array_equal(
                 bottom[n, c],
                 np.array([[0, 0, 2, 0, 0],
                           [2, 0, 0, 0, 2],
                           [0, 0, 2, 0, 0]]).astype(np.int32))
예제 #13
0
    def forward(self, bottom_data, bottom_label, top):
        accuracy = 0
        data = bottom_data
        label = bottom_label
        dim = np.prod(data.shape) / data.shape[0]

        # Perform a partial sort to find top_k
        for i in range(data.shape[0]):
            vec = Array.array([[data[i * dim + j], j] for j in range(dim)])
            vec.partition((0, self.top_k))

            # If label is in top_k increase accuracy
            for k in range(self.top_k):
                if vec[k][1] == label[i]:
                    accuracy += 1

        top[0] = accuracy / data.shape[0]
예제 #14
0
    def forward(self, bottom_data, bottom_label, top):
        accuracy = 0
        data = bottom_data
        label = bottom_label
        dim = np.prod(data.shape) / data.shape[0]

        # Perform a partial sort to find top_k
        for i in range(data.shape[0]):
            vec = Array.array(
                [[data[i * dim + j], j] for j in range(dim)])
            vec.partition((0, self.top_k))

            # If label is in top_k increase accuracy
            for k in range(self.top_k):
                if vec[k][1] == label[i]:
                    accuracy += 1

        top[0] = accuracy / data.shape[0]
    def test_range_of_ten(self):

        TOTAL_SIZE = 10
        height = 10             # height: (number of rows, or column length)
        width = 1               # width: (number of columns, or row length)
        pfov_length = 5

        # Creating a sample dataset for the SEJITS tests
        sejits_block_set = Array.array(list(range(TOTAL_SIZE)))
        sejits_block_set = sejits_block_set.reshape(height, width)
        sejits_block_set = sejits_block_set.astype(np.float32)

        # Creating a sample dataset for the Python tests
        pyop_block_set = np.array(list(range(TOTAL_SIZE)))
        pyop_block_set = pyop_block_set.reshape(height, width)
        pyop_block_set = pyop_block_set.astype(np.float32)

        python_result = dcRemPython(pyop_block_set, height, pfov_length)
        sejits_result = np.array(dcRemSejits(sejits_block_set, pfov_length, height))

        self._check(python_result, sejits_result)
예제 #16
0
 def matrix_mult_sample():
     A = Array.array([[1, 0], [0, 1]])
     B = Array.array([[1, 1], [1, 1]])
     C = dot(A, B)
     return C