cvt.common
A suite of common utility functions.
This module includes general utility functions used by the sub-packages of the CVTkit library.
build_coords_list(H, W, batch_size, device)
Constructs an batched index list of pixel coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
H
|
int
|
Height of the pixel grid. |
required |
W
|
int
|
Width of the pixel grid. |
required |
batch_size
|
int
|
Number of batches. |
required |
device
|
str
|
GPU device identifier. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The index list of shape [batch_size, H*W, 2] |
Source code in src/cvt/common.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
cosine_similarity(t1, t2)
Computes the cosine similarity between two tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t1
|
Tensor
|
First tensor. |
required |
t2
|
Tensor
|
Second tensor. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The cosine similarity between the two tensors. |
Source code in src/cvt/common.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
groupwise_correlation(t1, t2, num_groups)
Computes the Group-Wise Correlation (GWC) between two tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t1
|
Tensor
|
First tensor. |
required |
t2
|
Tensor
|
Second tensor. |
required |
num_groups
|
int
|
Number of groups. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The Group-Wise Correlation (GWC) between the two tensors. |
Source code in src/cvt/common.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
laplacian_pyramid(image)
Computes the Laplacian pyramid of an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Tensor
|
2D map to compute Laplacian over. |
required |
tau
|
Laplacian region threshold. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The map of the Laplacian regions. |
Source code in src/cvt/common.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
laplacian_pyramid_th(image, tau)
Computes the Laplacian pyramid of an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Tensor
|
2D map to compute Laplacian over. |
required |
tau
|
float
|
Laplacian region threshold. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The map of the Laplacian regions. |
Source code in src/cvt/common.py
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 105 106 |
|
non_zero_std(maps, device, dim=1, keepdim=False)
Computes the standard deviation of all non-zero values in an input Tensor along the given dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
maps
|
Tensor
|
|
required |
device
|
str
|
|
required |
keepdim
|
bool
|
|
False
|
Returns:
Type | Description |
---|---|
Tensor
|
The standard deviation of the non-zero elements of the input map. |
Source code in src/cvt/common.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
parameters_count(net, name, do_print=True)
Parameters:
Returns:
Source code in src/cvt/common.py
240 241 242 243 244 245 246 247 248 249 250 251 |
|
print_gpu_mem()
Prints the current unallocated memory of the GPU.
Source code in src/cvt/common.py
253 254 255 256 257 258 259 260 |
|
round_nearest(num, decimal=0)
Rounds a floating point number to the nearest decimal place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
float
|
Float to be rounded. |
required |
decimal
|
int
|
Decimal place to round to. |
0
|
Returns:
Type | Description |
---|---|
int
|
The given number rounded to the nearest decimal place. |
Examples:
>>> round_nearest(11.1)
11
>>> round_nearest(15.7)
16
>>> round_nearest(2.5)
2
>>> round_nearest(3.5)
3
>>> round_nearest(14.156, 1)
14.2
>>> round_nearest(15.156, 1)
15.2
>>> round_nearest(15.156, 2)
15.16
Source code in src/cvt/common.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
scale_camera(cam, scale=1.0)
Scales a camera intrinsic parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cam
|
ndarray
|
Input camera to be scaled. |
required |
scale
|
float
|
Scale factor. |
1.0
|
Returns:
Type | Description |
---|---|
ndarray
|
The scaled camera. |
Source code in src/cvt/common.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
scale_image(image, scale=1.0, interpolation='linear')
Scales an input pixel grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
Input image to be scaled. |
required |
scale
|
float
|
Scale factor. |
1.0
|
interpolation
|
str
|
Interpolation technique to be used. |
'linear'
|
Returns:
Type | Description |
---|---|
ndarray
|
The scaled image. |
Source code in src/cvt/common.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
scale_mvs_data(depths, confs, cams, scale=1.0, interpolation='linear')
Scales input depth maps, confidence maps, and cameras.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
depths
|
ndarray
|
Input depth maps to be scaled. |
required |
confs
|
ndarray
|
Input confidence maps to be scaled. |
required |
cams
|
ndarray
|
Input cameras to be scaled |
required |
scale
|
float
|
Scale factor. |
1.0
|
interpolation
|
str
|
Interpolation technique. |
'linear'
|
Returns:
Name | Type | Description |
---|---|---|
scaled_depths |
ndarray
|
The scaled depth maps. |
scaled_confs |
ndarray
|
The scaled confidence maps. |
cams |
ndarray
|
The scaled cameras. |
Source code in src/cvt/common.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
set_random_seed(seed)
Parameters:
Returns:
Source code in src/cvt/common.py
354 355 356 357 358 359 360 361 362 363 |
|
to_gpu(data, device)
Loads a dictionary of elements onto the GPU device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
Dictionary to be loaded. |
required |
device
|
str
|
GPU device identifier. |
required |
Source code in src/cvt/common.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|