1

Platform browser has already been set. Overwriting the platform with [object Object].

Error when trying to load file that has tfjs-node as an import:

const tf = require('@tensorflow/tfjs-node');

This only occurs in electron files that are loaded by the browser. I can set it up so that "script loaded by browser".js sends a request to main.js that sends a request to "file with tfjs-node".js and it works fine.

Wondering if there is a way to load the files directly without the intermediary requests

"dependencies": {
    "@tensorflow/tfjs-node": "^1.2.3",
    "cmake-js": "^6.0.0",
    "electron-reload": "^1.5.0",
    "esm": "^3.2.25",
    "file-saver": "^2.0.2",
    "fs-jetpack": "^2.1.0",
    "iohook": "^0.6.5",
    "jimp": "^0.9.3",
    "jquery": "^3.4.1",
    "keypress": "^0.2.1",
    "node-fetch": "^2.6.0",
    "node-png": "^0.4.3",
    "parse-full-name": "^1.2.4",
    "requirejs": "^2.3.6",
    "robotjs": "^0.6.0",
    "statman-stopwatch": "^2.11.1",
    "tesseract.js": "^2.0.2"
  },
Pascal Syma
  • 729
  • 1
  • 6
  • 19
BradleyB19
  • 147
  • 5
  • 10

2 Answers2

2

I had same trouble when i used tfjs-react-native package on my device. My app just had closes when i tried use something from this package. In console was only warning "Platform browser has already been set. Overwriting the platform with [object Object]".

This was solved by setting backend before used tfjs-react-native. Maybe it will help you too.

await tf.setBackend('cpu');
Max Fomin
  • 652
  • 5
  • 6
0

TensorflowJS chooses the best backend for processing automatically. You can specifially use -
Web/Electron -

 await tf.setBackend('wasm');

or

await tf.setBackend('cpu');

before

tf.ready()

statement to avoid errors.
you can also view current backend being used by using -

console.log(tf.getBackend());

reference

h3t1
  • 1,126
  • 2
  • 18
  • 29