Skip to content

Metric: PieAPP#184

Merged
snk4tr merged 12 commits intomasterfrom
feature/PieAPP
Jan 11, 2021
Merged

Metric: PieAPP#184
snk4tr merged 12 commits intomasterfrom
feature/PieAPP

Conversation

@jzakirov
Copy link
Collaborator

@jzakirov jzakirov commented Nov 9, 2020

Closes #181

Original code is badly written, so I changed it in a few places.
Model structure is similar to perceptual losses, but small differences required to overwrite every call, so I decided not to inherit from ContentLoss.

Proposed Changes

  • Metric re-implementation with equal performance to original version
  • Updated docs
  • Add model weights to last release
  • Tests

@codecov
Copy link

codecov bot commented Nov 9, 2020

Codecov Report

Merging #184 (e78dc73) into master (5f90706) will increase coverage by 0.23%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #184      +/-   ##
==========================================
+ Coverage   95.09%   95.32%   +0.23%     
==========================================
  Files          25       26       +1     
  Lines        1692     1777      +85     
==========================================
+ Hits         1609     1694      +85     
  Misses         83       83              
Flag Coverage Δ
unittests 95.32% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
piq/functional/__init__.py 100.00% <100.00%> (ø)
piq/functional/base.py 92.10% <100.00%> (+1.48%) ⬆️
piq/pieapp.py 100.00% <100.00%> (ø)

@jzakirov jzakirov added the feature New feature or request label Nov 24, 2020
@jzakirov jzakirov marked this pull request as ready for review December 10, 2020 11:40
@jzakirov jzakirov requested a review from snk4tr December 10, 2020 11:40
@snk4tr
Copy link
Contributor

snk4tr commented Dec 10, 2020

@zakajd thanks a lot for your contribution! I will have a look tomorrow morning.

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.

According to the codecov, replace_pooling functionality is not covered with tests. Could you add a test for the PieAPPModel that would verify that layers are replaces and model still works after this change?

Overall, this is a great PR! Only minor changes are required.

self.conv10 = nn.Conv2d(features * 4, features * 8, kernel_size=3, padding=1)
self.conv11 = nn.Conv2d(features * 8, features * 8, kernel_size=3, padding=1)

self.fc1_score = nn.Linear(in_features=120832, out_features=512, bias=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this line makes having features as a parameter senseless because number of input features is hardcoded. I also think that since you use pretrained model weights you can't really change parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree. Removed it from init and hardcoded for now.
As soon as dataset used for PieAPP model training will be released we can reconsider this implementation

Copy link
Contributor

Choose a reason for hiding this comment

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

I also added a TODO comment to not forget

piq/pieapp.py Outdated
target_weights - prediction_weights
)

# Shape (N, NUM_PATCHES)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is NUM_PATCHES? I don't see this variable in the module

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed this comment.
Number of patches depend on input image size, crop size and stride, it's not some fixed value.

piq/pieapp.py Outdated
Comment on lines +97 to +101
Input images are croped into smaller patches and final score is mean of patch scores.


Args:
reduction: Reduction over samples in batch: "mean"|"sum"|"none".
Copy link
Contributor

Choose a reason for hiding this comment

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

If final score is mean of patch scores, then I think reduction parameters is a bit redundant. We either should avoid explicit description in the doctoring (which would be weird if this is a part of an algorithm for the metric) or remove other redundancy options. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated docstring description. Final score for individual image is mean of it's patch scores. So we still may want to reduce results over batch.

piq/pieapp.py Outdated

x_patches = crop_patches(x, size=64, stride=self.stride)

features, weights = self.model(x_patches)
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about adding this line? May be useful when PieAPP is used as metric.

Suggested change
features, weights = self.model(x_patches)
with torch.no_grad():
features, weights = self.model(x_patches)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added torch.autograd.set_grad_enabled context manager and additional flag in init.
Some users may want to use PieAPP as a loss, so turning off all gradients isn't good idea.

@jzakirov jzakirov mentioned this pull request Dec 24, 2020
10 tasks
piq/pieapp.py Outdated
.. [2] https://github.com/prashnani/PerceptualImageError

"""
# TODO(zakajd) 10/12/2020: Load weights to release and change this link
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@snk4tr this PR is ready for merge if you don't have additional comments.

I'm currently in the place with very slow internet, so it would be great if you also upload model weights to last release and change the link in code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

Signed-off-by: Sergey Kastryulin <snk4tr@gmail.com>
Signed-off-by: Sergey Kastryulin <snk4tr@gmail.com>
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.

Nicely done, @zakajd!

self.conv10 = nn.Conv2d(features * 4, features * 8, kernel_size=3, padding=1)
self.conv11 = nn.Conv2d(features * 8, features * 8, kernel_size=3, padding=1)

self.fc1_score = nn.Linear(in_features=120832, out_features=512, bias=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

I also added a TODO comment to not forget

piq/pieapp.py Outdated
.. [2] https://github.com/prashnani/PerceptualImageError

"""
# TODO(zakajd) 10/12/2020: Load weights to release and change this link
Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@snk4tr snk4tr merged commit e03fbc9 into master Jan 11, 2021
@snk4tr snk4tr deleted the feature/PieAPP branch January 11, 2021 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add metric PieAPP

2 participants