# Art Style Transfer
This project implements **artistic style transfer** using PyTorch. It blends the artistic style of an image (e.g., a painting) into the content of another image (e.g., a photograph). The implementation uses a pretrained VGG19 model for feature extraction and computes content and style losses to optimize the generated image.
---
## 📂 Project Structure
Art_Style/ ├── artwork/ # Folder for style artwork images ├── content/ # Folder for content images ├── style/ # Folder for style images ├── generated/ # Folder for saving generated images (notebook) ├── generated_images/ # Folder for saving generated images (Streamlit app) ├── app.py # Streamlit web application ├── Art_Style_Transfer_Model.ipynb # Jupyter Notebook for experimentation ├── README.md # Project documentation └── requirements.txt # Python dependencies
---
## ✨ Features
- **Blend Styles**: Merges artistic styles into content images using neural networks.
- **Pretrained Model**: Uses a VGG19 model pretrained on ImageNet.
- **Intermediate Visualization**: Displays the generated image every 100 steps during optimization.
- **Output Storage**: Saves the final result in the `generated/` or `generated_images/` folder.
---
## 🔬 Methodology
This project implements a neural style transfer approach based on VGG19 for separating content from style information:
- **Deep Feature Extraction**: Content features are extracted from deeper convolutional layers of the VGG19 network, capturing high-level semantic information while preserving structural elements.
- **Style Modeling**: Artistic style is modeled using **Gram matrices** computed across multiple convolutional layers. Gram matrices capture the statistical correlations between feature maps, effectively representing texture and artistic patterns without preserving spatial layout.
- **Loss Function Optimization**: The stylized image is optimized through a composite loss function that balances:
- **Content Loss**: Ensures the generated image preserves the structural content of the original
- **Style Loss**: Encourages artistic expression by matching Gram matrices from the style image
- **Total Variation Loss** (optional): Promotes spatial smoothness and reduces artifacts
- **Evaluation Metrics**: Experimental validation includes:
- **PSNR** (Peak Signal-to-Noise Ratio): Measures reconstruction quality
- **SSIM** (Structural Similarity Index): Assesses perceptual similarity
- **TV-Loss Ablation Studies**: Demonstrates the impact of total variation regularization
The method achieves successful stylization while maintaining structural integrity and visual quality.
---
## 🔧 Installation
1. **Clone the repository:**
```bash
git clone https://github.com/your_username/Art_Style.git
cd Art_Style
-
Install dependencies:
pip install -r requirements.txt
-
Verify PyTorch installation (optional): Ensure that PyTorch is installed with CUDA support if you want to use a GPU.
python -c "import torch; print(torch.cuda.is_available())"
-
Run the Streamlit application:
streamlit run app.py
-
Upload images:
- Upload your content image through the web interface
- Upload your style image
- Adjust hyperparameters (alpha, beta, steps, TV loss weight)
- Click "Start Style Transfer"
-
View results:
- Generated images are saved in
generated_images/folder - View loss plots, metrics (PSNR, SSIM), and intermediate images
- Run ablation experiments (α/β sweep, TV loss comparison)
- Generated images are saved in
-
Prepare Images:
- Place your content images in the
content/folder. - Place your style images in the
style/folder.
- Place your content images in the
-
Modify File Paths: Update the
content_fileandstyle_filepaths in the notebook:content_file = "content/dog.png" style_file = "style/ab4.jpeg"
-
Run the Notebook: Open and run
Art_Style_Transfer_Model.ipynbin Jupyter. -
View Results: Generated images will be saved in the
generated/folder (or path specified in the notebook).
| Content Image | Style Image | Generated Image |
|---|---|---|
![]() |
![]() |
![]() |
You can tweak these parameters in app.py (via UI sliders) or Art_Style_Transfer_Model.ipynb to experiment with different results:
alpha: Weight for content loss (default:1.0). Higher values preserve more content structure.beta: Weight for style loss (default:0.1). Higher values apply stronger artistic style.total_steps: Number of optimization steps (default:3000for notebook,500for app). More steps = better results but longer processing.lr: Learning rate for the optimizer (default:0.0005). Controls the step size during optimization.tv_weight: Total variation loss weight (default:0.0or1e-6). Promotes smoothness and reduces artifacts.
The project requires the following libraries (listed in requirements.txt):
torch(PyTorch) - Deep learning frameworktorchvision- Pre-trained models and image transformsnumpy- Numerical computationsPillow- Image processingtqdm- Progress barsscikit-image- Image metrics (PSNR, SSIM)pandas- Data manipulation and analysisstreamlit- Web application interface (forapp.py)matplotlib- Plotting and visualization
Install them with:
pip install -r requirements.txt

