Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!