-
Notifications
You must be signed in to change notification settings - Fork 49
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
base: main
Are you sure you want to change the base?
[Feature] Support SWD and MS-SSIM metrics #82
Conversation
There was a problem hiding this 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.
6c17aa5
to
dc0e23f
Compare
dc0e23f
to
fb3387e
Compare
b84f63f
to
cc9d889
Compare
There was a problem hiding this 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
0095367
to
1f4675b
Compare
Hi, have you verified the PR in mmediting? |
tuple: Pair containing the mean SSIM and contrast sensitivity | ||
between `img1` and `img2`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`. |
"""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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""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 == []: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self._results == []: | |
if not self._results: |
del real_descs | ||
del fake_descs |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
while resolution >= 16 and len(self._resolutions) < 4: | ||
self._resolutions.append(resolution) | ||
resolution //= 2 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
results_fake, results_real = results | |
fake_results, real_results = results |
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