This project consists of a web application built with React for the frontend and Flask for the backend. The application allows users to perform neural style transfer on images, where the style of one image is applied to the content of another image to generate visually appealing results.
- Introduction
- Features
- Technologies Used
- Installation
- Usage
- Docker
- Endpoints
- VGG19 Algorithm
- File Structure
- Contributing
- License
Neural style transfer is a technique in deep learning that allows for the transfer of artistic styles from one image to another. This project provides a user-friendly interface for users to upload their content and style images, and then generate new images combining the content of the content image with the style of the style image.
- User Authentication: Users can sign up and log in securely to access the style transfer functionality.
- Image Upload: Users can upload both content and style images for style transfer.
- Style Transfer: The application performs neural style transfer using a pre-trained model.
- Generated Image Retrieval: Users can retrieve the generated images for reference or download.
- Frontend: React.js, React Router, HTML, CSS
- Backend: Flask, TensorFlow, NumPy
- Database: Firebase
- Deployment: Docker, Azure (or any other suitable platform)
To run this application locally, follow these steps:
-
Clone this repository to your local machine:
git clone https://github.com/jebinshaju/Neural_style_transfer_webapp.git
-
Navigate to the project directory:
cd Neural_style_transfer_webapp
-
Install the frontend dependencies:
cd frontend npm install
-
Install the backend dependencies:
cd ../backend pip install -r requirements.txt
-
Start the frontend and backend servers:
# In the frontend directory npm start # In the backend directory flask run
-
Open http://localhost:3000 in your web browser to access the application.
Once the application is running, users can perform the following actions:
- Sign Up: Register a new account using the provided form.
- Log In: Log in with the registered credentials to access the style transfer functionality.
- Upload Images: Upload both content and style images for style transfer.
- Generate Images: Initiate the style transfer process to generate new images.
- Retrieve Images: View and download the generated images from the application.
The backend of this project is available as a Docker image on Docker Hub. To run the backend using Docker, simply pull the image and run it:
docker pull jebinshaju/neuralstyletransfer_api
docker run -p 5000:5000 jebinshaju/neuralstyletransfer_api
The backend provides the following endpoints for performing style transfer and user management:
/signup
: Sign up a new user./login
: Log in an existing user./logout
: Log out the current user./transfer_style
: Perform style transfer for logged-in users./get_generated_images
: Retrieve generated images for the current user.
The VGG19 algorithm is used for neural style transfer in this project. It consists of a convolutional neural network architecture proposed by the Visual Geometry Group at the University of Oxford. VGG19 is implemented using TensorFlow for feature extraction and loss calculation during the style transfer process.
The project structure is organized as follows:
- frontend/: Contains the React frontend application.
- backend/: Contains the Flask backend application.
Contributions are welcome! If you'd like to contribute to this project, please follow these guidelines:
- Fork the repository and create your branch from
main
. - Make your changes and ensure the code is well-documented.
- Test your changes thoroughly.
- Create a pull request with a clear description of your changes.
This project is licensed under the MIT License.
VGG19 is a convolutional neural network architecture proposed by the Visual Geometry Group at the University of Oxford. It is widely used for image classification and feature extraction tasks. VGG19 consists of 19 layers, including 16 convolutional layers and 3 fully connected layers.
In the provided Flask application, VGG19 is implemented using TensorFlow for style transfer. Here's a brief overview of its implementation:
- Model Loading: The VGG19 model is loaded using TensorFlow's
tf.keras.applications.VGG19
module. - Preprocessing: Images are preprocessed using VGG19's
preprocess_input
function to ensure compatibility with the model. - Style Transfer: The style transfer process involves extracting features from both the style and content images using specific layers of the VGG19 model.
- Loss Calculation: Style loss and content loss are calculated based on the features extracted from the style and content images.
- Optimization: An Adam optimizer is used to minimize the combined loss function, resulting in the generation of a new image that combines the content of the content image with the style of the style image.
This implementation allows users to perform neural style transfer by providing style and content images, along with optional parameters for training epochs and steps per epoch. The generated image is then returned as output, which users can retrieve using the appropriate endpoints.
This Flask API allows users to perform neural style transfer on images. Users can sign up, log in, upload content and style images, and generate new images using a pre-trained neural style transfer model. Additionally, users can retrieve their generated images and reference images stored in the database.
- Endpoint:
/signup
- Method: POST
- Request Body: JSON
{ "name": "Your Name", "email": "[email protected]", "password": "YourPassword" }
- Response: JSON
- Success:
{ "success": true, "message": "User created successfully" }
- Error:
{ "success": false, "error": "Error message" }
- Success:
- Endpoint:
/login
- Method: POST
- Request Body: JSON
{ "email": "[email protected]", "password": "YourPassword" }
- Response: JSON
- Success:
{ "success": true, "message": "Login successful" }
- Error:
{ "success": false, "error": "Error message" }
- Success:
- Endpoint:
/reset_password
- Method: POST
- Request Body: JSON
{ "email": "[email protected]" }
- Response: JSON
- Success:
{ "message": "Password reset email sent successfully" }
- Error:
{ "error": "Error message" }
- Success:
- Endpoint:
/signout
- Method: GET
- Response: JSON
- Success:
{ "success": true, "message": "User signed out successfully" }
- Error:
{ "error": "Error message" }
- Success:
- Endpoint:
/transfer_style
- Method: POST
- Request Body: Form Data
style
: Style image filecontent
: Content image fileepochs
: Number of epochs for training (optional, default is 1)steps_per_epoch
: Steps per epoch (optional, default is 5)
- Response: JSON
- Success:
{ "result": "success", "generated_image": "generated_image.jpg" }
- Error:
{ "success": false, "error": "Error message" }
- Success:
- Endpoint:
/transfer_style_logged_out
- Method: POST
- Request Body: Form Data
style
: Style image filecontent
: Content image fileepochs
: Number of epochs for training (optional, default is 1)steps_per_epoch
: Steps per epoch (optional, default is 5)
- Response: JSON
- Success:
{ "result": "success", "generated_image": "generated_image.jpg" }
- Error:
{ "success": false, "error": "Error message" }
- Success:
- Endpoint:
/get_user_images
- Method: GET
- Response: JSON containing URLs of user's generated images
- Endpoint:
/reference_images
- Method: GET
- Response: JSON containing URLs of reference images stored in the database
- Endpoint:
/generated_image/<image_name>
- Method: GET
- Response: Returns the generated image file
- Sign Up: Register a new account using the
/signup
endpoint. - Log In: Log in using the
/login
endpoint. - Upload Images: Use the
/transfer_style
endpoint to perform neural style transfer. Upload both style and content images along with optional parameters. - Retrieve Generated Images: Use the
/get_user_images
endpoint to retrieve generated images associated with the logged-in user. - Log Out: Use the
/signout
endpoint to log out.