1

After training my tensorflow model, I converted it to the json format as required by tensorflow.js. However when I tried to load this model using javascript, I get a node-fetch error.

This is my code :

const tf = require("./tf.min.js");
(async function () {
  const modelURL = "model_js/model.json";
  const model = await tf.loadLayersModel(modelURL);
  model.summary();
})();

Complete error logs :

(node:35092) UnhandledPromiseRejectionWarning: Error: Cannot find module 'node-fetch'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at pw (/Users/suraj/Desktop/fake-news/tf.min.js:17:225676)
    at t.e.fetch (/Users/suraj/Desktop/fake-news/tf.min.js:17:225911)
    at t.<anonymous> (/Users/suraj/Desktop/fake-news/tf.min.js:17:255546)
    at u (/Users/suraj/Desktop/fake-news/tf.min.js:17:104674)
    at Generator._invoke (/Users/suraj/Desktop/fake-news/tf.min.js:17:104427)
    at Generator.forEach.t.(anonymous function) [as next] (/Users/suraj/Desktop/fake-news/tf.min.js:17:105031)
(node:35092) 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: 3)
(node:35092) [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.

1 Answer 1

0

The module is not imported correctly. You most probably is importing a minified script that is intended to run in the browser. The docs covers how to get started with tensorflow.js

Install the package:

npm install @tensorflow/tfjs

Usage

import * as tf from '@tensorflow/tfjs';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.