piqa.tv#
Total Variation (TV)
This module implements the TV in PyTorch.
Wikipedia
https://wikipedia.org/wiki/Total_variation
Functions#
Returns the TV of \(x\). |
Classes#
Measures the TV of an input. |
Descriptions#
- piqa.tv.tv(x, norm='L1')#
Returns the TV of \(x\).
With
'L1'
,\[\text{TV}(x) = \sum_{i, j} \left| x_{i+1, j} - x_{i, j} \right| + \left| x_{i, j+1} - x_{i, j} \right|\]Alternatively, with
'L2'
,\[\text{TV}(x) = \left( \sum_{c, i, j} (x_{c, i+1, j} - x_{c, i, j})^2 + (x_{c, i, j+1} - x_{c, i, j})^2 \right)^{\frac{1}{2}}\]- Parameters:
- Returns:
The TV tensor, \((*,)\).
- Return type:
Example
>>> x = torch.rand(5, 3, 256, 256) >>> l = tv(x) >>> l.shape torch.Size([5])
- class piqa.tv.TV(reduction='mean', **kwargs)#
Measures the TV of an input.
- Parameters:
Example
>>> criterion = TV() >>> x = torch.rand(5, 3, 256, 256, requires_grad=True) >>> l = criterion(x) >>> l.shape torch.Size([]) >>> l.backward()