A simple python script for neural style transfer, using the pre-trained fast arbitrary image style transfer model.
- Download or clone the code.
git clone https://github.com/duncanldaho/unstop && cd unstop
- Inside of the unstop directory create a virtual environment, activate the environment, and install the modules.
# Create a virtual environment:
python3 -m venv unstop
# Activate the environment:
source unstop/bin/activate
# Install python modules:
pip3 install -r requirements
- After set up, you only have to activate the environment and run the script.
source unstop/bin/activate
python3 unst.py
- When finished, deactivate the environment.
deactivate
Try changing the values for the resize function: preserve_aspect_ratio
and
antialias
. I typically preserve the aspect ratio and turn off anti-aliasing,
the effects are sometimes quite subtle.
There are example images in the /data directory. The script applied the style from "style.jpeg" to "content.jpeg" and generates "stylized.jpeg". Unfortunately tensorflow has a lot of dependencies, so it is highly recommended to use a virtual environment. Unstop may not work with future versions of the required modules. It works with the newest versions, and has been confirmed to work with at least:
numpy==1.22.1
tensorflow==2.7.0
tensorflow-hub==0.12.0.
This project works on a raspberry pi (tested on the model 4B). Some guides recommend installing the libatlas package, but unstop will work without it.
sudo apt install libatlas-base-dev