Neural style transfer is a way of manipulating images or other media to alter their appearance to that of another image.
The neural network takes two images as inputs (one referred to as the content image and the other as the style image) - the content image acts as the base image to which we'll apply the style from the style image.
As for the underlying network itself, the network contains a 'bottleneck' in the middle-most hidden layer. This 'bottleneck' acts as the boundary between the encoding and decoding processes - the encoding process is where the style image is broken down to its features and the decoding process is where the content image is built up using such features.
For a deeper explanation of the archiecture - Towards Data Science article
Google Magenta is the model we'll use to apply the style transfer without having to train our own - we'll make use of the version on TensorFlow Hub. Magenta is a open-source research project exploring the role of machine learning in the process of creating art and music.
Explore Magenta further - Project website
Magenta repo - Github repo
A Python module to explore the neural style transfer capabilities of Google Magneta.
Developed and tested in Python 3.8
Make sure you have Git installed - Download Git
Install Python - Download Python
- Clone this repository to your local machine
- Install the requirements:
>> cd <git-repo-root-dir>
>> pip install -r requirements.txt
Check that the installation was successful by running the following command from terminal / command-line in the src directory:
>> python .\google_magenta_example.py -h
This will print the helper for the command line interface which can be useful for working interactively:
usage: google_magenta_example.py [-h] -c </path/to/content-image> -s </path/to/style-image> -o </path/to/output_file>
This is the CLI for the google_magenta_example module
optional arguments:
-h, --help show this help message and exit
-c </path/to/content-image>, --content-image </path/to/content-image>
Specify path to content image file - including file extension.
-s </path/to/style-image>, --style-image </path/to/style-image>
Specify path to style image file - including file extension.
-o </path/to/output_file>, --output_file </path/to/output_file>
Specify path to output file - including .jpg extension.
Ethan Jones, 2021-08-31