transcranial / keras-js

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

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

update to keras 2.0

transcranial opened this issue · comments

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

Perhaps worth noting that the current version of keras.js included in dist appears to only be compatible with Keras 1.1.0 (breaks for me at least with Keras 1.1.1, 1.1.2 and 1.2.2).

@dribnet Can you describe what you are seeing when it breaks? Errors or incorrect predictions? I'm getting incorrect predictions and trying to track that down. I'm using keras 1.2.2.

The main thing I have seen is subtle changes to the output of model.to_json() across keras versions as the API changes. If you pretty print the json and diff across versions you can find these. For example, in 1.1.0, the MNIST VAE decoder json output includes:

...
"keras_version": "1.1.0",
...
      {
        "class_name": "Deconvolution2D",
        "config": {
          "output_shape": [
              null,
              14,
              14,
              64
          ],
...
      {
        "class_name": "Deconvolution2D",
        "config": {
          "output_shape": [
              null,
              28,
              28,
              64
          ],          

And the corresponding part of the json in 1.1.2 will be:

...
"keras_version": "1.1.2",
...
      {
        "class_name": "Deconvolution2D",
        "config": {
          "output_shape": [
              200,
              14,
              14,
              64
          ],
...
      {
        "class_name": "Deconvolution2D",
        "config": {
          "output_shape": [
              200,
              29,
              29,
              64
          ],          

I think these small changes sometimes manifest as prediction changes (eg: the slightly different output shape) and sometimes as failure to load in the pre-baked keras.js (the error I get is Unhandled rejection Error: cwise: Arrays do not all have the same shape! at addeq_cwise_thunk). One workaround I've used is using the model json from 1.1.0 but loading weights trained on 1.1.2 - which at least in my case seems to work fine.

I haven't dove into the keras.js source yet - I think these could probably be corrected - there were only about 10 lines that change across a ~300 line json model file. But I might argue that it would probably be better to invest in getting 2.x working at this point. I posted this information on this ticket because I hadn't seen any other information on what keras versions were supported (answer: 1.1.0 only without fiddling) and I thought looking at these minor incompatibilities might inform the more drastic upgrade to 2.x.

commented

My model is not working with keras 1.1.0 because of fixes that are made in later version(and keras js is not working with later version of keras).

Is there another solution for this? For my university I need this as soon as possible.

Updated everything to work on Keras 2.0.4 + TF 1.1.0. For those using Keras v2, give it a go and let me know if you run into any issues.

commented

Great! Really nice work! Now I am not getting the error of "Loading Weights".
Working good for simple model with Keras 2.0.4 and TF 1.1.0

But still one small problem... in README.md in Available layers there is Merge Layer.
but still in JS I get this "Layer Merge specified in model configuration is not implemented!".

Besides of this everything is just great! Thank you!

@Gor97 Merge from keras.legacy.layers is back, along with the new keras.layers.merge layers.

commented

Now that Merge layer is working fine! Great!
But here comes the next issue(please dont hate me) .

I have seen in another issue that, variable sized input layer is not supported. My Input is sentence so layer size is not constant. Will it be supported soon?

Is it planned to update Keras.js with the latest version of Keras (2.0.9) and Tensorflow (1.4.0)?
We have problems of loading models trained with the newest versions of Keras and Tensorflow.