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

Add GLEAN #296

Merged
merged 40 commits into from
May 27, 2021
Merged

Add GLEAN #296

merged 40 commits into from
May 27, 2021

Conversation

ckkelvinchan
Copy link
Member

This PR adds GLEAN for image super-resolution. It makes use of StyleGANv2 borrowed from MMGeneration.

Paper: GLEAN: Generative Latent Bank for Large-Factor Image Super-Resolution

@codecov
Copy link

codecov bot commented May 9, 2021

Codecov Report

Merging #296 (d1a05e1) into master (98a7ca3) will decrease coverage by 0.48%.
The diff coverage is 74.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #296      +/-   ##
==========================================
- Coverage   80.76%   80.28%   -0.49%     
==========================================
  Files         171      177       +6     
  Lines        8526     9280     +754     
  Branches     1234     1352     +118     
==========================================
+ Hits         6886     7450     +564     
- Misses       1488     1641     +153     
- Partials      152      189      +37     
Flag Coverage Δ
unittests 80.26% <74.70%> (-0.50%) ⬇️

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

Impacted Files Coverage Δ
mmedit/models/losses/perceptual_loss.py 56.75% <0.00%> (-1.58%) ⬇️
mmedit/models/restorers/glean.py 63.33% <63.33%> (ø)
mmedit/models/components/stylegan2/modules.py 64.40% <64.40%> (ø)
...ls/components/stylegan2/generator_discriminator.py 84.93% <84.93%> (ø)
mmedit/models/components/stylegan2/common.py 94.73% <94.73%> (ø)
.../models/backbones/sr_backbones/glean_styleganv2.py 97.00% <97.00%> (ø)
mmedit/models/backbones/__init__.py 100.00% <100.00%> (ø)
mmedit/models/backbones/sr_backbones/__init__.py 100.00% <100.00%> (ø)
mmedit/models/components/__init__.py 100.00% <100.00%> (ø)
mmedit/models/components/stylegan2/__init__.py 100.00% <100.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98a7ca3...d1a05e1. Read the comment docs.

@innerlee innerlee requested a review from Yshuo-Li May 11, 2021 11:51
@innerlee innerlee mentioned this pull request May 13, 2021
7 tasks
@ckkelvinchan
Copy link
Member Author

ckkelvinchan commented May 19, 2021

Hi @Yshuo-Li, many of the changes are added by @nbei. Here are the main changes related to GLEAN

  1. mmedit/models/backbones/sr_backbones/glean_styleganv2.py
  2. mmedit/models/restorers/glean.py
  3. mmedit/models/losses/perceptual_loss.py

self.encoder = nn.ModuleList()
self.encoder.append(
nn.Sequential(
RRDBFeatureExtractor(3, 64, num_blocks=23),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe adding mid_channels(defaults 64) , in_channels and out_channels to the class (GLEANStyleGANv2) will be better.

nn.LeakyReLU(negative_slope=0.2, inplace=True),
nn.Conv2d(64, 3, 3, 1, 1)))

def forward(self, lr):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Named LQ in other models of MMEditing



@torch.no_grad()
def get_mean_latent(generator, num_samples=4096, bs_per_repeat=1024):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need docstring

Copy link
Member Author

Choose a reason for hiding this comment

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

@nbei Could you help with that? I have copied the docstring of get_mean_latent from mmgeneration, but there is no docstring for style_mixing in mmgeneration.

with pytest.raises(AssertionError): # test with metric but gt is None
with torch.no_grad():
data_batch.pop('gt')
restorer(**data_batch, test_mode=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need unittests of the assertion errors

Copy link
Member Author

@ckkelvinchan ckkelvinchan May 21, 2021

Choose a reason for hiding this comment

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

The model for GLEAN has only this assertion error. Do you mean the backbone? The unittests are in test_glean_net.py.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Such as
mmedit/models/components/stylegan2/common.py#L16
mmedit/models/backbones/sr_backbones/glean_styleganv2.py#L271

Copy link
Member Author

Choose a reason for hiding this comment

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

For the unittests for glean_styleganv2.py, it is in test_glean_net.py. I will add unittests for common.py.

@ckkelvinchan ckkelvinchan added the status/WIP work in progress normally label May 22, 2021
@ckkelvinchan
Copy link
Member Author

Will add docstring for style_mixing.

@ckkelvinchan ckkelvinchan removed the status/WIP work in progress normally label May 25, 2021
channels = self.generator.channels

# encoder
num_styles = int(math.log2(out_size)) * 2 - 2
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, we use np for math ops

math.log2 -> np.log2

@innerlee
Copy link
Contributor

innerlee commented May 27, 2021

Some notes:

  • Replace all math.xx to np.xx
  • For the style-gan code, we will refactor it to use mmgen once the infrastructure is ready. Currently we simply do the copy-paste

And please rebase master.

@innerlee innerlee merged commit f0b2ab4 into open-mmlab:master May 27, 2021
Yshuo-Li pushed a commit to Yshuo-Li/mmediting that referenced this pull request Jul 15, 2022
* clone from MMEditing

* add GenerateFrameIndicesForRecurrent

* add unit test

* update format

* add stylegan2 with pretrained models

* add GLEAN architecture (WIP)

* GLEAN architecture

* Use build_component to build StyleGANv2

* add GenerateFrameIndicesForRecurrent

* add stylegan2 with pretrained models

* minor revision of architecture

* Minor fix

* Add MSELoss for perceptual loss

* merge master

* merge master

* sort

* Add GLEAN model

* Add unittest

* Remove pretrained in test

* Replace by test_srgan for verification

* Change disc to ModifiedVGG

* Remove init_weights

* Remove _load_pretrained_model

* revert to test_srgan

* Change Discriminator

* Use original StyleGAN2 discriminator

* Use GLEAN as generator

* Change to GLEAN model

* minor change

* remove redundancy in test_glean.py

* install

* Add unittests

* Revert to original StyleGAN2 discriminator

* Change math.log2 to np.log2

Co-authored-by: Rui Xu <[email protected]>
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