ADAIN STYLE TRANSFER

Upload a content image and style reference to generate stylized artwork in real time.

Select files or try demo images:
Content Image
Click to Select Content Image
Style Image
Click to Select Style Image
Project Video Demo & Architecture Walkthrough

Watch the complete walkthrough covering the AdaIN neural style transfer pipeline, real-time feature normalization, and interactive browser deployment.

Real-Time Inference AdaIN Feature Alignment Continuous Alpha Interpolation ONNX Serverless Engine
Examples

Click any example to load it directly into the studio above.

Content Image
Brad Pitt Content
Style Image (La Muse)
La Muse Style
->
Output
Brad Pitt La Muse Result
Content Image
Brad Pitt Content
Style Image (Sketch)
Sketch Style
->
Output
Brad Pitt Sketch Result
Content Image
Brad Pitt Content
Style Image (Picasso)
Picasso Style
->
Output
Brad Pitt Picasso Result
Technical Frequently Asked Questions

Deep learning concepts, architecture decisions, and software engineering details behind the AdaIN Neural Style Transfer system.

Traditional Neural Style Transfer (Gatys et al.) relies on iterative optimization via gradient descent, which requires minutes of backpropagation per image. AdaIN (Huang & Belongie) replaces this with direct statistical alignment in latent feature space.

AdaIN computes the channel-wise spatial mean and standard deviation of content activations and normalizes them (removing content textures). It then scales and shifts these normalized features using the mean and variance computed from the style image feature map. The inverted decoder then reconstructs the final stylized image in a single deterministic forward pass with sub-second latency.

VGG-19 pre-trained on ImageNet forms a hierarchical feature extractor. Shallow layers (relu1_1, relu2_1) encode local textures and fine brushstrokes, while deep layers (relu4_1) preserve high-level semantic layout and spatial geometry without encoding surface textures.

All encoder weights are frozen ($\nabla_\theta = 0$) during training. This ensures the encoder remains a static visual feature extractor, allowing the downstream decoder to learn an accurate inverse mapping from latent space back to RGB image space.

Standard transposed convolutions (Deconv layers) cause uneven kernel overlap, resulting in high-frequency checkerboard artifacts across the image. To eliminate this, our decoder employs Nearest-Neighbor Upsampling ($2\times$) paired with standard $3\times 3$ convolutions ($512 \to 256 \to 128 \to 64 \to 3$).

Additionally, standard zero-padding is replaced with Reflection Padding (ReflectionPad2d) on all convolutional blocks to prevent boundary darkening and edge distortion.

The style intensity slider modulates the target latent features $t$ using linear interpolation between the raw content feature representation $f(c)$ and the stylized AdaIN features $\text{AdaIN}(f(c), f(s))$:

Target Latent Features = α · AdaIN(f(c), f(s)) + (1 - α) · f(c)

Setting α = 0.0 reconstructs the original content photo, α = 1.0 produces full artistic texture transfer, and fractional values provide continuous, smooth transitions without re-running the feature encoder.

The decoder was trained end-to-end on MS-COCO (content) and WikiArt (style) datasets using a composite objective function:

  • Content Loss ($\mathcal{L}_c$): Euclidean distance ($\mathcal{L}_2$) between the stylized output's features and the target AdaIN features at layer relu4_1.
  • Multi-Scale Style Loss ($\mathcal{L}_s$): The sum of differences between channel-wise means and standard deviations across intermediate layers relu1_1, relu2_1, relu3_1, and relu4_1.
  • Total Loss: total = ℒc + γ ℒs (where style weight $\gamma = 5.0$).

To deploy within Vercel's serverless environment, the PyTorch models were converted into optimized ONNX (Open Neural Network Exchange) runtime graphs.

By using ONNX Runtime and vectorized NumPy AdaIN math, the deployment package was reduced from 4.7 GB (CUDA PyTorch) down to ~80 MB, eliminating cold-start latency and enabling instant sub-second CPU inference.

Because AdaIN extracts and transfers first- and second-order feature statistics dynamically, any arbitrary style image can be used without retraining—including Impressionism (Monet), Cubism (Picasso), Post-Impressionism (Van Gogh), Pencil Sketch, Watercolor, Stained Glass, and Abstract Expressionism.

  • Deep Learning Engine: PyTorch (Model Training), ONNX Runtime (Production Inference), NumPy (Vectorized AdaIN).
  • Backend & API: Python 3.12, Flask, Flask-WTF, Werkzeug WSGI server.
  • Frontend UI: HTML5, CSS3 Glassmorphism, Bootstrap 5, FontAwesome 6, Google Fonts (Orbitron & Inter).
  • Interactive Physics: Vanilla JavaScript HTML5 Canvas particle repulsion network.

Processing Style Transfer...