diff options
author | xAlpharax <42233094+xAlpharax@users.noreply.github.com> | 2023-02-26 02:50:33 +0200 |
---|---|---|
committer | xAlpharax <42233094+xAlpharax@users.noreply.github.com> | 2023-02-26 02:50:33 +0200 |
commit | 6fe8a3228e3170600b68d9b19e3b8f07e51222fe (patch) | |
tree | a648ce29c376aa32f3ace8f18b967ca3d5ea4b55 | |
parent | 4f51d2b619b5cd359ad853494cb826aa5e29495e (diff) |
massive changes in the pipeline and ease of use
-rw-r--r-- | .gitignore | 7 | ||||
-rw-r--r-- | Images/Azzalee.jpg | bin | 0 -> 233885 bytes | |||
-rwxr-xr-x | Images/Jitter_Doll.jpg | bin | 0 -> 288950 bytes | |||
-rw-r--r-- | Images/Monet.jpg | bin | 0 -> 8412856 bytes | |||
-rw-r--r-- | Images/Starry_Night.jpg | bin | 0 -> 2684897 bytes | |||
-rw-r--r-- | Images/bunnies.jpg | bin | 0 -> 110654 bytes | |||
-rw-r--r-- | Images/colorful.jpg | bin | 0 -> 296376 bytes | |||
-rwxr-xr-x | Images/cute.jpg | bin | 0 -> 48794 bytes | |||
-rwxr-xr-x | Images/demon.jpg | bin | 0 -> 145801 bytes | |||
-rwxr-xr-x | Images/kanade.png | bin | 0 -> 251615 bytes | |||
-rwxr-xr-x | Images/kek.png | bin | 0 -> 25833 bytes | |||
-rw-r--r-- | Output/.gitkeep | 0 | ||||
-rw-r--r-- | README.md | 8 | ||||
-rwxr-xr-x | clear_dir.sh | 6 | ||||
-rw-r--r-- | neuralart.py | 4 | ||||
-rw-r--r-- | preview/Starry_Night_in_Jitter_Doll.mp4 | bin | 2415391 -> 298125 bytes | |||
-rw-r--r-- | preview/bunnies_in_Azzalee.mp4 | bin | 0 -> 324140 bytes | |||
-rw-r--r-- | preview/colorful_in_Azzalee.mp4 | bin | 0 -> 309791 bytes | |||
-rw-r--r-- | preview/cute_in_Jitter_Doll.mp4 | bin | 1453537 -> 1484421 bytes | |||
-rw-r--r-- | renderer.py | 2 | ||||
-rwxr-xr-x | stylize.sh | 19 |
21 files changed, 28 insertions, 18 deletions
@@ -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 Binary files differnew file mode 100644 index 0000000..355c3c2 --- /dev/null +++ b/Images/Azzalee.jpg diff --git a/Images/Jitter_Doll.jpg b/Images/Jitter_Doll.jpg Binary files differnew file mode 100755 index 0000000..644f8b7 --- /dev/null +++ b/Images/Jitter_Doll.jpg diff --git a/Images/Monet.jpg b/Images/Monet.jpg Binary files differnew file mode 100644 index 0000000..d9a560a --- /dev/null +++ b/Images/Monet.jpg diff --git a/Images/Starry_Night.jpg b/Images/Starry_Night.jpg Binary files differnew file mode 100644 index 0000000..873b050 --- /dev/null +++ b/Images/Starry_Night.jpg diff --git a/Images/bunnies.jpg b/Images/bunnies.jpg Binary files differnew file mode 100644 index 0000000..0ba2238 --- /dev/null +++ b/Images/bunnies.jpg diff --git a/Images/colorful.jpg b/Images/colorful.jpg Binary files differnew file mode 100644 index 0000000..a4b5cf6 --- /dev/null +++ b/Images/colorful.jpg diff --git a/Images/cute.jpg b/Images/cute.jpg Binary files differnew file mode 100755 index 0000000..d039de4 --- /dev/null +++ b/Images/cute.jpg diff --git a/Images/demon.jpg b/Images/demon.jpg Binary files differnew file mode 100755 index 0000000..84aba91 --- /dev/null +++ b/Images/demon.jpg diff --git a/Images/kanade.png b/Images/kanade.png Binary files differnew file mode 100755 index 0000000..9ce09aa --- /dev/null +++ b/Images/kanade.png diff --git a/Images/kek.png b/Images/kek.png Binary files differnew file mode 100755 index 0000000..6234f73 --- /dev/null +++ b/Images/kek.png diff --git a/Output/.gitkeep b/Output/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Output/.gitkeep @@ -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 Binary files differindex b6a264d..bc75f35 100644 --- a/preview/Starry_Night_in_Jitter_Doll.mp4 +++ b/preview/Starry_Night_in_Jitter_Doll.mp4 diff --git a/preview/bunnies_in_Azzalee.mp4 b/preview/bunnies_in_Azzalee.mp4 Binary files differnew file mode 100644 index 0000000..08974da --- /dev/null +++ b/preview/bunnies_in_Azzalee.mp4 diff --git a/preview/colorful_in_Azzalee.mp4 b/preview/colorful_in_Azzalee.mp4 Binary files differnew file mode 100644 index 0000000..8b78d66 --- /dev/null +++ b/preview/colorful_in_Azzalee.mp4 diff --git a/preview/cute_in_Jitter_Doll.mp4 b/preview/cute_in_Jitter_Doll.mp4 Binary files differindex 15e0a23..897b989 100644 --- a/preview/cute_in_Jitter_Doll.mp4 +++ b/preview/cute_in_Jitter_Doll.mp4 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)): @@ -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 |