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

Are conv2d_transpose layers shift variant, too? #8

Closed
JuheonYi opened this issue Jul 17, 2019 · 8 comments
Closed

Are conv2d_transpose layers shift variant, too? #8

JuheonYi opened this issue Jul 17, 2019 · 8 comments

Comments

@JuheonYi
Copy link

Hi, thanks for sharing the code!
I really enjoyed reading your paper.

As I understand, you have mainly considered downsampling layers (pool, strided convolution)
does the same shift variance issue exist for conv2d_transpose layers as well?
If it does, could you share your insights on how to replace the layer?

Thanks very much!

@richzhang
Copy link
Contributor

Thanks for the question. Upsampling convolution is shift-invariant, but if you do it naively, it is aliased and leads to stippling patterns.

If you do bilinear upsampling (convolve with a [1 2 1] filter after doing the naive upsampling), then you are better antialiased. The StyleGAN paper does this, for example.

@JuheonYi
Copy link
Author

JuheonYi commented Jul 18, 2019

@richzhang
Thanks for the answer (and also the reference to StyleGAN example)!

Can I ask one more question?

In case of the strided convolutions, does the performance vary depending on whether the BlurPool is put before or after the convolution?
(i.e., Conv (stride 1) -> ReLU -> BlurPool (stride 2) vs. BlurPool (stride 2) -> Conv (stride 1) -> ReLU)
It seems that putting BlurPool before Conv could save computation, but I wonder how the performance would be.

Could you share your thoughts or experiences on this?

Thank you!

@richzhang
Copy link
Contributor

Yes, it makes a difference. The second (BlurPool-->Conv-->ReLU) works worse, because it destroys information as the first step.

@iperov
Copy link

iperov commented Aug 12, 2019

but subpixel upscale layer is not antialiased?

@mrgloom
Copy link

mrgloom commented Jan 6, 2020

In paper there is not much information on antialiased upsampling(or I just don't get it):

We mirror the downsampling by applying the same filter after upsampling. Note that applying the Rect-2 and Tri-3 filters while upsampling correspond to “nearest” and “bilinear” upsampling, respectively

Is it should be done via torch.nn.ConvTranspose2d with groups= in_channels and with same filter as in downsampling code?

Also seems there is not groups parameter in TensorFlow for conv_transpose, is there any workaround? i.e. use some layer that can do x2 upscale(bilinear resize, conv_traspose, pixel_shuffle, etc) and then add 'blur' layer(avr pool with stride 1 and kernel size 2x2) on top?

@richzhang
Copy link
Contributor

Thanks for the question!

Yes, upsample with ConvTranspose2d with groups=in_channels, and then use [1, 1] or [1, 2, 1] as your weights.

For TensorFlow, perhaps you can refer to the StyleGan2 code/paper, which does smoothed upsampling as well.

@mrgloom
Copy link

mrgloom commented Jan 8, 2020

Looking at StyleGan2 code, seems they are doing it like:

blur(upsample(x)):
https://github.com/NVlabs/stylegan2/blob/7d3145d23013607b987db30736f89fb1d3e10fad/training/networks_stylegan.py#L519

downsample(blur(x)):
https://github.com/NVlabs/stylegan2/blob/7d3145d23013607b987db30736f89fb1d3e10fad/training/networks_stylegan.py#L607

I wonder is this approach(i.e. via 2 steps) is different from resampling-by-convolution(i.e. via 1 step) ? https://clouard.users.greyc.fr/Pantheon/experiments/rescaling/index-en.html

@richzhang
Copy link
Contributor

It's the same. The two steps can be folded into one. We don't actually blur the whole map at every spatial location and then subsample by factor of 2, since many of the calculations are thrown away. We simply evaluate the blur at every other location.

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

No branches or pull requests

4 participants