GithubHelp home page GithubHelp logo

transcranial / keras-js Goto Github PK

View Code? Open in Web Editor NEW
5.0K 179.0 504.0 17.58 MB

Run Keras models in the browser, with GPU support using WebGL

Home Page: https://transcranial.github.io/keras-js

License: MIT License

HTML 1.09% JavaScript 96.27% Python 0.49% GLSL 2.15%
deep-learning machine-learning webgl tensorflow neural-networks keras javascript

keras-js's Introduction

**This project is no longer active. Please check out TensorFlow.js.**
The Keras.js demos still work but is no longer updated.

Run Keras models in the browser, with GPU support using WebGL



Run Keras models in the browser, with GPU support provided by WebGL 2. Models can be run in Node.js as well, but only in CPU mode. Because Keras abstracts away a number of frameworks as backends, the models can be trained in any backend, including TensorFlow, CNTK, etc.

Library version compatibility: Keras 2.1.2

Check out the demos/ directory for real examples running Keras.js in VueJS.

  • Basic Convnet for MNIST
  • Convolutional Variational Autoencoder, trained on MNIST
  • Auxiliary Classifier Generative Adversarial Networks (AC-GAN) on MNIST
  • 50-layer Residual Network, trained on ImageNet
  • Inception v3, trained on ImageNet
  • DenseNet-121, trained on ImageNet
  • SqueezeNet v1.1, trained on ImageNet
  • Bidirectional LSTM for IMDB sentiment classification

MIT License

keras-js's People

Contributors

4562448 avatar bikle avatar extend1994 avatar huyouare avatar jefffriesen avatar radarhere avatar stekaiser avatar transcranial avatar wassname avatar zafarali 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  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

keras-js's Issues

Demo is not working

webgl.js:56Uncaught TypeError: Cannot read property 'getShaderPrecisionFormat' of null
keras.js:4 Uncaught TypeError: Cannot read property 'getParameter' of null
bundle.js:15n @ bundle.js:1(anonymous function) @ bundle.js:1(anonymous function) @ bundle.js:1

screen shot 2016-10-16 at 12 17 16

update to keras 2.0

Breaking changes

  • remove legacy layers MaxoutDense, TimeDistributedDense, and Highway
  • BatchNormalization layer no longer supports the mode argument
  • update weights serialization

API changes

  • update changed layers, including Dense, BatchNormalization, and convolution layers
  • update weights serialization format

demos cannot be run locally.

I downloaded the github repo on my MBP (running Mac OSX 10.12). Then, at the directory containing "index.html", I started a HTTP server locally by using npm's http-server.

It is strange that demos cannot run in my Chrome browser. For example, in the mnist_cnn demo, I can draw numbers but the CNN prediction never occurs.

Any idea on the possible reason.

Update: After re-starting Chrome, the issue disappears.

repo clone failure

Cloning the repo is failing for me; this appears to be a git-lfs quota issue.

Cloning into 'keras-js'...
remote: Counting objects: 3557, done.
remote: Total 3557 (delta 0), reused 0 (delta 0), pack-reused 3556
Receiving objects: 100% (3557/3557), 6.06 MiB | 1.08 MiB/s, done.
Resolving deltas: 100% (2493/2493), done.
Checking connectivity... done.
Downloading demos/data/imdb_bidirectional_lstm/imdb_bidirectional_lstm_weights.buf (4.98 MB)Error downloading object: demos/data/imdb_bidirectional_lstm/imdb_bidirectional_lstm_weights.buf (66197c7e9d1414f49902004854b612732d743668166390b3f2d3ba16eceee73a)

Errors logged to /develop/nets/keras-js/.git/lfs/objects/logs/20170329T220458.783176265.log
Use `git lfs logs last` to view the log.
error: external filter git-lfs smudge -- %f failed 2
error: external filter git-lfs smudge -- %f failed
fatal: demos/data/imdb_bidirectional_lstm/imdb_bidirectional_lstm_weights.buf: smudge filter lfs failedwarning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'
$ git lfs pull
Git LFS: (0 of 5 files) 0 B / 201.85 MB                                                                                                            
batch response: This repository is over its data quota. Purchase more data packs to restore access.

(after a decade of using git this is the first repo that's ever failed to clone for me; I blame github)

Multiple named inputs need to be listed in order

I have a model with two inputs named input_a and input_b, defined in that order.

Trying to make a prediction with a keras.js model, this works:

model.predict({'input_a': data_a, 'input_b': data_b})
    .then(outputData => {
        // ...
    })

However, if you order them backwards in the object being passed to model.predict(), it throws an error:

model.predict({'input_b': data_b, 'input_a': data_a})
    .then(outputData => {
        // ...
    })

Error: predict() must take an object where the keys are the named inputs of the model: input_a,input_b.

Yikes! Small problem, but it stumped me for about an hour to figure out why it wasn't working, and the error message is misleading in this case

Great work, btw!

Decoder

Lost my .hdf5 weights, is it possible to decode the metadata, weights, etc into a .hdf5?

Error when importing keras.js in index.html

Hello everyone,
I am not an experienced developer with JS but I get weird error.

This is the error:
Error Image

This is my whole code (its just a simple testing code):

<!DOCTYPE html>
<html>
  <head>
    <title>Testing Deep Tingle</title>
    <meta charset="utf-8" />
  </head>
  <body>

  </body>
  <script src="dist/keras.js"></script>
  <script>
    const model = new KerasJS.Model({
      filepaths: {
        model: 'Gabb_Data/model.json',
        weights: 'Gabb_Data/model_weights.buf',
        metadata: 'Gabb_Data/model_metadata.json'
      },
      gpu: true
    });
    // model.ready().then(() => {}).catch(err => {});
  </script>
</html>

Error: [Model] error loading weights.

I'm running the latest Keras JS on a trained Keras model. Following the instructions given on the README, I tested loading my model before training (random initialized weights) and it works.

However, after I perform training and use the exact same way to called model.save_weights, Keras JS is unable to read the model file. When trying to parse the metadata, it gives [Model] error loading weights.

Any insight into why this would happen?

Trying to get SSD300 working with Keras.js

Hi,

I'm trying to get SSD300 (single shot detector) working.

I converted the model/weights over, but when I try to instantiate the model I get this error.

[Error: cwise: Arrays do not all have the same shape!]

I tried debugging it and found the problem starts in lib/Model.js:446 -> layer.setWeights(weights);

debug> n
break in node_modules/keras-js/lib/Model.js:462
 460             _this4.modelDAG[prevLayerConfig.name].outbound.push(layerConfig.name);
 461           }
>462         } else if (modelClass === 'Model') {
 463           if (layerDef.inbound_nodes && layerDef.inbound_nodes.length) {
 464             layerDef.inbound_nodes[0].forEach(function (node) {
debug> n
break in node_modules/keras-js/lib/Model.js:463
 461           }
 462         } else if (modelClass === 'Model') {
>463           if (layerDef.inbound_nodes && layerDef.inbound_nodes.length) {
 464             layerDef.inbound_nodes[0].forEach(function (node) {
 465               var inboundLayerName = node[0];
debug> n
break in node_modules/keras-js/lib/Model.js:464
 462         } else if (modelClass === 'Model') {
 463           if (layerDef.inbound_nodes && layerDef.inbound_nodes.length) {
>464             layerDef.inbound_nodes[0].forEach(function (node) {
 465               var inboundLayerName = node[0];
 466               _this4.modelDAG[layerConfig.name].inbound.push(inboundLayerName);
debug> n
break in node_modules/keras-js/lib/Model.js:471
 469           }
 470         }
>471       });
 472     }
 473
debug> n
< [Error: cwise: Arrays do not all have the same shape!]

Do you have any ideas what might cause this? The same model works fine in keras. The only change I had to make was renaming Conv2D -> Convolution2D.

Tests - Merge dot, cos operation Assertion Error

dot

[core.Merge.9] should produce expected values in dot mode (2D x 2D, dotAxes=1) ‣
AssertionError: expected [ 3, 3 ] to deeply equal [ 2, 2 ]

[core.Merge.10] should produce expected values in dot mode (2D x 2D, dotAxes=2) ‣
AssertionError: expected [ 2, 2 ] to deeply equal [ 3, 3 ]

cos

[core.Merge.11] should produce expected values in cos mode (2D x 2D, dotAxes=1) ‣
AssertionError: expected [ 1, 3, 3 ] to deeply equal [ 1, 2, 2 ]

[core.Merge.12] should produce expected values in cos mode (2D x 2D, dotAxes=2) ‣
AssertionError: expected [ 1, 2, 2 ] to deeply equal [ 1, 3, 3 ]

Multi-dimensional Sequential Inputs / unflattened float32 arrays

This library appears to be focused on the Model structure, which is okay, but most of my trained networks are in Sequential form. Specifically LSTM Sequentials.

LSTM Sequentials generally expect a three-dimensional input (batchSize, X,Y). However this repo requires there to be only one flattened input for Sequential, named "input". Has anyone found a good way to convert Sequentials to a Model or a way around this?

I would like to just do prediction in javascript. That means the model shouldn't even need to be compiled, so maybe I can just hack something together myself.

"TypeError: expecting a function but got [object Undefined]" occurs when I read the model

Hello. Thanks for a nice implementation!

I am new to Javascript and I would like you to explain how to use this library in detail.

I installed the keras-js using npm and I tried to check if the model created in Keras(Python) can be loaded correctly. But it didn't work.

Here is my log.

➜  simple-keras-js node
> const KerasJS = require('keras-js');
undefined
>
> var model = new KerasJS.Model({
...     filepaths: {
.....         model: './data/mnist_cnn.json',
.....         weights: './data/mnist_cnn_weights.buf',
.....         metadata: './data/mnist_cnn_metadata.json'
.....     },
...     filesystem: true
... });
TypeError: expecting a function but got [object Undefined]
    at Function.e.promisify (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:391803)
    at t.value (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:111338)
    at /Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:111107
    at Array.map (native)
    at t.value (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:111069)
    at new t (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:110823)
    at repl:1:13
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:339:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:241:10)
    at REPLServer.Interface._line (readline.js:590:8)
>
(To exit, press ^C again or type .exit)
> %

Theano compatibility issue

I get this error message from weblas:

%cUnhandled rejection Error: Second dimension must be of same size for input Tensors (second Tensor is transposed).

Comparing the model.json in the working example and mine, I've noticed that dimension ordering in mine is Theano convention (3x64x64 instead of 64x64x3). I think this should be documented, at least.

[Conv1D] TypeError: this.weights.b is undefined

I'm getting this error when running a Convolution1D model. The error is probably due to this.bias being undefined here.

Setting this.bias = true before that line resolves the error. Is there a smarter way than doing that? E.g. looking up if the bias contained in the weights metadata?

Possibly related to #21?

Why does this model not run in mobile Chrome and mobile Safari?

Just made a toy example of an insult dector using a character level CNN:
https://keras-predict-r.c9users.io/insults.html

The F1 score on the validation set is around 0.65, so it's not great but it works for many insults. It was trained on a small Kaggle insult dataset of around 3,500 examples.

It will take up to 10 seconds to load the first time, and a text form field will appear. The form appears after the model Promise says the model is ready.

In the mobile version, the problem is that never detects any insults that are detected in the non-mobile version on my laptop (desktop chrome and safari both work).

The weights are around 10mb, so I'm guessing this has to do with memory, unless it could be a gpu issue.

P.S. I did just notice this issue as well: #6

Error loading demo model ("RangeError: Invalid typed array length")

Hi, I am trying to load the mnist_vae model weights demo with the following html:

<html>
<head>
  <meta charset="utf-8">
  <script language="javascript" type="text/javascript" src="scripts/lib/keras.js"></script>
</head>
<body>
  <script language="javascript" type="text/javascript">
	  const model = new KerasJS.Model({
	  filepaths: {
	    model: 'static/model/mnist_vae.json',
	    weights: 'static/model/mnist_vae_weights.buf',
	    metadata: 'static/model/mnist_vae_metadata.json'
	  },
	  gpu: false
	});
  </script>
</body>
</html>

This is the error I get in Chrome:

RangeError: Invalid typed array length
    at new Float32Array (native)
    at http://0.0.0.0:8000/scripts/lib/keras.js:4:18505
    at Array.map (native)
    at http://0.0.0.0:8000/scripts/lib/keras.js:4:18250
    at Array.forEach (native)
    at t.value (http://0.0.0.0:8000/scripts/lib/keras.js:4:16687)
    at http://0.0.0.0:8000/scripts/lib/keras.js:4:15092
From previous event:
    at t.value (http://0.0.0.0:8000/scripts/lib/keras.js:4:15067)
    at new t (http://0.0.0.0:8000/scripts/lib/keras.js:4:14730)
    at http://0.0.0.0:8000/keras.html:8:18

I get a similar error in Firefox that begins with:

Error: WebGL: Exceeded 16 live WebGL contexts for this principal, losing the least recently used one.
RangeError: attempting to construct out-of-bounds TypedArray on ArrayBuffer
Stack trace:
[...]

Any ideas what might be going wrong?

Concurrent loops for large numbers of predictions

I'm running 100-300 predictions at a time in an interactive data visualization (like this: https://www.nytimes.com/interactive/2014/upshot/buy-rent-calculator.html)

I've read this thread: #27 and this works properly:

for (let arr of batch) {
  let output = await model.predict({ input: arr })
}

But I'm hoping to speed this up. The code above runs the predictions synchronously. For 100 predictions, I get 366ms with gpu: false and 2600ms with gpu: true (the GPU running slower is strange, but that's not the issue I'm posting about).

It seems like you could run the promises (and calculations?) concurrently. Here is a good overview: https://pouchdb.com/2015/03/05/taming-the-async-beast-with-es7.html (scroll down to concurrent loops).

let promises = docs.map((doc) => db.post(doc));
let results = await Promise.all(promises);
console.log(results);

When I try that with a batch of predictions, all of my predictions turn out the same (the last prediction).

async function getPredictions(inputs) {
  await model.ready();
  const promises = inputs.map(input => model.predict({ input: new Float32Array(input.data) }));
  const results = await Promise.all(promises);
}
getPredictions(inputs);

The synchronous (correctly working) code gives me back [0, 10, 73, 0, 77]. With the concurrent code above, I get [77, 77, 77, 77, 77].

I don't know a lot about concurrent promises. I know that javascript is typically single threaded. But we're in interesting territory accessing the GPU. I'm wonder if there is a way to use concurrent promises and the GPU (or CPU) to speed up predictions.

I'm also wondering why all of the predictions are returned as the final value. I understand if running it concurrently wasn't faster (because it's still on a single CPU), but it shouldn't be incorrect.

Any ideas on this?

feature request: dropout during prediction phase

Yarin Gal's thesis demonstrated that by allowing dropout during prediction, not just training, a set predictions can be produced and then analyzed to reveal model uncertainty (the quantiles of the predictions can produce confidence intervals, for example--like bootstrapping). The thesis has been praised several times by more senior researchers, although I don't have those links right now (the thesis is here: http://mlg.eng.cam.ac.uk/yarin/blog_2248.html ). One link is here, where Yann LeCun mentions that he developed a similar technique decades ago, and that he was Bayesian before it was cool: http://mlg.eng.cam.ac.uk/yarin/website/blog_3d801aa532c1ce.html

Today I got keras-js working, but after searching the code it appears the dropout layers are passthrough for prediciton.

In Keras, dropout can be done during prediction also with K.Function(model.inputs + [K.learning_phase()], model.outputs) or something like this ( see yaringal/BayesianRNN#3 (comment) ) . There is also a rule for recurrent layers so the layers use the same dropout mask in each layer, as is also the case in native tensorflow and torch.

Unfortunately, I don't know how to implement this in keras-js because it requires a particular combination of expert knowledge of javascript, keras and neural networks, but could perhaps help a bit because i am familiar with the three (e.g I've taken Andrew Ng's coursera course and am almost finished with Hinton's). Please advise.

I envision this as a possible 'killer application' of keras-js...producing confidence intervals on particular predictions without the overhead of taxing a main server, data visualization, visualizing uncertainty, and more. Please consider this.

resnet top-5 classes showing in Opera, not Firefox

First, very cool - great work! :-D

For your reference, keras-js runs fast in Opera; appears to run (slower) in Firefox, but does not display the top-5 classes (50-layer ResNet tried; supplied wolf image).

Firefox 49.0.1 - lots of plugins [re: this issue, disabled AdBlockPlus; uBlock Origin; Ghostery]
Opera 40.0 - minimal plugins
Arch Linux x86_64; Intel Core i7-4790 CPU; ...

Private message me -- if desired -- for my Firefox addons, configuration [about:support]; I don't want to share them, publicly.

Error when call model.predict

It's saying that there are a token |= but my code only has one file index.html and it has no such symbol.
What is the cause here?

SyntaxError: Unexpected token |=
    at new Function (<anonymous>)
    at u (https://off99555.github.io/HoNNeT/keras-js/keras.js:13:8807)
    at assigns_cwise_thunk (eval at r (https://off99555.github.io/HoNNeT/keras-js/keras.js:13:10619), <anonymous>:7:29)
    at Object.assigns_ndarrayops [as assigns] (eval at i (https://off99555.github.io/HoNNeT/keras-js/keras.js:1:6744), <anonymous>:3:44)
    at e.value (https://off99555.github.io/HoNNeT/keras-js/keras.js:7:19739)
    at e.value (https://off99555.github.io/HoNNeT/keras-js/keras.js:7:21879)
    at t.value (https://off99555.github.io/HoNNeT/keras-js/keras.js:4:15902)
    at t.<anonymous> (https://off99555.github.io/HoNNeT/keras-js/keras.js:4:16786)
    at o (https://off99555.github.io/HoNNeT/keras-js/keras.js:16:7592)
    at Generator._invoke (https://off99555.github.io/HoNNeT/keras-js/keras.js:16:9001)
    at Generator.t.(anonymous function) [as next] (https://off99555.github.io/HoNNeT/keras-js/keras.js:16:7771)
    at Generator.i (https://off99555.github.io/HoNNeT/keras-js/keras.js:11:1532)
    at u._promiseFulfilled (https://off99555.github.io/HoNNeT/keras-js/keras.js:9:22799)
    at t.<anonymous> (https://off99555.github.io/HoNNeT/keras-js/keras.js:9:24615)
From previous event:
    at t (https://off99555.github.io/HoNNeT/keras-js/keras.js:4:15972)
    at t.<anonymous> (https://off99555.github.io/HoNNeT/keras-js/keras.js:4:18474)
    at o (https://off99555.github.io/HoNNeT/keras-js/keras.js:16:7592)
    at Generator._invoke (https://off99555.github.io/HoNNeT/keras-js/keras.js:16:9001)
    at Generator.t.(anonymous function) [as next] (https://off99555.github.io/HoNNeT/keras-js/keras.js:16:7771)
From previous event:
    at t (https://off99555.github.io/HoNNeT/keras-js/keras.js:4:17225)
    at model.ready.then (https://off99555.github.io/HoNNeT/:165:16)
From previous event:
    at https://off99555.github.io/HoNNeT/:158:20

Here's the javascript part of that index.html file:

     const N_AVAIL_HEROES = 260
     const HERO_INPUT = new Array(2 * N_AVAIL_HEROES).fill(0)
     const vm = new Vue({
         el: '#app',
         data() {
             return {
                 model: null,
                 modelReady: false
             }
         },
         watch: {
             modelReady: function() {
                 if (this.modelReady)
                     console.log('the model is ready now')
             }
         }
     })
     const model = new KerasJS.Model({
         filepaths: {
             model: 'honnet_brain_architecture.json',
             weights: 'honnet_brain_weights_weights.buf',
             metadata: 'honnet_brain_weights_metadata.json'
         }
     })
     function getInputData(legion, hellbourne) {
        console.log('predicting with data')
        const inputData = {
            'hero_input': new Float32Array(HERO_INPUT)
        }
        return inputData
     }
     model.ready().then(() => {
         vm.model = model
         vm.modelReady = true

         // make predictions
         // outputData is an object keyed by names of the output layers
         // or `output` for Sequential models
         model.predict(getInputData([], [])).then(function(outputData) { // <====== error happens here!
             console.log('output')
             console.log(outputData)
         }).catch(err => {
             // handle error
             console.log('pred error: ')
             console.log(err)
         })
     }).catch(err => {
         // handle error
         console.log('ready error: ')
         console.log(err)
     })

Looking for library to train in the browser

Hello, if I understand correctly, this can only work for pre-trained networks? If so, do you know of another deep NN library that works in the browser and uses the GPU (WebGL) and allows training in the browser Thanks.

Node version doesn't work in browser

I use react-redux starter kit.
I installed keras-js with npm install keras-js --save
when I try to include {Model} from 'keras-js' then I get the following errors:

ERROR in .//keras-js/lib/Model.js
Module not found: Error: Cannot resolve module 'fs' in /media/v/a218f425-0329-45ac-8571-5497bea24d71/home/v/workspaces/webstorm/newMIDIcheck/node_modules/keras-js/lib
@ ./
/keras-js/lib/Model.js 215:50-63

ERROR in .//keras-js/lib/Tensor.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./texture_copy.glsl in /media/v/a218f425-0329-45ac-8571-5497bea24d71/home/v/workspaces/webstorm/newMIDIcheck/node_modules/keras-js/lib
@ ./
/keras-js/lib/Tensor.js 142:40-70

it misses a lot of other glsl files, and yes, they aren't there. Also as far as fs goes, It shouldn't be used in the browser, how to get around that?
Thanks everyone & srry for noob question.

ConvVAE is not working

Thanks for the great project! I get the following error with Chrome 54.0.2840.59 when I click on a point in the latent space.

image

Predictions in Batch

Hi!.

How could I do predictions in batch?

Taking mnist-cnn as example, how could I do
model.predict([Float32Array[784], Float32Array[784], Float32Array[784]])?

Just for one input is working: model.predict({input: [Float32Array[784]]})`

Thanks a lot!

Performance benchmark

Hi,
Very very impressive library, hope to let it run on a NodeJS server.

Did you perform some benchmark to compare the library to Tensorflor / Caffe app ? I assume it's slower but I wondering how much ?

"ReferenceError: XMLHttpRequest is not defined" occurs when I read the model

Hello. Thanks for a nice implementation!

I am new to Javascript and I would like you to explain how to use this library in detail.

I installed the keras-js using npm and I tried to check if the model created in Keras(Python) can be loaded correctly. But it didn't work.

Here is my log.

➜  simple-keras-js node
> const KerasJS = require('keras-js');
undefined
>
> var model = new KerasJS.Model({
... filepaths: {
.....   model: './data/mnist_cnn.json',
.....   weights: './data/mnist_cnn_weights.buf',
.....   metadata: './data/mnist_cnn_metadata.json'
..... },
... gpu: false
... });
undefined
> ReferenceError: XMLHttpRequest is not defined
    at /Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:75206
    at t.exports (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:75103)
    at t.exports (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:196561)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)
From previous event:
    at i.d [as _captureStackTrace] (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:346877)
    at s (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:404873)
    at r (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:404546)
    at s._iterate (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:388606)
    at s.t [as _init] (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:388390)
    at new s (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:387636)
    at Function.i.all (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:377696)
    at t.value (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:111063)
    at new t (/Users/kwatanabe/node_modules/keras-js/dist/keras.js:1:110823)
    at repl:1:13
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:339:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:241:10)
    at REPLServer.Interface._line (readline.js:590:8)
    at REPLServer.Interface._ttyWrite (readline.js:869:14)
    at REPLServer.self._ttyWrite (repl.js:609:7)
    at ReadStream.onkeypress (readline.js:120:10)

>

Thanks, advance.

Variable-size input layers appear to be unsupported

Keras supports variable-size input layers; they're specified as follows (where the two "None"s would typically be width and height):

inputlayer = Input(shape=(None, None, 4))

This feature is very useful for certain applications (e.g. entirely convolutional networks for image processing). This input layer is then encoded to JSON by encoder.py as:

...
    "config": {
        "batch_input_shape": [null, null, null, 4],
        "input_dtype": "float32",
        "sparse": false,
        "name": "input_1"
    },
...

However, trying to use this model in keras.js results in a "Specified shape incompatible with data." error from checkShape when trying to predict (since shape.reduce((a, b) => a * b, 1) is 0 if shape contains a null). This suggests that variable-size input layers are not yet supported as part of Keras.js.

I'm not sure if this is a planned feature, unplanned feature, or already implemented (and I just missed a configuration step somewhere), so feel free to label/delete this issue as appropriate. Thanks for the amazing library!

Doesn't work when MAX_TEXTURE_SIZE is not large enough

It seems the script is assuming weblasTensor is available after calling createWeblasTensor. However, when MAX_TEXTURE_SIZE is not enough, createWeblasTensor may create weblasTensorsSplit instead (or raise an error if it is really not enough).

If it is hard to use weblasTensorsSplit for this, I think it would be better to show some warning and gracefully fallback to CPU.

conv2d_tranpose in keras js?

Is there any known workaround for using conv2d_tranpose in keras.js? (which doesn't look like it is supported?)

edit: apparently deconv2d is the same as conv2d_tranpose in keras

simply importing keras.js results in "Uncaught SyntaxError: Invalid regular expression"

Hi transcranial, I just wanted to write a simple web page to import keras-js.
After cloning this repo, I create a file test.html containing the following codes:

<html>
<head>
<title>keras-js test</title>

<script src="dist/keras.js"></script>

<script type="text/javascript">

function periodic() {
  var d = document.getElementById('egdiv');
  d.innerHTML = 'Random number: ' + Math.random()
}

var net; // declared outside -> global variable in window scope
function start() {

  setInterval(periodic, 500);
}

}
</script>
</head>

<body onload="start()">

<div id="egdiv"></div>

</body>
</html>

Then I dragged this file into my Chrome browser, but in the console I received the following error:

Uncaught SyntaxError: Invalid regular expression: /[ªµºÀ-ÖØ-öø-�ˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-�Ҋ-ԧԱ-Ֆՙա-և�-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿ�ܒ-ܯ�-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽ�क़-ॡॱ-ॷॹ-ॿঅ-ঌ��ও-নপ-রলশ-হঽৎড়�য়-ৡৰৱਅ-ਊ��ਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-��-ઑઓ-નપ-રલળવ-હઽ�ૠૡଅ-ଌ��ଓ-ନପ-ରଲଳଵ-ହଽଡ଼�ୟ-ୡୱஃஅ-ஊஎ-�ஒ-கஙசஜஞடணதந-பம-ஹ�అ-ఌఎ-�ఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-�ಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-�ഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆ�-ะาำเ-ๆ�ຂຄງຈຊ�ດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿ�-��-�����-��-�ႎႠ-ჅჇ��-ჺჼ-ቈቊ-��-ቖቘቚ-�በ-ኈኊ-��-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-�ጒ-ጕጘ-�ᎀ-�Ꭰ-��-ᙬᙯ-ᙿ�-ᚚᚠ-ᛪᛮ-ᛰᜀ-ᜌᜎ-ᜑᜠ-ᜱ�-��-��-�ក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜ�-ᥭᥰ-ᥴᦀ-ᦫ�-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣ�-�ᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-�ἠ-ὅὈ-��-ὗὙὛ�Ὗ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌ�-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼ���-ₜℂℇℊ-ℓℕℙ-�ℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎ�-ⷖⷘ-ⷞⸯ々-〇〡-〩〱-〵〸-〼�-ゖ�-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ�-䶵一-鿌ꀀ-ꒌ�-ꓽꔀ-ꘌ�-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞎ�-ꞓꞠ-Ɦꟸ-�ꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲ�ꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-�ꫠ-ꫪꫲ-ꫴ�-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗ�ײַ-ﬨשׁ-זּטּ-לּמּנּ�ףּפּצּ-ﮱﯓ-ﴽ�-�ﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Z�-zヲ-하-ᅦᅧ-�ᅭ-ᅲᅳ-ᅵ]/: Range out of order in character class
    at new RegExp (<anonymous>)
    at Object.<anonymous> (keras.js:31478)
    at keras.js:31221
    at Object.e.read.s (keras.js:31221)
    at e (keras.js:1)
    at Object.<anonymous> (keras.js:31221)
    at Object.o (keras.js:31221)
    at e (keras.js:1)
    at Object.<anonymous> (keras.js:1)
    at e (keras.js:1)
    at Object.<anonymous> (keras.js:1)
    at e (keras.js:1)
    at Object.t.__esModule.default (keras.js:10644)
    at e (keras.js:1)
    at Object.t.__esModule.default (keras.js:10644)
    at e (keras.js:1)

Can you tell me why this happened and how to deal with it?

Best wishes,
Yiming

[Model] Error loading weights

Error building for Ubuntu 16.04

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'run', 'watch' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prewatch', 'watch', 'postwatch' ]
5 info lifecycle [email protected]~prewatch: [email protected]
6 silly lifecycle [email protected]~prewatch: no script for prewatch, continuing
7 info lifecycle [email protected]~watch: [email protected]
8 verbose lifecycle [email protected]~watch: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~watch: PATH: /usr/share/npm/bin/node-gyp-bin:/home/y/crypto/keras-js/node_modules/.bin:/home/y/bin:/home/y/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
10 verbose lifecycle [email protected]~watch: CWD: /home/y/crypto/keras-js
11 silly lifecycle [email protected]~watch: Args: [ '-c', 'webpack --watch --config webpack.dev.config.js' ]
12 info lifecycle [email protected]~watch: Failed to exec watch script
13 verbose stack Error: [email protected] watch: `webpack --watch --config webpack.dev.config.js`
13 verbose stack spawn ENOENT
13 verbose stack     at ChildProcess.<anonymous> (/usr/share/npm/lib/utils/spawn.js:17:16)
13 verbose stack     at emitTwo (events.js:87:13)
13 verbose stack     at ChildProcess.emit (events.js:172:7)
13 verbose stack     at maybeClose (internal/child_process.js:821:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
14 verbose pkgid [email protected]
15 verbose cwd /home/y/crypto/keras-js
16 error Linux 4.4.0-45-generic
17 error argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "watch"
18 error node v4.2.6
19 error npm  v3.5.2
20 error file sh
21 error code ELIFECYCLE
22 error errno ENOENT
23 error syscall spawn
24 error [email protected] watch: `webpack --watch --config webpack.dev.config.js`
24 error spawn ENOENT
25 error Failed at the [email protected] watch script 'webpack --watch --config webpack.dev.config.js'.
25 error Make sure you have the latest version of node.js and npm installed.
25 error If you do, this is most likely a problem with the keras-js package,
25 error not with npm itself.
25 error Tell the author that this fails on your system:
25 error     webpack --watch --config webpack.dev.config.js
25 error You can get information on how to open an issue for this project with:
25 error     npm bugs keras-js
25 error Or if that isn't available, you can get their info via:
25 error     npm owner ls keras-js
25 error There is likely additional logging output above.
26 verbose exit [ 1, true ]

When installing:

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN [email protected] scripts['server'] should probably be scripts['start'].

Fira sans is broken in Chrome and Firefox on Linux

On Debian testing at least but probably on other distros as well. Could be also broken on Mac, the issue with Fira sans was revealed in habrahabr.ru redesign (worked fine on Windows but was totally invisible on Mac/Linux). It looks like this:
2016-12-07_21-01-23
Disabling font-family in body reveals the text. Please replace the font with the working version.

Merge layer , mode 'dot' implementation

I think the implementation of 'dot' mode for Merge layer ignores the fact that the dot axis can be a tuple too instead of an integer. When a tuple dotAxes is sent as part of attr to Merge layer for dot mode in Merge.js
this.dotAxes = dotAxes <= 0 ? dotAxes : dotAxes - 1 sets this.dotAxes to NaN

Weights have been permuted for Convolution1D

I noticed an error building Convolutional1D layer in js when the input has 1 feature layer. I added a failing test for it to this fork, so that it can be easily reproduced.

Here is the error reported at localhost:3000/test (all other tests pass)

Error: cwise: Arrays do not all have the same shape!
    at assign_cwise_thunk (eval at createThunk (eval at <anonymous> (http://localhost:3000/dist/keras.js:2858:1)), <anonymous>:8:71)
    at Object.assign_ndarrayops [as assign] (eval at makeOp (eval at <anonymous> (http://localhost:3000/dist/keras.js:108:1)), <anonymous>:3:43)
    at Convolution2D._w2row (eval at <anonymous> (http://localhost:3000/dist/keras.js:493:1), <anonymous>:274:30)
    at Convolution2D.setWeights (eval at <anonymous> (http://localhost:3000/dist/keras.js:493:1), <anonymous>:126:12)
    at Convolution1D.setWeights (eval at <anonymous> (http://localhost:3000/dist/keras.js:1355:1), <anonymous>:103:20)
    at r.<anonymous> (convolutional/Convolution1D.js:61:19)
    at r (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:7852)
    at r.run (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:8853)
    at i.runTest (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13553)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:14192
    at r (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13024)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:13000
    at n (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:12791)
    at https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:2:12855
    at i (https://cdnjs.cloudflare.com/ajax/libs/mocha/3.0.2/mocha.min.js:1:559)

Node: TypeError: Cannot read property 'source' of undefined

Ok so I am trying to get this working in Node backend.

I only have these few lines of codes:

const KerasJS = require('keras-js');

// in node, gpu flag will always be off
// paths can be filesystem paths or absolute URLs
// if filesystem path, this must be specified:

const model = new KerasJS.Model({
  filepaths: {
    model: 'model.json',
    weights: 'first_try_weights.buf',
    metadata: 'first_try_metadata.json'
  },
  filesystem: true
})

I have installed keras-js using

npm install keras-js --save

At first it is complaining a babel-polyfill related error.

Then I installed that:

npm install babel-polyfill --save

Then I am facing this error:

node-test/node_modules/keras-js/lib/Model.js:67
var axiosSource = _axios2.default.CancelToken.source();
                                             ^

TypeError: Cannot read property 'source' of undefined
    at Object.<anonymous> (.../Keras/node-test/node_modules/keras-js/lib/Model.js:67:46)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (.../Keras/node-test/node_modules/keras-js/lib/index.js:10:14)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)

What is that?

Runtime Bug

Excellent project Leon! While running the demos using existing images, computational flow seems to stop 2-3 layers before end. I am running Firefox 49 on Mac OSX.

If you cannot replicate this, I can send you debug info from the console.

Great job again!

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.