{"id":13564653,"url":"https://github.com/vvmnnnkv/nodejs-style-transfer","last_synced_at":"2025-10-24T08:39:28.107Z","repository":{"id":37174625,"uuid":"164444020","full_name":"vvmnnnkv/nodejs-style-transfer","owner":"vvmnnnkv","description":"Sample Node.js app for image style transfer using libtorchjs","archived":false,"fork":false,"pushed_at":"2022-12-10T19:23:55.000Z","size":6402,"stargazers_count":20,"open_issues_count":4,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-02-24T02:31:17.269Z","etag":null,"topics":["libtorch","libtorchjs","nodejs","pytorch","style-transfer"],"latest_commit_sha":null,"homepage":"https://nodejs-style-transfer.herokuapp.com","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/vvmnnnkv.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}},"created_at":"2019-01-07T14:24:30.000Z","updated_at":"2023-07-18T12:50:12.000Z","dependencies_parsed_at":"2023-01-26T08:15:08.618Z","dependency_job_id":null,"html_url":"https://github.com/vvmnnnkv/nodejs-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/vvmnnnkv%2Fnodejs-style-transfer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvmnnnkv%2Fnodejs-style-transfer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvmnnnkv%2Fnodejs-style-transfer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvmnnnkv%2Fnodejs-style-transfer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vvmnnnkv","download_url":"https://codeload.github.com/vvmnnnkv/nodejs-style-transfer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250237845,"owners_count":21397403,"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":["libtorch","libtorchjs","nodejs","pytorch","style-transfer"],"created_at":"2024-08-01T13:01:34.079Z","updated_at":"2025-10-24T08:39:23.070Z","avatar_url":"https://github.com/vvmnnnkv.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Image Style Transfer with Node.JS \r\nDemo of image style transfer app based on Node.js and Express \r\nthat uses [fast neural style transfer](https://github.com/pytorch/examples/tree/master/fast_neural_style) model created and traced with Pytorch.\r\n \r\n## Usage\r\nOpen the site on your mobile or desktop, shoot or upload something, stylize :-)\r\n\r\n![Image Style Transfer with Node.js](/docs/screenshot.png?raw=true \"Image Style Transfer with Node.js\")\r\n\r\nLive demo: https://nodejs-style-transfer.herokuapp.com\r\n\r\n## Why? \r\nThis app is inspired by Lessons 6 \u0026 9 of [Facebook Pytorch Scholarship](https://www.udacity.com/facebook-pytorch-scholarship).\r\nIt shows how easy it is possible to deploy high-performance ML models these days combining \r\nsuch popular platforms as Node.js and NPM with newly released Torch Script feature of Pytorch.\r\n\r\nApart from that, Node.js non-blocking I/O seems to be good fit for running NN inference in Worker Pool.\r\n\r\nThe heavy lifting of image processing is done by [libtorch C++ library](https://pytorch.org/cppdocs/), which is wrapped in Node.js module [libtorchjs](https://www.npmjs.com/package/libtorchjs) \r\n created specially for this app to expose some bits of libtorch in JS.  \r\n\r\n## Running\r\nCurrently supported platforms are Linux and Windows. libtorch does have Mac variant,\r\n but it's not included in [libtorchjs](https://www.npmjs.com/package/libtorchjs) yet.\r\nGPU is also not supported yet.\r\n\r\n### Linux or Windows\r\nCheckout repo, install npm libraries, start app: \r\n```\r\n$ npm i\r\n$ npm run start\r\n```\r\nOpen http://localhost:3000/\r\n\r\n### Docker\r\nCheckout repo, build image and run: \r\n```\r\n$ docker build --tag=nodejs-style-transfer .\r\n$ docker run -P nodejs-style-transfer\r\n```\r\nOpen http://localhost:3000/\r\n\r\n## How to Add Style\r\nThis app has just one style included.  \r\nThe easiest way to create more models is to install [`fast_neural_style`](https://github.com/pytorch/examples/tree/master/fast_neural_style) from Pytorch examples \r\nand add following code in the end of `stylyze` function in\r\n[fast_neural_style/neural_style/neural_style.py](https://github.com/pytorch/examples/blob/master/fast_neural_style/neural_style/neural_style.py#L122): \r\n```python\r\ntraced_script_module = torch.jit.trace(style_model, content_image)\r\ntraced_script_module.save(\"style_model.pt\")\r\n```\r\nAnd after that, execute stylization script on any image and this will write out `style_model.pt`.\r\nNote that traced model will keep the size of your image and will be able to work only with same dimensions.\r\nFor this demo app, image size is fairly small (`224x224`) so it's fast even on CPU.\r\n\r\nSee [libtorch tutorial](https://pytorch.org/tutorials/advanced/cpp_export.html) for more info about model tracing.\r\n\r\n## Acknowledgements\r\n * Inspiration: https://www.udacity.com/facebook-pytorch-scholarship\r\n * Model: https://github.com/pytorch/examples/tree/master/fast_neural_style\r\n * Model tracing tutorial: https://pytorch.org/tutorials/advanced/cpp_export.html \r\n * Canvas \u0026 EXIF helpers: https://stackoverflow.com/a/40867559 https://stackoverflow.com/a/21961894\r\n * Spinners: https://loading.io/spinner/fidget-spinner\r\n\r\n## Disclamer\r\nNote that it's just a toy project and [libtorchjs](https://www.npmjs.com/package/libtorchjs) is too immature to use in production.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvvmnnnkv%2Fnodejs-style-transfer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvvmnnnkv%2Fnodejs-style-transfer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvvmnnnkv%2Fnodejs-style-transfer/lists"}