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: DISTS metric #131

Merged
merged 14 commits into from
Jul 14, 2020
Merged

Feature: DISTS metric #131

merged 14 commits into from
Jul 14, 2020

Conversation

zakajd
Copy link
Collaborator

@zakajd zakajd commented Jul 9, 2020

Closes #123

Proposed Changes

  • DISTS metric
  • Renamed use_average_pooling to replace_pooling because in DISTS pooling is replaced by L2pooling layer, not AveragePool.
  • Moved __init__ descriptions to class description, so that it's visible in VS Code and Jupyter IDA
  • Reduced image size in test to make them faster
  • Fixed small bug in FSIM testing

@zakajd zakajd requested a review from snk4tr July 9, 2020 12:40
@codecov
Copy link

codecov bot commented Jul 9, 2020

Codecov Report

Merging #131 into master will increase coverage by 0.50%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
+ Coverage   90.49%   91.00%   +0.50%     
==========================================
  Files          21       22       +1     
  Lines        1505     1556      +51     
==========================================
+ Hits         1362     1416      +54     
+ Misses        143      140       -3     
Flag Coverage Δ
#unittests 91.00% <100.00%> (+0.50%) ⬆️
Impacted Files Coverage Δ
piq/functional/__init__.py 100.00% <100.00%> (ø)
piq/functional/layers.py 100.00% <100.00%> (ø)
piq/perceptual.py 100.00% <100.00%> (ø)
piq/functional/filters.py 100.00% <0.00%> (+33.33%) ⬆️

Copy link
Collaborator

@denproc denproc left a comment

Choose a reason for hiding this comment

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

Great progress.
I suggest to address some changes

tests/test_perseptual.py Outdated Show resolved Hide resolved
tests/test_perseptual.py Outdated Show resolved Hide resolved
tests/test_perseptual.py Outdated Show resolved Hide resolved

class DISTS(ContentLoss):
r"""Deep Image Structure and Texture Similarity metric.
Expects input to be in range [0, 1] or normalized with ImageNet statistics into range [-1, 1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really support [-1, 1]? Let's add images with [-1, 1] dynamic range to the tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but forward pass fails because of _validate_input function :\

piq/perceptual.py Outdated Show resolved Hide resolved
Comment on lines 383 to 392
def construct_kernel(self, x: torch.Tensor) -> torch.Tensor:
r"""Returns 2D Hann window kernel with number of channels equal to input channels"""
C = x.size(1)

# Take bigger window and drop borders
window = torch.hann_window(self.kernel_size + 2, periodic=False)[1:-1]
kernel = window[:, None] * window[None, :]

# Normalize and reshape kernel
self.kernel = (kernel / kernel.sum()).repeat((C, 1, 1, 1)).to(x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we added functional.py into the project, which contains some filters, I would propose to move to there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I propose the following:

  1. Make a utils folder
  2. Put the functional.py here "as is"
  3. Rename utils.py -> utils/common.py
  4. Create a new file utils/layers.py
  5. Add L2Pool2d here

I also think that this refactoring is the subject of another PR. Current structure will work for the current PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did this refactoring in a single commit. It's not so big to require a separate PR

Copy link
Contributor

@snk4tr snk4tr left a comment

Choose a reason for hiding this comment

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

Nice one @zakajd!
Just a few minor changes are needed and then we are good to go 👍

piq/perceptual.py Outdated Show resolved Hide resolved
piq/perceptual.py Outdated Show resolved Hide resolved
Comment on lines 383 to 392
def construct_kernel(self, x: torch.Tensor) -> torch.Tensor:
r"""Returns 2D Hann window kernel with number of channels equal to input channels"""
C = x.size(1)

# Take bigger window and drop borders
window = torch.hann_window(self.kernel_size + 2, periodic=False)[1:-1]
kernel = window[:, None] * window[None, :]

# Normalize and reshape kernel
self.kernel = (kernel / kernel.sum()).repeat((C, 1, 1, 1)).to(x)
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose the following:

  1. Make a utils folder
  2. Put the functional.py here "as is"
  3. Rename utils.py -> utils/common.py
  4. Create a new file utils/layers.py
  5. Add L2Pool2d here

I also think that this refactoring is the subject of another PR. Current structure will work for the current PR.

tests/test_perseptual.py Outdated Show resolved Hide resolved
tests/test_perseptual.py Outdated Show resolved Hide resolved
@snk4tr snk4tr mentioned this pull request Jul 10, 2020
@zakajd
Copy link
Collaborator Author

zakajd commented Jul 10, 2020

Also closed #132 in one of the commits

@sonarcloud
Copy link

sonarcloud bot commented Jul 14, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@zakajd
Copy link
Collaborator Author

zakajd commented Jul 14, 2020

@snk4tr Ready to be merged

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.

Metric: DISTS
3 participants