bm_points_alignment.py 2.28 KB
Newer Older
Patrick Labatut's avatar
Patrick Labatut committed
1
2
3
4
5
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
David Novotny's avatar
Umeyama  
David Novotny committed
6
7
8
9

from copy import deepcopy
from itertools import product

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
10
from fvcore.common.benchmark import benchmark
David Novotny's avatar
David Novotny committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from test_points_alignment import TestCorrespondingPointsAlignment, TestICP


def bm_iterative_closest_point() -> None:

    case_grid = {
        "batch_size": [1, 10],
        "dim": [3, 20],
        "n_points_X": [100, 1000],
        "n_points_Y": [100, 1000],
        "use_pointclouds": [False],
    }

    test_args = sorted(case_grid.keys())
    test_cases = product(*case_grid.values())
    kwargs_list = [dict(zip(test_args, case)) for case in test_cases]

    # add the use_pointclouds=True test cases whenever we have dim==3
    kwargs_to_add = []
    for entry in kwargs_list:
        if entry["dim"] == 3:
            entry_add = deepcopy(entry)
            entry_add["use_pointclouds"] = True
            kwargs_to_add.append(entry_add)
    kwargs_list.extend(kwargs_to_add)

    benchmark(
        TestICP.iterative_closest_point,
        "IterativeClosestPoint",
        kwargs_list,
        warmup_iters=1,
    )
David Novotny's avatar
Umeyama  
David Novotny committed
43
44
45
46
47
48
49
50
51
52


def bm_corresponding_points_alignment() -> None:

    case_grid = {
        "allow_reflection": [True, False],
        "batch_size": [1, 10, 100],
        "dim": [3, 20],
        "estimate_scale": [True, False],
        "n_points": [100, 10000],
Roman Shapovalov's avatar
Roman Shapovalov committed
53
        "random_weights": [False, True],
David Novotny's avatar
Umeyama  
David Novotny committed
54
55
56
57
        "use_pointclouds": [False],
    }

    test_args = sorted(case_grid.keys())
David Novotny's avatar
David Novotny committed
58
    test_cases = product(*case_grid.values())
David Novotny's avatar
Umeyama  
David Novotny committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    kwargs_list = [dict(zip(test_args, case)) for case in test_cases]

    # add the use_pointclouds=True test cases whenever we have dim==3
    kwargs_to_add = []
    for entry in kwargs_list:
        if entry["dim"] == 3:
            entry_add = deepcopy(entry)
            entry_add["use_pointclouds"] = True
            kwargs_to_add.append(entry_add)
    kwargs_list.extend(kwargs_to_add)

    benchmark(
        TestCorrespondingPointsAlignment.corresponding_points_alignment,
        "CorrespodingPointsAlignment",
        kwargs_list,
        warmup_iters=1,
    )
Christoph Lassner's avatar
Christoph Lassner committed
76
77
78
79
80


if __name__ == "__main__":
    bm_corresponding_points_alignment()
    bm_iterative_closest_point()