Skip to content

Samarthuday/Art_Style

Repository files navigation

# 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
  1. Install dependencies:

    pip install -r requirements.txt
  2. 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())"

🚀 How to Use

Option 1: Streamlit Web App

  1. Run the Streamlit application:

    streamlit run app.py
  2. 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"
  3. 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)

Option 2: Jupyter Notebook

  1. Prepare Images:

    • Place your content images in the content/ folder.
    • Place your style images in the style/ folder.
  2. Modify File Paths: Update the content_file and style_file paths in the notebook:

    content_file = "content/dog.png"
    style_file = "style/ab4.jpeg"
  3. Run the Notebook: Open and run Art_Style_Transfer_Model.ipynb in Jupyter.

  4. View Results: Generated images will be saved in the generated/ folder (or path specified in the notebook).


📊 Example Outputs

Content Image Style Image Generated Image
Content Style Generated

⚙️ Hyperparameters

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: 3000 for notebook, 500 for 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.0 or 1e-6). Promotes smoothness and reduces artifacts.

📜 Dependencies

The project requires the following libraries (listed in requirements.txt):

  • torch (PyTorch) - Deep learning framework
  • torchvision - Pre-trained models and image transforms
  • numpy - Numerical computations
  • Pillow - Image processing
  • tqdm - Progress bars
  • scikit-image - Image metrics (PSNR, SSIM)
  • pandas - Data manipulation and analysis
  • streamlit - Web application interface (for app.py)
  • matplotlib - Plotting and visualization

Install them with:

pip install -r requirements.txt

About

Implement artistic style transfer using PyTorch to blend the content of one image with the style of another, leveraging convolutional neural networks. This project enables the transformation of images into visually stunning artworks inspired by famous styles.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors