The web app takes style and content image as input via upload or link and generates a stylized image using tensorflow pretrained style transfer model.
Flask==1.1.2
numpy==1.19.2
Pillow==8.2.0
requests==2.25.1
tensorflow==2.4.1
All other dependencies will be installed automatically.
The pretrained model is available at https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2
Flask is used for devloping this web application. As soon as the "POST" request is made,the image urls (or data urls in case of uploaded images) are send to backend server where they are stored in global variables so they can be accessed in other functions. The url images are loaded in cache using requests.get method while uploaded images are decoded back from base64 data urls. The images are then converted to pillow Image object followed by conversion to numpy.
image = Image.open(BytesIO(img))
image = np.array(image).astype(np.float32)
After this the images are preprocessed and loaded in tensorflow model.
The output image is then converted to base64 data url and send to front-end.
- Fork the project
- Create virtual environment and install requirements
- In project directory, run
python app.py
- Web app is live at localhost:5000
The deployment is done on heroku using gunicorn.
Please note the deployment is done using tensorflow-cpu and tensorflow-hub due to heroku slug limit (500MB). The app may not perform well due to the same memory limit.
https://colab.research.google.com/github/tensorflow/hub/blob/master/examples/colab/tf2_arbitrary_image_stylization.ipynb
Stack Overflow
https://codepen.io/FlorinPop17/pen/vPKWjd
https://codepen.io/vladracoare/pen/WNQGZxy
https://codepen.io/cipherbeta/pen/YLdVjw