Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
Local tensorflow.js won't work as a module in webworker

I'm using a local copy of tensorflow.js tfjs.js in an experimental setup. All is browser side, no node.js.

I want to move the tensorflow functionality to it's own thread in a webworker since it's heavy on the browser. However the way I got the tensorflow module to work in a worker does not make sense:

This was the initial idea:

//main.js
let predictor = new Worker ('prediction_ww.js', {type: 'module'})

//prediction_ww.js
import * as tf from "tfjs.js" 

But this produces the following error when I start execution (note: 'loadGraphModel' is a method in tensorflow.js):

prediction_ww.js:44 Uncaught (in promise) TypeError: tf.loadGraphModel is not a function...
etc...

After testing without a real idea of what I'm doing I get this code, without the type: 'module' to work:

//main.js
let predictor = new Worker ('prediction_ww.js')

//prediction_ww.js
var tf = import ("./tfjs.js")

I would like to understand why this works but not the case using module which my reading suggests should be the correct way of using an external module in a webworker on the browserside.

Also I noticed it only works using the ./ before the filename which I also don't understand why.

I use Chrome 96 on macOS 10.14.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First, tfjs works just fine in a web worker unless you try to use specific functions that rely on DOM (e.g. can't use tf.browser.* methods) - and that's not the case here.

When you say local tfjs.js - which variation of tfjs is that? it ships as many variations and only ESM modules can be loaded using {type: "module"}

Default tf.js is NOT ESM, but tf.es2017.js is

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda