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.

Question: What is the standard practice when performing inference on a video to maximise performance (FPS, Memory)?

See original GitHub issue

TensorFlow.js version

Using this source for the script : https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js

Describe the question

I am trying to perform inference on a video and feed it back to a canvas. Current pipeline is:
VideoTag -> Hidden Canvas -> OpencvJS(matrix conversions and resizing) -> TFJS Predict -> Post Processing using OpencvJS -> Display Canvas

Major blockages in the pipeline are DrawImage function which draws image to the Hidden Canvas and post processing functions. Any suggestions on how we can improve this pipeline by using any TFJS libraries or any other libraries that are commonly used?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
annxingyuancommented, Jul 3, 2020

Hi @sacredvoid - as Ping mentioned you should be able to achieve faster performance by directly rendering the TFJS output texture for post processing. The key is to initialize a custom WebGL backend with your own WebGL context, like so:

tf.registerBackend('webgl', () => {
    return new tf.webgl.MathBackendWebGL(
        new tf.webgl.GPGPUContext(canvasElement.getContext('webgl2', WEBGL_ATTRIBUTES)));
  });
await tf.setBackend('webgl');

This way, you can access the WebGL context that TFJS uses for computation and chain a rendering shader to the end of the inference pipeline. Within the rendering shader you could perform RGB -> YUV conversion, as described in this post: https://stackoverflow.com/questions/7901519/how-to-use-opengl-fragment-shader-to-convert-rgb-to-yuv420

0reactions
AbdallaGomaacommented, Jan 18, 2022

Hi @sacredvoid. I am trying to develop a very similar application to the one you’re making. Did you get it working by setting up the same context for the canvas and TFjs? Any chance you have some sample code to help out? Would be much appreciated!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object Detection from 9 FPS to 650 FPS in 6 Steps
This inference is a series of CUDA kernels submitted by the host (CPU) to the device (GPU) — the GPU is doing all...
Read more >
How to BOOST FPS and Increase Performance on any PC
This is a simple tutorial on how to improve your FPS on Shatterline. This guide will help you to optimize your game.This video...
Read more >
Performance Tuning Guide - PyTorch
Performance Tuning Guide is a set of optimizations and best practices which can accelerate training and inference of deep learning models in PyTorch....
Read more >
How To Optimize Settings in Call of Duty: Warzone ... - NVIDIA
Learn why frames per second (FPS) matter when playing COD: Warzone. ... Warzone To Maximize Performance And Gain A Competitive Advantage.
Read more >
YoloV5 way too less FPS, how can I fix it? - Stack Overflow
The easier, the better. Try with smaller models such as YOLOv5s or YOLOv5n · What about using your GPU for inference? Add this...
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