Creating Calculators in Mediapipe: Beyond the Documentation

Creating Calculators in Mediapipe: Beyond the Documentation

This article will build upon the basic knowledge from the documentation. Unfortunately, the documentation is sparse and the topics discussed here today can only be learned by rummaging through the already created examples.

Prerequisite

https://google.github.io/mediapipe/framework_concepts/calculators.html

Before reading this article, it’s necessary to read MediaPipe’s official documentation on how calculators, graphs, and packets work. This article will build upon the basic knowledge from the documentation. Unfortunately, the documentation is sparse and the topics discussed here today can only be learned by rummaging through the already created examples. Since we’re working with MediaPipe, an intermediate understanding of C++ is also required.

Before you create your MediaPipe calculator

Before you begin, you must chart out the purpose of your calculator. A calculator that works well with MediaPipe’s system is a calculator that either can be used many times or is a block of non-parallelizable code.

Parallelizable code is important because MediaPipe is multi-threaded. Calculators are run every time all inputs are fulfilled (with an exception we will get into later). Calculators come in many different complexities, but there should be an obvious floor to your complexity. For example, a calculator with the sole purpose of addition will cost more CPU cycles through overhead than save by being a parallelizable calculator.

Bazel BUILD Files

It is heavily suggested that you modify existing projects before creating your own. Firstly, you should create your own folder in the /mediapipe/calculators/ directory. Add a file called “BUILD” and your C++ file here (referred to as “example.cc”). In your BUILD file you must add a reference to your C++ file as follows:

cc_library(

name = “example”,

srcs = [“example.cc”],

visibility = [“//visibility:public”],

deps = [

“//mediapipe/framework:calculator_framework”,

],

alwayslink = 1,

)

This is a basic Bazel definition. Notice that we have to add a dependency of the calculator_framework, which will be a required dependency for every calculator you create. We are done with the BUILD file for now. Next, we should reference our finished BUILD file from another build file further up the build tree. If you are creating your own MediaPipe project, go to /mediapipe/examples/desktop and create your folder there, adding a BUILD file inside of it. If you are modifying an existing project, go to the BUILD file in that project’s folder. You will need to find what code is used to compile your project. Generally, it will be:

bazel build -c opt — define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/FOLDER_NAME:CC_LIBRARY_NAME

Where FOLDER_NAME should be the folder in your /mediapipe/examples/desktop that you are modifying or creating. Now inside of that folder, go to your BUILD file. If you are modifying an already existing project, add the build file you made earlier as a dependency in the deps list as such:

deps = [

“//mediapipe/calculators/CALCULATOR_FOLDER_NAME:example”,

],

If you are creating a project, you will have to create a cc_library as follows:

cc_library(

name = “CC_LIBRARY_NAME”,

deps = [

“//mediapipe/calculators/CALCULATOR_FOLDER_NAME:example”,

],

)

Now put some nonsense code into your .cc file that you know cannot compile. If you see a compile error caused by that code, you did it right! Remove the nonsense and get ready for the next stage. If you manage to compile with nonsense in your .cc file, you made a mistake somewhere and should backtrack to find it.

mediapipe machine-learning sign-language-interpreter programming tensorflow

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Pros and Cons of Machine Learning Language

AI, Machine learning, as its title defines, is involved as a process to make the machine operate a task automatically to know more join CETPA

What is Supervised Machine Learning

What is neuron analysis of a machine? Learn machine learning by designing Robotics algorithm. Click here for best machine learning course models with AI

How To Get Started With Machine Learning With The Right Mindset

You got intrigued by the machine learning world and wanted to get started as soon as possible, read all the articles, watched all the videos, but still isn’t sure about where to start, welcome to the club.

Guide to Interpretable Machine Learning

Techniques to dispel the black box myth of deep learning. If you can’t explain it simply, you don’t understand it well enough. — Albert Einstein.

What is Machine learning and Why is it Important?

Machine learning is quite an exciting field to study and rightly so. It is all around us in this modern world. From Facebook’s feed to Google Maps for navigation, machine learning finds its application in almost every aspect of our lives. It is quite frightening and interesting to think of how our lives would have been without the use of machine learning. That is why it becomes quite important to understand what is machine learning, its applications and importance.