Alias-Free Torch

0.0.6 · active · verified Thu Apr 16

Alias-Free Torch is a Python library providing a simple PyTorch module implementation of Alias-Free GAN (Generative Adversarial Networks) concepts. It includes Alias-Free GAN style lowpass sinc filters, up/downsampling, and activation modules. The library aims to reduce aliasing artifacts in generated images, which is crucial for deep learning models like diffusion architectures, by integrating signal processing-based alias-free resampling techniques. The current version is 0.0.6, and the project is actively maintained, though it is described as an unofficial implementation and may not perfectly align with official StyleGAN3 implementations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate and use an `Activation1d` module with a standard PyTorch activation like ReLU. It showcases the basic tensor flow through an alias-free processing block, which performs upsampling, applies the activation, and then downsampling to mitigate aliasing effects. The example uses a 1D input tensor, as the library also supports 2D operations.

import torch
import torch.nn as nn
from alias_free_torch.act import Activation1d

# Define a simple 1D activation module with ReLU as the base activation
# This will upsample, apply ReLU, then downsample to combat aliasing
activation_module = Activation1d(
    activation=nn.ReLU(), 
    up_ratio=2, 
    down_ratio=2, 
    up_kernel_size=12, 
    down_kernel_size=12
)

# Create a dummy 1D input tensor (Batch, Channels, Length)
# Current versions often expect channel dimension to be 1 for many operations
input_tensor = torch.randn(1, 1, 64)

# Pass the input through the alias-free activation module
output_tensor = activation_module(input_tensor)

print(f"Input tensor shape: {input_tensor.shape}")
print(f"Output tensor shape: {output_tensor.shape}")
# Expected output shape: (1, 1, 64) if up_ratio and down_ratio cancel out

view raw JSON →