This is a Python script for a Flask web application that performs neural style transfer on two uploaded images. The generated image will have the content of the first image and the style of the second image.
AbhiJais0786.pythonanywhere.com
- Flask
- Pillow (PIL)
- NumPy
- OpenCV (cv2)
- Tensorflow
- Run the script.
- Navigate to localhost in a web browser.
- Upload a content image and a style image.
- Click the "Upload" button.
- Wait for the script to generate the output image.
- The generated image will be displayed on the web page.
- The script checks if the uploaded files are images in PNG, JPEG, or JPG format.
- If the files are valid, the script saves them to the uploads/ folder.
- The script then uses the load_img() function to load the content and style images as NumPy arrays and preprocesses them.
- The script defines the content and style layers to extract from a pre-trained VGG19 network, which will be used to compute the loss functions.
- The script defines functions to compute the content and style loss functions.
- The script defines a function to generate the target image, which will be the generated image.
- The script defines the train_step() function, which performs a single step of optimization to minimize the total loss.
- The script runs a loop to perform the optimization, using the Adam optimizer to minimize the loss.
- The generated image is saved to the static/ folder with a randomly generated filename.
- The generated image is displayed on the web page.
- This script uses the pre-trained VGG19 network provided by TensorFlow Keras.
- The load_img() function resizes the images to a maximum dimension of 512 while maintaining the aspect ratio.
- The train_step() function performs 1000 iterations of optimization per call.
- The total loss is the sum of the content loss and the style loss multiplied by their respective weights.