Exemplo n.º 1
0
def get_data():
    X = []
    y = []

    basePath = join(dir_path, "..", "common", "data", "GTSRB_subset_2")
    imageFileNamesClass1 = absolute_file_paths([join(basePath, "class1")])
    for imgPath in imageFileNamesClass1:
        X.append(io.imread(imgPath))
        y.append(0)

    imageFileNamesClass2 = absolute_file_paths([join(basePath, "class2")])
    for imgPath in imageFileNamesClass2:
        X.append(io.imread(imgPath))
        y.append(1)

    X = (X - np.min(X)) / np.max(X)
    y = to_categorical(y, 2)

    return X, y
Exemplo n.º 2
0
def save_test_data(test_path, test_targets_path, test_coords_path,
                   test_shape_path, orig_test_dir, orig_test_targets_dir):
    """Loads, formats, and re-saves test data from original directories."""
    print('in save_test_data')
    # Gets original data files.
    test_files = sorted(absolute_file_paths(orig_test_dir))
    test_targets_files = sorted(absolute_file_paths(orig_test_targets_dir))

    # Loads and preprocesses data.
    test, test_coords, test_shape = load_data(test_files)
    test_targets, _, _ = load_data(test_targets_files, norm=False)

    # Re-saves data in specified directories.
    np.save(test_path, test)
    np.save(test_targets_path, test_targets)
    with open(test_coords_path, "wb") as a, open(test_shape_path, "wb") as b:
        pickle.dump(test_coords, a)
        pickle.dump(test_shape, b)

    return test, test_targets, test_coords, test_shape
Exemplo n.º 3
0
def save_train_data(train_path, valid_path, train_targets_path,
                    valid_targets_path, orig_train_dir, orig_valid_dir,
                    orig_train_targets_dir, orig_valid_targets_dir):
    """Loads, formats, and re-saves train data from original directories."""
    print('in save_train_data')
    # Gets original data files.
    train_files = sorted(absolute_file_paths(orig_train_dir))
    valid_files = sorted(absolute_file_paths(orig_valid_dir))
    train_targets_files = sorted(absolute_file_paths(orig_train_targets_dir))
    valid_targets_files = sorted(absolute_file_paths(orig_valid_targets_dir))

    # Loads and preprocesses data.
    train, _, _ = load_data(train_files)
    valid, _, _ = load_data(valid_files)
    train_targets, _, _ = load_data(train_targets_files, norm=False)
    valid_targets, _, _ = load_data(valid_targets_files, norm=False)

    # Re-saves data in specified directories.
    np.save(train_path, train)
    np.save(valid_path, valid)
    np.save(train_targets_path, train_targets)
    np.save(valid_targets_path, valid_targets)

    return train, valid, train_targets, valid_targets