Skip to content

Commit

Permalink
Enhancement: Added interface for GMSD and Multi-Scale GMSD (#151)
Browse files Browse the repository at this point in the history
* enh(gmsd): added functions to calculate GMSD and MS-GMSD

* enh(gmsd): hit 100% coverage

* enh(gmsd): Made changes to align the GMSD with MATLAB version
- tests to validate values with MATLAB results
- changed the valid colour transfer of the images before any pooling
- changes proposed by @zalajd

* enh(gmsd): changed the name of the constant to match the paper

* enh(ci): changes proposed by @snk4tr
  • Loading branch information
denproc authored Jul 24, 2020
1 parent f2c42cb commit 5ec2757
Show file tree
Hide file tree
Showing 4 changed files with 378 additions and 206 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ By default input images are normalized with ImageNet statistics before forwardin
This is port of MATLAB version from the authors of original paper.
It can be used both as a measure and as a loss function. In any case it should me minimized.
Usually values of GMSD lie in [0, 0.35] interval.

To compute GMSD as a measure, use lower case function from the library:
```python
import torch
from piq import gmsd

prediction = torch.rand(3, 3, 256, 256)
target = torch.rand(3, 3, 256, 256)
gmsd: torch.Tensor = gmsd(prediction, target, data_range=1.)
```

In order to use GMSD as a loss function, use corresponding PyTorch module:
```python
import torch
from piq import GMSDLoss
Expand Down Expand Up @@ -384,11 +396,25 @@ Now LPIPS is supported only for VGG16 model. If you need other models, check [or

<!-- MultiScale GMSD EXAMPLES -->
<details>
<summary>MultiScale GMSD (MS-GMSD)</summary>
<summary>Multi-Scale GMSD (MS-GMSD)</summary>
<p>

It can be used both as a measure and as a loss function. In any case it should me minimized.
By defualt scale weights are initialized with values from the paper. You can change them by passing a list of 4 variables to `scale_weights` argument during initialization. Both GMSD and MS-GMSD computed for greyscale images, but to take contrast changes into account authors propoced to also add chromatic component. Use flag `chromatic` to use MS-GMSDc version of the loss
By defualt scale weights are initialized with values from the paper. You can change them by passing a list of 4 variables to `scale_weights` argument during initialization. Both GMSD and MS-GMSD computed for greyscale images, but to take contrast changes into account authors propoced to also add chromatic component. Use flag `chromatic` to use MS-GMSDc version of the loss.

Note that input tensors should contain images with height and width equal `2 ** number_of_scales + 1` at least.

To compute Multi-Scale GMSD as a measure, use lower case function from the library:
```python
import torch
from piq import multi_scale_gmsd

prediction = torch.rand(3, 3, 256, 256)
target = torch.rand(3, 3, 256, 256)
multi_scale_gmsd: torch.Tensor = multi_scale_gmsd(prediction, target, data_range=1.)
```

In order to use Multi-Scale GMSD as a loss function, use corresponding PyTorch module:
```python
import torch
from piq import MultiScaleGMSDLoss
Expand Down
2 changes: 1 addition & 1 deletion piq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .fid import FID
from .kid import KID
from .tv import TVLoss, total_variation
from .gmsd import GMSDLoss, MultiScaleGMSDLoss
from .gmsd import gmsd, multi_scale_gmsd, GMSDLoss, MultiScaleGMSDLoss
from .gs import GS
from .isc import IS, inception_score
from .vif import VIFLoss, vif_p
Expand Down
Loading

0 comments on commit 5ec2757

Please sign in to comment.