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

Difference of spectral norm conv2d in Dblock/DBlockOptimized #32

Open
Leiwx52 opened this issue Sep 26, 2020 · 0 comments
Open

Difference of spectral norm conv2d in Dblock/DBlockOptimized #32

Leiwx52 opened this issue Sep 26, 2020 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@Leiwx52
Copy link

Leiwx52 commented Sep 26, 2020

Hi~ thanks for your great contribution!

I have a question for the implementation of Dblock and DBlockOptimized. When I was trying to visualize the spectral norm of some layers, I noticed that you have two version of implementation of SN: class SNConv2d in torch_mimicry/modules/spectral_norm.py and function SNConv2d in torch_mimicry/modules/layers.py. If it is true, in Dblock and DBlockOptimized, class SNConv2d with spectral_norm=True by default. However, I feel little confused when i run the following code:

  • Simply the following lines:

    from torch_mimicry.modules.resblocks import DBlockOptimized, DBlock, GBlock
    if __name__ == "__main__":
        block  = DBlockOptimized(3,128)
        print(block)

    the output was:

    DBlockOptimized(
      (c1): Conv2d(3, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (c2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (c_sc): Conv2d(3, 128, kernel_size=(1, 1), stride=(1, 1))
      (activation): ReLU(inplace=True)
    )

    I checked Conv2d in that block and it seems that it implemented SN using pytorch official spectral norm since the Conv2d has attribute weight_orig, which origins from pytorch official implementation.

  • Copied the whole file of torch_mimicry/modules/resblocks.py and add the following lines:

    ######
    ...
    contents of resblock.py
    ...
    ######
    
    ## adding the following lines
    if __name__ == "__main__":
        block  = DBlockOptimized(3,128)
        print(block)

    the output was:

    DBlockOptimized(
      (c1): SNConv2d(3, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (c2): SNConv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (c_sc): SNConv2d(3, 128, kernel_size=(1, 1), stride=(1, 1))
      (activation): ReLU(inplace=True)
    )

    here the SN is implemented as in class SNConv2d by the author.

Since class SNConv2d has a more convenient way to inspect the spectral norm(it has related function to do this directly), I wonder what caused this difference. Also when I call SNGANDiscriminator32 and print its modules, results show that all the SN conv2d is implemented by pytorch official SN function/wrapper. If you've already figured it out, plz tell me how to switch to class SNConv2d .

THANKS!

@kwotsin kwotsin added the help wanted Extra attention is needed label Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants