Exemplo n.º 1
0
def load_data():
    # Set seed
    seed = 123
    np.random.seed(seed)

    # Loading dataset
    print("Loading the whole dataset...")

    x_train, y_train = read_hoda_dataset(
        dataset_path='./DigitDB/Train 60000.cdb',
        images_height=32,
        images_width=32,
        one_hot=False,
        reshape=False)

    x_test, y_test = read_hoda_dataset(dataset_path='./DigitDB/Test 20000.cdb',
                                       images_height=32,
                                       images_width=32,
                                       one_hot=False,
                                       reshape=False)

    # concat to a whole dataset
    x, y = np.concatenate([x_train, x_test]), np.concatenate([y_train, y_test])

    # shuffle images
    idx = np.arange(x.shape[0])
    np.random.shuffle(idx)

    # set train and test size
    train_size = int(0.8 * x.shape[0])

    # selecting indices of train, test set
    train_idx = idx[:train_size]
    test_idx = idx[train_size:]

    x_train = x[train_idx]
    y_train = y[train_idx]

    x_test = x[test_idx]
    y_test = y[test_idx]

    x_train_rotated = rotate_transform(x_train, 30, 45)
    x_test_rotated = rotate_transform(x_test, 30, 45)

    x_train_rotated[x_train_rotated >= 0.5] = 1.
    x_train_rotated[x_train_rotated < 0.5] = 0.

    x_test_rotated[x_test_rotated >= 0.5] = 1.
    x_test_rotated[x_test_rotated < 0.5] = 0.

    return x_train, x_train_rotated, y_train, x_test, x_test_rotated, y_test
Exemplo n.º 2
0
def load_data():
    # Set seed
    seed = 123
    np.random.seed(seed)

    # Loading dataset
    print("Loading the whole dataset...")

    x_train, y_train = read_hoda_dataset(
        dataset_path='./DigitDB/Train 60000.cdb',
        images_height=32,
        images_width=32,
        one_hot=True,
        reshape=True)

    x_test, y_test = read_hoda_dataset(dataset_path='./DigitDB/Test 20000.cdb',
                                       images_height=32,
                                       images_width=32,
                                       one_hot=True,
                                       reshape=True)

    # concat to a whole dataset
    x, y = np.concatenate([x_train, x_test]), np.concatenate([y_train, y_test])

    # shuffle images
    idx = np.arange(x.shape[0])
    np.random.shuffle(idx)

    # set train and test size
    train_size = int(0.7 * x.shape[0])
    test_size = int(0.1 * x.shape[0])

    # selecting indices of train, val, test set
    train_idx = idx[:train_size]
    val_idx = idx[train_size:-test_size]
    test_idx = idx[-test_size:]

    x_train = x[train_idx]
    y_train = y[train_idx]

    x_val = x[val_idx]
    y_val = y[val_idx]

    x_test = x[test_idx]
    y_test = y[test_idx]

    return x_train, y_train, x_val, y_val, x_test, y_test