<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[DeGirum - Medium]]></title>
        <description><![CDATA[Simplifying edge AI development - Medium]]></description>
        <link>https://medium.com/degirum?source=rss----9ed8e4626d1f---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>DeGirum - Medium</title>
            <link>https://medium.com/degirum?source=rss----9ed8e4626d1f---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 19:43:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/degirum" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Eager batching on Hailo using DeGirum PySDK]]></title>
            <link>https://medium.com/degirum/eager-batching-on-hailo-using-degirum-pysdk-4d41987707ff?source=rss----9ed8e4626d1f---4</link>
            <guid isPermaLink="false">https://medium.com/p/4d41987707ff</guid>
            <category><![CDATA[batching]]></category>
            <category><![CDATA[degirum]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[edge-ai]]></category>
            <category><![CDATA[hailo]]></category>
            <dc:creator><![CDATA[Darshil Modi]]></dc:creator>
            <pubDate>Mon, 17 Nov 2025 18:18:20 GMT</pubDate>
            <atom:updated>2025-11-17T18:18:11.994Z</atom:updated>
            <content:encoded><![CDATA[<h4>If you’re running object detection models on Hailo-8 or Hailo-8L using DeGirum PySDK, you’ve probably asked this question at some point:</h4><blockquote>“Should I crank up the batch size to get more FPS?”</blockquote><p>The short answer: <strong>it depends on your model’s context usage.</strong></p><p>In this post, we’ll walk through a simple benchmark comparing two YOLOv8 models with different batch configurations and see where eager batching shines and where it does almost nothing. If you’re trying to squeeze more throughput out of larger models on your Hailo devices, this walkthrough should give you an intuition for when eager batching is worth enabling.</p><h3>Setting up the playground</h3><p>This guide assumes you already have the usual suspects installed:</p><ul><li><strong>DeGirum </strong><a href="https://docs.degirum.com/pysdk?utm_source=medium&amp;utm_medium=social&amp;utm_campaign=darshil_medium_article"><strong>PySDK</strong></a></li><li><a href="https://docs.degirum.com/pysdk/runtimes-and-drivers/hailort?utm_source=medium&amp;utm_medium=social&amp;utm_campaign=darshil_medium_article"><strong>Hailo AI runtime and driver</strong></a></li><li><a href="https://github.com/DeGirum/degirum_tools"><strong>DeGirum Tools</strong></a></li></ul><p>You can follow the official documentation for installing PySDK and the Hailo runtime/driver.</p><p>For degirum_tools, just install it in the same environment as PySDK:</p><pre>pip install degirum_tools</pre><p>Once that’s done, we’re ready to talk about what eager batching actually is and why it behaves differently for different models.</p><h3>What is eager batching, really?</h3><p>Eager batching is a simple idea: instead of sending inference requests one by one, you <strong>queue multiple requests and process them together as a batch</strong>.</p><p>In DeGirum PySDK, this shows up as setting a batch size (via HAILO_BATCH_SIZE) and letting the runtime group requests into that batch. Conceptually, it’s like this:</p><ul><li>No batching: sending one small car per person.</li><li>Eager batching: waiting until you have a bus full of people, then sending them all at once.</li></ul><p>The bus is more efficient <strong>only if the underlying model and hardware can actually take advantage of that batching</strong>.</p><p>On Hailo, this is where <strong>model contexts</strong> come into the picture. Eager batching <strong>only really helps</strong> when the model supports multiple contexts. If the model can’t be split across multiple execution contexts, increasing the batch size won’t magically speed you up — your “bus” isn’t big enough to give you an advantage.</p><h3>What is a model context on Hailo?</h3><p>On Hailo devices, a <strong>model context</strong> basically describes how many instances of a model can be loaded and executed simultaneously on the accelerator.</p><p>If a model <strong>fits entirely into the device memory</strong>, it’s considered a <strong>single-context</strong> model. These models already run at near full hardware utilization. Batching usually <strong>doesn’t give a big performance boost</strong>, because there isn’t much unused capacity to exploit. If a model <strong>does not fit fully into a single context</strong>, it’s split across <strong>multiple contexts</strong>. These models can use batching to keep multiple contexts busy. Here, eager batching <strong>can significantly improve throughput</strong>, because the accelerator has more parallel work to chew on.</p><p>So the key idea is:</p><blockquote><strong><em>Single-context model → batching usually doesn’t matter much.<br> Multi-context model → batching can be a game changer.</em></strong></blockquote><p>Let’s see that in action with real numbers.</p><h3>What we’re trying to measure</h3><p>We’re going to benchmark two YOLOv8 models:</p><ul><li><strong>YOLOv8n</strong> — a small model that fits into a <strong>single context</strong>.</li><li><strong>YOLOv8m</strong> — a larger model that requires <strong>multiple contexts</strong>.</li></ul><p>For each of these, we’ll run with:</p><ul><li>HAILO_BATCH_SIZE = 1 (no eager batching)</li><li>HAILO_BATCH_SIZE = 8 (eager batching enabled)</li></ul><p>We’ll use degirum_tools.model_time_profile to run repeated inferences and measure <strong>observed FPS (frames per second)</strong>.</p><h3>Installation and imports</h3><p>Let’s start with the basic imports you’ll use throughout the experiment:</p><pre>import degirum as dg<br>import degirum_tools<br>from degirum_tools import ModelSpec<br>import matplotlib.pyplot as plt</pre><p>We’ll be pulling models from the DeGirum AI Hub and running them via the Hailo backend.</p><h3>Model setup and configuration</h3><p>For this experiment, we’re using two models hosted on the <a href="https://degirum.us.auth0.com/login?state=hKFo2SBCWHVJY0hiWXhINnhTWjVtX0pqZzhTamJXem5qWXpSOKFupWxvZ2luo3RpZNkgdUNGRHFSNU5XbjY5Y3hvRWVTUjh5cUZxMU04U2hRZVWjY2lk2SBBQWxoeUltNFpxWWVBbEhQdjlqSnp0b09yRkhWQTNLYg&amp;client=AAlhyIm4ZqYeAlHPv9jJztoOrFHVA3Kb&amp;protocol=oauth2&amp;prompt=login&amp;scope=openid%20profile%20email%20offline_access&amp;redirect_uri=https%3A%2F%2Fhub.degirum.com%2Flogin&amp;audience=https%3A%2F%2Fdegirum.us.auth0.com%2Fapi%2Fv2%2F&amp;response_type=code&amp;response_mode=query&amp;nonce=Uzgxclh3YnFmQU9YY0hUUHZsT08ubF9vcURDcXg4VWlocklBelBaa3dnRQ%3D%3D&amp;code_challenge=1lhWAywx-rAOdj72P4BM9K7ZrVxmqgj22fBPwwPPPkU&amp;code_challenge_method=S256&amp;auth0Client=eyJuYW1lIjoiYXV0aDAtdnVlIiwidmVyc2lvbiI6IjIuMy4xIn0%3D">DeGirum AI Hub</a>:</p><ul><li>yolov8n_coco--640x640_quant_hailort_hailo8_1 → <strong>single-context</strong> model</li><li>yolov8m_coco--640x640_quant_hailort_hailo8_1 → <strong>multi-context</strong> model</li></ul><p>Here’s the shared configuration:</p><pre>iterations = 1000<br>model_zoo = &#39;degirum/hailo&#39;<br>inference_host_address = &#39;@local&#39;</pre><pre>single_context_model = &#39;yolov8n_coco-640x640_quant_hailort_hailo8_1&#39;<br>multi_context_model = &#39;yolov8m_coco--640x640_quant_hailort_hailo8_1&#39;</pre><ul><li>iterations: number of inference runs used to compute average FPS.</li><li>model_zoo: model zoo path on DeGirum AI Hub.</li><li>inference_host_address: where your inference device lives (@local, cloud, or a specific host).</li></ul><p>We’ll now see how changing HAILO_BATCH_SIZE affects these two very different models.</p><h3>Single-context model: YOLOv8n (batch 1 vs batch 8)</h3><p>First up: the <strong>small</strong> YOLOv8n model, which fits entirely into Hailo’s memory. This is your classic single-context case where the accelerator is already being used efficiently even without batching.</p><h3>Batch size = 1</h3><pre># Load the model<br>model_spec = ModelSpec(<br>    model_name=single_context_model,<br>    zoo_url=&quot;https://hub.degirum.com/degirum/hailo&quot;,<br>    inference_host_address=inference_host_address,<br>    model_properties={&quot;extra_device_params&quot;: {&quot;HAILO_BATCH_SIZE&quot;: 1}},  # batch size = 1<br>)</pre><pre>model_a = model_spec.load_model()<br>model_a.output_postprocess_type = &quot;None&quot;</pre><pre>single_context_bs_1_results = degirum_tools.model_time_profile(model_a, iterations)<br>print(<br>    f&quot;Running with batch size - {str(model_a.extra_device_params.HAILO_BATCH_SIZE)}, &quot;<br>    f&quot;Observed FPS: {single_context_bs_1_results.observed_fps:5.2f}&quot;<br>)</pre><p>Sample output:</p><pre>Running with batch size - 1, Observed FPS: 318.95</pre><h3>Batch size = 8</h3><p>Now we bump the batch size up:</p><pre># Load the model<br>model_spec = ModelSpec(<br>    model_name=single_context_model,<br>    zoo_url=&quot;https://hub.degirum.com/degirum/hailo&quot;,<br>    inference_host_address=inference_host_address,<br>    model_properties={&quot;extra_device_params&quot;: {&quot;HAILO_BATCH_SIZE&quot;: 8}},  # batch size = 8<br>)</pre><pre>model_b = model_spec.load_model()<br>model_b.output_postprocess_type = &quot;None&quot;</pre><pre>single_context_bs_8_results = degirum_tools.model_time_profile(model_b, iterations)<br>print(<br>    f&quot;Running with batch size - {str(model_b.extra_device_params.HAILO_BATCH_SIZE)}, &quot;<br>    f&quot;Observed FPS: {single_context_bs_8_results.observed_fps:5.2f}&quot;<br>)</pre><p>Sample output:</p><pre>Running with batch size - 8, Observed FPS: 318.57</pre><p>So we have roughly:</p><ul><li><strong>Batch size 1:</strong> ~318.95 FPS</li><li><strong>Batch size 8:</strong> ~318.57 FPS</li></ul><p>Basically identical.</p><h3>Visualizing the single-context results</h3><p>Here’s a quick way to plot those numbers:</p><pre>import matplotlib.pyplot as plt</pre><pre># Labels and data<br>labels = [&#39;FPS - bs 1&#39;, &#39;FPS - bs 8&#39;]<br>values = [single_context_bs_1_results.observed_fps, single_context_bs_8_results.observed_fps]</pre><pre># Plotting<br>plt.bar(labels, values)</pre><pre># Customizing<br>plt.ylabel(&#39;FPS&#39;)<br>plt.title(&#39;Impact of batch size on single-context model&#39;)</pre><pre># Show plot<br>plt.show()</pre><p>If you render this chart, you’ll see two bars with almost the same height. That’s exactly what we’d expect:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*OrrRyZi4Zi6W1wW_.png" /></figure><blockquote><em>For </em><strong><em>single-context models</em></strong><em>, eager batching doesn’t provide a significant performance boost. The model already fits into the device and fully utilizes the hardware with batch size 1.</em></blockquote><h3>Multi-context model: YOLOv8m (batch 1 vs batch 8)</h3><p>Now let’s switch to the bigger sibling: <strong>YOLOv8m</strong>. This model is large enough that it <strong>requires multiple contexts</strong> on Hailo. It doesn’t fit into a single context, which opens the door for batching to actually help.</p><p>We’ll repeat the same steps: run with HAILO_BATCH_SIZE = 1 and HAILO_BATCH_SIZE = 8 and compare the observed FPS.</p><h3>Batch size = 1</h3><pre>from degirum_tools import ModelSpec</pre><pre># Load the model<br>model_spec = ModelSpec(<br>    model_name=multi_context_model,<br>    zoo_url=&quot;https://hub.degirum.com/degirum/hailo&quot;,<br>    inference_host_address=inference_host_address,<br>    model_properties={&quot;extra_device_params&quot;: {&quot;HAILO_BATCH_SIZE&quot;: 1}},  # batch size = 1<br>)</pre><pre>model_a = model_spec.load_model()<br>model_a.output_postprocess_type = &quot;None&quot;</pre><pre>multi_context_bs_1_results = degirum_tools.model_time_profile(model_a, iterations)<br>print(<br>    f&quot;Running with batch size - {str(model_a.extra_device_params.HAILO_BATCH_SIZE)}, &quot;<br>    f&quot;Observed FPS: {multi_context_bs_1_results.observed_fps:5.2f}&quot;<br>)</pre><p>Sample output:</p><pre>Running with batch size - 1, Observed FPS: 50.70</pre><h3>Batch size = 8</h3><p>Now we let eager batching do its thing:</p><pre># Load the model<br>model_spec = ModelSpec(<br>    model_name=multi_context_model,<br>    zoo_url=&quot;https://hub.degirum.com/degirum/hailo&quot;,<br>    inference_host_address=inference_host_address,<br>    model_properties={&quot;extra_device_params&quot;: {&quot;HAILO_BATCH_SIZE&quot;: 8}},  # batch size = 8<br>)</pre><pre>model_b = model_spec.load_model()<br>model_b.output_postprocess_type = &quot;None&quot;</pre><pre>multi_context_bs_8_results = degirum_tools.model_time_profile(model_b, iterations)<br>print(<br>    f&quot;Running with batch size - {str(model_b.extra_device_params.HAILO_BATCH_SIZE)}, &quot;<br>    f&quot;Observed FPS: {multi_context_bs_8_results.observed_fps:5.2f}&quot;<br>)</pre><p>Sample output:</p><pre>Running with batch size - 8, Observed FPS: 102.13</pre><p>Now the change is very obvious:</p><ul><li><strong>Batch size 1:</strong> ~50.70 FPS</li><li><strong>Batch size 8:</strong> ~102.13 FPS</li></ul><p>That’s roughly a <strong>2× improvement in FPS</strong> just by enabling eager batching for a model that spans multiple contexts.</p><h3>Visualizing the multi-context results</h3><p>Again, a quick bar chart to make this intuitive:</p><pre>import matplotlib.pyplot as plt</pre><pre># Labels and data<br>labels = [&#39;FPS - bs 1&#39;, &#39;FPS - bs 8&#39;]<br>values = [multi_context_bs_1_results.observed_fps, multi_context_bs_8_results.observed_fps]</pre><pre># Plotting<br>plt.bar(labels, values)</pre><pre># Customizing<br>plt.ylabel(&#39;FPS&#39;)<br>plt.title(&#39;Impact of batch size on multi-context model&#39;)</pre><pre># Show plot<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*VAcHA-shCPQnFeuJ.png" /></figure><p>Here you’ll clearly see that the bar for batch size 8 is much taller than the bar for batch size 1 — the visual version of “eager batching really helps here.”</p><h3>What we learned from the benchmarks</h3><p>Putting both experiments side by side:</p><ul><li><strong>YOLOv8n (single-context)</strong></li><li>Batch size 1 → ~318.95 FPS</li><li>Batch size 8 → ~318.57 FPS</li></ul><p><strong>Conclusion:</strong> eager batching doesn’t move the needle.</p><ul><li><strong>YOLOv8m (multi-context)</strong></li><li>Batch size 1 → ~50.70 FPS</li><li>Batch size 8 → ~102.13 FPS</li></ul><p><strong>Conclusion:</strong> eager batching almost doubles the throughput.</p><p>This lines up perfectly with the theory:</p><ul><li>For <strong>small models</strong> that fit into a single context, Hailo is already fully utilized. The model doesn’t get faster just because you ask for a bigger batch.</li><li>For <strong>larger models</strong> that require multiple contexts, eager batching helps the accelerator do more parallel work, which translates into higher FPS.</li></ul><p>In short:</p><blockquote><strong><em>Eager batching is a powerful tool for larger, multi-context models on Hailo. For smaller single-context models, it’s usually not worth the complexity.</em></strong></blockquote><p>By understanding how model contexts work and taking a few minutes to test FPS under different batch sizes, you can make informed decisions and get the best possible throughput out of your Hailo-8 or Hailo-8L devices using DeGirum PySDK.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d41987707ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/degirum/eager-batching-on-hailo-using-degirum-pysdk-4d41987707ff">Eager batching on Hailo using DeGirum PySDK</a> was originally published in <a href="https://medium.com/degirum">DeGirum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[License plate recognition (ANPR/LPR) with DeGirum PySDK on Hailo accelerators]]></title>
            <link>https://medium.com/degirum/license-plate-recognition-anpr-lpr-with-degirum-pysdk-on-hailo-accelerators-42b1e8ac057e?source=rss----9ed8e4626d1f---4</link>
            <guid isPermaLink="false">https://medium.com/p/42b1e8ac057e</guid>
            <dc:creator><![CDATA[Franklinmoses M]]></dc:creator>
            <pubDate>Wed, 08 Oct 2025 21:43:01 GMT</pubDate>
            <atom:updated>2025-10-14T22:18:34.985Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhK-1wyuSd7U%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhK-1wyuSd7U&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FhK-1wyuSd7U%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/186270dc6c3b4845df1e973619566d85/href">https://medium.com/media/186270dc6c3b4845df1e973619566d85/href</a></iframe><p>Ever wondered how a parking gate lifts the moment you pull up, how a toll booth charges you without slowing down, or how traffic cameras catch a license plate in a split second?</p><p>Using <a href="https://www.linkedin.com/company/degirum/">DeGirum</a> PySDK with Hailo accelerators, you can build a complete License Plate Recognition (ANPR / LPR) pipeline that runs in real-time, chaining detection + OCR into one seamless workflow.</p><p>And here’s the best part: while this demo runs on Hailo, the same PySDK pipeline runs on NVIDIA, Intel, Google EdgeTPU, Rockchip, AMD, MemryX, BrainChip, Axelera AI, all with the <em>exact same code</em>, just by changing a single variable.</p><p>What makes this even more powerful is model pipelining: multiple models run in sequence, so the detector’s output feeds directly into the OCR model, giving you bounding boxes and recognized plate text in a single pass.</p><h3>What you’ll build</h3><ul><li>License plate detection → Finds plates in images or video</li><li>License plate OCR → Reads alphanumeric text from each plate</li><li>Combined results → Bounding boxes + recognized text overlayed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X7Y0H0T3cHOsYjlLHj6Jlw.png" /><figcaption>Example: License plate recognized as: DEGIRUM</figcaption></figure><h3>Getting started</h3><p>You’ll need:</p><ul><li><a href="https://docs.degirum.com/pysdk/installation?utm_source=medium.com&amp;utm_medium=referral&amp;utm_campaign=anpr-lpr-hailo-pysdk">DeGirum PySDK</a></li><li><a href="https://docs.degirum.com/pysdk/runtimes-and-drivers/hailort?utm_source=medium.com&amp;utm_medium=referral&amp;utm_campaign=anpr-lpr-hailo-pysdk">Hailo runtime &amp; driver</a></li><li><a href="https://docs.degirum.com/degirum-tools?utm_source=medium.com&amp;utm_medium=referral&amp;utm_campaign=anpr-lpr-hailo-pysdk">DeGirum Tools</a></li></ul><p>Install degirum_tools with:</p><pre>pip install degirum-tools</pre><p>Not on hardware yet? No problem. With the <a href="https://hub.degirum.com/compiler/?utm_source=medium.com&amp;utm_medium=referral&amp;utm_campaign=anpr-lpr-hailo-pysdk">AI Hub Cloud Compiler</a> you can prototype in the cloud on real accelerators right from your browser, then deploy locally with the same code. Follow the <a href="https://community.degirum.com/t/cloud-compiler-quickstart/212/4?utm_source=medium.com&amp;utm_medium=referral&amp;utm_campaign=anpr-lpr-hailo-pysdk">Quickstart Guide</a> to try it out.</p><h3>Models used (Hailo zoo)</h3><ul><li>Detector: yolov8n_relu6_global_lp_det — 640x640_quant_hailort_multidevice_1</li><li>OCR: yolov8s_relu6_lp_ocr_7ch — 256x128_quant_hailort_multidevice_1</li></ul><p>Here’s all it takes in Python to get real-time license plate recognition running.</p><pre>import degirum as dg, degirum_tools<br>from degirum_tools import remote_assets<br><br>hw_location = &quot;@cloud&quot;<br>model_zoo_url = &quot;degirum/hailo&quot;<br>lp_det_model_name = &quot;yolov8n_relu6_global_lp_det--640x640_quant_hailort_multidevice_1&quot;<br>lp_ocr_model_name = &quot;yolov8s_relu6_lp_ocr_7ch--256x128_quant_hailort_multidevice_1&quot;<br><br># Load license plate detection and license plate OCR models<br>lp_det_model=dg.load_model(<br>    model_name=lp_det_model_name,<br>    inference_host_address=hw_location,<br>    zoo_url=model_zoo_url<br>)<br>lp_ocr_model=dg.load_model(<br>    model_name=lp_ocr_model_name,<br>    inference_host_address=hw_location,<br>    zoo_url=model_zoo_url<br>)<br><br># Create a compound cropping model with 50% crop extent<br>crop_model = degirum_tools.CroppingAndClassifyingCompoundModel(<br>    lp_det_model,<br>    lp_ocr_model<br>)<br><br>image_source = remote_assets.car<br>inference_result = crop_model(image_source)<br><br># Display combined results<br>with degirum_tools.Display(&quot;License Plates&quot;) as display:<br>    display.show_image(inference_result)</pre><h3>How it works</h3><ol><li>Model loading: The license plate detection and OCR models are loaded using dg.load_model. Each is configured for Hailo inference or cloud/AI server runs.</li><li>Pipeline creation: A compound model is created with degirum_tools.CroppingAndClassifyingCompoundModel. It automatically crops plate regions from the detector and passes them to the OCR model. You can adjust the crop_extent parameter to expand or shrink the cropped region based on your needs.</li><li>Inference execution: You can run inference on still images or video streams. With predict_stream, each frame is processed, plates are detected, cropped, and recognized in sequence. Running inference on video using predict_stream is explained in the following section.</li><li>Result display: View bounding boxes and recognized plate text overlayed in real time.</li></ol><h3>Streaming inference with predict_stream</h3><p>degirum-tools provides a high-level helper:</p><pre>inference_results = degirum_tools.predict_stream(crop_model, video_source)<br><br># Display inference results<br># Press &#39;x&#39; or &#39;q&#39; to stop<br>with degirum_tools.Display(&quot;Faces and Gender&quot;) as display:<br>    for inference_result in inference_results:<br>        display.show(inference_result)</pre><p>This helper continuously reads frames, runs inference, and overlays results, all in just a few lines of Python.</p><h3>Real-world applications</h3><ul><li>🚦 Traffic monitoring</li><li>🅿️ Smart parking systems</li><li>🛣️ Automated toll booths</li><li>🚚 Fleet management</li><li>🏢 Secure vehicle access control</li></ul><p>With DeGirum PySDK and Hailo accelerators, building practical, real-time AI systems becomes straightforward. And because PySDK is compatible with multiple hardware, developers can prototype in the cloud and deploy across diverse edge devices with minimal adjustments.</p><h3>Want to dive deeper?</h3><p>Want to try additional DeGirum + Hailo examples? Explore the <a href="https://github.com/DeGirum/hailo_examples/">hailo_examples GitHub repo</a>.</p><ul><li>📖 Explore the step-by-step <a href="https://docs.degirum.com/pysdk?utm_source=medium.com&amp;utm_medium=referral&amp;utm_campaign=anpr-lpr-hailo-pysdk">DeGirum PySDK Documentation</a> to learn how to set up the SDK, load models, and build your own computer vision workflows.</li><li>💻 Ready to experiment hands-on? <a href="https://colab.research.google.com/drive/1NtfdSHylh7SBk6h-Z1bRsk4nO0lrbDkF?usp=sharing">Open the following Google Colab Notebook</a> and try out the License Plate Recognition (ANPR/LPR) pipeline directly in your browser using cloud inference mode. no local setup needed.</li></ul><ul><li><a href="https://colab.research.google.com/drive/1NtfdSHylh7SBk6h-Z1bRsk4nO0lrbDkF?usp=sharing">Google Colab</a></li><li><a href="https://github.com/DeGirum/hailo_examples/blob/main/examples/026_license_plate_recognition_pipelined.ipynb">hailo_examples/examples/026_license_plate_recognition_pipelined.ipynb at main · DeGirum/hailo_examples</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42b1e8ac057e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/degirum/license-plate-recognition-anpr-lpr-with-degirum-pysdk-on-hailo-accelerators-42b1e8ac057e">License plate recognition (ANPR/LPR) with DeGirum PySDK on Hailo accelerators</a> was originally published in <a href="https://medium.com/degirum">DeGirum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Detection and Zone Counting]]></title>
            <link>https://medium.com/degirum/object-detection-and-zone-counting-2b1762f8afd4?source=rss----9ed8e4626d1f---4</link>
            <guid isPermaLink="false">https://medium.com/p/2b1762f8afd4</guid>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Vladis Klimov]]></dc:creator>
            <pubDate>Sat, 03 Feb 2024 00:43:21 GMT</pubDate>
            <atom:updated>2025-09-08T21:04:02.742Z</atom:updated>
            <content:encoded><![CDATA[<h3>Object Detection and Polygon Zone Counting Using DeGirum SDK</h3><h4>Introduction</h4><p>Object detection on a video stream with object counting in a polygon zone is a sophisticated application of artificial intelligence (AI) that finds extensive use in various fields, including surveillance, traffic management, and industrial automation. This technology leverages advanced computer vision techniques to identify and track objects within a specified area of interest.</p><p>Object detection involves the use of AI models, such as convolutional neural networks (CNNs), to analyze video frames and identify objects present within them. In the context of video streams, these models analyze successive frames to track the movement and changes in object positions over time.</p><p>A polygon zone is a defined area of interest within the video frame where object counting needs to occur. It is usually specified by a set of vertices that form a closed shape. The application of a polygon zone allows for focused analysis, restricting object counting to a specific region within the video stream.</p><p>The implementation of object counting within a polygon zone involves the following steps:</p><ul><li><em>Polygon Definition</em>: define the polygon zone by specifying its vertices. This defines the region where object counting will take place.</li><li><em>Frame Analysis</em>: process each frame of the video stream using the object detection model. Identify and classify objects present in the frame.</li><li><em>Polygon Intersection</em>: check whether the detected objects intersect with the defined polygon zone. This step ensures that only objects within the specified region are considered for counting.</li><li><em>Counting Logic</em>: establish counting logic based on the number of objects within the polygon zones.</li><li><em>Real-Time Updates:</em> provide real-time updates on the object count within the polygon zone. This information can be utilized for various applications, such as monitoring crowd density, traffic flow, or object movement in a manufacturing environment.</li></ul><h4>Applications</h4><ul><li><em>Surveillance</em>: monitor specific areas within a surveillance camera’s field of view, counting and tracking objects for security purposes.</li><li><em>Traffic Management</em>: analyze vehicle movement within designated zones to optimize traffic flow and detect congestion.</li><li><em>Industrial Automation</em>: count and track objects on factory floors to enhance production efficiency and safety.</li><li><em>Retail Analytics</em>: monitor customer movement and product interactions within specific areas of a retail store for marketing and inventory management.</li></ul><h4>Using DeGirum SDK for Object Zone Counting</h4><h4>Prerequisites</h4><p>Assuming you have configured Python environment on your Windows, Linux, or MacOS computer, you need to install <strong>DeGirum PySDK</strong> and <strong>DeGirum Tools</strong> Python packages by running the following commands (follow <a href="https://docs.degirum.com/content/pysdk/installation/">this link</a> for details):</p><pre>pip install -U degirum<br>pip install -U degirum_tools</pre><p>Alternatively, you can use Google Colab to run <a href="https://colab.research.google.com/github/DeGirum/PySDKExamples/blob/main/examples/specialized/object_in_zone_counting_video_stream.ipynb">zone counting example Jupyter notebook</a> provided by DeGirum.</p><h4>Step-by-Step Guide</h4><h4>Import necessary packages</h4><p>You need to import degirum and degirum_tools packages:</p><pre>import degirum as dg, degirum_tools</pre><h4>Select object detection AI model</h4><p>As a starter, we will use YOLOv5s COCO model, which can detect 80 <a href="https://cocodataset.org/">COCO classes</a>. We will take this model from DeGirum cloud public model zoo.</p><p>Lets define the cloud zoo URL and the model name:</p><pre>model_zoo_url = &quot;https://cs.degirum.com/degirum/public&quot;<br>model_name = &quot;yolo_v5s_coco--512x512_quant_n2x_orca1_1&quot;</pre><p>Here cs.degirum.com is <a href="https://docs.degirum.com/content/delight/">DeGirum DeLight Cloud Platform</a> URL, and degirum/public is the path to DeGirum cloud public model zoo.</p><p>yolo_v5s_coco--512x512_quant_n2x_orca1_1 is the model name we will use for object detection. It is based on <a href="https://docs.ultralytics.com/yolov5/">YOLOv5 Ultralytics</a> model trained to detect 80 COCO classes and compiled for <a href="https://docs.degirum.com/content/orca/">DeGrium ORCA1</a> AI hardware accelerator.</p><h4>Define video source</h4><p>For simplicity, we will use short highway traffic video from <a href="https://github.com/DeGirum/PySDKExamples">DeGirum PySDK examples GitHub repo</a>:</p><pre>video_source = <br>&quot;https://github.com/DeGirum/PySDKExamples/raw/main/images/Traffic.mp4&quot;</pre><p>But you can use any video file you want. If you run the code locally and your computer has video camera, you may use video camera as a video source:</p><pre>video_source = 0 # specify index of local video camera</pre><h4>Define polygon zones</h4><p>For each zone, in which you want to count objects, you need to define the list of [x,y] pixel coordinates of polygon vertices, which surround that zone. Then you define a list containing all zone polygons:</p><pre>polygon_zones = [<br>    [[265, 260], [730, 260], [870, 450], [120, 450]], # zone 1<br>    [[400, 100], [610, 100], [690, 200], [320, 200]], # zone 2<br>]</pre><p>Here we defined two zone with four vertices in each zone.</p><h4>Obtains cloud API access token</h4><p>In order to use AI models from DeGirum Cloud Platform, you need to register and generate cloud API access token. Please follow <a href="https://docs.degirum.com/content/delight/token/">these instructions</a>. Registration is free.</p><h4>Connect to model zoo and load the model</h4><pre># connect to AI inference engine<br>zoo = dg.connect(dg.CLOUD, model_zoo_url, &quot;&lt;cloud API token&gt;&quot;)<br><br># load model<br>model = zoo.load_model(model_name)</pre><p>Here we connect to DeGirum Cloud Platform to run AI model inferences (by using dg.CLOUD parameter) and to cloud model zoo specified by model_zoo_url using cloud API access token obtained on the previous step. Then we load a model specified by model_name.</p><p>For more inference options please refer to <a href="https://docs.degirum.com/documentation/PySDK-0.10.2/user-guide/model-zoo-manager/">this documentation page</a>.</p><h4>Define interactive display</h4><p>If you would like to observe live real-time results of object detection and zone counting with AI annotations overlay, you may use Display class from DeGirum Tools package:</p><pre>with degirum_tools.Display(&quot;AI Camera&quot;) as display:<br>    ...</pre><h4>Define zone counting object</h4><p>We will use ZoneCounter object from DeGirum Tools package, which greatly simplifies the task of object zone counting.</p><pre>with degirum_tools.Display(&quot;AI Camera&quot;) as display:<br>    zone_counter = degirum_tools.ZoneCounter(<br>        polygon_zones,<br>        class_list=[&quot;car&quot;, &quot;motorbike&quot;, &quot;truck&quot;],<br>        per_class_display=True,<br>        triggering_position=degirum_tools.AnchorPoint.CENTER,<br>        window_name=display.window_name,<br>    )</pre><p>Here we specify the list of classes we want to count: class_list=[&quot;car&quot;, &quot;motorbike&quot;, &quot;truck&quot;]. You may omit this parameter to count all classes the model reports.</p><p>We also specify per-class counting mode: per_class_display=True. You may omit this parameter to count all classes together.</p><p>We specify the triggering position to be the center of the object bounding box: triggering_position=degirum_tools.AnchorPoint.CENTER. Possible triggering positions are all four vertices and all four centers of bounding box edges.</p><p>If you want to adjust polygon zones on interactive display during run-time, you can specify the OpenCV window name of that interactive display: window_name=display.window_name. You can drag the whole zone polygon by left mouse button and you can move polygon vertices by right mouse button.</p><h4>Define inference loop</h4><pre>with degirum_tools.open_video_stream(video_source) as stream:<br>        for result in model.predict_batch(<br>            degirum_tools.video_source(stream)<br>        ):<br>            img = result.image_overlay<br>            img = zone_counter.analyze_and_annotate(result, img)<br>            display.show(img)</pre><p>We open the video stream using degirum_tools.open_video_stream.</p><p>Then we supply video source to the input of model.predict_batch method, which performs AI model inference on each frame retrieved from the video stream in effective pipelined manner.</p><p>The result object contains the inference results, which are stored in the result.results list.</p><p>The result.image_overlay method draws AI annotations on a top of original video frame image. These annotations include bounding boxes of all detected objects.</p><p>The zone_counter.analyze_and_annotate method counts objects in polygon zones and draws object counts on a top of provided image.</p><p>Finally, display.show(img) displays fully annotated image in OpenCV interactive window.</p><p>To simplify the boilerplate code you may use degirum_tools.predict_stream function, which effectively performs the same steps as above:</p><pre>for result in degirum_tools.predict_stream(<br>    model, video_source, analyzers=zone_counter<br>):<br><br>    display.show(result)</pre><h4>Access zone counting results</h4><p>If you want to know, which object belongs to which zone, you may analyze &quot;in_zone&quot; key of each result dictionary: when present, its value is the index of the zone where this object is detected:</p><pre>for detection in result.results:<br>    if (zone_index := detection.get(&quot;in_zone&quot;, None)) is not None:<br>        # this `detection` belongs to zone with index `zone_index`</pre><p>If you want to obtain per-zone counts, you may use the following expression:</p><pre>zones,counts = np.unique([d[&quot;in_zone&quot;] <br>    for d in result.results <br>    if d[&quot;label&quot;] in class_list and &quot;in_zone&quot; in d], <br>    return_counts=True)<br>print(dict(zip(zones,counts)))</pre><p>The whole code of the example described above is available in <a href="https://github.com/DeGirum/PySDKExamples/blob/main/examples/specialized/object_in_zone_counting_video_stream.ipynb">this Jupyter notebook</a></p><p>The following is the sample screenshot of a live video produced by that example:</p><figure><img alt="Zone Counting" src="https://cdn-images-1.medium.com/proxy/1*Yqbv1KpUysy6-IgaSFAqEg.png" /><figcaption>Zone Counting</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b1762f8afd4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/degirum/object-detection-and-zone-counting-2b1762f8afd4">Object Detection and Zone Counting</a> was originally published in <a href="https://medium.com/degirum">DeGirum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Tracking and Line Counting]]></title>
            <link>https://medium.com/degirum/object-tracking-and-line-counting-7df5ad9f1f5d?source=rss----9ed8e4626d1f---4</link>
            <guid isPermaLink="false">https://medium.com/p/7df5ad9f1f5d</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Vladis Klimov]]></dc:creator>
            <pubDate>Sat, 03 Feb 2024 00:41:52 GMT</pubDate>
            <atom:updated>2025-09-08T21:03:25.380Z</atom:updated>
            <content:encoded><![CDATA[<h3>Multi-Object Tracking and Line Counting Using DeGirum SDK</h3><h4>Introduction</h4><p>AI models for object detection on a video stream with multi-object tracking and line intersection counting represent an advanced application of computer vision that is widely employed in surveillance, traffic management, and various other domains. This sophisticated technology combines the capabilities of object detection, multi-object tracking, and counting to analyze the movement of multiple objects within a video stream and ascertain when they intersect with predefined lines or boundaries.</p><p>Multi-object tracking (MOT) algorithms play a crucial role in computer vision applications by enabling the simultaneous detection and tracking of multiple objects in a video sequence. These algorithms aim to maintain the identities of objects <strong>across frames</strong>, facilitating the analysis of object interactions, movements, and behaviors. Various MOT algorithms exist, each with unique characteristics and approaches.</p><p>DeGirum toolkit incorporates <a href="https://github.com/ifzhang/ByteTrack">ByteTrack</a> algorithm implementation for Multi-object tracking.</p><p>Key components of the object tracking and line counting application are:</p><ul><li><em>Object Detection Model</em>: utilizes a trained AI model for real-time identification and classification of objects in the video stream.</li><li><em>Multi-Object Tracking Algorithm</em>: keeps track of individual objects over time, maintaining their trajectories as they move through different frames.</li><li><em>Line Definition</em>: specifies one or more lines within the video frame where intersection counting will occur. These lines are typically defined by their coordinates.</li><li><em>Intersection Logic</em>: implements algorithms to detect when and in which direction an object’s trajectory intersects with the defined lines. This triggers the counting mechanism.</li><li><em>Counting Mechanism</em>: tracks the number of objects crossing the specified lines, incrementing the count whenever an intersection is detected, but only once for every trajectory.</li></ul><h4>Applications</h4><ul><li><em>Traffic Monitoring</em>: counts and tracks vehicles as they move through intersections, helping in traffic flow analysis and congestion management.</li><li><em>Pedestrian Flow Analysis</em>: monitors the movement of people at key points, aiding in crowd management and ensuring safety in public spaces.</li><li><em>Retail Analytics</em>: tracks customer movements within a store, helping retailers understand foot traffic patterns and optimize store layouts.</li><li><em>Security Surveillance</em>: identifies and counts individuals or objects crossing predefined security perimeters, enhancing surveillance capabilities.</li></ul><h4>Using DeGirum SDK for Object Tracking and Line Intersection Counting</h4><h4>Prerequisites</h4><p>Assuming you have configured Python environment on your Windows, Linux, or MacOS computer, you need to install DeGirum PySDK and DeGirum Tools Python packages by running the following commands (follow <a href="https://docs.degirum.com/content/pysdk/installation/">this link</a> for details):</p><pre>pip install -U degirum<br>pip install -U degirum_tools</pre><p>Alternatively, you can use Google Colab to run <a href="https://colab.research.google.com/github/DeGirum/PySDKExamples/blob/main/examples/specialized/multi_object_tracking_video_file.ipynb">zone counting example Jupyter notebook</a> provided by DeGirum.</p><h4>Step-by-Step Guide</h4><h4>Import necessary packages</h4><p>You need to import degirum and degirum_tools packages:</p><pre>import cv2</pre><pre>import degirum as dg, degirum_tools</pre><h4>Select object detection AI model</h4><p>As a starter, we will use YOLOv5s COCO model, which can detect 80 <a href="https://cocodataset.org/">COCO classes</a>. We will take this model from DeGirum cloud public model zoo.</p><p>Lets define the cloud zoo URL and the model name:</p><pre>model_zoo_url = &quot;https://cs.degirum.com/degirum/public&quot;<br>model_name = &quot;yolo_v5s_coco--512x512_quant_n2x_orca1_1&quot;</pre><p>Here cs.degirum.com is <a href="https://docs.degirum.com/content/delight/">DeGirum DeLight Cloud Platform</a> URL, and degirum/public is the path to DeGirum cloud public model zoo.</p><p>yolo_v5s_coco--512x512_quant_n2x_orca1_1 is the model name we will use for object detection. It is based on <a href="https://docs.ultralytics.com/yolov5/">YOLOv5 Ultralytics</a> model trained to detect 80 COCO classes and compiled for <a href="https://docs.degirum.com/content/orca/">DeGrium ORCA1</a> AI hardware accelerator.</p><h4>Define video source</h4><p>For simplicity, we will use short highway traffic video from <a href="https://github.com/DeGirum/PySDKExamples">DeGirum PySDK examples GitHub repo</a>:</p><pre>video_source <br>=&quot;https://github.com/DeGirum/PySDKExamples/raw/main/images/Traffic.mp4&quot;</pre><p>But you can use any video file you want. If you run the code locally and your computer has video camera, you may use video camera as a video source:</p><pre>video_source = 0 # specify index of local video camera</pre><h4>Obtain cloud API access token</h4><p>In order to use AI models from DeGirum Cloud Platform, you need to register and generate cloud API access token. Please follow <a href="https://docs.degirum.com/content/delight/token/">these instructions</a>. Registration is free.</p><h4>Connect to model zoo and load the model</h4><pre># connect to AI inference engine<br>zoo = dg.connect(dg.CLOUD, model_zoo_url, &quot;&lt;cloud API token&gt;&quot;)<br><br># load model<br>model = zoo.load_model(model_name)</pre><p>Here we connect to DeGirum Cloud Platform to run AI model inferences (by using dg.CLOUD parameter) and to cloud model zoo specified by model_zoo_url using cloud API access token obtained on the previous step. Then we load a model specified by model_name.</p><p>For more inference options please refer to <a href="https://docs.degirum.com/documentation/PySDK-0.10.2/user-guide/model-zoo-manager/">this documentation page</a>.</p><h4>Define intersection lines</h4><p>For each intersection line you need to define the four-element tuple (x1, y1, x2, y2) of line endpoints pixel coordinates. Then you define a list containing all line tuples:</p><pre>lines = [(120, 430, 870, 430), (860, 80, 860, 210)]</pre><p>Here we defined two lines.</p><h4>Define object tracker</h4><p>We will use degirum_tools.ObjectTracker object from DeGirum Tools package, which implements ByteTrack MoT algorithm:</p><pre>tracker = degirum_tools.ObjectTracker(<br>    class_list=[&quot;car&quot;],<br>    track_thresh=0.35,<br>    track_buffer=100,<br>    match_thresh=0.9999,<br>    trail_depth=20,<br>    anchor_point=degirum_tools.AnchorPoint.BOTTOM_CENTER,<br>)</pre><p>Here we specify the list of classes we want to track: class_list=[&quot;car&quot;]. You may omit this parameter to track all classes the model reports.</p><p>We can specify various parameters of ByteTrack algorithm to fine-tune its performance:</p><ul><li>track_thresh: AI object detection model confidence threshold for track activation;</li><li>track_buffer: number of frames to buffer when a track is lost;</li><li>match_thresh: IOU threshold for matching tracks with detections.</li></ul><p>Also we specify the tracing parameters:</p><ul><li>trail_depth: number of frames in object trail to keep; 0 to disable tracing;</li><li>anchor_point: bounding box anchor point to be used for tracing object trails.</li></ul><p>We specify the anchor point to be the center of the bottom edge of the object bounding box: triggering_position=degirum_tools.AnchorPoint.BOTTOM_CENTER. Possible triggering positions are all four vertices and all four centers of bounding box edges.</p><h4>Define line counting object</h4><p>We will use degirum_tools.LineCounter object from DeGirum Tools package, which provides line intersection detection and counting functionality:</p><pre>line_counter = degirum_tools.LineCounter(lines)</pre><p>We initialize line counter passing the list of lines we defined on earlier step.</p><h4>Define inference loop</h4><pre>with degirum_tools.Display(&quot;AI Camera&quot;) as display, \<br>    degirum_tools.open_video_stream(video_source) as stream:<br><br>    for result in model.predict_batch(<br>        degirum_tools.video_source(stream)<br>    ):<br>        tracker.analyze(result)<br>        line_counter.analyze(result)<br><br>        img = result.image_overlay<br>        img = tracker.annotate(result, img)<br>        img = line_counter.annotate(result, img)<br>        display.show(img)</pre><p>To observe live results, we open the interactive display using degirum_tools.Display class.</p><p>Then we open the video stream using degirum_tools.open_video_stream.</p><p>Then we supply video source to the input of model.predict_batch method, which performs AI model inference on each frame retrieved from the video stream in effective pipelined manner.</p><p>The result object contains the inference results, which are stored in the result.results list.</p><p>tracker.analyze(result) call applies the object tracking algorithm to object detection inference results, adding object tracking results back to result object.</p><p>line_counter.analyze(result) call applies the line counting algorithm to object tracking results, obtained on the previous step, again adding new information back to result object.</p><p>After all these steps the result object contains three sets of information:</p><ul><li>object detection inference results,</li><li>object tracking results,</li><li>line counting results.</li></ul><p>The result.image_overlay method draws AI annotations on a top of original video frame image. These annotations include bounding boxes of all detected objects.</p><p>To display the results of object tracking and line counting, we use annotate methods of tracker and line_counter objects.</p><p>Finally, we call display.show(img) to display fully annotated image in OpenCV interactive window.</p><p>To simplify the boilerplate code you may use degirum_tools.predict_stream function, which effectively performs the same steps as above:</p><pre>with degirum_tools.Display(&quot;AI Camera&quot;) as display:<br>    for result in degirum_tools.predict_stream(model, \<br>        video_source, analyzers=[tracker, line_counter]):<br><br>        display.show(result)</pre><h4>Access object tracking results</h4><p>The object tracker provides two kinds of results:</p><ul><li>unique object tracking IDs,</li><li>object trajectories (or <em>traces</em>).</li></ul><p>Object tracking IDs are stored in elements of result.results list. Each such element is a dictionary initially containing AI model object detection results such as scores, bounding box coordinates etc. For each tracked object the object tracker adds a key-value pair to the corresponding element of result.results list. The key is &quot;track_id&quot; and the value is the unique object tracking ID. Please note that not all detected objects are assigned with IDs, so you need to check, if &quot;track_id&quot; key is present or not.</p><p>The following code iterates over all detections and extracts tracking IDs:</p><pre>for detection in result.results:<br>    if (track_id := detection.get(&quot;track_id&quot;, None)) is not None:<br>        # this `detection` has object tracking ID `track_id`</pre><p>If you enabled storing traces (you specified non-zero trail_depth parameter in degirum_tools.ObjectTracker constructor), then the object tracker will also add trails dictionary to the result object.</p><p>The result.trails dictionary contains traces of all tracked objects. This dictionary is keyed by the track IDs and contains lists of trail (x,y) coordinates for every active trail.</p><p>The following code illustrates how to display all trails with at least two points, using OpenCV polylines function:</p><pre>all_trails = [<br>    np.array(trail) <br>    for id, trail in result.trails.items() <br>    if len(trail) &gt; 1<br>]<br>cv2.polylines(img, all_trails, False, line_color)</pre><h4>Access line counting results</h4><p>Line counting results are stores in the result.line_counts list, one element per each defined line. Each element of this list is degirum_tools.LineCounts dataclass object, which has the following integer attributes:</p><ul><li>left: number of trajectories intersected a line from frame left to frame right,</li><li>right: from right to left,</li><li>top: from top to bottom,</li><li>bottom: from bottom to top.</li></ul><p>The whole code of the example described above is available in <a href="https://github.com/DeGirum/PySDKExamples/blob/main/examples/specialized/multi_object_tracking_video_file.ipynb">this Jupyter notebook</a></p><p>The following is the sample screenshot of a live video produced by that example:</p><figure><img alt="Line Counting" src="https://cdn-images-1.medium.com/proxy/1*us3tNXAFlDjMoxlRjf3A6A.png" /><figcaption>Line Counting</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7df5ad9f1f5d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/degirum/object-tracking-and-line-counting-7df5ad9f1f5d">Object Tracking and Line Counting</a> was originally published in <a href="https://medium.com/degirum">DeGirum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developing AI Applications for the Edge: A New Approach]]></title>
            <link>https://medium.com/degirum/developing-ai-applications-for-the-edge-a-new-approach-59dd8b96a0bb?source=rss----9ed8e4626d1f---4</link>
            <guid isPermaLink="false">https://medium.com/p/59dd8b96a0bb</guid>
            <category><![CDATA[cloud-platform]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[hardware-accelerator]]></category>
            <category><![CDATA[edge-ai]]></category>
            <dc:creator><![CDATA[Shashi Kiran Chilappagari]]></dc:creator>
            <pubDate>Tue, 02 Jan 2024 04:21:40 GMT</pubDate>
            <atom:updated>2024-01-02T05:33:15.946Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_6iGBZwgbg8__W0YBk0xJw.jpeg" /><figcaption>Image generated using Bing Chat Enterprise</figcaption></figure><p>The past few years have seen a dramatic surge in the number of hardware accelerators for running AI inference at the edge. These offerings, instead of making life easier for developers, have turned the process of developing edge AI applications into a complex, expensive, time consuming, and frustrating experience. <strong>Complex</strong> because it requires bringing together hardware, software, business logic, and machine learning (ML) models together. <strong>Expensive </strong>because developers need to invest time and money to bring up different hardware options. <strong>Time consuming</strong> because each hardware option is accompanied by its own software stack and toolchain for porting models. And <strong>frustrating </strong>because the toolchains are still not reliable and the whole pipeline of going from a problem to deployed ML model is highly fragmented. Before we delve into how the process can be simplified, it is worthwhile to spend some time on understanding why we are in this situation in the first place.</p><h3>Developer’s Dilemma:</h3><p>To understand why developers need to spend a lot of time, money, and engineering resources on evaluating different HW options, it is instructive to look at the fundamental dilemma that Edge AI application developers face when it comes to developing their applications: should they first develop their application software and then pick the hardware, or should they first pick the hardware and then develop the software?</p><p>Ideally, developers would like to first develop the software and defer the selection of hardware until they can evaluate the performance on different hardware options and pick the best one. Unfortunately, they cannot develop application software first without choosing the hardware, as software and ML models are closely tied to the hardware, and there is no unified software stack that works with multiple hardware.</p><p>At the same time, they cannot pick hardware first because it is difficult to choose hardware without knowing what performance it will give in the application. Consequently, this leaves them with no choice but to develop the application for each target hardware they want to evaluate, benchmark the performance, and then pick the optimal hardware option that caters to their needs. The development workflow is depicted in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdX4n_ccHbIaQcEV5cyhQA.png" /><figcaption>Current Edge AI Development Workflow</figcaption></figure><p>A quick look at the workflow tells us why the application development process is complex, expensive, time-consuming, and frustrating, as claimed earlier. At this point, you might be wondering why choosing the right hardware is such a big challenge. Surely, the hardware vendors must be providing enough information in their data sheets to allow developers to make the correct choice, right? Of course, hardware vendors provide datasheets, benchmarks, demos, and a plethora of other supporting material to establish the supremacy of their offerings. However, even armed with all this information, picking the right hardware is a highly non-trivial task.</p><h3>Choosing the Right AI Hardware</h3><p>We will now delve deeper into the world of HW selection and understand what makes it such an interesting and complex problem. You would have no doubt come across the various terms used by HW vendors to publicize the strength of their products: Trillion Operations Per Second (TOPS), TOPS/Watt, Frames Per Second (FPS), FPS/Watt, FPS/$, FPS/TOPS (believe me, I am not making up this metric), and so on. We will see why these metrics alone cannot guide HW selection.</p><h4>AI Hardware Accelerators: Where Everyone is the Best at Something</h4><p>Every hardware vendor building an AI accelerator or SoC makes the same claims: they have the most powerful hardware combined with the easiest to use software. It’s like a bunch of chefs trying to outdo each other with their secret recipes. “My recipe is better than yours!” “No, mine is better!” “No, mine is the best!” 😂 But, as with recipes, it’s not always easy to pick the best one based on the number of ingredients it has. Ultimately, what matters is that the recipe tastes good and is easy to follow. Similarly, when choosing a hardware option, it’s important to ensure that it meets your requirements and is easy to use. After all, the goal is to create a delicious dish, not just a dish with a lot of ingredients. 😋</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-whIWQMiyWfwIGEtFjZTQg.png" /><figcaption>Image generated using Bing Chat Enterprise</figcaption></figure><h4><strong>TOPS is Like a Box of Chocolates: You Never Know What You’re Going to Get</strong></h4><p>Metrics like TOPS do not translate to real application performance in a standardized way. Consider two hardware options: A and B. If A has 2x TOPS compared to B, it does not necessarily mean that for a given machine learning (ML) model, A will have 2x FPS compared to B. In fact, this is the case even if A and B are different products from the same company. Now, consider two ML models M1 and M2 running on the same hardware. If M1 has 2x more compute than M2, it does not necessarily mean that M2 will have 2x FPS compared to M1. This is true even if M1 and M2 are the same model architecture running at different input resolution.</p><p>One might argue that normalized metrics like TOPS/Watt address the above issue. Unfortunately, this metric is not measured in a standardized way. Some vendors measure only the power consumption of the matrix multiplication unit, which is responsible for the majority of computation, while not accounting for power drawn by other components. Comparing SoCs with pure accelerators is another challenge, as end users are typically interested in overall power budget rather than the narrow scope for which numbers are published.</p><h4><strong>FPS: The Metric That Tells You Everything and Nothing at the Same Time</strong></h4><p>You might ask, ‘what about absolute performance metrics like FPS?’ They measure the real performance of the hardware and should allow us to compare apples-to-apples, right? The reality is that while FPS is a good metric that can give us an idea of the power of the hardware, it is far from being perfect. For a given hardware, if you know FPS for one ML model, you cannot reliably estimate the FPS for other models. Even if FPS numbers for all the models you are interested in are published, there is no guarantee that you will achieve those numbers in real usage. This is due to the fact that the conditions under which benchmarks are generated might not match the real use case. Application software load on the system can degrade the ML performance, or the real use case may not be able to supply inputs in batch sizes for which benchmarks are reported.</p><p>Moreover, real-world AI applications employ multiple models either in series or in parallel. Performance numbers for a single model do not translate to multiple models. In fact, for some hardware options optimized for running a single model, the performance penalty of switching a model can be very high. Emerging hardware options typically achieve power and performance efficiency by localizing the ML models on the chip. Such hardware options provide high performance for models up to a certain size but experience a drastic performance drop once the models do not fit on the chip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RkKNhi7NoxpNw0301WzXVw.jpeg" /><figcaption>Image generated using Bing Chat Enterprise</figcaption></figure><h4><strong>Hardware Options: All Equal, But Some More Equal Than Others 😉</strong></h4><p>To further complicate matters, not all hardware options are created equal. Every vendor makes certain design choices that make a fair comparison very difficult. Some options only support INT models, while others give the flexibility of supporting floating-point models. Some hardware options give very high performance on smaller models while suffering performance degradation for larger models. Some other hardware options are optimized for delivering high performance on a single model with a certain batch size. Other hardware options can handle multiplexing multiple models efficiently. So, how can one choose between hardware that is very flexible but has lower performance and another hardware that is very efficient for a small subset of ML models and use cases?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irGrQv2rLBS9XeOUjbX06A.png" /><figcaption>Image generated using Bing Chat Enterprise</figcaption></figure><h4>The ML Model Compatibility Conundrum 😕</h4><p>The varying capabilities of different hardware options also bring another important point into focus: ML model compatibility. Anyone who has spent time porting an ML model to new hardware knows how frustrating the process can be. The trained model (typically a PyTorch or TensorFlow checkpoint) needs to be exported to a format (like ONNX or TFLite) that can be compiled for a hardware target. For hardware that can only run quantized models, there needs to be an intermediate quantization step that may require providing some calibration data. These intermediate steps use tools that are not very reliable: we are in luck when they work but in really deep trouble when they do not work and throw not-so-useful error messages. Not to mention, the hassles of getting all pre-processing and post-processing methods to match the original training settings to ensure that the ported models perform as well as the trained model.</p><h3>Is there a better way to do things?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*py5E_nVWFcpjPCs6bLHDoQ.jpeg" /><figcaption>Image generated using Bing Chat Enterprise</figcaption></figure><p>Those of you who made it this far have probably been nodding along and thinking to yourselves that ‘all this sounds okay, but what can be done?’ Some of you might also be feeling that these are idle ramblings of a frustrated ML engineer who lost quite a few nights of sleep dealing with AI accelerators and ML models. You are not completely wrong 😊. But instead of just highlighting the difficulties, it is clear that there is a need to actively develop solutions that simplify the edge AI development process. To address the challenges outlined above, a new approach is needed to develop edge AI applications.</p><p>Even without developing a solution, one can see that the right approach to solving these issues should have the following features:</p><ol><li>Easy-to-use software that allows development of complex real-world AI applications.</li><li>Software that works with multiple hardware options.</li><li>A mechanism that allows hardware evaluation in a short amount of time with little to no investment in buying the hardware.</li><li>Reliable toolchains to optimize and port ML models to different hardware options.</li></ol><p>And this is what we have been developing at DeGirum for the past few years. While we are still far away from solving every aspect of the problem, we believe that we have made enough progress in the past couple of years to share with the ML community at large.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qY9tPoBkfIPAUzfebQmA2Q.png" /></figure><p>This is probably a good time to introduce ourselves without turning this article into the type of marketing pitch that we were critical of earlier in the article. We are a fabless semiconductor company developing hardware, software, and cloud services to simplify the development of edge AI applications. A couple of years ago, we had our working test chip (codenamed Orca) and started working with prospective customers. It was at this point that we started realizing the many challenges that AI solution providers face when bringing AI into real-world applications</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YyKGB1dNoPXvIbSJjR-GlA.png" /></figure><p>When we started working on our hardware, we naively assumed (like all other hardware vendors) that powerful hardware combined with an efficient runtime is enough for solution providers to start integrating AI into their product lines. We soon realized that end users do not have the bandwidth to evaluate new hardware options (no matter how good the numbers look on paper and how easy the vendor claims the software is). While the cost of buying new hardware and the time it takes to work on new hardware are the obvious reasons, the pain of finding and porting suitable ML models to the hardware, and lack of tools that can provide fair ways to benchmark performance also contribute to the reluctance to try new hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWPmyEO9AlXLeKKqFkWp6g.png" /></figure><p>Based on our customer feedback, we started working on ways to make evaluating our hardware easier. Towards this goal, we developed the DeGirum Cloud Platform that allows users to access our hardware in the cloud, thereby eliminating the need to buy our hardware for the evaluation process. Combined with our Python software development kit, which we creatively named PySDK, the platform turned a process that can take a couple of weeks into under five minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VmfoRFZuM009rw71KcZLpA.png" /></figure><p>Developers who evaluated our hardware using our cloud platform and PySDK started making requests to extend the convenience to other hardware options as well. It dawned upon us that developers started viewing our cloud platform as a tool that they can use to develop applications in the cloud for multiple hardware options before investing in buying the hardware and evaluating their performance. At this point, we decided to make our PySDK work with multiple hardware options as well as provide access to these hardware options in the cloud. We feel we are just at the beginning of an adventure and are very excited about the potential of our hardware, software, and cloud platform to simplify edge AI development.</p><p>We started the DeGirum publication on Medium to share with the ML community at large how our cloud platform and software can be used to develop AI applications for the edge. The articles in this publication will delve deep into the features of the cloud platform and the various software APIs. We will also cover some model development and model porting related topics. While we populate our publication with these in-depth articles, here is a quick overview of our PySDK and Cloud Platform features:</p><h4><strong>DeGirum PySDK Features</strong></h4><p>Users can install DeGirum PySDK and get started with AI application development in under five minutes. Instructions for installation and API documentation are available at <a href="https://docs.degirum.com/content/">Overview — DeGirum Development Tools</a>. Examples on how to use PySDK to develop applications are provided at: <a href="https://github.com/DeGirum/PySDKExamples">DeGirum/PySDKExamples: DeGirum PySDK Usage Examples (github.com)</a>. You can even run the examples in Google Colab, which means you do not have to install any SW locally to experiment with our SW. Below are the main features of our PySDK.</p><ol><li>Supports three types of inference: Cloud, AI Server, and Local. An article detailing these options will be published soon.</li><li>Supports multiple hardware options: DeGirum Orca, Intel CPUs/GPUs, Nvidia GPUs and SoCs, Google Edge TPU, Arm SoCs (Raspberry pi etc), AMD CPUs</li><li>Supports advanced functionality such as tracking, slicing, zone counting with simple to use APIs</li></ol><h4><strong>DeGirum Cloud Platform Features</strong></h4><p>Users can now sign up for our cloud platform at <a href="https://degirum.com/">DeGirum</a>. Below are the main features of our cloud platform.</p><ol><li>Cloud access to multiple AI HW accelerators: DeGirum Orca, Intel CPUs/GPUs, and Google Edge TPU. Support for Nvidia coming soon.</li><li>Cloud compiler: Go from PyTorch checkpoint to compiled model in a single click (including quantization). SOTA model architectures such as YOLOv5 and YOLOv8 are supported.</li><li>Inference in browser: Get performance estimate for different models on different hardware right in the browser without the need to install any SW.</li><li>Rich model zoos: Access to model zoos with latest models such as YOLOv5 and YOLOv8 trained on different datasets and compiled for different hardware options.</li></ol><h3>Closing Thoughts</h3><p>We are at an exciting time now where we are in the middle of enabling AI on a vast number of use cases at the edge. Exciting advances are happening on the hardware, software, and models front at a breakneck speed. For application developers to keep with the pace of emerging technologies, there is a need for tools that can shorten the time between model development to model deployment. We are very excited to be playing a part in this endeavor and hope you all can join us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59dd8b96a0bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/degirum/developing-ai-applications-for-the-edge-a-new-approach-59dd8b96a0bb">Developing AI Applications for the Edge: A New Approach</a> was originally published in <a href="https://medium.com/degirum">DeGirum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>