tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.5k stars 1.93k forks source link

Argument 'tensors[0]' passed to 'concat' must be a Tensor or TensorLike, but got 'null' #5410

Closed RJ-1998 closed 3 years ago

RJ-1998 commented 3 years ago

I am trying to predict the results from the converted python keras model into tensorflow js, I have tried a lot of possible combinations to get the answer but it keeps throwing this error. The input shape it expects is [null,7] which I am providing it but still not working :-( Any help would be appreciated. Below is model and it's summary.

model = Sequential()        
model.add(Embedding(self.vocab_length, embed_dim, input_length=self.maxlen))
model.add(Flatten())
model.add(Dense(32,activation="relu"))
model.add(Dense(self.output_dim,activation="softmax"))  
# compile the model      
model.compile(loss='categorical_crossentropy', optimizer=tf.keras.optimizers.SGD(
    learning_rate=0.01, momentum=0.0, nesterov=False, name='SGD'), metrics=['accuracy'])
model.summary()

Model: "sequential_2"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
embedding_2 (Embedding)      (None, 7, 20)             1320      
_________________________________________________________________
flatten_2 (Flatten)          (None, 140)               0         
_________________________________________________________________
dense_4 (Dense)              (None, 32)                4512      
_________________________________________________________________
dense_5 (Dense)              (None, 10)                330       
=================================================================
Total params: 6,162
Trainable params: 6,162
Non-trainable params: 0
rthadur commented 3 years ago

In order to expedite the trouble-shooting process, please provide a code snippet to reproduce the issue reported here. Thanks!

RJ-1998 commented 3 years ago

Hello @rthadur ! Thanks for replying to my issue. Please find this repo containing all the code and model.json file whch I am using.

rthadur commented 3 years ago

I see this error while running the above code

image

can you please resolve this and also load the model from local folder like this

$( document ).ready(async function () { $('.progress-bar').show(); console.log( "Loading model..." ); model = await tf.loadGraphModel('model/model.json'); console.log( "Model loaded." ); $('.progress-bar').hide(); });

RJ-1998 commented 3 years ago

@rthadur I am using a cors extension in my browser and turning CORS extension on solves this error. You can use this cors extension in firefox

rthadur commented 3 years ago

Same error please check below image

RJ-1998 commented 3 years ago

@rthadur Please check the following steps:-

  1. In the parent directory run npm install it has libraries to run express server
  2. Make sure you are able to open http://localhost:4001/static/model.json
  3. Turn on cors. If still not working please find below snapshot of the main error in tensorflow Screenshot from 2021-08-11 22-31-11
RJ-1998 commented 3 years ago

@rthadur , @lina128 Hey Guys. Any updates on the issue?

lina128 commented 3 years ago

Hi @RJ-1998 , why don't you pass in model from loadLayersModel directly in this line? https://github.com/RJ-1998/react-chatbot-nlp/blob/bf8680b120452979c2c7ff450feb7549864a4070/chatbot/src/App.js#L15

RJ-1998 commented 3 years ago

Thanks @lina128 it worked!! Actually I was following one article that suggested the other way. I wish I knew it before.

google-ml-butler[bot] commented 3 years ago

Are you satisfied with the resolution of your issue? Yes No