1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# 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://files.catbox.moe/wcao20.pth). The downloaded file (renamed to `vgg_conv_weights.pth`) should be placed in `./weights/` and it will be ignored when pushing, as seen in `./.gitignore`. **Update:** Alternatively, if the `./weights/` directory is empty, `./neuralart.py` will automatically download publicly available VGG19 weights for the user.
More in depth information about Neural Style Transfer ( NST ) can be found in this great [paper](https://arxiv.org/abs/1705.04058). Make sure to check [Requirements](#requirements) and [Usage](#usage).
### 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 inputting a style and content image rather than a well curated prompt with a dozen of switches. Consider this repo as a quick and simple ***just works*** solution that can run on both CPU and GPU effectively.
I developed this tool as a means to obtain fancy images and visuals for me and my friends. It somehow grew into something bigger that is actually usable, so much so that I got to integrate it in a workflow in conjunction with [Stable Diffusion](https://github.com/CompVis/stable-diffusion) ( see also [here](https://github.com/AUTOMATIC1111/stable-diffusion-webui) ).
## Requirements
Clone the repository:
```bash
git clone https://github.com/xAlpharax/neural-art
```
Create a virtual environment to separate the required packages from system-wide packages:
```bash
virtualenv path/to/neural-art
source path/to/neural-art/bin/activate
```
( ! ) When you're finished with the environment:
```bash
# deactivate
```
All the required packages are listed in `./requirements.txt` as per python etiquette:
```bash
pip install -r requirements.txt
```
## Usage
The main script sits comfortably in `./stylize.sh` so run it from the project's directory:
```bash
./stylize.sh path/to/style_image path/to/content_image
```
A helper script is also available to run `./stylize.sh` for each distinct pair of images present in the `./Images/` directory:
```bash
./all.sh
```
Moreover, `./all.sh` is aware of the already rendered mp4 files and will skip stylizing the combinations that are already present.
### Output videos / images and temporary files
If, at any point, curious of the individual frames that comprise the generated `./content_in_style.mp4` check `./Output/` for PNG images with exactly that. Keep in mind that these files get removed and overwritten each time ./stylize.sh is called ( this is also why running multiple instances of `./stylize.sh` is advised against; if you need to batch/automate the process, try `./all.sh` )
The `./images.npy` file contains raw numpy array data generated by `./neuralart.py` and is manipulated by `./renderer.py` to achieve the `./Output` directory of PNG images.
Considering this workflow, `./clear_dir.sh` removes temporary files each time a new call to `./stylize.sh` is made.
<details>
<summary><h2>Results after running neural-art (Click on dropdown for video gallery)</h2></summary>
[//]: # (Bunnies in Monet)
https://github.com/xAlpharax/neural-art/assets/42233094/0094a10b-e452-4284-b0d6-08df471d1848
[//]: # (Bunnies in Azzalee)
https://github.com/xAlpharax/neural-art/assets/42233094/ef7e5fa8-203d-48a7-92da-7f462cb17601
[//]: # (Bunnies in Starry Night)
https://github.com/xAlpharax/neural-art/assets/42233094/bdfc854e-cb01-4398-9dbd-c8fa34e99310
[//]: # (Azzalee in Monet)
https://github.com/xAlpharax/neural-art/assets/42233094/38313363-a8d9-4496-b596-34e56d444642
[//]: # (Monet in Azalee)
https://github.com/xAlpharax/neural-art/assets/42233094/59b7f348-d599-432e-bbd9-b613b114a4ac
[//]: # (Starry Night in Azzalee)
https://github.com/xAlpharax/neural-art/assets/42233094/7993f61f-b5ed-49a7-8167-10b266cbf591
[//]: # (Azzalee in Starry Night)
https://github.com/xAlpharax/neural-art/assets/42233094/c46b326c-7b96-4ef4-b6fd-dbfcb7a3572f
[//]: # (Jitter Doll in Starry Night)
https://github.com/xAlpharax/neural-art/assets/42233094/216b9e44-b563-42f7-9d66-f1d48bb3493a
[//]: # (Starry Night in Jitter Doll)
https://github.com/xAlpharax/neural-art/assets/42233094/c6c4f4d1-f00e-4388-b726-5f6358cb5bc8
[//]: # (Cute in Jitter Doll a.k.a. how my profile pic was generated)
https://github.com/xAlpharax/neural-art/assets/42233094/981f2855-2524-4c83-87f4-beac6ff5cfa6
</details>
## Contributing
Any sort of help, especially regarding the QoS ( Quality of Service ) of the project, is appreciated. Feel free to open an issue in the **Issues** tab and discuss the possible changes there. As of now, **neural-art** would be in great need of a clean and friendly arguments handler ( i.e. the one the `argparse` python package provides ) in order to accommodate to a cleaner interface for `./neuralart.py` and / or `./stylize.sh`.
Thank you. Happy neural-art-ing !
|