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

118
Vistas
Simple tensorflow.js model kills browser performance

I've made an app to run simple tfjs model on live camera in browser. The problem is that it kills the web page performance completely. The refresh rate is around 1-2fps and whole browser is laggy (other tabs, youtube movies, even system gui). What is strange, after the first model execution that is slow (model is compiled so it is understandable), model execution time is in range of 1.5-4ms (measured as in scrip below). So it should not be a problem for the browser.

if (navigator.mediaDevices.getUserMedia) {
    navigator.mediaDevices.getUserMedia({ video: true })
    .then(function (stream) {
        video!.srcObject = stream;
    })
    .catch(function (_) {
        console.log("Something went wrong!");
    });
}

let model = await tf.loadGraphModel('model/model.json')
let video = document.querySelector("#videoElement") as HTMLVideoElement;

async function do_inference()
{
  let startTime = performance.now();

  const image = tf.expandDims(tf.browser.fromPixels(video));
  const image_fl32 = tf.cast(image, 'float32');

  let final_pred = tf.tidy(() => 
  {
    return model.predict(image_fl32) as tf.Tensor4D;
  });

  image.dispose();
  image_fl32.dispose();
  final_pred.dispose();
  let total = performance.now() - startTime;
  console.log(total);

  if (running)
  {
    requestAnimationFrame(do_inference);
  }
}

Additional notes:

  • model is a very simple fully convolution model. Basically few layers of 3x3 and 5x5 convolutions. I also made a test with even smaller model (2 layers) and it has same problems.
  • the tfjs runs using webgl backend, changing it to wasm result in much greater execution time (around 150-200ms) but video is smooth. On production I would like to use even bigger model, so I cannot accept such execution time.
  • I've tested in on RTX 3060, 32 threads Ryzen, 128GB RAM. So PC should not be a problem
  • It seems that there are are no memory leaks on the tfjs side
  • the model is converted from tensorflow.keras.Model model using Model.save method and then using tensorflowjs_converter@3.9 with --output_format=tfjs_graph_model

Am I doing something wrong? Is there a way to make video smooth?

about 4 years ago · Santiago Trujillo
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