Exemplo n.º 1
0
def convert_h5(data_dir,
               label_dir,
               data_split,
               train_volumes,
               test_volumes,
               f,
               data_id,
               remap_config='Neo',
               orientation=preprocessor.ORIENTATION['coronal']):
    # Data splitting
    if data_split:
        train_file_paths, test_file_paths = apply_split(
            data_split, data_dir, label_dir)
    elif train_volumes and test_volumes:
        train_file_paths = du.load_file_paths(data_dir, label_dir, data_id,
                                              train_volumes)
        test_file_paths = du.load_file_paths(data_dir, label_dir, data_id,
                                             test_volumes)
    else:
        raise ValueError(
            'You must either provide the split ratio or a train, train dataset list'
        )

    reduce_slices = False  #True  #BORIS

    print("Train dataset size: %d, Test dataset size: %d" %
          (len(train_file_paths), len(test_file_paths)))
    # loading,pre-processing and writing train data
    print("===Train data===")
    data_train, label_train, class_weights_train, weights_train, _ = du.load_dataset(
        train_file_paths,
        orientation,
        remap_config=remap_config,
        return_weights=True,
        reduce_slices=reduce_slices,  #BORIS
        remove_black=True)

    _write_h5(data_train,
              label_train,
              class_weights_train,
              weights_train,
              f,
              mode='train')

    # loading,pre-processing and writing test data
    print("===Test data===")
    data_test, label_test, class_weights_test, weights_test, _ = du.load_dataset(
        test_file_paths,
        orientation,
        remap_config=remap_config,
        return_weights=True,
        reduce_slices=reduce_slices,  #BORIS
        remove_black=True)

    _write_h5(data_test,
              label_test,
              class_weights_test,
              weights_test,
              f,
              mode='test')
Exemplo n.º 2
0
def apply_split(data_split, data_dir, label_dir):
    file_paths = du.load_file_paths(data_dir, label_dir)
    print("Total no of volumes to process : %d" % len(file_paths))
    train_ratio, test_ratio = data_split.split(",")
    train_len = int((int(train_ratio) / 100) * len(file_paths))
    train_idx = np.random.choice(len(file_paths), train_len, replace=False)
    test_idx = np.array(
        [i for i in range(len(file_paths)) if i not in train_idx])
    train_file_paths = [file_paths[i] for i in train_idx]
    test_file_paths = [file_paths[i] for i in test_idx]
    return train_file_paths, test_file_paths