question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model:body-segmentation browser freezes for ~7-9 seconds in initial run

See original GitHub issue

Hi, I am not sure if this is a bug so am posting it here.
This line take ~7-9 seconds to run and freezes the browser when running for the first time, then it just takes ~100ms.

bodySegmenter.segmentPeople(video);
video is a HTMLVideoElement

Running on chrome 107 with webgl backend.
The tf and backend and the segmenter has already loaded and is ready before running this.

import * as bodySegmentation from '@tensorflow-models/body-segmentation';
import * as tf from '@tensorflow/tfjs-core';
import '@tensorflow/tfjs-backend-webgl';
import '@tensorflow/tfjs-backend-wasm';

const model = bodySegmentation.SupportedModels.MediaPipeSelfieSegmentation;
const bodySegmenterConfig: MediaPipeSelfieSegmentationTfjsModelConfig = {
  runtime: 'tfjs', //mediapipe or 'tfjs'
  modelType: 'general', // or 'landscape'
};

let bodySegmenter: BodySegmenter;

tf.ready().then(() => {
  log('backend ready  :', tf.getBackend()); // <--------------webgl
  bodySegmentation.createSegmenter(model, bodySegmenterConfig).then((value) => {
    log('segmenter created');
    bodySegmenter = value;
  });
});
    "@tensorflow-models/body-segmentation": "^1.0.1",
    "@tensorflow/tfjs": "^4.0.0",
    "@tensorflow/tfjs-backend-wasm": "^4.0.0",
    "@tensorflow/tfjs-backend-webgl": "^4.0.0",
    "@tensorflow/tfjs-converter": "^4.0.0",
    "@tensorflow/tfjs-core": "^4.0.0",
------------------
System Information
------------------
Operating System: Windows 10 Enterprise N 64-bit (10.0, Build 19043) (19041.vb_release.191206-1406)
System Manufacturer: ASUS
BIOS: 1401 (type: UEFI)
Processor: Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz (12 CPUs), ~2.9GHz
Memory: 32768MB RAM
Available OS Memory: 32686MB RAM
Page File: 26483MB used, 8250MB available
DirectX Version: DirectX 12
User DPI Setting: 96 DPI (100 percent)
System DPI Setting: 96 DPI (100 percent)
DWM DPI Scaling: Disabled
DirectX Database Version: 1.0.8
DxDiag Version: 10.00.19041.2075 64bit Unicode

---------------
Display Devices
---------------
Card name: NVIDIA GeForce RTX 3060
DAC type: Integrated RAMDAC
Device Type: Full Device (POST)
Device Status: 0180200A [DN_DRIVER_LOADED|DN_STARTED|DN_DISABLEABLE|DN_NT_ENUMERATOR|DN_NT_DRIVER] 
Device Problem Code: No Problem
Driver Problem Code: Unknown
Display Memory: 28484 MB
Dedicated Memory: 12142 MB
Shared Memory: 16342 MB
Current Mode: 1920 x 1080 (32 bit) (60Hz)

Any points or ideas ?

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
Linchenncommented, Nov 11, 2022

Thank you Jiajia for redirecting the solution!

@Exlord for your case, you could use tf.env().set('WEBGL_USE_SHAPES_UNIFORMS', true); when tf is ready as Jiajia mentioned. Also using ENGINE_COMPILE_ONLY may have obvious perf gain. Specifically, you could add the following codes before your first inference:

    tf.env().set('ENGINE_COMPILE_ONLY', true);
    bodySegmenter.segmentPeople(video);
    tf.backend().checkCompileCompletion();
    tf.backend().getUniformLocations();
    tf.env().set('ENGINE_COMPILE_ONLY', false);

If it still does not work, I could help you tell a look at your codes.

1reaction
Linchenncommented, Nov 14, 2022

For WebGL backend, it’s MathBackendWebGL (class MathBackendWebGL extends KernelBackend) and you could use it as tf.MathBackendWebGL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pages frequently freeze randomly for 2-10 seconds at a time
The problem first appeared in Chrome 79. It can be reproduced on any site. It makes the browser virtually unusable when touch typing....
Read more >
How to Fix It When Chrome Keeps Freezing
Causes of Chrome Freezing. There are several reasons why the Chrome browser may slow down to a crawl, crash, or freeze, and sometimes,...
Read more >
chrome 79 pages freezes(hangs)
Freezes can be 10-20 seconds. Tab switch in browser helps to avoid freeze, then page work for some time without of freezes. I...
Read more >
Chrome freezes for ~60 seconds after first open when ...
Go to Settings and clear all saved data, including cached data, saved passwords, and cookies; close all browsers; Restart the machine.
Read more >
Internet Explorer Keeps Freezing For a Few Seconds
Whenever im typing my internet explorer will freeze for about 3 seconds ... Method 1: Run Internet Explorer Performance Troubleshooter.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found