tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

index.js:88 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')

Open sameermahajan opened this issue 3 years ago • 10 comments

While trying to "Train" using this code I am getting an error:

DevTools failed to load source map: Could not load content for https://cdn.jsdelivr.net/npm/@tensorflow/tf.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE index.js:88 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length') at flatten (index.js:88:26) at train (index.js:48:23) at HTMLButtonElement.onclick (index.html:14:42)

This is on latest chrome browser on Windows 10 machine.

sameermahajan avatar Apr 29 '22 11:04 sameermahajan

In order to expedite the trouble-shooting process, please provide a codepen example to reproduce the issue reported here. Thanks! Based on the error , I would say input parameter is not valid which you are passing.

rthadur avatar Apr 29 '22 16:04 rthadur

Attached is my code (inde.html and index.js just remove the .pdf suffix and you can execute them). It is based on your sample. I think it used to work about a month ago when I had got it. Nothing changed from my side but now I am getting this error.

Open index.html, click on button "Train" and the UI will grey out completely. You can see the exception, error and stack trace that I reported in developer tools.

index.html.pdf index.js.pdf

sameermahajan avatar Apr 30 '22 06:04 sameermahajan

Could not open pdf , can you please paste here https://codepen.io/pen/ and share it.

rthadur avatar Apr 30 '22 16:04 rthadur

Here you go: https://codepen.io/sameermahajan/pen/YzezQej

sameermahajan avatar May 01 '22 05:05 sameermahajan

Initially I did not get which colab you were working on , by seeing the code I see you are TensorFlow.js - Audio recognition using transfer learning. I was able to run the colab successfully here https://codepen.io/rthadur/pen/JjpoKbE . Codepen which you shared is also working fine for me , could you please let me know where you are seeing the issue ?

rthadur avatar May 02 '22 18:05 rthadur

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'type') at eval (barPolar.js?120a:63:1) at GlobalModel.eval (Global.js?05a0:682:1)

juntaoxiang avatar May 04 '22 03:05 juntaoxiang

I am getting error as reported at line 88 of index.js when clicked on button "Train". I get the error locally as well as in uploaded codepen. It is with latest chrome on windows 10 machine in case it matters.

The initial part of the codelab that you have shared works for me. The issue is with "Train" part when I add and try it.

sameermahajan avatar May 06 '22 05:05 sameermahajan

Sorry my windows machine is broken , could not test this , I have the complete example working here https://codepen.io/rthadur/pen/QWQvNpO , can you try this once. I had no issues running it. Thank you

rthadur avatar May 18 '22 17:05 rthadur

I get the same error with this from my machine / browser. Developer tools show the same error and stack.

sameermahajan avatar May 19 '22 07:05 sameermahajan

Also faced with this issue

<script type="text/javascript">
    function start_model() {
        // const modelJson = require('https://tempdeltavalue.github.io/model.json');
        // const modelWeights = require('https://tempdeltavalue.github.io/group1-shard1of1.bin');

        model = tf.loadGraphModel('https://tempdeltavalue.github.io/f_w2223_js_graph/model.json');

        states =[];
        next_char = ['Пр ']
        result = [next_char]


                const prediction = res.executeAsync(
                    {"args_0" : next_char, "unknown" : next_char, "unknown_8" : next_char},

                    // [next_char, states]
                    );
                console.log(prediction);
            }, function (err) {
                console.log(err);
            });
        }


    }
    window.onload = start_model;
</script>


https://colab.research.google.com/drive/1zPeOgjKipPGyMJz-i99_LLFBYbr__JTr#scrollTo=DRKmCHi7vfSm

logs: 127.0.0.1-1654436622960.log

tempdeltavalue avatar Jun 05 '22 13:06 tempdeltavalue

Hi @sameermahajan , I apologise for the delayed response. I have reviewed your code and encountered the same error you reported: index.js:88 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length’) when attempting to train the model directly without any data. This error occurs due to passing an empty array to the flatten(tensors) function, resulting in a length error at the following line: const size = tensors[0].length. To avoid this error, I suggest clicking on the left, right, or noise button first to fill the example array with some data using the following code: let vals = normalize(data.subarray(-frameSize * NUM_FRAMES)); examples.push({vals, label});. Once the example array has been populated with data, you can safely click on the train button without encountering any errors. Output : image

You could also refer to tf.tensor documentation. Let me know if have I missed something here. Thank You !

shmishra99 avatar May 10 '23 13:05 shmishra99

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

google-ml-butler[bot] avatar May 17 '23 14:05 google-ml-butler[bot]

Closing as stale. Please @mention us if this needs more attention.

google-ml-butler[bot] avatar May 24 '23 14:05 google-ml-butler[bot]

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

google-ml-butler[bot] avatar May 24 '23 14:05 google-ml-butler[bot]