diff options
author | xAlpharax <42233094+xAlpharax@users.noreply.github.com> | 2023-07-04 23:34:41 +0300 |
---|---|---|
committer | xAlpharax <42233094+xAlpharax@users.noreply.github.com> | 2023-07-04 23:34:41 +0300 |
commit | 0ccf762225924f50f692db19cb6e097095c2d14c (patch) | |
tree | 0fc64e15ec17807d38b9733ede3b3c2292b546fa | |
parent | 8d9d3dc8913a9d6488890188ae4bc73d187f1e0d (diff) |
Subtle changes within stylize.sh, neuralart.py and the README.md files.
Mostly QoS changes and better instructions and error handling.
Changes to be committed:
modified: README.md
modified: neuralart.py
modified: stylize.sh
-rw-r--r-- | README.md | 59 | ||||
-rw-r--r-- | neuralart.py | 2 | ||||
-rwxr-xr-x | stylize.sh | 2 |
3 files changed, 52 insertions, 11 deletions
@@ -2,15 +2,47 @@ 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). The downloaded file should be placed in `./weights/` and any file will be ignored from there when pushing, as seen in `./.gitignore`. Update: Alternatively, if the `./weights/` directory is empty, `./neuralart.py` will automatically download the aforementioned default weights. +Weights can be downloaded from [here](https://m1.afileditch.ch/ajjMsHrRhnikrrCiUXgY.pth). The downloaded file should be placed in `./weights/` and any file will be ignored from there 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 ***just works*** solution that can run on either CPU or GPU effectively. +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 script sits comfortably in `./stylize.sh` so run it (strictly from the project directory): +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 @@ -22,13 +54,20 @@ A helper script is also available to run `./stylize.sh` for each distinct pair o ./all.sh ``` -If, at any point, curious of the individual frames that comprise the generated `./content_in_style.mp4` check `./Output/` -There's also a (redundant) `./images.npy` file that contains raw array data. `./clear_dir.sh` removes redundant files each time they're no longer needed. +Moreover, `./all.sh` is aware of the a;ready rendered mp4 files in the current working directory and will skip stylizing the combinations that are already present. -### Requirements +### Output videos/images and temporary files -All requirements are specified in `./requirements.txt` as per python etiquette: +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 the script in `./stylize.sh` is advised against; if you need something batched/automated, try `./all.sh`) -```bash -pip install -r requirements.txt -``` +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. + +## Contribuiting + +Any sort of help, especially regarding the QoS 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. like the ones the `argparse` python package provides) in order to provide a cleaner interface for working with `./neuralart.py` and/or `./stylize.sh`. + +Thank you. + +Happy neural-art-ing ! diff --git a/neuralart.py b/neuralart.py index d556d2f..7aab03e 100644 --- a/neuralart.py +++ b/neuralart.py @@ -25,7 +25,7 @@ from PIL import Image ### path definitions model_path = 'weights/vgg_conv_weights.pth' -image_path = '' # root (neural-art) directory +image_path = '' # by default use neural-art as relative dir ### userland testing for multiple instances, a big nono currently @@ -2,6 +2,8 @@ set -e ### exit the script if any part of it fails +cd "$(dirname "${BASH_SOURCE[0]}")" + cwd=$(pwd | sed -r 's%.*/%%g') if [ $cwd != "neural-art" ] ; then echo "You must be in the 'neural-art' directory when you run this" |