Skip to content

Commit

Permalink
Style Transfer with Neural Network (#441)
Browse files Browse the repository at this point in the history
## Pull Request for PyVerse 💡

### Requesting to submit a pull request to the PyVerse repository.

---

#### Issue Title
**Please enter the title of the issue related to your pull request.**  
*Style Transfer with Neural Network*

- [x] I have provided the issue title.

---

#### Info about the Related Issue
**What's the goal of the project?**  
*This project aims to implement a style transfer technique using neural
networks to blend content and style images, allowing users to generate
artistic images by combining different visual elements.*

- [x] I have described the aim of the project.

---

#### Name
**Please mention your name.**  
*Alolika Bhowmik*

- [x] I have provided my name.

---

#### GitHub ID
**Please mention your GitHub ID.**  
*alo7lika*

- [x] I have provided my GitHub ID.

---

#### Email ID
**Please mention your email ID for further communication.**  
*alolikabhowmik72@gmail.com*

- [x] I have provided my email ID.

---

#### Identify Yourself
**Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC,
SWOC).**
*GSSOC*

- [x] I have mentioned my participant role.

---

#### Closes
**Enter the issue number that will be closed through this PR.**  #405 
*Closes: 

- [x] I have provided the issue number.

---

#### Describe the Add-ons or Changes You've Made
**Give a clear description of what you have added or modified.**  
*Implemented a Jupyter Notebook that demonstrates style transfer using
PyTorch. Added sample images, updated documentation, and included a
requirements.txt file for dependencies.*

- [x] I have described my changes.

---

#### Type of Change
**Select the type of change:**  
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Code style update (formatting, local variables)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

---

#### How Has This Been Tested?
**Describe how your changes have been tested.**  
*Tested the style transfer implementation with various content and style
images, ensuring that the output is generated correctly and meets
expectations.*

- [x] I have described my testing process.

---

#### Checklist
**Please confirm the following:**  
- [x] My code follows the guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly wherever it was hard to
understand.
- [x] I have made corresponding changes to the documentation.
- [x] My changes generate no new warnings.
- [x] I have added things that prove my fix is effective or that my
feature works.
- [x] Any dependent changes have been merged and published in downstream
modules.
  • Loading branch information
UTSAVS26 authored Oct 14, 2024
2 parents d73d70a + e4aab11 commit c824115
Show file tree
Hide file tree
Showing 4 changed files with 476 additions and 0 deletions.
103 changes: 103 additions & 0 deletions Machine_Learning/Style Transfer with Neural Network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# 🎨 Style Transfer with Neural Networks 🖼️

Welcome to the **Style Transfer with Neural Networks** project! In this project, we explore the application of neural networks to perform artistic style transfer, allowing us to blend the artistic style of one image with the content of another.

## Table of Content

1. [Project Overview](#-project-overview)
2. [Setup & Installation](#-setup--installation)
3. [File Structure](#-file-structure)
4. [How to Run](#-how-to-run)
5. [Sample Run](#-sample-run)
6. [Concepts Behind the Project](#-concepts-behind-the-project)
7. [Examples of Generated Images](#-examples-of-generated-images)
8. [Technologies Used](#-technologies-used)
9. [Parameters & Tuning](#-parameters--tuning)
10. [License](#-license)
11. [Contact](#-contact)

## 📚 Project Overview

Style transfer is a technique in deep learning that involves using Convolutional Neural Networks (CNNs) to separate and combine the style of one image with the content of another image. This project implements a neural style transfer model using **PyTorch** and **pre-trained VGG19**.

### Key Features:
- Use of **pre-trained neural networks** for feature extraction (VGG19)
- Content loss and style loss based on **Gram matrices**
- Supports custom content and style images
- Optimization with **L-BFGS** optimizer for faster convergence

## 🛠️ Setup & Installation

To get started with this project, you'll need to install the following dependencies:

```bash
pip install torch torchvision matplotlib Pillow
```

### File Structure:

| File/Folder | Description |
|---------------------------------------|-------------------------------------------------------|
| `Style Transfer with Neural Networks.ipynb` | The main notebook implementing style transfer |
| `images/` | Directory containing sample content and style images |
| `output/` | Folder to store the generated images |
| `requirements.txt` | List of dependencies |

## 🚀 How to Run

1. **Clone the repository** and navigate to the project folder:

```bash
git clone https://github.com/yourusername/style-transfer-project.git
cd style-transfer-project
```
2. **Run the Jupyter Notebook** to perform style transfer on your custom images. You can upload your content and style images directly in the notebook.

3. Adjust parameters like `content_weight`, `style_weight`, and `num_steps` to tweak the results according to your preferences.

4. View and save the generated images in the `output/` folder.

## 📸 Sample Run

- **Content Image**: Defines the structure and objects in the final image.
- **Style Image**: Provides the textures, colors, and patterns.

| Content Image | Style Image |
|------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| ![Content Image](https://raw.githubusercontent.com/alo7lika/PyVerse/refs/heads/main/Machine_Learning/Style%20Transfer%20with%20Neural%20Network/content%20image.jpg) | ![Style Image](https://raw.githubusercontent.com/alo7lika/PyVerse/refs/heads/main/Machine_Learning/Style%20Transfer%20with%20Neural%20Network/style%20image.jpg) |


## 🔬 Concepts Behind the Project

- **Content Representation**: Extracted from deeper layers of the network to capture high-level structures in the image.

- **Style Representation**: Captured using the **Gram matrix** of feature maps, representing correlations between different feature maps.

- **Optimization**: The neural network optimizes a noise image to minimize both **content loss** and **style loss**, blending the content and style.

## 🧠 Technologies Used

- **Python** 🐍
- **PyTorch** for deep learning
- **Jupyter Notebook** for interactive coding
- **Matplotlib** for visualizations

## 📊 Parameters & Tuning

You can adjust the following parameters to control the output of the style transfer model:

| Parameter | Default Value | Description |
|-----------------|---------------|-------------------------------------|
| `content_weight` | `1e5` | Weight for the content loss |
| `style_weight` | `1e10` | Weight for the style loss |
| `num_steps` | `300` | Number of optimization steps |
| `learning_rate` | `0.01` | Learning rate for the optimizer |


## 📄 License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## 💬 Contact

If you have any questions, feel free to reach out to me at [alolikabhowmik72@gmail.com]
Loading

0 comments on commit c824115

Please sign in to comment.