Applying a random picture style to a set of images preserving original image size using Tensorflow.
Clone this repo and cd to the directory.
Install dependencies using the following command:
pip install -r requirements.txt
Drop your content images into the "img" folder.
Drop image styles into the "styles" folder.
Run the script using the following command:
python fumanji.py
The script will generate a set of images based on the content images and applying a random image style. The generated images will be saved in the "results" folder.
usage: fumanji.py [-h] [-o OUTPUT_SIZE] [-s STYLE_SIZE] [-t] [-q QUANTITY] [-i ITERATIONS] [-f INTENSITY] [-r]
options:
-h, --help show this help message and exit
-o OUTPUT_SIZE, --output_size OUTPUT_SIZE
Image output size. [small, medium, large, original] GPU memory can prevent using 'original' image size.
(default: medium)
-s STYLE_SIZE, --style_size STYLE_SIZE
Style size. [xsmall, small, medium, large, xlarge] (default: small)
-t, --trained Uses pre-trained model. (default: False)
-q QUANTITY, --quantity QUANTITY
How many images to process. (default: None)
-i ITERATIONS, --iterations ITERATIONS
How many iterations to apply. Min 1, Max 100. (default: 1)
-f INTENSITY, --intensity INTENSITY
Effect Strenght. (default: 30)
-r, --show_result Shows result after each iteration. (default: False)
Take note that each time the script runs it will empty the "results" folder.
Tested on Windows
To speed up, if you have a NVIDIA GPU, you must install the following stuff:
- NVIDIA CUDA Toolkit - Please, check before download, so you can download the one that suits your environment.
- NVIDIA cuDNN(NVIDIA CUDA Neural Network Library) - Download, unpack and copy contents from cuda to NVIDIA CUDA Toolkit folder. (example:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\
)
To download both CUDA and cuDNN, you need to have a NVIDIA Developer account.
If you found some error at run, like Error 193, check if your CUDA version is compatible with cuDNN. You must download/install compatible CUDA and cuDNN. Also check if your Tensorflow is compatible with your CUDA version. Documentation suggest to use CUDA Toolkit 11.2 and cuDNN 8.1.0.
For this, you need to install Tensorflow for Mac. The process is:
- Install Anaconda for Mac
- Install Miniforge: This allows to download packages precompiled for Apple Silicon (arm). Running:
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh" bash Mambaforge-$(uname)-$(uname -m).sh
orwget "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh" bash Mambaforge-$(uname)-$(uname -m).sh
should do the trick. - Follow this article by Prabat with all the steps here
It is supposed that you can improve this script using CUDA.
Thanks to Behic Guven article. It was a great help to understand how to use Tensorflow.