示例#1
0
def get_cifar10_date_batches(batch_size_train = 512, batch_size_test = 512, transforms = [Crop(32, 32), FlipLR(), Cutout(8, 8)]):
    CIAFR10_DATA_DIR = './data'
    dataset_10 = cifar10(root = CIAFR10_DATA_DIR)
    train_set_10 = list(zip(transpose(normalise(pad(dataset_10['train']['data'], 4))), dataset_10['train']['labels']))
    test_set_10 = list(zip(transpose(normalise(dataset_10['test']['data'])), dataset_10['test']['labels']))
    train_batches_cifar10 = Batches(Transform(train_set_10, transforms), batch_size_train, shuffle=True, 
                            set_random_choices=True, drop_last=True)
    test_batches_cifar10 = Batches(test_set_10, batch_size_test, shuffle=False, drop_last=False)
    return train_batches_cifar10, test_batches_cifar10
示例#2
0
def get_cifar100_date_batches(batch_size = 512, transforms = [Crop(32, 32), FlipLR(), Cutout(8, 8)]):
    CIAFR100_DATA_DIR = './data'
    dataset_100 = cifar100(root = CIAFR100_DATA_DIR)
    train_set_100 = list(zip(transpose(normalise(pad(dataset_100['train']['data'], 4), mean=[0.4914, 0.4822, 0.4465], std=[0.2675, 0.2565, 0.2761])), dataset_100['train']['labels']))
    test_set_100 = list(zip(transpose(normalise(dataset_100['test']['data'], mean=[0.4914, 0.4822, 0.4465], std=[0.2675, 0.2565, 0.2761])), dataset_100['test']['labels']))
    train_batches_cifar100 = Batches(Transform(train_set_100, transforms), batch_size, shuffle=True, 
                            set_random_choices=True, drop_last=True)
    test_batches_cifar100 = Batches(test_set_100, batch_size, shuffle=False, drop_last=False)
    return train_batches_cifar100, test_batches_cifar100
示例#3
0
def preprocess(experiment, dataset):
    with timed("Preprocessing training data"):
        train_set = list(
            zip(transpose(normalise(pad(dataset['train']['data'], 4))),
                dataset['train']['labels']))
    with timed("Preprocessing test data"):
        test_set = list(
            zip(transpose(normalise(dataset['test']['data'])),
                dataset['test']['labels']))

    return train_set, test_set
示例#4
0
    def normal_to_world(self, normal):
        normal = multiply_tuple(transpose(self.__inverse_transform), normal)
        normal[3] = 0
        normal = normalize(normal)

        if self.parent:
            normal = self.parent.normal_to_world(normal)

        return normal
示例#5
0
def main():
    print("What happens when you invert the identity matrix?")
    a = identity_matrix()
    print(inverse(a))

    print()
    print("What do you get when you multiply a matrix by its inverse?")
    a = identity_matrix()
    a[1][0] = 2
    a[0][3] = -5
    b = multiply_matrix(a, inverse(a))
    print(b)

    print()
    print(
        "Is there any difference between the inverse of the transpose of a matrix, and the transpose of the inverse?"
    )
    c = inverse(transpose(a))
    d = transpose(inverse(a))
    print(c)
    print(d)

    print()
    print(
        "Remember how multiplying the identity matrix by a tuple gives you the tuple, unchanged?"
    )
    t = tuple_4d(5, 4, 3, 1)
    i = identity_matrix()
    c = multiply_tuple(i, t)
    print(c)

    print()
    print(
        "Now, try changing any single element of the identity matrix to a different number, and then multiplying it by a tuple. What happens to the tuple?"
    )
    i[1][1] = 2
    i[2][2] = 3
    c = multiply_tuple(i, t)
    print(c)
def step_impl(context):
    expected = matrix(4, 4)
    for r in range(4):
        for c in range(4):
            expected[r][c] = float(context.table[r][c])
    assert transpose(context.a) == expected
def step_impl(context):
    context.a = transpose(identity_matrix())