summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxAlpharax <42233094+xAlpharax@users.noreply.github.com>2023-02-26 02:50:33 +0200
committerxAlpharax <42233094+xAlpharax@users.noreply.github.com>2023-02-26 02:50:33 +0200
commit6fe8a3228e3170600b68d9b19e3b8f07e51222fe (patch)
treea648ce29c376aa32f3ace8f18b967ca3d5ea4b55
parent4f51d2b619b5cd359ad853494cb826aa5e29495e (diff)
massive changes in the pipeline and ease of use
-rw-r--r--.gitignore7
-rw-r--r--Images/Azzalee.jpgbin0 -> 233885 bytes
-rwxr-xr-xImages/Jitter_Doll.jpgbin0 -> 288950 bytes
-rw-r--r--Images/Monet.jpgbin0 -> 8412856 bytes
-rw-r--r--Images/Starry_Night.jpgbin0 -> 2684897 bytes
-rw-r--r--Images/bunnies.jpgbin0 -> 110654 bytes
-rw-r--r--Images/colorful.jpgbin0 -> 296376 bytes
-rwxr-xr-xImages/cute.jpgbin0 -> 48794 bytes
-rwxr-xr-xImages/demon.jpgbin0 -> 145801 bytes
-rwxr-xr-xImages/kanade.pngbin0 -> 251615 bytes
-rwxr-xr-xImages/kek.pngbin0 -> 25833 bytes
-rw-r--r--Output/.gitkeep0
-rw-r--r--README.md8
-rwxr-xr-xclear_dir.sh6
-rw-r--r--neuralart.py4
-rw-r--r--preview/Starry_Night_in_Jitter_Doll.mp4bin2415391 -> 298125 bytes
-rw-r--r--preview/bunnies_in_Azzalee.mp4bin0 -> 324140 bytes
-rw-r--r--preview/colorful_in_Azzalee.mp4bin0 -> 309791 bytes
-rw-r--r--preview/cute_in_Jitter_Doll.mp4bin1453537 -> 1484421 bytes
-rw-r--r--renderer.py2
-rwxr-xr-xstylize.sh19
21 files changed, 28 insertions, 18 deletions
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
--- /dev/null
+++ b/Images/Azzalee.jpg
Binary files differ
diff --git a/Images/Jitter_Doll.jpg b/Images/Jitter_Doll.jpg
new file mode 100755
index 0000000..644f8b7
--- /dev/null
+++ b/Images/Jitter_Doll.jpg
Binary files differ
diff --git a/Images/Monet.jpg b/Images/Monet.jpg
new file mode 100644
index 0000000..d9a560a
--- /dev/null
+++ b/Images/Monet.jpg
Binary files differ
diff --git a/Images/Starry_Night.jpg b/Images/Starry_Night.jpg
new file mode 100644
index 0000000..873b050
--- /dev/null
+++ b/Images/Starry_Night.jpg
Binary files differ
diff --git a/Images/bunnies.jpg b/Images/bunnies.jpg
new file mode 100644
index 0000000..0ba2238
--- /dev/null
+++ b/Images/bunnies.jpg
Binary files differ
diff --git a/Images/colorful.jpg b/Images/colorful.jpg
new file mode 100644
index 0000000..a4b5cf6
--- /dev/null
+++ b/Images/colorful.jpg
Binary files differ
diff --git a/Images/cute.jpg b/Images/cute.jpg
new file mode 100755
index 0000000..d039de4
--- /dev/null
+++ b/Images/cute.jpg
Binary files differ
diff --git a/Images/demon.jpg b/Images/demon.jpg
new file mode 100755
index 0000000..84aba91
--- /dev/null
+++ b/Images/demon.jpg
Binary files differ
diff --git a/Images/kanade.png b/Images/kanade.png
new file mode 100755
index 0000000..9ce09aa
--- /dev/null
+++ b/Images/kanade.png
Binary files differ
diff --git a/Images/kek.png b/Images/kek.png
new file mode 100755
index 0000000..6234f73
--- /dev/null
+++ b/Images/kek.png
Binary files differ
diff --git a/Output/.gitkeep b/Output/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Output/.gitkeep
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
--- a/preview/Starry_Night_in_Jitter_Doll.mp4
+++ b/preview/Starry_Night_in_Jitter_Doll.mp4
Binary files differ
diff --git a/preview/bunnies_in_Azzalee.mp4 b/preview/bunnies_in_Azzalee.mp4
new file mode 100644
index 0000000..08974da
--- /dev/null
+++ b/preview/bunnies_in_Azzalee.mp4
Binary files differ
diff --git a/preview/colorful_in_Azzalee.mp4 b/preview/colorful_in_Azzalee.mp4
new file mode 100644
index 0000000..8b78d66
--- /dev/null
+++ b/preview/colorful_in_Azzalee.mp4
Binary files differ
diff --git a/preview/cute_in_Jitter_Doll.mp4 b/preview/cute_in_Jitter_Doll.mp4
index 15e0a23..897b989 100644
--- a/preview/cute_in_Jitter_Doll.mp4
+++ b/preview/cute_in_Jitter_Doll.mp4
Binary files 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