Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support SWD and MS-SSIM metrics #82

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

LeoXing1996
Copy link
Collaborator

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Support SWD and MS-SSIM.

Modification

As title.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@LeoXing1996 LeoXing1996 requested a review from ice-tong January 18, 2023 08:18
@LeoXing1996 LeoXing1996 self-assigned this Jan 18, 2023
@CLAassistant
Copy link

CLAassistant commented Jan 18, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@C1rN09 C1rN09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally good! Please also update api docs.

mmeval/metrics/ms_ssim.py Outdated Show resolved Hide resolved
mmeval/metrics/ms_ssim.py Show resolved Hide resolved
tests/test_metrics/test_swd.py Show resolved Hide resolved
mmeval/metrics/ms_ssim.py Outdated Show resolved Hide resolved
mmeval/metrics/swd.py Outdated Show resolved Hide resolved
mmeval/metrics/swd.py Outdated Show resolved Hide resolved
@LeoXing1996 LeoXing1996 force-pushed the leoxing/add-swd-and-ms-ssim branch from 6c17aa5 to dc0e23f Compare March 2, 2023 05:58
@LeoXing1996 LeoXing1996 requested a review from zhouzaida as a code owner March 2, 2023 05:58
@LeoXing1996 LeoXing1996 requested a review from C1rN09 March 2, 2023 06:27
mmeval/metrics/ms_ssim.py Outdated Show resolved Hide resolved
mmeval/metrics/ms_ssim.py Outdated Show resolved Hide resolved
mmeval/metrics/ms_ssim.py Outdated Show resolved Hide resolved
mmeval/metrics/ms_ssim.py Show resolved Hide resolved
mmeval/metrics/ms_ssim.py Outdated Show resolved Hide resolved
mmeval/metrics/ms_ssim.py Outdated Show resolved Hide resolved
mmeval/metrics/swd.py Outdated Show resolved Hide resolved
@LeoXing1996 LeoXing1996 force-pushed the leoxing/add-swd-and-ms-ssim branch from dc0e23f to fb3387e Compare March 8, 2023 11:11
@LeoXing1996 LeoXing1996 requested a review from C1rN09 March 8, 2023 11:41
@LeoXing1996 LeoXing1996 force-pushed the leoxing/add-swd-and-ms-ssim branch from b84f63f to cc9d889 Compare March 9, 2023 05:13
Copy link
Collaborator

@C1rN09 C1rN09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with 1 minor comment

mmeval/metrics/ms_ssim.py Outdated Show resolved Hide resolved
@LeoXing1996 LeoXing1996 requested a review from C1rN09 March 10, 2023 05:34
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@LeoXing1996 LeoXing1996 force-pushed the leoxing/add-swd-and-ms-ssim branch from 0095367 to 1f4675b Compare March 14, 2023 12:10
@LeoXing1996 LeoXing1996 requested a review from zhouzaida March 14, 2023 12:11
@LeoXing1996 LeoXing1996 requested a review from zhouzaida March 14, 2023 13:12
@zhouzaida
Copy link
Collaborator

Hi, have you verified the PR in mmediting?

Comment on lines +252 to +253
tuple: Pair containing the mean SSIM and contrast sensitivity
between `img1` and `img2`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tuple: Pair containing the mean SSIM and contrast sensitivity
between `img1` and `img2`.
tuple: Pair containing the mean SSIM and contrast sensitivity
between `img1` and `img2`.

Comment on lines +10 to +19
"""SWD (Sliced Wasserstein distance) metric. We calculate the SWD of two
sets of images in the following way. In every 'feed', we obtain the
Laplacian pyramids of every images and extract patches from the Laplacian
pyramids as descriptors. In 'summary', we normalize these descriptors along
channel, and reshape them so that we can use these descriptors to represent
the distribution of real/fake images. And we can calculate the sliced
Wasserstein distance of the real and fake descriptors as the SWD of the
real and fake images. Note that, as with the official implementation, we
multiply the result by 10 to prevent the value from being too small and to
facilitate comparison.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""SWD (Sliced Wasserstein distance) metric. We calculate the SWD of two
sets of images in the following way. In every 'feed', we obtain the
Laplacian pyramids of every images and extract patches from the Laplacian
pyramids as descriptors. In 'summary', we normalize these descriptors along
channel, and reshape them so that we can use these descriptors to represent
the distribution of real/fake images. And we can calculate the sliced
Wasserstein distance of the real and fake descriptors as the SWD of the
real and fake images. Note that, as with the official implementation, we
multiply the result by 10 to prevent the value from being too small and to
facilitate comparison.
"""SWD (Sliced Wasserstein distance) metric.
We calculate the SWD of two sets of images in the following way. In every
'feed', we obtain the Laplacian pyramids of every image and extract patches
from the Laplacian pyramids as descriptors. In 'summary', we normalize
these descriptors along channel, and reshape them so that we can use
these descriptors to represent the distribution of real/fake images. And
we can calculate the sliced Wasserstein distance of the real and fake
descriptors as the SWD of the real and fake images. Note that, as with the
official implementation, we multiply the result by 10 to prevent the value
from being too small and to facilitate comparison.

self.gaussian_k)

# init list to save fake desp and real desp
if self._results == []:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self._results == []:
if not self._results:

Comment on lines +141 to +142
del real_descs
del fake_descs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to delete them immediately?

self.dir_repeats = 4 # times of sampling directions
self.dirs_per_repeat = 128 # number of directions per sampling

self.resolution = resolution
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is not used.

Comment on lines +60 to +62
while resolution >= 16 and len(self._resolutions) < 4:
self._resolutions.append(resolution)
resolution //= 2
Copy link
Collaborator

@zhouzaida zhouzaida Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if resolution is less than 16?


Returns: Dict[str, float]: The computed SWD metric.
"""
results_fake, results_real = results
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
results_fake, results_real = results
fake_results, real_results = results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants