Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorflowJS: TypeError: Cannot read property 'fetch' of undefined

I have an angular 7 application and I'm trying to load the mobilenet model by following this example.

I installed the tensorflowjs by running npm install @tensorflow/tfjs (following this instructions) and the mobilenet model by running @tensorflow-models/mobilenet.

After that I imported the mobile net by doing:

import * as mobilenet from '@tensorflow-models/mobilenet';

And execute the following code in order to load the model:

mobilenet.load().then(() => {
     obs.next();
}).catch((err) => {
     console.log(err);
     console.log("ERROR");
});

But I'm receiving the following error:

TypeError: Cannot read property 'fetch' of undefined
    at new e (tf-core.esm.js:17)
    at browserHTTPRequest (tf-core.esm.js:17)
    at httpRequestRouter (tf-core.esm.js:17)
    at tf-core.esm.js:17
    at Array.forEach (<anonymous>)
    at Function.e.getHandlers (tf-core.esm.js:17)
    at Function.e.getLoadHandlers (tf-core.esm.js:17)
    at Object.getLoadHandlers (tf-core.esm.js:17)
    at e.findIOHandler (tf-converter.esm.js:17)
    at e.<anonymous> (tf-converter.esm.js:17)

Does anyone know what is the issue?

like image 362
Ricardo Rocha Avatar asked Nov 23 '25 08:11

Ricardo Rocha


1 Answers

I found out that the problem was that I had different versions for @tensorflow/tfs and @tensorflow/tfjs-core on my packade.json.

So, I change my package config from:

...
"@tensorflow/tfjs": "^1.1.2",
"@tensorflow/tfjs-core": "^1.0.2",
...

To:

...
"@tensorflow/tfjs": "^1.1.2",
"@tensorflow/tfjs-core": "^1.1.2",
...

And the error vanished.

like image 76
Ricardo Rocha Avatar answered Nov 25 '25 21:11

Ricardo Rocha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!