Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda