Giter VIP home page Giter VIP logo

fast-style-transfer-deeplearnjs's Introduction

Fast Neural Style Transfer in browser with deeplearn.js

DEPRECATED: This repository has been deprecated and is no longer actively maintained (build instructions no longer work either). There is a much, much better version (where you can use ANY style) at https://github.com/reiinakano/arbitrary-image-stylization-tfjs. If you're really interested in this version of fast style transfer, this code has been integrated into the ml5.js library and the TensorFlow.js version is actively maintained over there.

This repository contains an implementation of the Fast Neural Style Transfer algorithm running fully inside a browser using the Deeplearn.JS library.

Demo website: https://reiinakano.github.io/fast-style-transfer-deeplearnjs

demo_screen

FAQ

What is this about?

This is an implementation of the Fast Neural Style Transfer algorithm running purely on the browser using the Deeplearn.JS library. Basically, a neural network attempts to "draw" one picture, the Content, in the style of another, the Style.

Is my data safe? Can you see my webcam pics?

Your data and pictures here never leave your computer! In fact, this is one of the main advantages of running neural networks in your browser. Instead of sending us your data, we send you both the model and the code to run the model. These are then run by your browser.

How big are the models I'm downloading?

For each available style, your browser will download a model around ~6.6MB in size. Be careful if you have limited bandwidth (mobile data users).

The web page is ugly.

I know. Sorry, I'm not really a UI designer. I have about a 10 minute tolerance for tweaking HTML and CSS until I give up. The good news is, it's all open source on Github! If you want to help improve the page's design, please send a pull request! :)

Development

To run this locally, clone the project and prepare the development environment:

$ git clone https://github.com/reiinakano/fast-style-transfer-deeplearnjs.git
$ cd fast-style-transfer-deeplearnjs
$ npm install && bower install # Install node modules and bower components

To interactively develop the application

$ ./scripts/watch-demo src/styletransfer-demo.ts
>> Waiting for initial compile...
>> 1023189 bytes written to src/bundle.js (0.71 seconds) at 2:20:06 AM
>> Starting up http-server, serving ./
>> Available on:
>>   http://127.0.0.1:8080
>> Hit CTRL-C to stop the server

The application will be available at http://localhost:8080/src/styletransfer-demo.html and will watch for changes of typescript code.

Adding your own styles

The way Fast Neural Style Transfer works is, one has to train a new neural network for each "Style" image and upload it to the server. Training takes 4-6 hours on a relatively powerful GPU (Maxwell Titan X).

To train your own style model from scratch, please follow the instructions from this Github repository to get your own .ckpt file. You will need Python, Tensorflow, and a decent GPU.

Once you have the model.ckpt file for your style, run the following:

$ python scripts/dump_checkpoint_vars.py --output_dir=src/ckpts/my-new-style --checkpoint_file=/path/to/model.ckpt
$ python scripts/remove_optimizer_variables.py --output_dir=src/ckpts/my-new-style

If all goes well, src/ckpts/my-new-style should contain ~6.7MB of 49 items including a manifest.json file.

Adding the style to the application is then as simple as modifying the STYLE_MAPPINGS variable in src/styletransfer-demo.ts.

If you're able to successfully achieve cool new styles, I'd be glad to add them to this demo!

Credits

Credits belong to the following:

fast-style-transfer-deeplearnjs's People

Contributors

reiinakano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fast-style-transfer-deeplearnjs's Issues

Build and deploy

Hi,

I really like your project.

Recently I tried it in the "watch" mode and decided to build it and then run on my local node.js server. After executing the deploy-demo script I got a single HTML file (730 kB) in a new folder (I called it "distr"). I tried to run it, but it does not work properly. It shows the controls, but does not show the pictures (source and style) and the button does nothing.

Please explain how to build the project properly and what files and folders does it need to work. For example, it requires a script from bower_components\webcomponentsjs folder, I copied this folder to the distr folder, but it changed nothing.

Thank you in advance.

Error in net.ts

Error text ($ ./scripts/deploy-demo ... ) :

TypeScript error: src/net.ts(7,14): Error TS2420: Class 'TransformNet' incorrectly implements interface 'Model'.
Types of property 'predict' are incompatible.
Type '(preprocessedInput: Array3D<"float32" | "int32" | "bool">) => Promise<Array3D<"float32" | "int32"...' is not assignable to type '(input: NDArray<"float32" | "int32" | "bool", "0" | "1" | "2" | "3" | "4" | "higher">) => NDArray...'.
Type 'Promise<Array3D<"float32" | "int32" | "bool">>' is not assignable to type 'NDArray<"float32" | "int32" | "bool", "0" | "1" | "2" | "3" | "4" | "higher">'.
Property 'id' is missing in type 'Promise<Array3D<"float32" | "int32" | "bool">>'.

How to Deploy on GitHub Pages (if you did)

Hi

I really liked your work and I have tried on my local sytem and I want to know if I forked this repo and wanted to deploy on my github pages, then how do I do it ?

A neural algorithm of artistic style

Hello! I am pleased with Your project and would like to suggest you to implement another stylization algorithm proposed by Leon Gatis(A neural algorithm of artistic style). It allows you to stylize images for absolutely any style. There are a lot of realizations. Here's one made on Tenzorflow: https://github.com/woodrush/neural-art-tf. I hope this will interest you.

'Repository has exceeded LFS data quota' - LFS really needed?

Hey, I really like the project and would like to help with further improvements (e.g. adding the optimizations made by Dumoulin et al.), but it seems like this repository has exceeded it's LFS quota:

Error downloading object: src/ckpts/la_muse/Variable (5fb0a17): Smudge error: Error downloading src/ckpts/la_muse/Variable 
(5fb0a170666f9305d6b2640156b025af45a1c118cefb5da3708c1820a2613c7b): batch response: This repository is over its data quota. Purchase more data packs to restore access.

Is it really necessary to use LFS for the example images and checkpoints? As far as I know, a single checkpoint should weigh in at ~7MB, so I don't really see the need for LFS to store 42MB of checkpoints and a few images. I would create a pull request that adds the actual files, but I'm currently unable to clone the repository due to the error above.

Thanks for the great work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.