- About the Project
- How AdaIN Works
- Demo & Screenshots
- Features
- Project Structure
- Installation
- Running the App
- Deploying to Render
- Dependencies
- Credits & References
Neural Style Transfer with AdaIN is a Flask web application that blends the content of one image with the artistic style of another — in real time. Powered by Adaptive Instance Normalization (AdaIN) and a pre-trained VGG encoder/decoder network, the app lets you:
- Upload a content image (your photo, landscape, portrait — anything)
- Upload a style image (a painting, artwork, or texture)
- Adjust the style strength (alpha) to control how heavily the style is applied
- Download the stylized output — a brand-new artistic image Unlike traditional optimization-based style transfer (which can take minutes), AdaIN produces results in seconds, making it practical for real-world use.
A beginner-friendly explanation
Think of every image as having two things: content (the shapes and structure — what's in the image) and style (the colors, textures, and brush strokes — how it looks).
AdaIN (Adaptive Instance Normalization) transfers style by matching statistical properties between images:
Content Image ──┐
├──► VGG Encoder ──► AdaIN Layer ──► Decoder ──► Stylized Image
Style Image ──┘
Here's the key idea, step by step:
- Encode — Both the content image and style image are passed through a pre-trained VGG network, which extracts their deep feature representations (essentially, a "description" of their content and style).
- Normalize — The AdaIN layer takes the content features and adjusts their mean and variance to match those of the style features. This is the magic — it's like dipping the content into the statistical "fingerprint" of the style.
The formula is elegantly simple:
where
AdaIN(x, y) = σ(y) * ((x − μ(x)) / σ(x)) + μ(y)μis the mean andσis the standard deviation. - Decode — A decoder network reconstructs a full image from the normalized features, producing the final stylized result.
- Alpha blending — An
alphaparameter (0.0 → 1.0) lets you control the style intensity.alpha = 1.0gives full style transfer; lower values preserve more of the original photo. This approach is fast (no iterative optimization) and flexible (works with any arbitrary content/style pair at inference time).
Web Interface:
- 🖼️ Upload any image as content or style — JPG, JPEG, PNG supported
- 🎚️ Adjustable alpha slider to fine-tune how much style is applied
- ⚡ Fast inference — results generated in seconds using AdaIN
- 🧠 VGG-based encoder with a trained decoder for high-quality output
- 🌐 Clean web UI built with Flask-Bootstrap
- 🔒 Secure file handling via Werkzeug's
secure_filename - ☁️ Cloud-deployed on Render for easy access from any browser
- 💻 CPU & GPU compatible — auto-detects available hardware
AI-Neural-Style-Transfer-AdaIn/
│
├── app.py # Main Flask application
├── train.py # Model training script
├── vgg_normalised.pth # Pre-trained VGG encoder weights
├── requirements.txt # Python dependencies
├── Procfile.txt # Render/Gunicorn startup command
├── adain_algo.png # AdaIN algorithm diagram
├── .gitignore
│
├── utils/
│ ├── models.py # VGGEncoder and Decoder architectures
│ └── utils.py # AdaIN core logic (adaptive_instance_normalization, calc_mean_std)
│
├── templates/
│ └── index.html # Main HTML template (Flask-Bootstrap)
│
├── static/
│ └── uploads/ # Uploaded and generated images (runtime)
│
└── examples/ # Sample content/style image pairs
- Python 3.9 or higher
pippackage manager- (Optional) A CUDA-compatible GPU for faster inference
git clone https://github.com/saakshiscode19/AI-Neural-Style-Transfer-AdaIn.git
cd AI-Neural-Style-Transfer-AdaIn# Create virtual environment
python -m venv venv
# Activate — macOS/Linux
source venv/bin/activate
# Activate — Windows
venv\Scripts\activatepip install -r requirements.txtThe app requires a trained decoder checkpoint (decoder_1.pth). Update the path in app.py:
# Line ~37 in app.py — update this to your local path
decoder.load_state_dict(torch.load('path/to/your/decoder_1.pth'))📌 If you've trained your own decoder using
train.py, point this to your output checkpoint.
Start the Flask development server:
python app.pyThen open your browser and navigate to:
http://localhost:5000
You'll see the upload form. Select a content image, a style image, set your desired alpha value, and click Transfer Style!
This app is configured for deployment on Render using Gunicorn.
- Push your code to a GitHub repository (ensure
Procfile.txtandrequirements.txtare committed). - Go to render.com and create a new Web Service.
- Connect your GitHub repo and configure:
- Build Command:
pip install -r requirements.txt - Start Command:
gunicorn app:app(from your Procfile) - Environment: Python 3
- Build Command:
- Add any environment variables if needed (e.g.,
SECRET_KEY). - Deploy — Render will build and host your app automatically.
- Your live app will be available at:
(Replace with your actual Render URL)
https://your-app-name.onrender.com
⚠️ Note: Render's free tier spins down after inactivity. The first request after idle may take ~30 seconds to wake up.
| Package | Version | Purpose |
|---|---|---|
Flask |
3.1.2 | Web framework |
Flask-Bootstrap |
3.3.7.1 | UI styling |
flask-wtf |
1.2.2 | Form handling & CSRF protection |
torch |
2.2.2 | Deep learning framework |
torchvision |
0.17.2 | Image transforms & pretrained models |
Pillow |
12.0.0 | Image loading and saving |
numpy |
≥1.24, <2.0 | Numerical operations |
Werkzeug |
3.1.4 | WSGI utilities & secure file handling |
WTForms |
3.2.1 | Form validation |
tqdm |
4.66.4 | Training progress bars |
gunicorn |
latest | Production WSGI server (Render) |
Install all at once:
pip install -r requirements.txtCore Research:
Huang, X., & Belongie, S. (2017). Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization. In Proceedings of the IEEE International Conference on Computer Vision (ICCV), 2017. 📄 arXiv:1703.06868
Model Architecture:
The encoder uses a VGG-19 network pre-trained on ImageNet (weights normalized for style transfer), paired with a learned mirror-decoder network trained to reconstruct images from AdaIN-transformed features.
Built With:
- PyTorch — Deep learning framework
- Flask — Python web framework
- Render — Cloud deployment platform
- Flask-Bootstrap — Frontend UI components
⭐ If you found this project useful, please consider giving it a star!



