{"id":17139718,"url":"https://github.com/hwalsuklee/tensorflow-style-transfer","last_synced_at":"2025-04-09T14:15:25.482Z","repository":{"id":110398825,"uuid":"80836771","full_name":"hwalsuklee/tensorflow-style-transfer","owner":"hwalsuklee","description":"A simple, concise tensorflow implementation of style transfer (neural style)","archived":false,"fork":false,"pushed_at":"2017-02-17T17:12:57.000Z","size":3693,"stargazers_count":296,"open_issues_count":4,"forks_count":108,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-02T08:37:29.864Z","etag":null,"topics":["change-style","neural-style","online","style-transfer","tensorflow"],"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/hwalsuklee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-03T14:35:03.000Z","updated_at":"2025-02-13T05:06:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"8d59c6b9-7e2b-482c-9606-891be4bb5542","html_url":"https://github.com/hwalsuklee/tensorflow-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/hwalsuklee%2Ftensorflow-style-transfer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwalsuklee%2Ftensorflow-style-transfer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwalsuklee%2Ftensorflow-style-transfer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hwalsuklee%2Ftensorflow-style-transfer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hwalsuklee","download_url":"https://codeload.github.com/hwalsuklee/tensorflow-style-transfer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054194,"owners_count":21039952,"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":["change-style","neural-style","online","style-transfer","tensorflow"],"created_at":"2024-10-14T20:12:53.870Z","updated_at":"2025-04-09T14:15:25.444Z","avatar_url":"https://github.com/hwalsuklee.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Style Transfer (Neural Style)\n\nA tensorflow implementation of style transfer (neural style) described in the papers:\n* [A Neural Algorithm of Artistic Style](https://arxiv.org/pdf/1508.06576v2.pdf) : *submitted version*\n* [Image Style Transfer Using Convolutional Neural Networks](http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Gatys_Image_Style_Transfer_CVPR_2016_paper.pdf) : *published version*  \nby Leon A. Gatys, Alexander S. Ecker, Matthias Bethge\n\nThe implementation is coincided with the paper both in variable-names and algorithms so that a reader of the paper can understand the code without too much effort.\n\n## Usage\n\n### Prerequisites\n1. Tensorflow\n2. Python packages : numpy, scipy, PIL(or Pillow), matplotlib\n3. Pretrained VGG19 file : [imagenet-vgg-verydeep-19.mat](http://www.vlfeat.org/matconvnet/models/imagenet-vgg-verydeep-19.mat)\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;* Please download the file from link above.  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;* Save the file under `pre_trained_model`\n\n### Running\n```\npython run_main.py --content \u003ccontent file\u003e --style \u003cstyle file\u003e --output \u003coutput file\u003e\n```\n*Example*:\n`python run_main.py --content images/tubingen.jpg --style images/starry-night.jpg --output result.jpg`\n\n#### Arguments\n*Required* :  \n* `--content`: Filename of the content image. *Default*: `images/tubingen.jpg`\n* `--style`: Filename of the style image. *Default*: `images/starry-night.jpg`\n* `--output`: Filename of the output image. *Default*: `result.jpg`  \n\n*Optional* :  \n* `--model_path`: Relative or absolute directory path to pre trained model. *Default*: `pre_trained_model`\n* `--loss_ratio`: Weight of content-loss relative to style-loss. Alpha over beta in the paper. *Default*: `1e-3`\n* `--content_layers`: *Space-separated* VGG-19 layer names used for content loss computation. *Default*: `conv4_2`\n* `--style_layers`: *Space-separated* VGG-19 layer names used for style loss computation. *Default*: `relu1_1 relu2_1 relu3_1 relu4_1 relu5_1`\n* `--content_layer_weights`: *Space-separated* weights of each content layer to the content loss. *Default*: `1.0`\n* `--style_layer_weights`: *Space-separated* weights of each style layer to loss. *Default*: `0.2 0.2 0.2 0.2 0.2`\n* `--max_size`: Maximum width or height of the input images. *Default*: `512`\n* `--num_iter`: The number of iterations to run. *Default*: `1000`\n* `--initial_type`: The initial image for optimization. (notation in the paper : x) *Choices*: content, style, random. *Default*: `'content'`\n* `--content_loss_norm_type`: Different types of normalization for content loss. *Choices*: [1](https://arxiv.org/pdf/1508.06576v2.pdf), [2](https://arxiv.org/abs/1604.08610), [3](https://github.com/cysmith/neural-style-tf). *Default*: `3`\n\n## Sample results\n### The Neckarfront in Tübingen, Germany\nResults were obtained from default setting.  \nAn image was rendered approximately after 4 mins on GTX 980 ti.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"images/tubingen.jpg\" height=\"192px\"\u003e\n\u003cimg src=\"samples/tubingen_shipwreck.jpg\" height=\"192px\"\u003e\n\u003cimg src=\"samples/tubingen_starry-night.jpg\" height=\"192px\"\u003e\n\n\u003cimg src=\"samples/tubingen_seated-nude.jpg\" height=\"192px\"\u003e\n\u003cimg src=\"samples/tubingen_the_scream.jpg\" height=\"192px\"\u003e\n\u003cimg src=\"samples/tubingen_kandinsky.jpg\" height=\"192px\"\u003e\n\u003c/p\u003e\n\n### The Gyeongbokgung Palace in Seoul, South Korea\nResults were obtained from default setting except `--max_size 1200`.  \nAn image was rendered approximately after 19.5 mins on  GTX 980 ti.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"images/gyeongbokgung.jpg\" height=\"172px\"\u003e\n\u003cimg src=\"samples/gyeongbokgung_shipwreck.jpg\" height=\"172px\"\u003e\n\u003cimg src=\"samples/gyeongbokgung_starry-night.jpg\" height=\"172px\"\u003e\n\n\u003cimg src=\"samples/gyeongbokgung_seated-nude.jpg\" height=\"172px\"\u003e\n\u003cimg src=\"samples/gyeongbokgung_the_scream.jpg\" height=\"172px\"\u003e\n\u003cimg src=\"samples/gyeongbokgung_kandinsky.jpg\" height=\"172px\"\u003e\n\u003c/p\u003e\n\n## References\n\nThe implementation is based on the projects:\n\n#### https://github.com/Hvass-Labs/TensorFlow-Tutorials/blob/master/15_Style_Transfer.ipynb  \n* This is a tutorial version. Comments on code are well provided. Some exercises are given to check what you learn.  \n\n#### https://github.com/anishathalye/neural-style  \n* This is a simple and well written implemetation, but some parts like optimizer are not conincided with the paper.  \n\n#### https://github.com/cysmith/neural-style-tf  \n* There are other implementations related to style transfer like video style transfer, color-preserving style transfer etc.  \n\nI went through these implementations and found some differences from each other.\n\n1. Style image shape : there are some variations how to resize a style image.  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; *In this implementation, a style image is resized to the shape of a content image.*  \n2. Optimizer : gradient descent, Adam, L-BFGS.  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; *In this implementation, only L-BFGS is provided.*  \n3. Scale factor of loss : scale factors for content-loss and style-loss are different.  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; *In this implementation, style loss is implemented as in the paper.*  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; *About content loss, there are 3 choices.*  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; * *Choice 1 : as in* [A Neural Algorithm of Artistic Style](https://arxiv.org/pdf/1508.06576v2.pdf)     \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; * *Choice 2 : as in* [Artistic style transfer for videos](https://arxiv.org/abs/1604.08610)  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; * *Choice 3 : as in* https://github.com/cysmith/neural-style-tf  \n\n4. Total variance denoising : implementation details for total variance denoising are slightly different.  \n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; *In this implementation, total variance denoising is not provided since the paper does not use it.*\n\n## Acknowledgements\nThis implementation has been tested with Tensorflow r0.12 on Windows 10 and Ubuntu 14.04.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwalsuklee%2Ftensorflow-style-transfer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhwalsuklee%2Ftensorflow-style-transfer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwalsuklee%2Ftensorflow-style-transfer/lists"}