Simple torch.nn.module implementation of Alias-Free-GAN style filter and resample

Overview

Alias-Free-Torch

Simple torch module implementation of Alias-Free GAN.

This repository including

Note: Since this repository is unofficial, filter and upsample could be different with official implementation.

Note: 2d lowpass filter is applying sinc instead of jinc (first order Bessel function of the first kind) in paper

Requirements

Due to torch.kaiser_window and torch.i0 are implemeted after 1.7.0, our repository need torch>=1.7.0.

  • Pytorch>=1.7.0

TODO

  • 2d sinc filter
  • 2d resample
  • devide 1d and 2d modules
  • pip packaging

Test results 1d

Filter sine Filter noise
filtersin filternoise
upsample downsample
up2 down10
up256 down100

Test results 2d

Filter L1 norm sine Filter noise
filter2dsin filter2dnoise
upsample downsample
up2d2 downsample2d2
up2d8 downsample2d4
Activation
act

References

  • Alias-Free GAN
  • adefossez/julius
  • A. V. Oppenheim and R. W. Schafer. Discrete-Time Signal Processing. Pearson, International Edition, 3rd edition, 2010

Acknowledgement

This work is done at MINDsLab Inc.

Thanks to teammates at MINDsLab Inc.

Comments
  •  Batched resampling for the new implementation

    Batched resampling for the new implementation

    Hi, thank you very much for the contribution.

    I think the new implementation of resample.Upsample1d and resample.Downsample1d breaks batched resampling when using groups=C without expanding the filter to match the shape. Perhaps the implementation should be like the below (maybe similar goes to 2d):

    Upsample1d.forward()

        # x: [B,C,T]
        def forward(self, x):
            B, C, T = x.shape
            x = F.pad(x, (self.pad, self.pad), mode='reflect')
            # TConv with filter expanded to C with C groups for depthwise op
            x = self.ratio * F.conv_transpose1d(
                x, self.filter.expand(C, -1, -1), stride=self.stride, groups=C)
            pad_left = self.pad * self.stride + (self.kernel_size -
                                                 self.stride) // 2
            pad_right = self.pad * self.stride + (self.kernel_size - self.stride +
                                                  1) // 2
            x = x[..., pad_left:-pad_right]
    

    LowPassFilter1d.forward()

        #input [B,C,T]
        def forward(self, x):
            B, C, T = x.shape
            if self.padding:
                x = F.pad(x, (self.left_pad, self.right_pad),
                          mode=self.padding_mode)
            # Conv with filter expanded to C with C groups for depthwise op
            out = F.conv1d(x, self.filter.expand(C, -1, -1), stride=self.stride, groups=C) # typo 'groupds' btw
            return out
    

    Could you check the correctness? Thanks again for the implementation!

    opened by L0SG 2
  • torch.speical.i1 typo

    torch.speical.i1 typo

    https://github.com/junjun3518/alias-free-torch/blob/f1fddd52fdd068ee475e82ae60c92e1bc24ffe02/src/alias_free_torch/filter.py#L22

    At this line I believe you wanted torch.special.i1.

    opened by torridgristle 2
  • "if self.pad / self.padding" in LowPassFilter2d

    https://github.com/junjun3518/alias-free-torch/blob/258551410ff7bf02e06ece7c597466dc970fe5c7/src/alias_free_torch/filter.py#L165 https://github.com/junjun3518/alias-free-torch/blob/258551410ff7bf02e06ece7c597466dc970fe5c7/src/alias_free_torch/filter.py#L173

    In LowPassFilter2d it looks like if self.pad: should change to if self.padding:, or self.padding = padding should change to self.pad = padding to match LowPassFilter1d.

    opened by torridgristle 1
  • Padding Bool typo

    Padding Bool typo

    https://github.com/junjun3518/alias-free-torch/blob/258551410ff7bf02e06ece7c597466dc970fe5c7/src/alias_free_torch/filter.py#L73

    padding: bool: True, should be padding: bool = True,

    I'm not sure if this causes an error with every version of PyTorch, but it does with PyTorch 1.12.0+cu113 on Python 3.7.13

    opened by torridgristle 1
  • 2D Filter Jinc appears to be wrong

    2D Filter Jinc appears to be wrong

    Here is a plot of the generated 1D sinc filter kernel. sinc looks right

    Here is a plot of the generated 2D jinc filter kernel. jinc looks wrong

    I'd expect it to look more like a series of rings or ripples, rather than a donut or torus.

    jinc filtered noise fft

    The FFT output for randn noise put through the 2D filter doesn't look right either.

    change jinc to sinc in 2d filter

    Changing filter_ = 2 * cutoff * window * jinc(2 * cutoff * time) to filter_ = 2 * cutoff * window * sinc(2 * cutoff * time) in kaiser_jinc_filter2d makes a more familiar kernel.

    change jinc to sinc in 2d filter fft out

    And the FFT output for randn noise put through this 2D filter looks about how I'd expect.

    opened by torridgristle 3
Releases(v0.0.6)
Owner
이준혁(Junhyeok Lee)
Audio/Speech Deep Learning Researcher @mindslab-ai
이준혁(Junhyeok Lee)
Trying to understand alias-free-gan.

alias-free-gan-explanation Trying to understand alias-free-gan in my own way. [Chinese Version 中文版本] CC-BY-4.0 License. Tzu-Heng Lin motivation of thi

Tzu-Heng Lin 12 Mar 17, 2022
FuseDream: Training-Free Text-to-Image Generationwith Improved CLIP+GAN Space OptimizationFuseDream: Training-Free Text-to-Image Generationwith Improved CLIP+GAN Space Optimization

FuseDream This repo contains code for our paper (paper link): FuseDream: Training-Free Text-to-Image Generation with Improved CLIP+GAN Space Optimizat

XCL 191 Dec 31, 2022
Unofficial implementation of Alias-Free Generative Adversarial Networks. (https://arxiv.org/abs/2106.12423) in PyTorch

alias-free-gan-pytorch Unofficial implementation of Alias-Free Generative Adversarial Networks. (https://arxiv.org/abs/2106.12423) This implementation

Kim Seonghyeon 502 Jan 3, 2023
Alias-Free Generative Adversarial Networks (StyleGAN3) Official PyTorch implementation

Alias-Free Generative Adversarial Networks (StyleGAN3) Official PyTorch implementation

NVIDIA Research Projects 4.8k Jan 9, 2023
Transfer style api - An API to use with Tranfer Style App, where you can use two image and transfer the style

Transfer Style API It's an API to use with Tranfer Style App, where you can use

Brian Alejandro 1 Feb 13, 2022
Torch-mutable-modules - Use in-place and assignment operations on PyTorch module parameters with support for autograd

Torch Mutable Modules Use in-place and assignment operations on PyTorch module p

Kento Nishi 7 Jun 6, 2022
DR-GAN: Automatic Radial Distortion Rectification Using Conditional GAN in Real-Time

DR-GAN: Automatic Radial Distortion Rectification Using Conditional GAN in Real-Time Introduction This is official implementation for DR-GAN (IEEE TCS

Kang Liao 18 Dec 23, 2022
Style-based Neural Drum Synthesis with GAN inversion

Style-based Drum Synthesis with GAN Inversion Demo TensorFlow implementation of a style-based version of the adversarial drum synth (ADS) from the pap

Sound and Music Analysis (SoMA) Group 29 Nov 19, 2022
Torch implementation of "Enhanced Deep Residual Networks for Single Image Super-Resolution"

NTIRE2017 Super-resolution Challenge: SNU_CVLab Introduction This is our project repository for CVPR 2017 Workshop (2nd NTIRE). We, Team SNU_CVLab, (B

Bee Lim 625 Dec 30, 2022
Torch-ngp - A pytorch implementation of the hash encoder proposed in instant-ngp

HashGrid Encoder (WIP) A pytorch implementation of the HashGrid Encoder from ins

hawkey 1k Jan 1, 2023
Only a Matter of Style: Age Transformation Using a Style-Based Regression Model

Only a Matter of Style: Age Transformation Using a Style-Based Regression Model The task of age transformation illustrates the change of an individual

null 444 Dec 30, 2022
Fast Neural Style for Image Style Transform by Pytorch

FastNeuralStyle by Pytorch Fast Neural Style for Image Style Transform by Pytorch This is famous Fast Neural Style of Paper Perceptual Losses for Real

Bengxy 81 Sep 3, 2022
A machine learning library for spiking neural networks. Supports training with both torch and jax pipelines, and deployment to neuromorphic hardware.

Rockpool Rockpool is a Python package for developing signal processing applications with spiking neural networks. Rockpool allows you to build network

SynSense 21 Dec 14, 2022
Implements Stacked-RNN in numpy and torch with manual forward and backward functions

Recurrent Neural Networks Implements simple recurrent network and a stacked recurrent network in numpy and torch respectively. Both flavours implement

Vishal R 1 Nov 16, 2021
Bayesian-Torch is a library of neural network layers and utilities extending the core of PyTorch to enable the user to perform stochastic variational inference in Bayesian deep neural networks

Bayesian-Torch is a library of neural network layers and utilities extending the core of PyTorch to enable the user to perform stochastic variational inference in Bayesian deep neural networks. Bayesian-Torch is designed to be flexible and seamless in extending a deterministic deep neural network architecture to corresponding Bayesian form by simply replacing the deterministic layers with Bayesian layers.

Intel Labs 210 Jan 4, 2023
A torch.Tensor-like DataFrame library supporting multiple execution runtimes and Arrow as a common memory format

TorchArrow (Warning: Unstable Prototype) This is a prototype library currently under heavy development. It does not currently have stable releases, an

Facebook Research 536 Jan 6, 2023
Pytorch and Torch testing code of CartoonGAN

CartoonGAN-Test-Pytorch-Torch Pytorch and Torch testing code of CartoonGAN [Chen et al., CVPR18]. With the released pretrained models by the authors,

Yijun Li 642 Dec 27, 2022
Pytorch Implementations of large number classical backbone CNNs, data enhancement, torch loss, attention, visualization and some common algorithms.

Torch-template-for-deep-learning Pytorch implementations of some **classical backbone CNNs, data enhancement, torch loss, attention, visualization and

Li Shengyan 270 Dec 31, 2022
A simple implementation of Kalman filter in single object tracking

kalman-filter-in-single-object-tracking A simple implementation of Kalman filter in single object tracking https://www.bilibili.com/video/BV1Qf4y1J7D4

null 130 Dec 26, 2022