How to get inference/latency time from the mediapipe JavaScript Solution API?

102 views
Skip to first unread message

MIN ZHANG

unread,
Jul 2, 2021, 3:41:57 AM7/2/21
to MediaPipe

Hi,

I am trying to get the FPS and inference/latency time from the mediapipe JavaScript Solution API.

In the compressed control_utils_local.js, the FPS data can be obtained from b.toFixed(0) in function qa(a, b).

W.prototype.tick = function() { var a = Math.floor(performance.now() / 1E3); 1 <= a - this.i && (qa(this, this.counter), this.i = a, this.counter = 0); ++this.counter };

function qa(a, b) {
      a.g.shift();
      a.g.push(b);
      ......
      a.h.textContent = b.toFixed(0) + " fps"
  };

My questions, is there any JS API for getting the inference/latency time for MediaPipe Selfie Segmentation and other models supported with JS API?

In https://mediapipe.dev/demo/holistic_remote/default_demo_bin.js , there is r.latency.toFixed(2) but it's not a official API from mediapipe JavaScript Solution?

Thanks,
Min Zhang

MIN ZHANG

unread,
Jul 2, 2021, 4:47:26 AM7/2/21
to MediaPipe
Added following code in function onResults(results){ ... }, please let me know if it's reasonable or there is official JS API. Thank you!

function onResults(results) {

end = performance.now()


if(start) {


delta = end - start


spaninference.html(delta.toFixed(1))


}


fpsControl.tick();


canvasCtx.save();


canvasCtx.clearRect(0, 0, cW, cH);

...
canvasCtx.drawImage(results.segmentationMask, 0, 0, cW, cH);

...
canvasCtx.restore();


start = performance.now()

}
Reply all
Reply to author
Forward
0 new messages