Skip to content

Instantly share code, notes, and snippets.

@olegs
Last active January 20, 2019 11:56
Show Gist options
  • Save olegs/fd5db571e5c5b23426831649a38cce1f to your computer and use it in GitHub Desktop.
Save olegs/fd5db571e5c5b23426831649a38cce1f to your computer and use it in GitHub Desktop.
Batch processing of fast-style-transfer for Udacity Deep Learning Nanodegree
# This is a bash script for batch images processing using https://github.com/lengstrom/fast-style-transfer code.
# Used in udacity Deep Learning Nanodegree https://www.udacity.com/course/deep-learning-nanodegree--nd101
# Step 1. Configure environment
# conda create -n style-transfer python=3
# activate style-transfer
# conda install tensorflow scipy pillow
# pip install moviepy
# python -c "import imageio; imageio.plugins.ffmpeg.download()"
#
# Step 2. Close source code and have fun
# git clone https://github.com/lengstrom/fast-style-transfer.git
#
# Create the following subfolders:
# ./checkpoints - folder with style checkpoints
# ./inputs - folder with images in *.jpg format
# ./outputs - folder with results. Resulting filenames: <original_image_name>_<style_name>.jpg
#
# Step 3. My experience
# In case you experiencing OMP related problems visit: https://github.com/dmlc/xgboost/issues/1715
#
# Step 4. Questions or comments? oleg.shpynov[at]gmail.com
for IMG in $(find $(pwd)/inputs -name "*.jpg"); do
echo "IMG: ${IMG}"
for STYLE in $(find $(pwd)/checkpoints -name "*.ckpt"); do
echo "STYLE: ${STYLE}"
NAME=$(echo ${STYLE} | sed -e 's#.*/##g' | sed 's#.ckpt##g')
RESULT="$(echo ${IMG} | sed 's#.jpg##g' | sed 's#inputs#outputs#g')_${NAME}.jpg"
echo "RESULT: ${RESULT}"
if [[ ! -f ${RESULT} ]]; then
python evaluate.py --checkpoint ${STYLE} --in-path ${IMG} --out-path ${RESULT}
fi
done
done
# The following python code can be used to create animated GIF results
# import glob
# import imageio as io
# import re
#
# for img in glob.glob('inputs/*.jpg'):
# print('Processing {}'.format(img))
# name = re.sub('inputs/|\.jpg', '', img)
# images = [ img ] + glob.glob('outputs/{}*.jpg'.format(name))
# gif = 'outputs/{}.gif'.format(name)
# io.mimsave(gif, [ io.imread(i) for i in images ], duration=0.5)
# print('Saved {}'.format(gif))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment