{"id":13440188,"url":"https://github.com/lengstrom/fast-style-transfer","last_synced_at":"2025-05-13T23:04:44.961Z","repository":{"id":37405735,"uuid":"63832089","full_name":"lengstrom/fast-style-transfer","owner":"lengstrom","description":"TensorFlow CNN for fast style transfer ⚡🖥🎨🖼","archived":false,"fork":false,"pushed_at":"2023-07-16T02:36:30.000Z","size":11288,"stargazers_count":10952,"open_issues_count":111,"forks_count":2595,"subscribers_count":317,"default_branch":"master","last_synced_at":"2025-04-30T08:51:44.573Z","etag":null,"topics":["deep-learning","neural-networks","neural-style","style-transfer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lengstrom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["lengstrom"]}},"created_at":"2016-07-21T02:59:11.000Z","updated_at":"2025-04-28T11:41:06.000Z","dependencies_parsed_at":"2022-07-11T22:00:30.695Z","dependency_job_id":"8dc32583-44ee-4359-99de-2ea0192cbfb6","html_url":"https://github.com/lengstrom/fast-style-transfer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lengstrom%2Ffast-style-transfer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lengstrom%2Ffast-style-transfer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lengstrom%2Ffast-style-transfer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lengstrom%2Ffast-style-transfer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lengstrom","download_url":"https://codeload.github.com/lengstrom/fast-style-transfer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254040555,"owners_count":22004565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","neural-networks","neural-style","style-transfer"],"created_at":"2024-07-31T03:01:20.535Z","updated_at":"2025-05-13T23:04:39.951Z","avatar_url":"https://github.com/lengstrom.png","language":"Python","funding_links":["https://github.com/sponsors/lengstrom"],"categories":["Python","Machine Learning (ML)","图像风格","Project 9.1 Style, Compositions and Patterns","Style Transfer"],"sub_categories":["Tutorials","网络服务_其他"],"readme":"## Fast Style Transfer in [TensorFlow](https://github.com/tensorflow/tensorflow)\n\nAdd styles from famous paintings to any photo in a fraction of a second! [You can even style videos!](#video-stylization)\n\n\u003cp align = 'center'\u003e\n\u003cimg src = 'examples/style/udnie.jpg' height = '246px'\u003e\n\u003cimg src = 'examples/content/stata.jpg' height = '246px'\u003e\n\u003ca href = 'examples/results/stata_udnie.jpg'\u003e\u003cimg src = 'examples/results/stata_udnie_header.jpg' width = '627px'\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align = 'center'\u003e\nIt takes 100ms on a 2015 Titan X to style the MIT Stata Center (1024×680) like Udnie, by Francis Picabia.\n\u003c/p\u003e\n\nOur implementation is based off of a combination of Gatys' [A Neural Algorithm of Artistic Style](https://arxiv.org/abs/1508.06576), Johnson's [Perceptual Losses for Real-Time Style Transfer and Super-Resolution](http://cs.stanford.edu/people/jcjohns/eccv16/), and Ulyanov's [Instance Normalization](https://arxiv.org/abs/1607.08022). \n\n### Sponsorship\nPlease consider sponsoring my work on this project!\n\n### License\nCopyright (c) 2016 Logan Engstrom. Contact me for commercial use (or rather any use that is not academic research) (email: engstrom at my university's domain dot edu). Free for research use, as long as proper attribution is given and this copyright notice is retained.\n\n## Video Stylization \nHere we transformed every frame in a video, then combined the results. [Click to go to the full demo on YouTube!](https://www.youtube.com/watch?v=xVJwwWQlQ1o) The style here is Udnie, as above.\n\u003cdiv align = 'center'\u003e\n     \u003ca href = 'https://www.youtube.com/watch?v=xVJwwWQlQ1o'\u003e\n        \u003cimg src = 'examples/results/fox_udnie.gif' alt = 'Stylized fox video. Click to go to YouTube!' width = '800px' height = '400px'\u003e\n     \u003c/a\u003e\n\u003c/div\u003e\n\nSee how to generate these videos [here](#stylizing-video)!\n\n## Image Stylization\nWe added styles from various paintings to a photo of Chicago. Click on thumbnails to see full applied style images.\n\u003cdiv align='center'\u003e\n\u003cimg src = 'examples/content/chicago.jpg' height=\"200px\"\u003e\n\u003c/div\u003e\n     \n\u003cdiv align = 'center'\u003e\n\u003ca href = 'examples/style/wave.jpg'\u003e\u003cimg src = 'examples/thumbs/wave.jpg' height = '200px'\u003e\u003c/a\u003e\n\u003cimg src = 'examples/results/chicago_wave.jpg' height = '200px'\u003e\n\u003cimg src = 'examples/results/chicago_udnie.jpg' height = '200px'\u003e\n\u003ca href = 'examples/style/udnie.jpg'\u003e\u003cimg src = 'examples/thumbs/udnie.jpg' height = '200px'\u003e\u003c/a\u003e\n\u003cbr\u003e\n\u003ca href = 'examples/style/rain_princess.jpg'\u003e\u003cimg src = 'examples/thumbs/rain_princess.jpg' height = '200px'\u003e\u003c/a\u003e\n\u003cimg src = 'examples/results/chicago_rain_princess.jpg' height = '200px'\u003e\n\u003cimg src = 'examples/results/chicago_la_muse.jpg' height = '200px'\u003e\n\u003ca href = 'examples/style/la_muse.jpg'\u003e\u003cimg src = 'examples/thumbs/la_muse.jpg' height = '200px'\u003e\u003c/a\u003e\n\n\u003cbr\u003e\n\u003ca href = 'examples/style/the_shipwreck_of_the_minotaur.jpg'\u003e\u003cimg src = 'examples/thumbs/the_shipwreck_of_the_minotaur.jpg' height = '200px'\u003e\u003c/a\u003e\n\u003cimg src = 'examples/results/chicago_wreck.jpg' height = '200px'\u003e\n\u003cimg src = 'examples/results/chicago_the_scream.jpg' height = '200px'\u003e\n\u003ca href = 'examples/style/the_scream.jpg'\u003e\u003cimg src = 'examples/thumbs/the_scream.jpg' height = '200px'\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n## Implementation Details\nOur implementation uses TensorFlow to train a fast style transfer network. We use roughly the same transformation network as described in Johnson, except that batch normalization is replaced with Ulyanov's instance normalization, and the scaling/offset of the output `tanh` layer is slightly different. We use a loss function close to the one described in Gatys, using VGG19 instead of VGG16 and typically using \"shallower\" layers than in Johnson's implementation (e.g. we use `relu1_1` rather than `relu1_2`). Empirically, this results in larger scale style features in transformations.\n## Virtual Environment Setup (Anaconda) - Windows/Linux\nTested on\n| Spec                        |                                                             |\n|-----------------------------|-------------------------------------------------------------|\n| Operating System            | Windows 10 Home                                             |\n| GPU                         | Nvidia GTX 2080 TI                                          |\n| CUDA Version                | 11.0                                                        |\n| Driver Version              | 445.75                                                      |\n### Step 1：Install Anaconda\nhttps://docs.anaconda.com/anaconda/install/\n### Step 2：Build a virtual environment\nRun the following commands in sequence in Anaconda Prompt:\n```\nconda create -n tf-gpu tensorflow-gpu=2.1.0\nconda activate tf-gpu\nconda install jupyterlab\njupyter lab\n```\nRun the following command in the notebook or just conda install the package:\n```\n!pip install moviepy==1.0.2\n```\nFollow the commands below to use fast-style-transfer\n## Documentation\n### Training Style Transfer Networks\nUse `style.py` to train a new style transfer network. Run `python style.py` to view all the possible parameters. Training takes 4-6 hours on a Maxwell Titan X. [More detailed documentation here](docs.md#stylepy). **Before you run this, you should run `setup.sh`**. Example usage:\n\n    python style.py --style path/to/style/img.jpg \\\n      --checkpoint-dir checkpoint/path \\\n      --test path/to/test/img.jpg \\\n      --test-dir path/to/test/dir \\\n      --content-weight 1.5e1 \\\n      --checkpoint-iterations 1000 \\\n      --batch-size 20\n\n### Evaluating Style Transfer Networks\nUse `evaluate.py` to evaluate a style transfer network. Run `python evaluate.py` to view all the possible parameters. Evaluation takes 100 ms per frame (when batch size is 1) on a Maxwell Titan X. [More detailed documentation here](docs.md#evaluatepy). Takes several seconds per frame on a CPU. **Models for evaluation are [located here](https://drive.google.com/drive/folders/0B9jhaT37ydSyRk9UX0wwX3BpMzQ?resourcekey=0-Z9LcNHC-BTB4feKwm4loXw\u0026usp=sharing)**. Example usage:\n\n    python evaluate.py --checkpoint path/to/style/model.ckpt \\\n      --in-path dir/of/test/imgs/ \\\n      --out-path dir/for/results/\n\n### Stylizing Video\nUse `transform_video.py` to transfer style into a video. Run `python transform_video.py` to view all the possible parameters. Requires `ffmpeg`. [More detailed documentation here](docs.md#transform_videopy). Example usage:\n\n    python transform_video.py --in-path path/to/input/vid.mp4 \\\n      --checkpoint path/to/style/model.ckpt \\\n      --out-path out/video.mp4 \\\n      --device /gpu:0 \\\n      --batch-size 4\n\n### Requirements\nYou will need the following to run the above:\n- TensorFlow 0.11.0\n- Python 2.7.9, Pillow 3.4.2, scipy 0.18.1, numpy 1.11.2\n- If you want to train (and don't want to wait for 4 months):\n  - A decent GPU\n  - All the required NVIDIA software to run TF on a GPU (cuda, etc)\n- ffmpeg 3.1.3 if you want to stylize video\n\n### Citation\n```\n  @misc{engstrom2016faststyletransfer,\n    author = {Logan Engstrom},\n    title = {Fast Style Transfer},\n    year = {2016},\n    howpublished = {\\url{https://github.com/lengstrom/fast-style-transfer/}},\n    note = {commit xxxxxxx}\n  }\n```\n\n### Attributions/Thanks\n- This project could not have happened without the advice (and GPU access) given by [Anish Athalye](http://www.anishathalye.com/). \n  - The project also borrowed some code from Anish's [Neural Style](https://github.com/anishathalye/neural-style/)\n- Some readme/docs formatting was borrowed from Justin Johnson's [Fast Neural Style](https://github.com/jcjohnson/fast-neural-style)\n- The image of the Stata Center at the very beginning of the README was taken by [Juan Paulo](https://juanpaulo.me/)\n\n### Related Work\n- Michael Ramos ported this network [to use CoreML on iOS](https://medium.com/@rambossa/diy-prisma-fast-style-transfer-app-with-coreml-and-tensorflow-817c3b90dacd)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flengstrom%2Ffast-style-transfer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flengstrom%2Ffast-style-transfer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flengstrom%2Ffast-style-transfer/lists"}