{"id":20419827,"url":"https://github.com/nhatsmrt/torch-styletransfer","last_synced_at":"2026-05-11T15:02:13.577Z","repository":{"id":105924788,"uuid":"191057388","full_name":"nhatsmrt/torch-styletransfer","owner":"nhatsmrt","description":"Implementing style transfer using pytorch","archived":false,"fork":false,"pushed_at":"2019-07-12T11:29:42.000Z","size":108371,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T04:24:25.882Z","etag":null,"topics":["computer-vision","deep-learning","pytorch","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/nhatsmrt.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":"2019-06-09T21:31:50.000Z","updated_at":"2021-12-20T03:06:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"09b81028-ec1d-4484-8975-d0105c5efa68","html_url":"https://github.com/nhatsmrt/torch-styletransfer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nhatsmrt/torch-styletransfer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatsmrt%2Ftorch-styletransfer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatsmrt%2Ftorch-styletransfer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatsmrt%2Ftorch-styletransfer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatsmrt%2Ftorch-styletransfer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhatsmrt","download_url":"https://codeload.github.com/nhatsmrt/torch-styletransfer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatsmrt%2Ftorch-styletransfer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32900044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"online","status_checked_at":"2026-05-11T02:00:05.975Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["computer-vision","deep-learning","pytorch","style-transfer"],"created_at":"2024-11-15T06:38:45.196Z","updated_at":"2026-05-11T15:02:13.541Z","avatar_url":"https://github.com/nhatsmrt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neural Style Transfer with Pytorch\n## Introduction\nImplementation of a neural network that can transfer the style of an arbitrary image to another photo.\n\u003cbr /\u003e\nMuch of the code (e.g the layers) is implemented in my [neural network toolbox](https://github.com/nhatsmrt/nn-toolbox/tree/experimental). The training procedure can be found [here](https://github.com/nhatsmrt/nn-toolbox/blob/experimental/nntoolbox/vision/learner/style.py). This repository contains only the testing code. To replicate my work, please also clone the experimental branch of my nntoolbox repository.\n## Some results\n### Small Experiment:\nI train the thing for 850 iterations, using COCO dataset (resize to 256 for each size), and the train_9 subset of the wikiart dataset. For each dataset, I split 80% of them as training data and use the rest for evaluating. I train the network for a total of 850 iterations (1 \"epoch\"). Some look pretty good:\n\n\u003cimg src=\"demo/PixelShuffle/content_3.png\" alt=\"content\" width=\"175\" /\u003e \u003cimg src=\"demo/PixelShuffle/style_3.png\" alt=\"style\" width=\"175\" /\u003e \u003cimg src=\"demo/PixelShuffle/styled_3.png\" alt=\"styled\" width=\"175\" /\u003e\n\u003cbr /\u003e\n\u003cimg src=\"demo/PixelShuffle/content_1.png\" alt=\"content\" width=\"175\" /\u003e \u003cimg src=\"demo/PixelShuffle/style_1.png\" alt=\"style\" width=\"175\" /\u003e \u003cimg src=\"demo/PixelShuffle/styled_1.png\" alt=\"styled\" width=\"175\" /\u003e\n\nOther less so:\n\n\u003cimg src=\"demo/PixelShuffle/less_successful.png\" alt=\"styled\" width=\"750\" /\u003e\n\nIt seems to work pretty well on resized COCO data (even on untrained/unseen photos), but does not generalize that well too random photos. I suspect the problems lie in resolution discrepancy. Or maybe I just haven't trained for long enough (although in my experiment the quality of the images seem to degrade as I trained more and more).\n\n### Bigger Experiment:\n\nI decided to download the entire wikiart dataset, and use the same preprocessing for both image in the pair (i.e resize to 512 for the smaller side then random crop a square patch of size 256). I also increased the style weight to 10.0, reduced the learning rate to 1e-4 and used a multiplicative learning rate decay. Here are some results after training for 15598 iterations:\n\n\u003cimg src=\"demo/version_2/1.png\" alt=\"styled\" width=\"750\" /\u003e\n\u003cimg src=\"demo/version_2/2.png\" alt=\"styled\" width=\"750\" /\u003e\n\u003cimg src=\"demo/version_2/3.png\" alt=\"styled\" width=\"750\" /\u003e\n\u003cimg src=\"demo/version_2/4.png\" alt=\"styled\" width=\"750\" /\u003e\n\nIt seems like the stylistic elements are more distinct now. The general stroke style, texture, and color scheme are transferred to the source image, without destroying its content structure.\n\n## Reproduction\nCode for reproducing my bigger experiment can be found in src/test. Note that this requires the experimental branch of my nn-toolbox repo (which will be released soon on PyPI).\n\u003cbr /\u003e\nPretrained model (of bigger experiment) can be downloaded [here](https://drive.google.com/open?id=1-EgdKMRq8zk2TqzycNYmI8NInuNKHAXg).\n## Resources\n1. \u003cem\u003eXun Huang, Serge Belongie.\u003c/em\u003e Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization: https://arxiv.org/abs/1703.06868\n\n2. Art images are from WikiArt.org. All images are protected by copyright and utilize the images only for the purposes of data mining, which constitutes a form of fair use.\nData can be download from: https://www.kaggle.com/c/painter-by-numbers/data\n\n3. COCO dataset: http://cocodataset.org/#download\nLicensed under a Creative Commons Attribution 4.0 License.\n\n4. All test images are either from the COCO dataset, except for the cat photos, which are from:\n\nhttps://www.pexels.com/photo/cat-whiskers-kitty-tabby-20787\n\u003cbr /\u003e\nhttps://pxhere.com/en/photo/997773\n\n5. Other AdaIN implementations that are very helpful for my own attempt:\n\nhttps://github.com/naoto0804/pytorch-AdaIN\n\u003cbr /\u003e\nhttps://github.com/xunhuang1995/AdaIN-style\n\n6. The fastai library and lessons have been really useful (I adapted some of the elements of fastai library in my nn-toolbox repository and here).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatsmrt%2Ftorch-styletransfer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhatsmrt%2Ftorch-styletransfer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatsmrt%2Ftorch-styletransfer/lists"}