Utilities
- fvdb.utils.fvdbCudaExtension(name: str, sources: Sequence[str], *args: Any, **kwargs: Any) Extension[source]
Utility function for creating pytorch extensions that depend on fvdb. You then have access to all fVDB’s internal headers to program with. Example usage:
from fvdb.utils import FVDBExtension ext = FVDBExtension( name='my_extension', sources=['my_extension.cpp'], extra_compile_args={'cxx': ['-std=c++17']}, libraries=['mylib'], )
- Parameters:
name (str) – The name of the extension.
sources (Sequence[str]) – The list of source files.
args (list[Any]) – Other arguments to pass to
torch.utils.cpp_extension.CppExtension().kwargs (dict) – Other keyword arguments to pass to
torch.utils.cpp_extension.CppExtension().
- Returns:
cpp_extension (setuptools.Extension) – to build a PyTorch C++ extension that depends on fVDB.
fvdb.utils.metrics
- fvdb.utils.metrics.psnr(noisy_images: Tensor, ground_truth_images: Tensor, max_value: float = 1.0, reduction: Literal['none', 'mean', 'sum'] = 'mean') Tensor[source]
Compute the Peak-Signal-to-Noise-Ratio (PSNR) ratio between two batches of images.
- Parameters:
noisy_images (torch.Tensor) – A batch of noisy images of shape
(B, C, H, W)ground_truth_images (torch.Tensor) – A batch of ground truth images of shape
(B, C, H, W)max_value (float) – The maximum possible value images computed with this loss can have. Default is 1.0.
reduction (Literal["none", "mean", "sum"]) – How to reduce over the batch dimension.
"sum"and"mean"will add-up and average the losses across the batch respectively."none"will return each loss as a separate entry in the tensor. Default is"mean".
- Returns:
psnr (torch.Tensor) – The PSNR between the two images. If reduction is not “none”, the result will be reduced over the batch dimension (i.e. will be a single scalar), otherwise it will be a tensor of shape
(B,).
- fvdb.utils.metrics.ssim(img1: Tensor, img2: Tensor, padding: Literal['same', 'valid'] = 'same', train: bool = True) Tensor[source]
Compute the Structural Similarity Index (SSIM) between two images.
- Parameters:
img1 (torch.Tensor) – A batch of images of shape
(B, C, H, W)img2 (torch.Tensor) – A batch of images of shape
(B, C, H, W)padding (str) – The padding to use for the images (
"same"or"valid"). Default is"same".train (bool) – Whether or not to compute the gradients through the SSIM loss. Default is
True.
- Returns:
ssim (torch.Tensor) – The average SSIM between each image over the batch.