コード例 #1
0
def main(args):
    """
    This method starts the rfd-discovery algorithm. It takes various command line parameters like a valid dataset's
    path, the division on rhs and lhs needed and more. See the section Usage of the README for
    more informations about the available parameters. If the user does not give a valid sequence of
    parameters, the program will end and print on the standard output a message with the required
    format to run the program.
    :param args: list of parameters given as input
    :type args: list
    """
    c_sep, csv_file, has_header, semantic, has_dt, missing, index_col, human = extract_args(args)
    try:
        check_correctness(has_dt, hss, index_col)
    except getopt.GetoptError as gex:
        usage()
        print(str(gex))
        sys.exit(1)
    except AssertionError as aex:
        usage()
        print(str(aex))
        sys.exit(1)

    if hss is None:
        usage()
    if isinstance(hss, list):
        with ut.timeit_context("Whole time"):
            with ut.timeit_context("Distance time"):
                if isinstance(has_header, int) and not has_header:
                    diff_mtx = DiffMatrix(csv_file,
                                          sep=c_sep,
                                          index_col=index_col,
                                          semantic=semantic,
                                          missing=missing,
                                          datetime=has_dt)
                else:
                    diff_mtx = DiffMatrix(csv_file,
                                          sep=c_sep,
                                          first_col_header=has_header,
                                          semantic=semantic,
                                          index_col=index_col,
                                          missing=missing,
                                          datetime=has_dt)
            for combination in hss:
                comb_dist_mtx = diff_mtx.split_sides(combination)
                with ut.timeit_context("RFD Discover time for {}".format(str(combination))):
                    nd = RFDDiscovery(comb_dist_mtx)
                    if human:
                        print(combination)
                        print_human(nd.get_rfds(nd.standard_algorithm, combination))
                    else:
                        print(nd.get_rfds(nd.standard_algorithm, combination))
コード例 #2
0
ファイル: dataset_valid.py プロジェクト: mbilalai/kaggle-rsna
def test_augmentations(sample_num=12, aug_level=20):
    """Test augmentations on a single sample
    Args:
        sample_num: sample number from the dataset
        aug_level: augmentations level        
    """
    with timeit_context("load ds"):
        ds = DatasetValid(
            is_training=False, 
            meta_file= "stage_1_test_meta.csv", 
            debug=True, 
            img_size=224,
            augmentation_level=aug_level)
        # print and plot sample
        print(ds[sample_num])
        plt.figure()
        plt.imshow(ds[sample_num]["img"], cmap=plt.cm.gist_gray)
        for annot in ds[sample_num]["annot"]:
            p0 = annot[0:2]
            p1 = annot[2:4]
            plt.gca().add_patch(plt.Rectangle(p0, width=(p1 - p0)[0], height=(p1 - p0)[1], fill=False, edgecolor="r", linewidth=2))
        # plot augmented sample, 10 examples
        plt.figure()
        for i in range(10):
            sample = ds[sample_num]
            plt.imshow(sample["img"], cmap=plt.cm.gist_gray)
            for annot in sample["annot"]:
                p0 = annot[0:2]
                p1 = annot[2:4]
                plt.gca().add_patch(plt.Rectangle(p0, width=(p1 - p0)[0], height=(p1 - p0)[1], fill=False, edgecolor="r", linewidth=2))
            plt.show()
コード例 #3
0
def test_performance():
    """Test dataloder performance"""
    with timeit_context("load ds"):
        ds = DatasetAugs(fold=0, is_training=True, debug=False, img_size=224)

    dataloader_train = torch.utils.data.DataLoader(
        ds,
        num_workers=4,
        batch_size=16,
        shuffle=True,
        collate_fn=pytorch_retinanet.dataloader.collater2d)
    data_iter = tqdm(enumerate(dataloader_train), total=len(dataloader_train))

    with timeit_context("1000 batches:"):
        for iter_num, data in data_iter:
            if iter_num > 1000:
                break
コード例 #4
0
def main(args):
    """
    This method start the rfd-discovery algorithm. It takes various command line parameters like a valid dataset's
    path, the division on rhs and lhs needed and more. See the section Usage of the README for
    more information about the available parameters. If the user does not give a valid sequence of
    parameters, the program will end and print on the standard output a message with the required
    format to run the program.
    :param args: list of parameters given as input
    :type args: list
    """
    separator_character, csv_file, has_header, semantic, has_date_time, missing, index_column, human_readable = extract_args(
        args)
    print("\nCommand-Line Arguments:")
    print("-separator_character:", separator_character)
    print("-csv_file:", csv_file)
    print("-has_header:", has_header)
    print("-semantic:", semantic)
    print("-has_date_time:", has_date_time)
    print("-missing:", missing)
    print("-index_column:", index_column)
    print("-human_readable:", human_readable)
    print()

    try:
        check_correctness(has_date_time, half_sides_specifications,
                          index_column)
    except getopt.GetoptError as gex:
        usage()
        print(str(gex))
        sys.exit(1)
    except AssertionError as aex:
        usage()
        print(str(aex))
        sys.exit(1)

    if half_sides_specifications is None:
        usage()
    if isinstance(half_sides_specifications, list):
        with ut.timeit_context("Whole time"):
            with ut.timeit_context("Distance time"):
                if isinstance(has_header, int) and not has_header:
                    distance_matrix = DiffMatrix(csv_file,
                                                 sep=separator_character,
                                                 index_col=index_column,
                                                 semantic=semantic,
                                                 missing=missing,
                                                 datetime=has_date_time)
                else:  # has header
                    distance_matrix = DiffMatrix(csv_file,
                                                 sep=separator_character,
                                                 first_col_header=has_header,
                                                 semantic=semantic,
                                                 index_col=index_column,
                                                 missing=missing,
                                                 datetime=has_date_time)
            for combination in half_sides_specifications:
                combination_distance_matrix = distance_matrix.split_sides(
                    combination)
                with ut.timeit_context("RFD Discover time for {}".format(
                        str(combination))):
                    rfd_discovery = RFDDiscovery(combination_distance_matrix)
                    if human_readable:
                        print(combination)
                        print_human(
                            rfd_discovery.get_rfds(
                                rfd_discovery.standard_algorithm, combination))
                    else:
                        print(
                            rfd_discovery.get_rfds(
                                rfd_discovery.standard_algorithm, combination))