From 6fe8a3228e3170600b68d9b19e3b8f07e51222fe Mon Sep 17 00:00:00 2001 From: xAlpharax <42233094+xAlpharax@users.noreply.github.com> Date: Sun, 26 Feb 2023 02:50:33 +0200 Subject: massive changes in the pipeline and ease of use --- .gitignore | 7 +++++-- Images/Azzalee.jpg | Bin 0 -> 233885 bytes Images/Jitter_Doll.jpg | Bin 0 -> 288950 bytes Images/Monet.jpg | Bin 0 -> 8412856 bytes Images/Starry_Night.jpg | Bin 0 -> 2684897 bytes Images/bunnies.jpg | Bin 0 -> 110654 bytes Images/colorful.jpg | Bin 0 -> 296376 bytes Images/cute.jpg | Bin 0 -> 48794 bytes Images/demon.jpg | Bin 0 -> 145801 bytes Images/kanade.png | Bin 0 -> 251615 bytes Images/kek.png | Bin 0 -> 25833 bytes Output/.gitkeep | 0 README.md | 8 ++++---- clear_dir.sh | 6 +++--- neuralart.py | 4 ++-- preview/Starry_Night_in_Jitter_Doll.mp4 | Bin 2415391 -> 298125 bytes preview/bunnies_in_Azzalee.mp4 | Bin 0 -> 324140 bytes preview/colorful_in_Azzalee.mp4 | Bin 0 -> 309791 bytes preview/cute_in_Jitter_Doll.mp4 | Bin 1453537 -> 1484421 bytes renderer.py | 2 +- stylize.sh | 19 +++++++++++++------ 21 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 Images/Azzalee.jpg create mode 100755 Images/Jitter_Doll.jpg create mode 100644 Images/Monet.jpg create mode 100644 Images/Starry_Night.jpg create mode 100644 Images/bunnies.jpg create mode 100644 Images/colorful.jpg create mode 100755 Images/cute.jpg create mode 100755 Images/demon.jpg create mode 100755 Images/kanade.png create mode 100755 Images/kek.png create mode 100644 Output/.gitkeep create mode 100644 preview/bunnies_in_Azzalee.mp4 create mode 100644 preview/colorful_in_Azzalee.mp4 diff --git a/.gitignore b/.gitignore index 4ec1e79..b25872c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ ### custom ignores here -Images/* -images.npy +weights/*.pth +Images/personal/ +Output/*.png +*.npy +todo # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/Images/Azzalee.jpg b/Images/Azzalee.jpg new file mode 100644 index 0000000..355c3c2 Binary files /dev/null and b/Images/Azzalee.jpg differ diff --git a/Images/Jitter_Doll.jpg b/Images/Jitter_Doll.jpg new file mode 100755 index 0000000..644f8b7 Binary files /dev/null and b/Images/Jitter_Doll.jpg differ diff --git a/Images/Monet.jpg b/Images/Monet.jpg new file mode 100644 index 0000000..d9a560a Binary files /dev/null and b/Images/Monet.jpg differ diff --git a/Images/Starry_Night.jpg b/Images/Starry_Night.jpg new file mode 100644 index 0000000..873b050 Binary files /dev/null and b/Images/Starry_Night.jpg differ diff --git a/Images/bunnies.jpg b/Images/bunnies.jpg new file mode 100644 index 0000000..0ba2238 Binary files /dev/null and b/Images/bunnies.jpg differ diff --git a/Images/colorful.jpg b/Images/colorful.jpg new file mode 100644 index 0000000..a4b5cf6 Binary files /dev/null and b/Images/colorful.jpg differ diff --git a/Images/cute.jpg b/Images/cute.jpg new file mode 100755 index 0000000..d039de4 Binary files /dev/null and b/Images/cute.jpg differ diff --git a/Images/demon.jpg b/Images/demon.jpg new file mode 100755 index 0000000..84aba91 Binary files /dev/null and b/Images/demon.jpg differ diff --git a/Images/kanade.png b/Images/kanade.png new file mode 100755 index 0000000..9ce09aa Binary files /dev/null and b/Images/kanade.png differ diff --git a/Images/kek.png b/Images/kek.png new file mode 100755 index 0000000..6234f73 Binary files /dev/null and b/Images/kek.png differ diff --git a/Output/.gitkeep b/Output/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index df38437..3a2e442 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # neural-art Neural Style Transfer done from the CLI using a VGG backbone and presented as an MP4. -Weights can be downloaded from [here](https://m1.afileditch.ch/ajjMsHrRhnikrrCiUXgY.pth). This is done to put as little strain as possible on github. The downloaded file should be placed in `./weights/` +Weights can be downloaded from [here](https://m1.afileditch.ch/ajjMsHrRhnikrrCiUXgY.pth). The downloaded file should be placed in `./weights/` and will be ignored when pushing as per `./.gitignore` ### Why use this in 2023 ? -Because style transfer hasn't changed drastically in terms of actual results in the past years. I personally find a certain beauty in inputing an image with a desired style rather than a well curated prompt with a dozen of switches. +Because style transfer hasn't changed drastically in terms of actual results in the past years. I personally find a certain beauty in inputing an image with a desired style rather than a well curated prompt with a dozen of switches. Consider using this repo as a quick *just works* solution that can run on both CPU and GPU. ## Usage -The script sits comfortably in `./stylize.sh` so just run it: +The script sits comfortably in `./stylize.sh` so just run it from the project directory: ```bash -./stylize.sh path/to/style_image path/to/content_image content_in_style.mp4 +./stylize.sh path/to/style_image path/to/content_image ``` diff --git a/clear_dir.sh b/clear_dir.sh index 6b7e3db..57f891a 100755 --- a/clear_dir.sh +++ b/clear_dir.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/zsh ### clearing up the directory ### from temporary files -rm -rf __pycache__ -rm -f Output/* images.npy +rm -rf __pycache__ # Output* future proof +rm -f Output/* *.npy diff --git a/neuralart.py b/neuralart.py index 4b29d21..ebbbb94 100644 --- a/neuralart.py +++ b/neuralart.py @@ -147,7 +147,7 @@ prep = transforms.Compose([transforms.Resize(img_size), ]) # POST-PROCESSING A -postpa = transforms.Compose([transforms.Lambda(lambda x: x.mul_(1./255)), +postpa = transforms.Compose([transforms.Lambda(lambda x: x.mul_(1./255)), # REVERT EVERYTHING DONE IN THE PRE-PROCESSING STEP transforms.Normalize(mean = [-0.40760392, -0.45795686, -0.48501961], std = [1, 1, 1]), transforms.Lambda(lambda x: x[torch.LongTensor([2,1,0])]) ]) @@ -234,7 +234,7 @@ targets = style_targets + content_targets import numpy as np from tqdm import tqdm -vis_factor = 3 +vis_factor = 5 max_iter = 600 * vis_factor show_iter = 1 * vis_factor diff --git a/preview/Starry_Night_in_Jitter_Doll.mp4 b/preview/Starry_Night_in_Jitter_Doll.mp4 index b6a264d..bc75f35 100644 Binary files a/preview/Starry_Night_in_Jitter_Doll.mp4 and b/preview/Starry_Night_in_Jitter_Doll.mp4 differ diff --git a/preview/bunnies_in_Azzalee.mp4 b/preview/bunnies_in_Azzalee.mp4 new file mode 100644 index 0000000..08974da Binary files /dev/null and b/preview/bunnies_in_Azzalee.mp4 differ diff --git a/preview/colorful_in_Azzalee.mp4 b/preview/colorful_in_Azzalee.mp4 new file mode 100644 index 0000000..8b78d66 Binary files /dev/null and b/preview/colorful_in_Azzalee.mp4 differ diff --git a/preview/cute_in_Jitter_Doll.mp4 b/preview/cute_in_Jitter_Doll.mp4 index 15e0a23..897b989 100644 Binary files a/preview/cute_in_Jitter_Doll.mp4 and b/preview/cute_in_Jitter_Doll.mp4 differ diff --git a/renderer.py b/renderer.py index 98b32f5..7eaae9a 100644 --- a/renderer.py +++ b/renderer.py @@ -24,7 +24,7 @@ def render(index): plt.axis('off') plt.imshow(image_array[index]) - plt.savefig(name, dpi=258, bbox_inches='tight', pad_inches=0) # dpi 258 -> 720p ; dpi 387 -> 1080p output image resolution + plt.savefig(name, bbox_inches='tight', pad_inches=0) # dpi 258 -> 720p ; dpi 387 -> 1080p output image resolution plt.close('all') for index in range(0, len(image_array)): diff --git a/stylize.sh b/stylize.sh index 0095629..434c079 100755 --- a/stylize.sh +++ b/stylize.sh @@ -1,18 +1,25 @@ -#!/bin/bash +#!/bin/zsh ### You must be in the 'neural-art' directory when you run this -if [ $# -eq 2 ] +if [ $# -eq 0 ] then - echo "Video file needs to be specified" + echo "Style Image and Content Image need to be specified as arguments" + echo "Example: ./stylize.sh Images/Jitter_Doll.jpg Images/cute.jpg" + exit 1 +fi + +if [ $# -eq 1 ] + then + echo "Content image needs to be specified" exit 1 fi # stylize data [pair (style, content)] python neuralart.py $1 $2 -# render images (actual frames) from images.npy -python renderer.py +# render images (actual frames) from (an) images.npy +python renderer.py $1 $2 # turn everything into a video -ffmpeg -framerate 60 -pattern_type glob -i 'Output/neural_art_*.png' -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" $3 +ffmpeg -framerate 60 -pattern_type glob -i 'Output/neural_art_*.png' -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" ${${2/*\/}/.*}_in_${${1/*\/}/.*}.mp4 -- cgit v1.2.3