Localized Style Transfer is an application that performs style transfer while allowing the user control over which portion of the image the style transfer gets applied to. The user provides two images: a style image to emulate and a content image to apply the style to. The Flask web application provides the user with a list of objects detected to create a mask and control where the style transfer gets applied to, leaving the rest of the image intact.
In order to host and run the web application on local machines, follow these steps:
-
Clone the repository.
-
For Ubuntu, install
libasound2-dev
:sudo apt-get install libasound2-dev
-
Create a virtual environment to install dependencies:
python3 -m venv path/to/my_venv
-
Activate the virtual enviroment created:
source activate
-
Install dependencies from
requirements.txt
:pip install -r requirements.txt
-
To install dependencies needed to access MS COCO:
On Linux, run
pip install git+https://github.com/waleedka/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI
On Windows, run
pip install git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^&subdirectory=PythonAPI
*Try
pip3 install git+https://github.com/waleedka/coco.git#subdirectory=PythonAPI
if experiencing errors with above lines. -
Run
pip install magenta
to install magenta machine learning packages.
- Activate virtual environment and run the web application using the command
python main.py
- The script will automatically download mask_rcnn_coco.h5 file for the object detection model and arbitrary_style_transfer folder for the style transfer model.
- Open a web browser and enter the address
localhost:5000
orhttp://127.0.0.1:5000
- Select a style image and a content image.
- Choose whether to apply the style transfer to:
- the whole image
- the whole image with adjustable style weights
- selected objects
- inverse of the selected objects.
- In the case of the third and forth options, pick objects by inputing a comma or space separated list of numbers. Each number corresponds to the label number appeared at th beginning of the detected captions. Enter 1000 to select all detected objects.