Stateless vs Stateful hooks in your computer vision applications with Pipeless

miguelaeh

Miguel Ángel Cabrera Miñagorri

Posted on November 30, 2023

Stateless vs Stateful hooks in your computer vision applications with Pipeless

Pipeless is an open-source framework that allows you to create and deploy computer vision applications in minutes. Similar to how you develop serverless web applications, with Pipeless you just need to provide basic code functions, for example in Python, that take some frame data.

In Pipeless, all the hooks (functions) are written in the same way, however, there are two main kinds of hooks depending on whether they need to maintain an internal state or not.

Stateless hooks

Stateless hooks do not require to maintain an internal state. This is the default kind of hook that is created.

A stateless function is a function that produces an output that only depends on the inputs. A previous call to the function does not affect the result of the next calls.

In the context of Pipeless, where you provide hooks (functions) that take a video frame as input and produce some data as output, you often implement stateless hooks.

Direct examples of stateless hooks are pre-processing and post-processing hooks. A direct example of a stateless hook is a pre-processing hook to resize the frame. Resizing the frame is a typical step where you change the frame dimensions to match a model input format. This operation depends exclusively on the input frame, it does not get affected by the resizing of previous frames, thus, it is a stateless operation.

The best of stateless operations is that they can be easily parallelized for several frames, making the processing faster. In the example, if you provide Pipeless with a stateless pre-processing hook that resizes the image, Pipeless will resize several frames at the same time, thus, resizing a frame number N + 1 does not need to wait for the frame N to be resized.

In a traditional computer vision pipeline, pre-processing and post-processing are the steps taking most of the time, thus, if your use case allows you to implement them in a stateless way, Pipeless will automatically make your application significantly faster.

Stateful hooks

Stateful hooks are the opposite of stateless hooks.

A stateful function is a function whose result does not only depend on the inputs, but also in previous calls to the function.

A direct example of when you want to use stateful hooks in Pipeless is when using object tracking or object-counting models. These models require to maintain an internal state in order to work, thus, a stateless approach is not suitable for them.

In Pipeless, you can easily convert your hook into a stateful hook by simply adding a comment at the top of your code file when using a programming language or adding a field when using JSON hooks.

Stateful hooks come with a drawback, they offer a reduced performance compared to stateless hooks. This difference comes from the fact that, to avoid corrupting the internal state, stateful hooks cannot be executed for several frames at the same time, thus, a stateful hook guarantees that it won’t be executed for a frame N + 1 until it finishes for frame N.

Conclusion

With Pipeless you can create computer vision applications very easily, whether they need to maintain an internal state or not. Indeed, you will write the code in the exact same way in both cases, you just need to indicate to Pipeless which function should be stateful and it will handle everything for you, allowing you to be focused on your application and not on the low-level details.

You can find more information about stateless and stateful hooks in the Pipeless docs.

If you like what we are doing at Pipeless consider sharing it and starring the GitHub repository.

We also invite you to join the community and contribute to the project!

GitHub logo pipeless-ai / pipeless

An open-source computer vision framework to build and deploy apps in minutes

Pipeless

Easily create, deploy and run computer vision applications.



Loading video...



Check out our hosted agents solution

Pipeless is an open-source framework that takes care of everything you need to develop and deploy computer vision applications in just minutes. That includes code parallelization, multimedia pipelines, memory management, model inference, multi-stream management, and more. Pipeless allows you to ship applications that work in real-time in minutes instead of weeks/months.

Pipeless is inspired by modern serverless technologies. You provide some functions and Pipeless takes care of executing them for new video frames and everything involved.

With Pipeless you create self-contained boxes that we call "stages". Each stage is a micro pipeline that performs a specific task. Then, you can combine stages dynamically per stream, allowing you to process each stream with a different pipeline without changing your code and without restarting the program. To create a stage you simply provide a pre-process function…




💖 💪 🙅 🚩
miguelaeh
Miguel Ángel Cabrera Miñagorri

Posted on November 30, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related