-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhubconf.py
104 lines (75 loc) · 3.43 KB
/
hubconf.py
1
2
3
4
5
6
7
8
9
10
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from torch.hub import load_state_dict_from_url
from metrics.extractor.rangenet import build_rangenet as _build_rangenet
from metrics.extractor.rangenet import crf_rnn as _crf_rnn
from metrics.extractor.rangenet import knn as _knn
from metrics.extractor.rangenet import rangenet21 as _rangenet21
from metrics.extractor.rangenet import rangenet53 as _rangenet53
from utils.inference import setup_model as _setup_model
dependencies = ["torch", "torchvision", "numpy", "einops", "tqdm", "pydantic"]
# =================================================================================
# Pre-trained R2DM
# =================================================================================
def _get_r2dm_url(key: str) -> str:
return f"https://github.com/kazuto1011/r2dm/releases/download/weights/{key}.pth"
def pretrained_r2dm(config: str = "r2dm-h-kitti360-300k", ckpt: str = None, **kwargs):
"""
R2DM models proposed in "LiDAR Data Synthesis with Denoising Diffusion Probabilistic Models" https://arxiv.org/abs/2309.09256
Please refer to the project release page for available pre-trained weights: https://github.com/kazuto1011/r2dm/releases/tag/weights
Args:
config (str): Configuration string. (default: "r2dm-h-kitti360-300k")
ckpt (str): Path to a checkpoint file. If specified, config will be ignored. (default: None)
**kwargs: Additional keyword arguments for model setup.
Returns:
tuple: A tuple of the model, LiDAR utilities, and a configuration dict.
"""
if ckpt is None:
ckpt = load_state_dict_from_url(_get_r2dm_url(config), map_location="cpu")
ddpm, lidar_utils, cfg = _setup_model(ckpt, **kwargs)
return ddpm, lidar_utils, cfg
# =================================================================================
# Bonus! RangeNet++ ported from https://github.com/PRBonn/lidar-bonnetal
# =================================================================================
def rangenet(url_or_file: str, **kwargs):
"""
Dynamic building of RangeNet-21/53
Args:
url_or_file (str): URL or local path to the checkpoint file (*.tar.gz).
Returns:
tuple: A tuple of the model and a preprocessing function.
"""
model, preprocess = _build_rangenet(url_or_file, **kwargs)
return model, preprocess
def rangenet21(weights: str = "SemanticKITTI_64x2048", **kwargs):
"""
RangeNet-21 pre-trained on SemanticKITTI.
Args:
weights (str): "SemanticKITTI_64x2048"
Returns:
tuple: A tuple of the model and a preprocessing function.
"""
model, preprocess = _rangenet21(weights, **kwargs)
return model, preprocess
def rangenet53(weights: str = "SemanticKITTI_64x2048", **kwargs):
"""
RangeNet-53 pre-trained on SemanticKITTI.
Args:
weights (str): "SemanticKITTI_64x2048", "SemanticKITTI_64x1024", "SemanticKITTI_64x512"
Returns:
tuple: A tuple of the model and a preprocessing function.
"""
model, preprocess = _rangenet53(weights, **kwargs)
return model, preprocess
def knn(num_classes: int = 20, **kwargs):
"""
KNN post-processing for RangeNet++.
Args:
num_classes (int): Number of classes (default: 20)
"""
return _knn(num_classes, **kwargs)
def crf_rnn(num_classes: int = 20, **kwargs):
"""
CRF-RNN post-processing for RangeNet++.
Args:
num_classes (int): Number of classes (default: 20)
"""
return _crf_rnn(num_classes, **kwargs)