question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@tensorflow-models/mobilenet does not work under Node.js

See original GitHub issue

Trying to use the @tensorflow-models/mobilenet package under Node.js throws the following exception:

2018-09-27 15:25:56.699190: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.2 AVX AVX2 FMA (node:98265) Warning: N-API is an experimental feature and could change at any time. (node:98265) UnhandledPromiseRejectionWarning: Error: browserHTTPRequest is not supported outside the web browser without a fetch polyfill. at new BrowserHTTPRequest (/Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-core/dist/io/browser_http.js:46:19) at Object.browserHTTPRequest (/Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-core/dist/io/browser_http.js:247:12) at Object.<anonymous> (/Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-layers/dist/models.js:98:50) at step (/Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-layers/dist/models.js:42:23) at Object.next (/Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-layers/dist/models.js:23:53) at /Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-layers/dist/models.js:17:71 at new Promise (<anonymous>) at __awaiter (/Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-layers/dist/models.js:13:12) at Object.loadModelInternal (/Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-layers/dist/models.js:92:12) at Object.loadModel (/Users/kreeger/workspace/mn-test/node_modules/@tensorflow/tfjs-layers/dist/exports.js:16:21) (node:98265) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4) (node:98265) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
daisy-ycguocommented, Oct 25, 2018

I finally worked it out.

I use global.fetch = require('node-fetch'). In script.sh I change the loading mode script from file to https:

  mn.path = `https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_1.0_224/model.json`
  await mn.load()

Then I met with an error Error: Unknown feature TENSORLIKE_CHECK_SHAPE_CONSISTENCY.

And then , I bump tfjs to the latest release:

    "@tensorflow/tfjs": "^0.13.0",
    "@tensorflow/tfjs-node": "^0.1.19",

It works for me now.

5reactions
jthomascommented, Oct 8, 2018

If people come across this issue, I found a (relatively) simple workaround using the node-fetch library from NPM. https://www.npmjs.com/package/node-fetch

const mobilenet = require('@tensorflow-models/mobilenet')
global.fetch = require('node-fetch')
const model = await mobilenet.load()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Worker threads | Node.js v19.3.0 Documentation
Workers (threads) are useful for performing CPU-intensive JavaScript operations. They do not help much with I/O-intensive work. The Node.js built-in ...
Read more >
6 reasons your Node.js apps are failing - IBM Developer
6 reasons your Node.js apps are failing. Learn about common problems in Node applications and the tools that you can use to find...
Read more >
Getting Started in Node.js - AWS SDK for JavaScript
This additional module is named uuid . Prerequisite Tasks. To set up and run this example, you must first complete these tasks: Create...
Read more >
How can I wait In Node.js (JavaScript)? l need to pause for a ...
using async / await all over your code, so this is really not an issue. All modern browsers today support it. Giving a...
Read more >
Debug Node.js Apps using Visual Studio Code
There are a few ways you can debug your Node.js programs in VS Code: Use auto attach to debug ... You can modify...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found