Can't load keras model exported with tfjs.converters

375 views
Skip to first unread message

Timothée BERNARD

unread,
Apr 29, 2018, 1:51:07 PM4/29/18
to TensorFlow.js Discussion
Hi everyone and thanks for the great work!

When I run this code into my browser:

<!doctype html>
<html>
   <head>
       <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tf...@0.10.3"> </script>
   </head>
   <body></body>
   <script>
   
           .then(m => {
               console.log(m)
           })
   
   </script>
</html>

tfjs doesn't manage to load my model, the tab freezes and after ~2-3 minutes, the console outputs: 

WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost
tf...@0.10.3:1 Uncaught (in promise) Error: Failed to link vertex and fragment shaders.
    at Object.n.linkProgram (tf...@0.10.3:1)
    at e.createProgram (tf...@0.10.3:1)
    at Object.n.compileProgram (tf...@0.10.3:1)
    at tf...@0.10.3:1
    at e.getAndSaveBinary (tf...@0.10.3:1)
    at e.compileAndRun (tf...@0.10.3:1)
    at e.matMul (tf...@0.10.3:1)
    at a.ENV.engine.runKernel.a (tf...@0.10.3:1)
    at e.runKernel (tf...@0.10.3:1)
    at e.matMul (tf...@0.10.3:1)

However, loading one of the example models works, ex: https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json.

My model simply consists of:

model = Sequential()
model.add(LSTM(256, input_shape=(seq_length, vocab_size)))
model.add(Dropout(0.2))
model.add(Dense(vocab_size))
model.add(Activation('softmax'))

optimizer = RMSprop(lr=0.01)
model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['acc'])

exported via:

  • Keras: 2.1.5
  • tfjs: 0.10.3
  • tensorflowjs (pip): 0.1.1
  • Chrome: Version 66.0.3359.139 (Official Build) (64-bit)

Thank you in advance for your help,

Nikhil Thorat

unread,
Apr 29, 2018, 2:10:21 PM4/29/18
to Timothée BERNARD, Shanqing Cai, TensorFlow.js Discussion
Hi Timothee,

It's freezing up for me too - then I get an error about weights names. When you write the model, can you make sure that you only have a single instance of the model? It looks like the weights in your model.json are getting "_1" appended - this happens when there are multiple models.

Also, how big is your vocabulary size?

--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+unsubscribe@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/tfjs/.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/751551f5-eefc-46ad-b484-302a7bb88a3e%40tensorflow.org.

Timothée BERNARD

unread,
Apr 29, 2018, 2:36:08 PM4/29/18
to TensorFlow.js Discussion, bernard....@gmail.com, ca...@google.com
Hi Nikhil,

thanks for your quick answer.

>It's freezing up for me too - then I get an error about weights names. When you write the model, can you make sure that you only have a single instance of the model? It looks like the weights in your model.json are getting "_1" appended - this happens when there are multiple models.

I restarted my jupyter kernel for exporting a clean json and it indeed removed the _1: https://timotheebernard.github.io/models/model.json

>Also, how big is your vocabulary size?

393

I re-ran my code with the new model.json and still got the same issue.


Do you think that my vocabulary size is the issue? 
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.

Nikhil Thorat

unread,
Apr 29, 2018, 3:18:46 PM4/29/18
to Timothée BERNARD, TensorFlow.js Discussion, Shanqing Cai
No, I don't think that's the issue.

I filed a bug here, hopefully one of the layers folks can look soon: https://github.com/tensorflow/tfjs/issues/245

Basically, I think something in the recurrent layers are causing a huge memory blowout and not cleaning up intermediate Tensors. So basically, it's on our end. We'll take a look asap!

To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+unsubscribe@tensorflow.org.
Reply all
Reply to author
Forward
0 new messages