Common
A suite of common utility functions.
This module includes general utility functions used by the sub-packages of the CVTkit library.
This module contains the following functions:
non_zero_std(maps, device, dim, keepdim)
- Computes the standard deviation of all non-zero values in an input Tensor along the given dimension.print_gpu_mem()
- Prints the current unallocated memory of the GPU.round_nearest(num, decimal=0)
- Rounds a floating point number to the nearest decimal place.scale_image(image, scale, interpolation)
- Scales an input pixel grid.
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 |
torch.Tensor
|
required | |
device |
str
|
required | |
keepdim |
bool
|
False
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
The standard deviation of the non-zero elements of the input map. |
Source code in 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 |
|
print_gpu_mem()
Prints the current unallocated memory of the GPU.
Source code in cvt/common.py
133 134 135 136 137 138 139 140 |
|
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 cvt/common.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
scale_camera(cam, scale=1.0)
Scales a camera intrinsic parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cam |
np.ndarray
|
Input camera to be scaled. |
required |
scale |
float
|
Scale factor. |
1.0
|
Returns:
Type | Description |
---|---|
np.ndarray
|
The scaled camera. |
Source code in cvt/common.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
scale_image(image, scale=1.0, interpolation='linear')
Scales an input pixel grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.ndarray
|
Input image to be scaled. |
required |
scale |
float
|
Scale factor. |
1.0
|
interpolation |
str
|
Interpolation technique to be used. |
'linear'
|
Returns:
Type | Description |
---|---|
np.ndarray
|
The scaled image. |
Source code in cvt/common.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
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 |
np.ndarray
|
Input depth maps to be scaled. |
required |
confs |
np.ndarray
|
Input confidence maps to be scaled. |
required |
cams |
np.ndarray
|
Input cameras to be scaled |
required |
scale |
float
|
Scale factor. |
1.0
|
interpolation |
str
|
Interpolation technique. |
'linear'
|
Returns:
Name | Type | Description |
---|---|---|
scaled_depths |
np.ndarray
|
The scaled depth maps. |
scaled_confs |
np.ndarray
|
The scaled confidence maps. |
cams |
np.ndarray
|
The scaled cameras. |
Source code in cvt/common.py
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 |
|
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 |
string
|
GPU device identifier. |
required |
Source code in cvt/common.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|