Add neural style transfer example

This commit is contained in:
Matt McWilliams 2021-05-09 12:55:14 -04:00
parent 6537ada194
commit cb0684a574
4 changed files with 54 additions and 0 deletions

BIN
img/normanlewisuntitled.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

6
python/install_neural.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash -e
#https://github.com/ProGamerGov/neural-style-pt
python3 -m pip install neural-style
neural-style -download_models ./

24
python/neural.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
INPUT="${1}"
STYLE="${2}"
OUTPUT="${3}"
mkdir -p frames
mkdir -p neural-frames
ffmpeg -i "${INPUT}" frames/frame-%06d.png
FRAMES=frames/*.png
for frame in ${FRAMES}; do
echo "Running style transfer $frame -> neural-$frame ..."
bash python/style_transfer.sh "${frame}" "${STYLE}" "neural-${frame}"
done
sleep 10
ffmpeg -f image2 -i frames/neural-frame-%06d.png -c:v prores_ks -profile:v 3 "${OUTPUT}"
#rm -rf frames
#rm -rf neural-frames

24
python/style_transfer.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
INPUT="${1}"
STYLE="${2}"
OUTPUT="${3}"
# https://github.com/ProGamerGov/neural-style-pt
neural-style \
-style_image "${STYLE}" \
-content_image "${INPUT}" \
-output_image "${OUTPUT}" \
-model_file python/nin_imagenet.pth \
-gpu c \
-backend nn \
-num_iterations 500 \
-seed 123 \
-content_layers relu0,relu3,relu7,relu12 \
-style_layers relu0,relu3,relu7,relu12 \
-content_weight 10 \
-style_weight 500 \
-save_iter 0 \
-image_size 720 \
-optimizer adam