Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught (in promise) TypeError: Cannot read property 'producer' of undefined #1432

Closed
Swocky opened this issue Mar 21, 2019 · 4 comments
Closed
Assignees

Comments

@Swocky
Copy link

Swocky commented Mar 21, 2019

Uncaught (in promise) TypeError: Cannot read property 'producer' of undefined
at e. (tfjs-converter:17)
at tfjs-converter:17
at Object.next (tfjs-converter:17)
at o (tfjs-converter:17)

My model is from Keras.
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"> </script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter"></script>

<script> const MODEL_URL = './web_model/model.json'; async function predict(){ const model = await tf.loadGraphModel(MODEL_URL); const input_x = tf.tensor([[2714, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],shape=[1,50],dtype='int32'); const output = model.execute({input_x:input_x}); console.log(output); } predict(); </script>

Maybe because the version?
I'll appreciate it if you could give me some help. Thanks.

@pyu10055
Copy link
Collaborator

@Swocky can you share the model.json file?
If your model is from Keras, it is likely you need to use tf.loadLayersModel API instead of tf.laodGraphModel API.
In the model.json file, there should be a field 'format' that indicates whether it is a graph or layers model.

@Swocky
Copy link
Author

Swocky commented Mar 22, 2019

@Swocky can you share the model.json file?
If your model is from Keras, it is likely you need to use tf.loadLayersModel API instead of tf.laodGraphModel API.
In the model.json file, there should be a field 'format' that indicates whether it is a graph or layers model.

You are right, I'm so casreless, as I used tf model before. But a new issue appears, I use a Lambda layer in my model, the result is
Uncaught (in promise) Error: Unknown layer: Lambda. This may be due to one of the following reasons:

  1. The layer is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
  2. The custom layer is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().
    at new e (tfjs:2)
    at Dp (tfjs:2)
    at pd (tfjs:2)
    at u (tfjs:2)
    at e.fromConfig (tfjs:2)
    at Dp (tfjs:2)
    at pd (tfjs:2)
    at tfjs:2
    at tfjs:2
    at Object.next (tfjs:2)
    def __init__(
      self, sequence_length, num_classes, vocab_size,
      embedding_size, filter_sizes, num_filters, l2_reg_lambda=0.0):

        # input layer
        input_x = Input(shape=(sequence_length, ), dtype='int32')

        # embedding layer
        embedding_layer = Embedding(vocab_size,
                                    embedding_size,
                                    embeddings_initializer=random_uniform(minval=-1.0, maxval=1.0))(input_x)
        embedded_sequences = Lambda(lambda x: expand_dims(x, -1))(embedding_layer)

@Swocky
Copy link
Author

Swocky commented Mar 22, 2019

It seems that Lambda layer is not supported in tfjs. So I wonder if I have any alternative to expand my dim?

@Swocky
Copy link
Author

Swocky commented Mar 22, 2019

I solved it by myself. Just use reshape.

from keras.backend import int_shape
        ......
        embedded_sequences = Reshape((int_shape(embedding_layer)[1], int_shape(embedding_layer)[2], 1))(embedding_layer)
        ......

You could expand dim without using expand_dims and Lambda layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants