<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>yolo - Inero Software - Software Consulting</title>
	<atom:link href="https://inero-software.com/tag/yolo-en/feed/" rel="self" type="application/rss+xml" />
	<link>https://inero-software.com/tag/yolo-en/</link>
	<description>We unleash innovations using cutting-edge technologies, modern design and AI</description>
	<lastBuildDate>Fri, 14 Feb 2025 14:39:39 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://inero-software.com/wp-content/uploads/2018/11/inero-logo-favicon.png</url>
	<title>yolo - Inero Software - Software Consulting</title>
	<link>https://inero-software.com/tag/yolo-en/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">153509928</site>	<item>
		<title>Running AI in client-side: Real-Time Face Detection in the Browser Using YOLO and TensorFlow.js &#8211; use case study</title>
		<link>https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/</link>
		
		<dc:creator><![CDATA[Martyna Mul]]></dc:creator>
		<pubDate>Wed, 09 Oct 2024 12:32:00 +0000</pubDate>
				<category><![CDATA[Company]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[ML]]></category>
		<category><![CDATA[TensorFlow.js]]></category>
		<category><![CDATA[yolo]]></category>
		<guid isPermaLink="false">https://inero-software.com/?p=6202</guid>

					<description><![CDATA[<p>In this post, we'll explore how to implement object detection directly in the browser using YOLO </p>
<p>Artykuł <a href="https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/">Running AI in client-side: Real-Time Face Detection in the Browser Using YOLO and TensorFlow.js &#8211; use case study</a> pochodzi z serwisu <a href="https://inero-software.com">Inero Software - Software Consulting</a>.</p>
]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="6202" class="elementor elementor-6202" data-elementor-post-type="post">
				<div class="elementor-element elementor-element-d225397 e-flex e-con-boxed e-con e-parent" data-id="d225397" data-element_type="container">
					<div class="e-con-inner">
				<div class="elementor-element elementor-element-4df78db elementor-widget elementor-widget-html" data-id="4df78db" data-element_type="widget" data-widget_type="html.default">
				<div class="elementor-widget-container">
					</div>
				</div>
					</div>
				</div>
		<div class="elementor-element elementor-element-0827b19 e-flex e-con-boxed e-con e-parent" data-id="0827b19" data-element_type="container">
					<div class="e-con-inner">
		<div class="elementor-element elementor-element-afa200d e-con-full e-flex e-con e-child" data-id="afa200d" data-element_type="container">
				</div>
		<div class="elementor-element elementor-element-3302212 e-con-full e-flex e-con e-child" data-id="3302212" data-element_type="container">
				<div class="elementor-element elementor-element-640ca1b elementor-widget elementor-widget-text-editor" data-id="640ca1b" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><strong><span class="TextRun SCXW252636194 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW252636194 BCX0">With the growing demand for real-time applications, running deep learning models in the browser has become more accessible and powerful. </span> </span><span class="TextRun SCXW252636194 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW252636194 BCX0">In this post, we&#8217;ll explore how to implement </span></span><span class="TextRun SCXW252636194 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW252636194 BCX0">object detection</span></span><span class="TextRun SCXW252636194 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW252636194 BCX0"> directly in the browser using </span></span><span class="TextRun SCXW252636194 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW252636194 BCX0">YOLO (You Only Look Once)</span></span><span class="TextRun SCXW252636194 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW252636194 BCX0"> and </span></span><span class="TextRun SCXW252636194 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW252636194 BCX0">TensorFlow.js</span></span><span class="TextRun SCXW252636194 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW252636194 BCX0">.</span></span><span class="TextRun SCXW252636194 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"> <span class="NormalTextRun SCXW252636194 BCX0">We will focus specifically on using a custom-trained YOLOv8 model for detecting human faces. By the end of this guide, </span><span class="NormalTextRun SCXW252636194 BCX0">you&#8217;ll</span><span class="NormalTextRun SCXW252636194 BCX0"> learn how to set up and run the YOLO model for face detection using the TensorFlow.js library, process the results, and </span><span class="NormalTextRun SCXW252636194 BCX0">optimize</span><span class="NormalTextRun SCXW252636194 BCX0"> its performance—all without needing a server or backend processing.</span></span><span class="EOP SCXW252636194 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></strong></p>						</div>
				</div>
				<div class="elementor-element elementor-element-aed25a2 elementor-widget elementor-widget-heading" data-id="aed25a2" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h3 class="elementor-heading-title elementor-size-default">Why Run Neural Networks in the Browser? </h3>		</div>
				</div>
				<div class="elementor-element elementor-element-344fad5 elementor-widget elementor-widget-text-editor" data-id="344fad5" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span data-contrast="auto">Running neural networks in the browser offers several advantages:</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p><ol><li><b><span data-contrast="auto">Low Latency</span></b><span data-contrast="auto">: Everything happens client-side, avoiding the delay of sending data to a server and waiting for a response.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></li><li><b><span data-contrast="auto">Enhanced Privacy</span></b><span data-contrast="auto">: Sensitive data remains on the user&#8217;s device, reducing the risk of breaches or exposure.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></li><li><b><span data-contrast="auto">Offline Capabilities</span></b><span data-contrast="auto">: Users can access machine learning functionalities without a continuous internet connection.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></li><li><b><span data-contrast="auto">Cross-Platform Compatibility</span></b><span data-contrast="auto">: Your application can run on any device with a browser—desktop, tablet, or smartphone.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></li></ol>						</div>
				</div>
				<div class="elementor-element elementor-element-9e13d20 elementor-widget elementor-widget-heading" data-id="9e13d20" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h3 class="elementor-heading-title elementor-size-default">Choosing and Preparing Your Neural Network </h3>		</div>
				</div>
				<div class="elementor-element elementor-element-769829b elementor-widget elementor-widget-text-editor" data-id="769829b" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span data-contrast="auto">When selecting a neural network for browser implementation, consider factors like model size, speed, memory usage, and compatibility with browser technologies such as WebGL. For optimal performance on resource-limited hardware, it&#8217;s recommended to use models smaller than 30MB. Suitable models include MobileNetV2, SqueezeNet, EfficientNet, and certain YOLO variants. In our case, we opted for a custom-trained YOLOv8 model for detecting human faces in images.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p><p><span data-contrast="auto">If your model exceeds the recommended size, consider optimization techniques like quantization and pruning. </span><b><span data-contrast="auto">Quantization</span></b><span data-contrast="auto"> reduces the precision of the model&#8217;s weights, typically converting 32-bit floating-point values to 16-bit or 8-bit integers. </span><b><span data-contrast="auto">Pruning</span></b><span data-contrast="auto"> removes redundant connections in the neural network. Both methods shrink the model and reduce computational complexity, enhancing inference speed—especially on devices like smartphones—though they may slightly affect accuracy.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-76a71b3 elementor-widget elementor-widget-heading" data-id="76a71b3" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h3 class="elementor-heading-title elementor-size-default">Optimizing YOLOv8 for Face Detection: Results from Our Custom Model </h3>		</div>
				</div>
				<div class="elementor-element elementor-element-9111e72 elementor-widget elementor-widget-text-editor" data-id="9111e72" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW165867707 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW165867707 BCX0">Our model is a YOLOv8 model trained on custom dataset to streamline document workflows. The goal was to automatically verify whether an attachment </span><span class="NormalTextRun SCXW165867707 BCX0">contains</span><span class="NormalTextRun SCXW165867707 BCX0"> a clear, front-facing human photo, with no obstructions like masks. This is crucial for processes like ID verification, where the visibility of the person&#8217;s face is essential. Our dataset consisted of 1,500 images, split into 1,200 for training and 300 for validation. This allowed the model to learn how to distinguish between acceptable and unacceptable photos, ensuring accuracy in real-world use cases. </span><span class="NormalTextRun SCXW165867707 BCX0">The following images </span><span class="NormalTextRun SCXW165867707 BCX0">demonstrate</span><span class="NormalTextRun SCXW165867707 BCX0"> how the network functions in practice.</span></span><span class="EOP SCXW165867707 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-fd798a3 elementor-widget elementor-widget-image" data-id="fd798a3" data-element_type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
													<img fetchpriority="high" decoding="async" data-attachment-id="6206" data-permalink="https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/9102024gr1/" data-orig-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr1.jpg" data-orig-size="934,258" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="9102024gr1" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr1-300x83.jpg" data-large-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr1.jpg" tabindex="0" role="button" width="934" height="258" src="https://inero-software.com/wp-content/uploads/2024/10/9102024gr1.jpg" class="attachment-large size-large wp-image-6206" alt="" srcset="https://inero-software.com/wp-content/uploads/2024/10/9102024gr1.jpg 934w, https://inero-software.com/wp-content/uploads/2024/10/9102024gr1-300x83.jpg 300w, https://inero-software.com/wp-content/uploads/2024/10/9102024gr1-768x212.jpg 768w" sizes="(max-width: 934px) 100vw, 934px" data-attachment-id="6206" data-permalink="https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/9102024gr1/" data-orig-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr1.jpg" data-orig-size="934,258" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="9102024gr1" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr1-300x83.jpg" data-large-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr1.jpg" role="button" />													</div>
				</div>
				<div class="elementor-element elementor-element-34bbb24 elementor-widget elementor-widget-heading" data-id="34bbb24" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<p class="elementor-heading-title elementor-size-default">(source of images: https://www.kaggle.com/datasets/ashwingupta3012/human-faces, https://www.kaggle.com/datasets/andrewmvd/face-mask-detection) </p>		</div>
				</div>
				<div class="elementor-element elementor-element-12bfcb4 elementor-widget elementor-widget-text-editor" data-id="12bfcb4" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW245593581 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW245593581 BCX0">Inference results on four examples – the two faces on the left were detected correctly, while the two on the right were not, as they were partially covered.</span></span></p><p><span class="TextRun SCXW206579471 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW206579471 BCX0">As a baseline for our </span><span class="NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW206579471 BCX0">model</span><span class="NormalTextRun SCXW206579471 BCX0"> we </span><span class="NormalTextRun SCXW206579471 BCX0">selected</span><span class="NormalTextRun SCXW206579471 BCX0"> YOLOv8s (small)</span><span class="NormalTextRun SCXW206579471 BCX0">, which resulted in a model size of 44 MB and achieved</span></span> <span class="TextRun SCXW206579471 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW206579471 BCX0">99.9% precision and 99.1% recall on our custom validation dataset.</span></span> <span class="TextRun SCXW206579471 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW206579471 BCX0">To explore model optimizations, we also tested a smaller baseline model, YOLOv8n (nano), and examined the effects of model quantization. Training with the YOLOv8n baseline produced a model sized at just 12 MB, with </span><span class="NormalTextRun SCXW206579471 BCX0">nearly identical</span><span class="NormalTextRun SCXW206579471 BCX0"> accuracy metrics (99.7% precision and 99.1% recall).</span></span><span class="TextRun SCXW206579471 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"> <span class="NormalTextRun SCXW206579471 BCX0">Next, we performed quantization on both models, the resultant model size and accuracy is shown in the table below: </span></span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-859298c elementor-widget elementor-widget-text-editor" data-id="859298c" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<table class=" aligncenter" style="font-weight: 400;" data-tablestyle="MsoNormalTable" data-tablelook="1568" aria-rowcount="4"><tbody><tr aria-rowindex="1"><td colspan="1" rowspan="2" data-celllook="69905"><p><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td colspan="3" data-celllook="69905"><p><b><span data-contrast="auto">Baseline model</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td colspan="3" data-celllook="69905"><p><b><span data-contrast="auto">16-bit quantized model</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td></tr><tr aria-rowindex="2"><td data-celllook="69905"><p><b><span data-contrast="auto">Size</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><b><span data-contrast="auto">Precision</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><b><span data-contrast="auto">Recall</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><b><span data-contrast="auto">Size</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><b><span data-contrast="auto">Precision</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><b><span data-contrast="auto">Recall</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td></tr><tr aria-rowindex="3"><td data-celllook="69905"><p><b><span data-contrast="auto">YOLOv8 small</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><b><span data-contrast="auto">44 MB</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">0.999</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">0.991</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">22 MB</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">0.997</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">0.991</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td></tr><tr aria-rowindex="4"><td data-celllook="69905"><p><b><span data-contrast="auto">YOLOv8 nano</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">12 MB</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">0.997</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">0.991</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><b><span data-contrast="auto">6 MB</span></b><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">0.989</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td><td data-celllook="69905"><p><span data-contrast="auto">0.991</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p></td></tr></tbody></table>						</div>
				</div>
				<div class="elementor-element elementor-element-a7be2ba elementor-widget elementor-widget-text-editor" data-id="a7be2ba" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><b><span data-contrast="auto">Note</span></b><span data-contrast="auto">: Recall measures how many actual positive samples were correctly identified, while precision indicates how many predicted positives were truly positive. For ideal case, they both are equal to 1.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p><p><span data-contrast="auto">In our example, using a smaller baseline model with quantization reduced accuracy by less than 1%, while shrinking the model size from 44 MB to just 6 MB.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p><p data-ccp-border-bottom="0px none #000000" data-ccp-padding-bottom="0px" data-ccp-border-between="0px none #000000" data-ccp-padding-between="0px"><span data-contrast="auto">Below are several example photos that illustrate how two networks: YOLOv8s and YOLOv8n with quantization operate:</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-ba300a9 elementor-widget elementor-widget-image" data-id="ba300a9" data-element_type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
													<img decoding="async" data-attachment-id="6208" data-permalink="https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/9102024gr2/" data-orig-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr2.jpg" data-orig-size="934,307" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="9102024gr2" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr2-300x99.jpg" data-large-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr2.jpg" tabindex="0" role="button" width="934" height="307" src="https://inero-software.com/wp-content/uploads/2024/10/9102024gr2.jpg" class="attachment-large size-large wp-image-6208" alt="" srcset="https://inero-software.com/wp-content/uploads/2024/10/9102024gr2.jpg 934w, https://inero-software.com/wp-content/uploads/2024/10/9102024gr2-300x99.jpg 300w, https://inero-software.com/wp-content/uploads/2024/10/9102024gr2-768x252.jpg 768w, https://inero-software.com/wp-content/uploads/2024/10/9102024gr2-913x300.jpg 913w" sizes="(max-width: 934px) 100vw, 934px" data-attachment-id="6208" data-permalink="https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/9102024gr2/" data-orig-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr2.jpg" data-orig-size="934,307" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="9102024gr2" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr2-300x99.jpg" data-large-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr2.jpg" role="button" />													</div>
				</div>
				<div class="elementor-element elementor-element-3d14285 elementor-widget elementor-widget-text-editor" data-id="3d14285" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW46079478 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW46079478 BCX0">The results of inference with YOLOv8s model, without quantization (of size 44 MB)</span><span class="NormalTextRun SCXW46079478 BCX0">. (source of images: </span><span class="NormalTextRun SCXW46079478 BCX0">https://www.kaggle.com/datasets/ashwingupta3012/human-faces</span><span class="NormalTextRun SCXW46079478 BCX0">).</span></span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-e4f1955 elementor-widget elementor-widget-image" data-id="e4f1955" data-element_type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
													<img decoding="async" data-attachment-id="6207" data-permalink="https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/9102024gr3/" data-orig-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr3.jpg" data-orig-size="934,313" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="9102024gr3" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr3-300x101.jpg" data-large-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr3.jpg" tabindex="0" role="button" width="934" height="313" src="https://inero-software.com/wp-content/uploads/2024/10/9102024gr3.jpg" class="attachment-large size-large wp-image-6207" alt="" srcset="https://inero-software.com/wp-content/uploads/2024/10/9102024gr3.jpg 934w, https://inero-software.com/wp-content/uploads/2024/10/9102024gr3-300x101.jpg 300w, https://inero-software.com/wp-content/uploads/2024/10/9102024gr3-768x257.jpg 768w, https://inero-software.com/wp-content/uploads/2024/10/9102024gr3-895x300.jpg 895w" sizes="(max-width: 934px) 100vw, 934px" data-attachment-id="6207" data-permalink="https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/9102024gr3/" data-orig-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr3.jpg" data-orig-size="934,313" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="9102024gr3" data-image-description="" data-image-caption="" data-medium-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr3-300x101.jpg" data-large-file="https://inero-software.com/wp-content/uploads/2024/10/9102024gr3.jpg" role="button" />													</div>
				</div>
				<div class="elementor-element elementor-element-bba7a47 elementor-widget elementor-widget-text-editor" data-id="bba7a47" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<table style="font-weight: 400;" data-tablestyle="MsoTableGrid" data-tablelook="1696" aria-rowcount="5"><tbody><tr aria-rowindex="1"><td colspan="1" rowspan="2" data-celllook="0"><p><span data-ccp-props="{}"> </span></p></td><td colspan="3" data-celllook="0"><p><b><span data-contrast="auto">Loading model</span></b><span data-ccp-props="{}"> </span></p></td><td colspan="3" data-celllook="0"><p><b><span data-contrast="auto">Single inference</span></b><span data-ccp-props="{}"> </span></p></td></tr><tr aria-rowindex="2"><td data-celllook="0"><p><b><span data-contrast="auto">CPU 1</span></b><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><b><span data-contrast="auto">CPU 2</span></b><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><b><span data-contrast="auto">CPU 3</span></b><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><b><span data-contrast="auto">CPU 1</span></b><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><b><span data-contrast="auto">CPU 2</span></b><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><b><span data-contrast="auto">CPU 3</span></b><span data-ccp-props="{}"> </span></p></td></tr><tr aria-rowindex="3"><td data-celllook="0"><p><b><span data-contrast="auto">YOLOv8 small</span></b><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">1050 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">3700 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">4200 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">21 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">117.5 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">196.5 ms</span><span data-ccp-props="{}"> </span></p></td></tr><tr aria-rowindex="4"><td data-celllook="0"><p><b><span data-contrast="auto">YOLOv8 nano 16-bit</span></b><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">980 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">3200 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">3700 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">16 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">112.5 ms</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">189 ms</span><span data-ccp-props="{}"> </span></p></td></tr><tr aria-rowindex="5"><td data-celllook="0"><p><b><span data-contrast="auto">Time improvement</span></b><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">6.7 %</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">13.5 %</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">11.9 %</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">23.8 %</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">4.2 %</span><span data-ccp-props="{}"> </span></p></td><td data-celllook="0"><p><span data-contrast="auto">3.8 %</span><span data-ccp-props="{}"> </span></p></td></tr></tbody></table>						</div>
				</div>
				<div class="elementor-element elementor-element-8185505 elementor-widget elementor-widget-text-editor" data-id="8185505" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p data-ccp-border-bottom="0px none #000000" data-ccp-padding-bottom="0px" data-ccp-border-between="0px none #000000" data-ccp-padding-between="0px"><span data-contrast="auto">The results of inference with YOLOv8n model, with 16-bit quantization (of size 6 MB). There is only slight difference in confidence level, while location of bounding boxes is the same.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></p><p data-ccp-border-bottom="0px none #000000" data-ccp-padding-bottom="0px" data-ccp-border-between="0px none #000000" data-ccp-padding-between="0px"><span data-contrast="auto">We tested the performance of two models—YOLOv8 small (44 MB) and YOLOv8 nano 16 bit quantized (6 MB)—across three different CPUs. The smaller model, YOLOv8 nano, consistently outperformed its larger counterpart in terms of both loading times and inference speed. Detailed performance metrics, including CPU-based loading and inference times, are summarized in the table above.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-cc12989 elementor-widget elementor-widget-text-editor" data-id="cc12989" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW10200005 BCX0" lang="EN-US" xml:lang="EN-US" data-contrast="auto"><span class="NormalTextRun SCXW10200005 BCX0">In addition to the CPU-based loading and inference times, another key factor to consider is the time </span><span class="NormalTextRun SCXW10200005 BCX0">required</span><span class="NormalTextRun SCXW10200005 BCX0"> to download the models, which is not included in the table. Download times are directly proportional to the model size and are heavily influenced by the user’s network speed.</span></span><span class="EOP SCXW10200005 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-d6f4734 elementor-widget elementor-widget-heading" data-id="d6f4734" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h3 class="elementor-heading-title elementor-size-default">Getting Started: Setting up TensorFlow.js </h3>		</div>
				</div>
				<div class="elementor-element elementor-element-e00fb33 elementor-widget elementor-widget-text-editor" data-id="e00fb33" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW203997583 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW203997583 BCX0">To deploy your machine learning model in the browser, we’ll use </span></span><span class="TextRun SCXW203997583 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW203997583 BCX0">TensorFlow.js</span></span><span class="TextRun SCXW203997583 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW203997583 BCX0">, a powerful library that allows you to run pre-trained models or train new ones entirely in the browser. In this guide, we’ll focus on deploying a pre-trained YOLOv8 model for face detection. Below is a step-by-step guide to get TensorFlow.js set up and running.</span></span><span class="EOP SCXW203997583 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-d18e614 elementor-widget elementor-widget-heading" data-id="d18e614" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h4 class="elementor-heading-title elementor-size-default">1. Install TensorFlow.js </h4>		</div>
				</div>
				<div class="elementor-element elementor-element-cb9241f elementor-widget elementor-widget-text-editor" data-id="cb9241f" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW103495611 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW103495611 BCX0">If you&#8217;re using a JavaScript bundler like Webpack or Parcel, you can install TensorFlow.js via npm:</span></span><span class="EOP SCXW103495611 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-c5deef0 elementor-widget elementor-widget-text-editor" data-id="c5deef0" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre>npm install @tensorflow/tfjs </pre>						</div>
				</div>
				<div class="elementor-element elementor-element-cd338d1 elementor-widget elementor-widget-heading" data-id="cd338d1" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h4 class="elementor-heading-title elementor-size-default">2. Load the Model </h4>		</div>
				</div>
				<div class="elementor-element elementor-element-d54d572 elementor-widget elementor-widget-text-editor" data-id="d54d572" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW90093782 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW90093782 BCX0">Since we&#8217;re using the TensorFlow.js library, you need to convert your model to the TensorFlow.js (Tf.js) format. In case of YOLO models, Ultralytics provides an easy way to achieve this with a simple command:</span></span><span class="EOP SCXW90093782 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-8acf4f8 elementor-widget elementor-widget-text-editor" data-id="8acf4f8" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW164933469 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW164933469 BCX0">yolo </span></span><span class="TextRun Highlight SCXW164933469 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW164933469 BCX0">export</span></span><span class="TextRun Highlight SCXW164933469 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW164933469 BCX0"> model=path/to/best.pt format=tfjs</span></span><span class="EOP SCXW164933469 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-a9c3625 elementor-widget elementor-widget-text-editor" data-id="a9c3625" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW204512639 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW204512639 BCX0">Once converted, your model will be saved as binary files along with a JSON file called </span></span><span class="TextRun SCXW204512639 BCX0" lang="PL" style="color: #339966;" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW204512639 BCX0">model.json</span></span><span class="TextRun SCXW204512639 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW204512639 BCX0">. These files can be loaded into your application using the </span></span><span class="TextRun SCXW204512639 BCX0" lang="PL" style="color: #339966;" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW204512639 BCX0">tf.loadGraphModel()</span></span><span class="TextRun SCXW204512639 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW204512639 BCX0"> function. Here’s an example of how to load the model, including warming it up with dummy input for performance:</span></span><span class="EOP SCXW204512639 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-8ae265d elementor-widget elementor-widget-text-editor" data-id="8ae265d" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">export</span></span> <span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">async</span></span> <span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">function</span></span> <span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">loadModel</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">(modelPath) {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">  </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">try</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0"> {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">    </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">// Load the model using a URL</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">    </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">const</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0"> model = </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">await</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0"> tf.loadGraphModel(</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">`${modelPath}/model.json`</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">    </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">// Warm up the model</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">    </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">const</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0"> dummyInput = tf.ones(model.inputs[</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">0</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">].shape);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">    </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">await</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0"> model.execute(dummyInput);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">    </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">return</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0"> model;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">  } </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">catch</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0"> (error) {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">    </span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">throw</span></span> <span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">new</span></span> <span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">Error</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">(</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">`Failed to load model: ${error.message}`</span></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">  }</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW28304209 BCX0"><span class="SCXW28304209 BCX0"> </span><br class="SCXW28304209 BCX0" /></span><span class="TextRun Highlight SCXW28304209 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW28304209 BCX0">}</span></span><span class="EOP SCXW28304209 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-4fb7ba0 elementor-widget elementor-widget-heading" data-id="4fb7ba0" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h4 class="elementor-heading-title elementor-size-default">3. Prepare the Input </h4>		</div>
				</div>
				<div class="elementor-element elementor-element-bcd536f elementor-widget elementor-widget-text-editor" data-id="bcd536f" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span data-contrast="auto">Before running the model, we need to preprocess the input image. YOLO models expect images of a specific size, and ensuring that the input meets these requirements is crucial. Instead of merely resizing the image, we recommend a more sophisticated preprocessing method that maintains the aspect ratio and applies letterbox padding. This approach is consistent with the preprocessing used by Ultralytics during the training of the YOLO model.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p><p><span data-contrast="auto">The function below resizes, pads, and normalizes the input image to match the model&#8217;s required input size:</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-dd83945 elementor-widget elementor-widget-text-editor" data-id="dd83945" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">function</span></span> <span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">preprocessImage</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">(base64Image, imgSize) {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> image = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">new</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> Image();</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  image.src = base64Image;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> canvas = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">document</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">.createElement(</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">'canvas'</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  canvas.width = image.width;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  canvas.height = image.height;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> ctx = canvas.getContext(</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">'2d'</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  ctx.drawImage(image, </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">0</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">, </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">0</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">, image.width, image.height);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">// Convert canvas image to a tensor</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">let</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> imgTensor = tf.browser.fromPixels(canvas);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">// Determine rescale factor</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> xFactor = image.width / imgSize;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> yFactor = image.height / imgSize;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> factor = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">Math</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">.max(xFactor, yFactor);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> newWidth = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">Math</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">.round(image.width / factor);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> newHeight = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">Math</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">.round(image.height / factor);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">// Resize to expected input shape </span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  imgTensor = tf.image.resizeBilinear(imgTensor, [newHeight, newWidth]);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">// Add padding</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> xPad = (imgSize - newWidth) / </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">2</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> yPad = (imgSize - newHeight) / </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">2</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> top = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">Math</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">.floor(yPad);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">co</span><span class="NormalTextRun SCXW147374849 BCX0">nst</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> bottom = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">Math</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">.ceil(yPad);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> left = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">Math</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">.floor(xPad);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">const</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> right = </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">Math</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">.ceil(xPad);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  imgTensor = tf.pad(imgTensor, [[top, bottom], [left, right], [</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">0</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">, </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">0</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">]], </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">114</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">// Normalize pixel values</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  imgTensor = imgTensor.div(</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">255.0</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">).expandDims(</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">0</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">); </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">// Add batch dimension</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">  </span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">return</span></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0"> { imgTensor, left, top, factor };</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW147374849 BCX0"><span class="SCXW147374849 BCX0"> </span><br class="SCXW147374849 BCX0" /></span><span class="TextRun Highlight SCXW147374849 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW147374849 BCX0">}</span></span><span class="EOP SCXW147374849 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-183b6cf elementor-widget elementor-widget-heading" data-id="183b6cf" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h4 class="elementor-heading-title elementor-size-default">4. Run Inference </h4>		</div>
				</div>
				<div class="elementor-element elementor-element-639b754 elementor-widget elementor-widget-text-editor" data-id="639b754" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW162333265 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW162333265 BCX0">With the model loaded and the input preprocessed, we can now run inference to detect faces in the image:</span></span><span class="EOP SCXW162333265 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-25f3c6b elementor-widget elementor-widget-text-editor" data-id="25f3c6b" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW75192197 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW75192197 BCX0">const</span></span><span class="TextRun Highlight SCXW75192197 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW75192197 BCX0"> prediction = </span></span><span class="TextRun Highlight SCXW75192197 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW75192197 BCX0">await</span></span><span class="TextRun Highlight SCXW75192197 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW75192197 BCX0"> model.execute(inputTensor);</span></span><span class="EOP SCXW75192197 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-0830169 elementor-widget elementor-widget-heading" data-id="0830169" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h4 class="elementor-heading-title elementor-size-default">5. Postprocess the Model Output </h4>		</div>
				</div>
				<div class="elementor-element elementor-element-aeca953 elementor-widget elementor-widget-text-editor" data-id="aeca953" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW196843037 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW196843037 BCX0">The YOLO network output is a tensor that needs to be properly interpreted. Below are the steps in our </span></span><span class="TextRun SCXW196843037 BCX0" lang="PL" style="color: #008000;" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW196843037 BCX0">postprocessInferenceResults()</span></span><span class="TextRun SCXW196843037 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW196843037 BCX0"> function to extract the coordinates of all bounding boxes, classes, and confidence scores:</span></span><span class="EOP SCXW196843037 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-04c9010 elementor-widget elementor-widget-text-editor" data-id="04c9010" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre data-ccp-border-bottom="0px none #000000" data-ccp-padding-bottom="0px" data-ccp-border-between="0px none #000000" data-ccp-padding-between="0px"><span data-contrast="none">const</span><span data-contrast="none"> results = prediction.transpose([</span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">2</span><span data-contrast="none">, </span><span data-contrast="none">1</span><span data-contrast="none">]); </span> <br /><span data-contrast="none">const</span><span data-contrast="none"> numClass = </span><span data-contrast="none">1</span><span data-contrast="none">; </span><span data-contrast="none">// Only one class in our case</span> <br /><span data-contrast="none">const</span><span data-contrast="none"> boxes = tf.tidy(() =&gt; {</span> <br /><span data-contrast="none">const</span><span data-contrast="none"> w = results.slice([</span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">2</span><span data-contrast="none">], [</span><span data-contrast="none">-1</span><span data-contrast="none">, </span><span data-contrast="none">-1</span><span data-contrast="none">, </span><span data-contrast="none">1</span><span data-contrast="none">]); </span><span data-contrast="none">// Get width</span> <br /><span data-contrast="none">const</span><span data-contrast="none"> h = results.slice([</span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">3</span><span data-contrast="none">], [</span><span data-contrast="none">-1</span><span data-contrast="none">, </span><span data-contrast="none">-1</span><span data-contrast="none">, </span><span data-contrast="none">1</span><span data-contrast="none">]); </span><span data-contrast="none">// Get height</span> <br /><span data-contrast="none">const</span><span data-contrast="none"> x1 = tf.sub(results.slice([</span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">0</span><span data-contrast="none">], [</span><span data-contrast="none">-1</span><span data-contrast="none">, </span><span data-contrast="none">-1</span><span data-contrast="none">, </span><span data-contrast="none">1</span><span data-contrast="none">]), tf.div(w, </span><span data-contrast="none">2</span><span data-contrast="none">)); </span><span data-contrast="none">// Get x1</span><span data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span><br /><br /><span data-contrast="none">const</span><span data-contrast="none"> y1 = tf.sub(results.slice([</span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">0</span><span data-contrast="none">, </span><span data-contrast="none">1</span><span data-contrast="none">], [</span><span data-contrast="none">-1</span><span data-contrast="none">, </span><span data-contrast="none">-1</span><span data-contrast="none">, </span><span data-contrast="none">1</span><span data-contrast="none">]), tf.div(h, </span><span data-contrast="none">2</span><span data-contrast="none">)); </span><span data-contrast="none">// Get y1</span> <br /><span data-contrast="none">return</span><span data-contrast="none"> tf.concat([y1, x1, y1.add(h), x1.add(w)], </span><span data-contrast="none">2</span><span data-contrast="none">).squeeze();</span> <br /><span data-contrast="none">});</span><span data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-70bdd06 elementor-widget elementor-widget-text-editor" data-id="70bdd06" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span data-contrast="auto">To extract classes and confidence scores:</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}">&nbsp;</span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-4e859a7 elementor-widget elementor-widget-text-editor" data-id="4e859a7" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">const</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0"> numClass = labels.length;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW92870568 BCX0"><span class="SCXW92870568 BCX0"> </span><br class="SCXW92870568 BCX0" /></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">const</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0"> [scores, classes] = tf.tidy(() =&gt; {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW92870568 BCX0"><span class="SCXW92870568 BCX0"> </span><br class="SCXW92870568 BCX0" /></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">const</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0"> rawData = results.slice([</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">0</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">, </span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">0</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">, </span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">4</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">], [</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">-1</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">, </span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">-1</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">, numClass]).squeeze(</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">0</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW92870568 BCX0"><span class="SCXW92870568 BCX0"> </span><br class="SCXW92870568 BCX0" /></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">  </span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">return</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0"> [rawData.max(</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">1</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">), rawData.argMax(</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">1</span></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">)];</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW92870568 BCX0"><span class="SCXW92870568 BCX0"> </span><br class="SCXW92870568 BCX0" /></span><span class="TextRun Highlight SCXW92870568 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW92870568 BCX0">});</span></span><span class="EOP SCXW92870568 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-c29f2bf elementor-widget elementor-widget-text-editor" data-id="c29f2bf" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW52052999 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW52052999 BCX0">Next, filter out detections with confidence scores below a threshold (0.4) and overlapping bounding boxes:</span></span><span class="EOP SCXW52052999 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-2bbe314 elementor-widget elementor-widget-text-editor" data-id="2bbe314" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">const</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0"> array = </span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">await</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0"> scores.array();</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW227521811 BCX0"><span class="SCXW227521811 BCX0"> </span><br class="SCXW227521811 BCX0" /></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">const</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0"> highConfidenceIndices = array.reduce((acc, value, index) =&gt; {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW227521811 BCX0"><span class="SCXW227521811 BCX0"> </span><br class="SCXW227521811 BCX0" /></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">  </span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">if</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0"> (value &gt; </span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">0.4</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">) acc.push(index);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW227521811 BCX0"><span class="SCXW227521811 BCX0"> </span><br class="SCXW227521811 BCX0" /></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">  </span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">return</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0"> acc;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW227521811 BCX0"><span class="SCXW227521811 BCX0"> </span><br class="SCXW227521811 BCX0" /></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">}, []);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW227521811 BCX0"><span class="SCXW227521811 BCX0"> </span><br class="SCXW227521811 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW227521811 BCX0"><span class="SCXW227521811 BCX0"> </span><br class="SCXW227521811 BCX0" /></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">const</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0"> highConfidenceBoxes = boxes.gather(highConfidenceIndices);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW227521811 BCX0"><span class="SCXW227521811 BCX0"> </span><br class="SCXW227521811 BCX0" /></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">const</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0"> highConfidenceScores = scores.gather(highConfidenceIndices);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW227521811 BCX0"><span class="SCXW227521811 BCX0"> </span><br class="SCXW227521811 BCX0" /></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0">const</span></span><span class="TextRun Highlight SCXW227521811 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW227521811 BCX0"> highConfidenceClasses = classes.gather(highConfidenceIndices);</span></span><span class="EOP SCXW227521811 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-6d455b0 elementor-widget elementor-widget-text-editor" data-id="6d455b0" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW186806948 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW186806948 BCX0">Finally, apply Non-Max Suppression (NMS) to filter out overlapping bounding boxes:</span></span><span class="EOP SCXW186806948 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-a51ed9c elementor-widget elementor-widget-text-editor" data-id="a51ed9c" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">const</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0"> nms = </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">await</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0"> tf.image.nonMaxSuppressionAsync(highConfidenceBoxes, highConfidenceScores, </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">40</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">, </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">0.45</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">, </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">0.4</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">); </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">// NMS to filter boxes</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW150352841 BCX0"><span class="SCXW150352841 BCX0"> </span><br class="SCXW150352841 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW150352841 BCX0"><span class="SCXW150352841 BCX0"> </span><br class="SCXW150352841 BCX0" /></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">const</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0"> boxesData = highConfidenceBoxes.gather(nms, </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">0</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">); </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">// Indexing boxes by NMS index</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW150352841 BCX0"><span class="SCXW150352841 BCX0"> </span><br class="SCXW150352841 BCX0" /></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">const</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0"> scoresData = highConfidenceScores.gather(nms, </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">0</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">).dataSync(); </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">// Indexing scores by</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW150352841 BCX0"><span class="SCXW150352841 BCX0"> </span><br class="SCXW150352841 BCX0" /></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">const</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0"> classesData = highConfidenceClasses.gather(nms, </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">0</span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">).dataSync(); </span></span><span class="TextRun Highlight SCXW150352841 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW150352841 BCX0">// Indexing classes by NMS index</span></span><span class="EOP SCXW150352841 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-a61bead elementor-widget elementor-widget-text-editor" data-id="a61bead" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW86839594 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW86839594 BCX0">The last step is recalculating the coordinates to fit them into the shape of the original image:</span></span><span class="EOP SCXW86839594 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-84b07f0 elementor-widget elementor-widget-text-editor" data-id="84b07f0" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">// Precompute the margins and factors outside the stack</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">const</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0"> yMarginTensor = tf.scalar(yMargin);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">const</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0"> xMarginTensor = tf.scalar(xMargin);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">const</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0"> resizeFactorTensor = tf.scalar(resizeFactor);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">// Slice the boxesData and apply transformations in one step</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">const</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0"> [yCoordinates, xCoordinates, height, width] = </span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">  [</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">'0'</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">, </span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">'1'</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">, </span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">'2'</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">, </span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">'3'</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">].map((index) =&gt; </span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">    boxesData.slice([</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">0</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">, </span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">parseInt</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">(index)], [</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">-1</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">, </span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">1</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">]).sub(index % </span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">2</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0"> === </span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">0</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0"> ? yMarginTensor : xMarginTensor).mul(resizeFactorTensor)</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">// Stack the tensors without converting to arrays (unless needed)</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">const</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0"> bbox = tf.stack([yCoordinates, xCoordinates, height, width], </span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">1</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">// Convert to an array only if absolutely necessary</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW260954935 BCX0"><span class="SCXW260954935 BCX0"> </span><br class="SCXW260954935 BCX0" /></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0">const</span></span><span class="TextRun Highlight SCXW260954935 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW260954935 BCX0"> bboxArray = bbox.arraySync();</span></span><span class="EOP SCXW260954935 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-b542632 elementor-widget elementor-widget-text-editor" data-id="b542632" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW184442681 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW184442681 BCX0">At the end, we can define the </span></span><span class="TextRun SCXW184442681 BCX0" lang="PL" style="color: #008000;" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW184442681 BCX0">runInference</span></span><span class="TextRun SCXW184442681 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW184442681 BCX0"> function, which summarizes the entire process of object detection. This function will handle image preprocessing, execute the model inference, and extract the resulting bounding boxes, confidence scores, and class labels. Here’s how it looks:</span></span><span class="EOP SCXW184442681 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-d6642ff elementor-widget elementor-widget-text-editor" data-id="d6642ff" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">export</span></span> <span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">async</span></span> <span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">function</span></span> <span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">runInference</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">(model, labels, image, confidenceThreshold = </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">0.4</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">) {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">  </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">try</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">// Preprocess the image</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">const</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> imgSize = model.inputs[</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">0</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">].shape[</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">1</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">];</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">const</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> { imgTensor: inputTensor, left: xMargin, top: yMargin, factor: resizeFactor } = preprocessImage(image, imgSize);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">// Run inference</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">const</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> prediction = </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">await</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> model.execute(inputTensor);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">// Post-process the model output</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">const</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> [boxes, scores, classes] = </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">await</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> postprocessInferenceResults(prediction, labels, xMargin, yMargin, resizeFactor, confidenceThreshold);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">return</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> [boxes, scores, classes];</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">  } </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">catch</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0"> (error) {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">    </span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">throw</span></span> <span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">new</span></span> <span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">Error</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">(</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">`Inference failed: ${error.message}`</span></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">  }</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW217269171 BCX0"><span class="SCXW217269171 BCX0"> </span><br class="SCXW217269171 BCX0" /></span><span class="TextRun Highlight SCXW217269171 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW217269171 BCX0">}</span></span><span class="EOP SCXW217269171 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-d087385 elementor-widget elementor-widget-heading" data-id="d087385" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h4 class="elementor-heading-title elementor-size-default">6. Visualize the Results </h4>		</div>
				</div>
				<div class="elementor-element elementor-element-84689b0 elementor-widget elementor-widget-text-editor" data-id="84689b0" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span class="TextRun SCXW40047048 BCX0" lang="PL" xml:lang="PL" data-contrast="auto"><span class="NormalTextRun SCXW40047048 BCX0">Once we have our processed detections, it’s time to draw them on the canvas:</span></span><span class="EOP SCXW40047048 BCX0" data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
				<div class="elementor-element elementor-element-d769790 elementor-widget elementor-widget-text-editor" data-id="d769790" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<pre><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">function</span></span> <span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">drawBoxesOnCanvas</span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">(ctx, boxes, classes, scores, colors) {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">  boxes.forEach((box, i) =&gt; {</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">    </span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">const</span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0"> [x1, y1, x2, y2] = box;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">    ctx.strokeStyle = colors[classes[i]];</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">    ctx.lineWidth = </span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">2</span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">;</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">    ctx.strokeRect(x1, y1, x2 - x1, y2 - y1);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">    ctx.fillStyle = colors[classes[i]];</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">    ctx.fillText(</span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">`${labels[classes[i]]} (${</span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">Math</span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">.round(scores[i] * </span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">100</span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">)}%)`</span></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">, x1, y1);</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">  });</span></span><span class="LineBreakBlob BlobObject DragDrop SCXW6384134 BCX0"><span class="SCXW6384134 BCX0"> </span><br class="SCXW6384134 BCX0" /></span><span class="TextRun Highlight SCXW6384134 BCX0" lang="PL" xml:lang="PL" data-contrast="none"><span class="NormalTextRun SCXW6384134 BCX0">}</span></span><span class="EOP SCXW6384134 BCX0" data-ccp-props="{&quot;134245417&quot;:false,&quot;201341983&quot;:0,&quot;335559740&quot;:360,&quot;335572071&quot;:0,&quot;335572072&quot;:0,&quot;335572073&quot;:0,&quot;335572075&quot;:0,&quot;335572076&quot;:0,&quot;335572077&quot;:0,&quot;335572079&quot;:0,&quot;335572080&quot;:0,&quot;335572081&quot;:0,&quot;335572083&quot;:0,&quot;335572084&quot;:0,&quot;335572085&quot;:0,&quot;335572087&quot;:0,&quot;335572088&quot;:0,&quot;335572089&quot;:0,&quot;469789798&quot;:&quot;nil&quot;,&quot;469789802&quot;:&quot;nil&quot;,&quot;469789806&quot;:&quot;nil&quot;,&quot;469789810&quot;:&quot;nil&quot;,&quot;469789814&quot;:&quot;nil&quot;}"> </span></pre>						</div>
				</div>
				<div class="elementor-element elementor-element-0a7536b elementor-widget elementor-widget-text-editor" data-id="0a7536b" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
							<p><span data-contrast="auto">Running a YOLO model for object detection directly in the browser using TensorFlow.js opens up new possibilities for real-time applications. This guide covered everything from setting up TensorFlow.js to loading models, preprocessing images, running inference, and visualizing results. As you continue to explore this exciting technology, consider experimenting with different models, optimization techniques, and use cases to fully leverage the power of machine learning in web applications.</span><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p><p> </p><p><span data-ccp-props="{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:360}"> </span></p>						</div>
				</div>
		<div class="elementor-element elementor-element-b23a8f8 e-grid e-con-full e-con e-child" data-id="b23a8f8" data-element_type="container">
				<div class="elementor-element elementor-element-2e189c2 elementor-widget elementor-widget-heading" data-id="2e189c2" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
			<h4 class="elementor-heading-title elementor-size-default">Feel free to reach out if you have any questions or want to share your implementations! </h4>		</div>
				</div>
				<div class="elementor-element elementor-element-a749555 elementor-button-success elementor-align-center elementor-widget elementor-widget-button" data-id="a749555" data-element_type="widget" data-widget_type="button.default">
				<div class="elementor-widget-container">
							<div class="elementor-button-wrapper">
					<a class="elementor-button elementor-button-link elementor-size-sm" href="https://inero-software.com/contact-us/">
						<span class="elementor-button-content-wrapper">
						<span class="elementor-button-icon">
				<svg aria-hidden="true" class="e-font-icon-svg e-fas-envelope" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z"></path></svg>			</span>
									<span class="elementor-button-text">CONTACT</span>
					</span>
					</a>
				</div>
						</div>
				</div>
				</div>
				</div>
		<div class="elementor-element elementor-element-38cdd54 e-con-full e-flex e-con e-child" data-id="38cdd54" data-element_type="container">
				</div>
					</div>
				</div>
				</div>
		<p>Artykuł <a href="https://inero-software.com/running-ai-in-client-side-real-time-face-detection-in-the-browser-using-yolo-and-tensorflow-js-use-case-study/">Running AI in client-side: Real-Time Face Detection in the Browser Using YOLO and TensorFlow.js &#8211; use case study</a> pochodzi z serwisu <a href="https://inero-software.com">Inero Software - Software Consulting</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6202</post-id>	</item>
	</channel>
</rss>
