Tfjs: Error: Based on the provided shape, [256,108], and dtype float32, the tensor should have 27648 values but has 434

Created on 18 Oct 2018  路  7Comments  路  Source: tensorflow/tfjs

TensorFlow.js version

0.13.0

Browser version

Version 69.0.3497.100 - 64 bit

Describe the problem or feature request

I have trained the translation LSTM example here with default values and the parallel corpus provided by Anki (fr-en).
I get this error


Error: Based on the provided shape, [256,108], and dtype float32, the tensor should have 27648 values but has 434
    at assert (tf-core.esm.js:17)
    at new e (tf-core.esm.js:17)
    at Function.e.make (tf-core.esm.js:17)
    at tensor (tf-core.esm.js:17)
    at o (tf-core.esm.js:17)
    at Object.decodeWeights (tf-core.esm.js:17)
    at tf-layers.esm.js:17
    at tf-layers.esm.js:17
    at Object.next (tf-layers.esm.js:17)
    at o (tf-layers.esm.js:17)
loadHostedPretrainedModel @ loader.js:50
async function (async)
loadHostedPretrainedModel @ loader.js:42
init @ index.js:41
button.addEventListener @ index.js:206
14:57:42.394 ui.js:19 Loading pretrained model failed.

when loading the model in the tensorflow-js example here

Code to reproduce the bug / link to feature request

I have put model.json here the metadata.json here and you can download the model shard from here

group1-shard1of1.zip

question

Most helpful comment

We can reproduce this error msg in a browser (Chrome) environment:

"Uncaught (in promise) Error: Based on the provided shape, [1280], the tensor should have 1280 values but has 1279"

In our setup, the error occurs up after making small changes to a model (adding a class to the final classification layer), retraining and exporting. When loading the page that imports the model, it seems that the browser delivers the cached shards from the older model but the updated model.json. Solution is to clear the browser cache and reload the page.

All 7 comments

@loretoparisi I tried reproducing this issue but failed. The model loaded correctly for me in both Node.js (tfjs-node 0.19.1) and in the browser (tfjs 0.13.2). The summary is as follows:

__________________________________________________________________________________________________
Layer (type)                    Output shape         Param #     Receives inputs                  
==================================================================================================
input_1 (InputLayer)            [null,null,81]       0                                            
__________________________________________________________________________________________________
input_2 (InputLayer)            [null,null,108]      0                                            
__________________________________________________________________________________________________
lstm_1 (LSTM)                   [[null,256],[null,25 346112      input_1[0][0]                    
__________________________________________________________________________________________________
lstm_2 (LSTM)                   [[null,null,256],[nu 373760      input_2[0][0]                    
                                                                 lstm_1[0][1]                     
                                                                 lstm_1[0][2]                     
__________________________________________________________________________________________________
dense_1 (Dense)                 [null,null,108]      27756       lstm_2[0][0]                     
==================================================================================================
Total params: 747628
Trainable params: 747628
Non-trainable params: 0
__________________________________________________________________________________________________

In the past, I've run into issues that look similar to this one. In those cases, the reason was that the weight file wasn't loaded correctly and somehow got cut off before the end of the file. Can you verify in the "Network" tab of your browser's devtool that the weight response has a correct size (about 2.9 MB) in your case?

@caisq thanks a lot for this test, so the file is ok

-rw-r--r--@ 1 loretoparisi  staff   2,9M 18 Ott 14:50 group1-shard1of1
-rw-r--r--  1 loretoparisi  staff   1,7K 19 Ott 09:18 index.html
-rw-r--r--@ 1 loretoparisi  staff   1,8K 18 Ott 15:37 metadata_2.json
-rw-r--r--@ 1 loretoparisi  staff   3,8K 18 Ott 15:38 model_2.json
-rw-r--r--  1 loretoparisi  staff   1,5M 19 Ott 09:18 translation.2a48f7fd.js
-rw-r--r--  1 loretoparisi  staff   2,8M 19 Ott 09:18 translation.2a48f7fd.map

while in the browser I can see

schermata 2018-10-19 alle 09 20 02

So this seems to be due to the serving of the file from the browser. The file is loaded in the example from a local url like:

const LOCAL_URLS = {
  model: 'http://localhost:1234/model.json',
  metadata: 'http://localhost:1234/metadata.json'
};

@caisq I was able to make it working in Node.js and I prepared a fully fledged example for Node.js, hopefully this will help in the PR I have sent - https://github.com/tensorflow/tfjs-examples/pull/157

Regarding the browser, could it be due to this comment in serve.sh script:

# prevents it from serving the pretrained models; see
# https://github.com/parcel-bundler/parcel/issues/1098.  Once that issue is
# resolved, a single Parcel server will be sufficient.

Thank you.

@loretoparisi Yeah, i think that is a possibility.

Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!

I ran into this issue when using the serve NPM/Yarn package. It seems to not work well with TensorflowJS. When I used Firebase Serve, it worked great.

We can reproduce this error msg in a browser (Chrome) environment:

"Uncaught (in promise) Error: Based on the provided shape, [1280], the tensor should have 1280 values but has 1279"

In our setup, the error occurs up after making small changes to a model (adding a class to the final classification layer), retraining and exporting. When loading the page that imports the model, it seems that the browser delivers the cached shards from the older model but the updated model.json. Solution is to clear the browser cache and reload the page.

Was this page helpful?
0 / 5 - 0 ratings