<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: gdemarcq</title>
    <description>The latest articles on Forem by gdemarcq (@gdemarcq).</description>
    <link>https://forem.com/gdemarcq</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F956459%2F51968529-a460-40d3-8e97-70ee2bfcbba7.jpeg</url>
      <title>Forem: gdemarcq</title>
      <link>https://forem.com/gdemarcq</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gdemarcq"/>
    <language>en</language>
    <item>
      <title>Easy stable diffusion inpainting with Segment Anything Model (SAM)</title>
      <dc:creator>gdemarcq</dc:creator>
      <pubDate>Tue, 03 Oct 2023 16:37:28 +0000</pubDate>
      <link>https://forem.com/gdemarcq/easy-stable-diffusion-inpainting-with-segment-anything-model-sam-807</link>
      <guid>https://forem.com/gdemarcq/easy-stable-diffusion-inpainting-with-segment-anything-model-sam-807</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oTsr4_CH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3190/0%2A4UXWrijJCEX8CfCC.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oTsr4_CH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3190/0%2A4UXWrijJCEX8CfCC.jpg" alt="Featured image" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the Ikomia API, creating a workflow using Segment Anything Model (SAM) for segmentation followed by Stable diffusion inpainting becomes effortless, requiring only a few lines of code. To get started, you need to install the API in a virtual environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.ikomia.ai/blog/a-step-by-step-guide-to-creating-virtual-environments-in-python"&gt;How to install a virtual environment&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;ikomia
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;API documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Ikomia-dev/IkomiaApi"&gt;API repo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Run SAM and stable diffusion inpainting with a few lines of code
&lt;/h2&gt;

&lt;p&gt;You can also charge directly the open-source &lt;a href="https://github.com/Ikomia-dev/notebooks/blob/main/examples/HOWTO_use_SAM_and_SD_inpaint_with_Ikomia_API.ipynb"&gt;notebook&lt;/a&gt; we have prepared.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: The workflow bellow requires 6.1 GB of GPU RAM. However, by choosing the smallest SAM model, the memory usage can be decreased to 4.9 GB of GPU RAM.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ik&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils.displayIO&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;

&lt;span class="c1"&gt;# Init your workflow
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Add the SAM algorithm
&lt;/span&gt;&lt;span class="n"&gt;sam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_segment_anything&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'vit_l'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;input_box&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'[204.8, 221.8, 769.7, 928.5]'&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Add the stable diffusion inpainting algorithm
&lt;/span&gt;&lt;span class="n"&gt;sd_inpaint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_hf_stable_diffusion_inpaint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'stabilityai/stable-diffusion-2-inpainting'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'dog, high resolution'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;negative_prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'low quality'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;num_inference_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'100'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;guidance_scale&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'7.5'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;num_images_per_prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Run directly on your image
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://raw.githubusercontent.com/Ikomia-dev/notebooks/main/examples/img/img_cat.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Inspect your result
&lt;/span&gt;&lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_image_with_mask&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sd_inpaint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;get_image&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mWUA8k6T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2200/1%2AB4Xu8CTOqI1id2S5PbNNug.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mWUA8k6T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2200/1%2AB4Xu8CTOqI1id2S5PbNNug.jpeg" alt="Box drawing as prompt for SAM — segmentation output — stable diffusion inpaint output. [Cat image [source](https://www.pexels.com/photo/selective-focus-photo-of-grey-cat-1521304/)]" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing SAM: The Segment Anything Model
&lt;/h2&gt;

&lt;p&gt;Image segmentation is a critical task in Computer Vision, enabling machines to understand and analyze the contents of images at a pixel level. The &lt;a href="https://github.com/facebookresearch/segment-anything"&gt;Segment Anything Model&lt;/a&gt; (SAM) is a groundbreaking instance segmentation model developed by Meta Research, which has taken the field by storm since its release in April 2023.&lt;/p&gt;

&lt;p&gt;SAM offers unparalleled versatility and efficiency in image analysis tasks, making it a powerful tool for a wide range of applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  SAM's promptable features
&lt;/h2&gt;

&lt;p&gt;SAM was specifically designed to address the limitations of existing image segmentation models and to introduce new capabilities that revolutionize the field.&lt;/p&gt;

&lt;p&gt;One of SAM's standout features is its promptable segmentation task, which allows users to generate valid segmentation masks by providing prompts such as spatial or text clues (feature not yet released at the time of writing) that identify specific objects within an image.&lt;/p&gt;

&lt;p&gt;This flexibility empowers users to obtain precise and tailored segmentation results effortlessly:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generate segmentation masks for all objects SAM can detect.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2X4aSyDc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2560/0%2AykH5jS8aWo-9DqPZ.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2X4aSyDc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2560/0%2AykH5jS8aWo-9DqPZ.jpg" alt="Automated SAM segmentation (32 masks). [Original image [source]](https://www.pexels.com/photo/red-coupe-on-parking-space-590481/)" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Provide boxes to guide SAM in generating a mask for specific objects in an image.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--70R3ygus--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4486/0%2Ayk4AVeQ914MewAwr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--70R3ygus--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4486/0%2Ayk4AVeQ914MewAwr.jpg" alt="box guided" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Provide a box and a point to guide SAM in generating a mask with an area to exclude.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MvcKzg2l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4486/0%2AvYqAQNpfGIAEvmzC.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MvcKzg2l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4486/0%2AvYqAQNpfGIAEvmzC.jpg" alt="box and point guided" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Key features of the Segment Anything Model (SAM)
&lt;/h2&gt;

&lt;p&gt;At the core of SAM lies its advanced architecture, which comprises three key components: an image encoder, a prompt encoder, and a lightweight mask decoder. This design enables SAM to perform real-time mask computation, adapt to new image distributions and tasks without prior knowledge, and exhibit ambiguity awareness in segmentation tasks.&lt;/p&gt;

&lt;p&gt;By leveraging these capabilities, SAM offers remarkable flexibility and adaptability, setting new standards in image segmentation models.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yZOgqWtZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4586/0%2A0o9ovTJzt5nOr80g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yZOgqWtZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4586/0%2A0o9ovTJzt5nOr80g.png" alt="Segment Anything Model diagram [[Source](https://github.com/facebookresearch/segment-anything)]" width="800" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The SA-1B dataset: enabling unmatched training data scale
&lt;/h2&gt;

&lt;p&gt;A fundamental factor contributing to SAM's exceptional performance is the &lt;a href="https://ai.meta.com/datasets/segment-anything/"&gt;SA-1B dataset&lt;/a&gt;, the largest segmentation dataset to date, introduced by the Segment Anything project. With over 1 billion masks spread across 11 million carefully curated images, the SA-1B dataset provides SAM with a diverse and extensive training data source.&lt;/p&gt;

&lt;p&gt;This abundance of high-quality training data equips SAM with a comprehensive understanding of various object categories, enhancing its ability to generalize and perform accurately across different segmentation tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Zero-shot transfer: adapting to new tasks without prior knowledge
&lt;/h2&gt;

&lt;p&gt;One of SAM's most impressive attributes is its zero-shot transfer capability. SAM has been trained to achieve outstanding zero-shot performance, surpassing previous fully supervised results in numerous cases.&lt;/p&gt;

&lt;p&gt;Zero-shot transfer refers to SAM's ability to adapt to new tasks and object categories without requiring explicit training or prior exposure to specific examples. This feature allows users to leverage SAM for diverse applications with minimal need for prompt engineering, making it a truly versatile and ready-to-use tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Diverse applications of SAM in image segmentation
&lt;/h2&gt;

&lt;p&gt;With its numerous applications and innovative features, SAM unlocks new possibilities in the field of image segmentation. As a zero-shot detection model, SAM can be paired with object detection models to assign labels to specific objects accurately. Additionally, SAM serves as an annotation assistant, supporting the annotation process by generating masks for objects that require manual labeling.&lt;/p&gt;

&lt;p&gt;Moreover, SAM can be used as a standalone tool for feature extraction. It allows users to extract object features or remove backgrounds from images effortlessly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Versatility in image analysis tasks
&lt;/h2&gt;

&lt;p&gt;In conclusion, the Segment Anything Model represents a significant leap forward in the field of image segmentation. With its promptable segmentation task, advanced architecture, zero-shot transfer capability, and access to the SA-1B dataset, SAM offers unparalleled versatility and performance.&lt;/p&gt;

&lt;p&gt;As the capabilities of Computer Vision continue to expand, SAM paves the way for cutting-edge applications and facilitates breakthroughs in various industries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exploring stable diffusion inpainting
&lt;/h2&gt;

&lt;p&gt;Inpainting refers to the process of restoring or repairing an image by filling in missing or damaged parts. It is a valuable technique widely used in image editing and restoration, enabling the removal of flaws and unwanted objects to achieve a seamless and natural-looking final image. Inpainting finds applications in film restoration, photo editing, and digital art, among others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding stable diffusion inpainting
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/runwayml/stable-diffusion"&gt;Stable Diffusion&lt;/a&gt; Inpainting is a specific type of inpainting technique that leverages the properties of heat diffusion to fill in missing or damaged areas of an image. It accomplishes this by applying a heat diffusion process to the surrounding pixels.&lt;/p&gt;

&lt;p&gt;During this process, values are assigned to these pixels based on their proximity to the affected area. The heat equation is then utilized to redistribute intensity values, resulting in a seamless and natural patch. The repetition of this equation ensures the complete filling of the image patch, ultimately creating a smooth and seamless result that blends harmoniously with the rest of the image.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unique advantages of stable diffusion inpainting
&lt;/h2&gt;

&lt;p&gt;Stable Diffusion Inpainting sets itself apart from other inpainting techniques due to its notable stability and smoothness. Unlike slower or less reliable alternatives that can produce visible artifacts, Stable Diffusion Inpainting guarantees a stable and seamless patch. It excels particularly in handling images with complex structures, including textures, edges, and sharp transitions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xrd5qK-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3072/0%2AXxywtqKPuVIc22bW.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xrd5qK-x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3072/0%2AXxywtqKPuVIc22bW.jpg" alt="Replacing object with stable diffusion v1.5 [[Source](https://github.com/runwayml/stable-diffusion)]" width="800" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Applications of stable diffusion inpainting
&lt;/h2&gt;

&lt;p&gt;Stable Diffusion Inpainting finds practical applications in various fields.&lt;/p&gt;

&lt;h3&gt;
  
  
  In photography
&lt;/h3&gt;

&lt;p&gt;it proves valuable for removing unwanted objects or blemishes from images.&lt;/p&gt;

&lt;h3&gt;
  
  
  In film restoration
&lt;/h3&gt;

&lt;p&gt;it aids in repairing damaged or missing frames.&lt;/p&gt;

&lt;h3&gt;
  
  
  Medical imaging
&lt;/h3&gt;

&lt;p&gt;It benefits from Stable Diffusion Inpainting by removing artifacts or enhancing scan quality.&lt;/p&gt;

&lt;h3&gt;
  
  
  In digital art
&lt;/h3&gt;

&lt;p&gt;It can be utilized to create seamless compositions or eliminate undesired elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d-krQhDJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2566/0%2AcBoMZKbneGFZ8qtd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d-krQhDJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2566/0%2AcBoMZKbneGFZ8qtd.jpg" alt="Stable Diffusion inpainting v2 for object removal" width="800" height="1072"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful tips for effective inpainting
&lt;/h2&gt;

&lt;p&gt;To achieve optimal inpainting results, consider the following tips:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Experiment with different inpainting techniques to find the most suitable one for your specific use case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Utilize good-quality source images to achieve accurate and efficient inpainting results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adjust the parameters of Stable Diffusion Inpainting to optimize outcomes for your particular needs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Combine Stable Diffusion Inpainting with other segmentation algorithm such as &lt;a href="https://app.ikomia.ai/hub/algorithms/infer_yolo_v8_seg/"&gt;YOLOv8-seg&lt;/a&gt;, for enhanced results.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Stable Diffusion Inpainting stands out as an advanced and effective image processing technique for restoring or repairing missing or damaged parts of an image. Its applications include film restoration, photography, medical imaging, and digital art.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step by step segmentation and inpainting with the Ikomia API
&lt;/h2&gt;

&lt;p&gt;In this section, we will demonstrate how to utilize the Ikomia API to create a workflow for segmentation and diffusion inpainting as presented above.‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: import
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ik&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils.displayIO&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;‘Workflow’&lt;/strong&gt; class is the base object for creating a workflow. It provides methods for setting inputs (image, video, directory), configuring task parameters, obtaining time metrics, and retrieving specific task outputs, such as graphics, segmentation masks, and texts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;‘&lt;strong&gt;ik’&lt;/strong&gt; is an auto-completion system designed for convenient and easy access to algorithms and settings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;‘display’&lt;/strong&gt; function offers a flexible and customizable way to display images (input/output) and graphics, such as bounding boxes and segmentation masks&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: create workflow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We initialize a workflow instance. The &lt;strong&gt;“wf”&lt;/strong&gt; object can then be used to add tasks to the workflow instance, configure their parameters, and run them on input data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: add and connect SAM
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;sam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_segment_anything&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'vit_l'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;input_box&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'[204.8, 221.8, 769.7, 928.5]'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;‘model_name’&lt;/strong&gt;: The SAM model can be loaded with three different encoders: ‘vit_b’, ‘vit_l’, ‘vit_h’. The encoders differ in parameter counts, with ViT-B (base) containing 91M, ViT-L (large) containing 308M, and ViT-H (huge) containing 636M parameters.&lt;/li&gt;
&lt;li&gt;ViT-H offers significant improvements over ViT-B, though the gains over ViT-L are minimal.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Based on our tests, ViT-L presents the best balance between performance and accuracy. While ViT-H is the most accurate, it's also the slowest, and ViT-B is the quickest but sacrifices accuracy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;'input_box'&lt;/strong&gt; (list): A Nx4 array of given box prompts to the model, in [XYXY] or [[XYXY], [XYXY]] format.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Additional SAM parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;'draw_graphic_input'&lt;/strong&gt; (Boolean): When set to True, it allows you to draw graphics (box or point) over the object you wish to segment. If set to False, SAM will automatically generate masks for the entire image.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;'points_per_side'&lt;/strong&gt; (int or None): The number of points to be sampled for mask generation when running automatic segmentation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;'input_point'&lt;/strong&gt; (list): A Nx2 array of point prompts to the model. Each point is in [X,Y] in pixels.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;'input_point_label'&lt;/strong&gt; (list): A length N array of labels for the point prompts. 1 indicates a foreground point and 0 indicates a background point.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: add and connect the stable diffusion inpainting algorithm
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;sd_inpaint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_hf_stable_diffusion_inpaint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'stabilityai/stable-diffusion-2-inpainting'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'tiger, high resolution'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;negative_prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'low quality'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;num_inference_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'100'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;guidance_scale&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'7.5'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;num_images_per_prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;'prompt'&lt;/strong&gt; (str): Input prompt.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;'negative_prompt'&lt;/strong&gt; (str): The prompt not to guide the image generation. Ignored when not using guidance (i.e., ignored if &lt;code&gt;**guidance_scale**&lt;/code&gt; is less than &lt;code&gt;1&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;‘&lt;strong&gt;num_inference_steps’&lt;/strong&gt;:Number of denoising steps (minimum: 1; maximum: 500).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;‘&lt;strong&gt;guidance_scale’&lt;/strong&gt;: Scale for classifier-free guidance (minimum: 1; maximum: 20).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;‘&lt;strong&gt;num_images_per_prompt’&lt;/strong&gt;: Number of images to output.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 5: Apply your workflow to your image
&lt;/h2&gt;

&lt;p&gt;You can apply the workflow to your image using the &lt;strong&gt;‘run_on()’&lt;/strong&gt; function. In this example, we use the image path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/your/image"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: Display your results
&lt;/h2&gt;

&lt;p&gt;Finally, you can display our image results using the display function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_image_with_mask&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sd_inpaint&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_output&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;get_image&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, we show the segmentation mask output from the Segment Anything Model. Then, display the stable diffusion inpainting output.&lt;/p&gt;

&lt;p&gt;Here are some more stable diffusion inpainting outputs (prompts: ‘dog’, ‘fox’, ‘lioness’, ‘tiger’, ‘white cat’):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WUiMxALp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3190/0%2Aje69brqXYvP4sn7m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WUiMxALp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3190/0%2Aje69brqXYvP4sn7m.jpg" alt="A cute grey cat replaced by a dog, fox, lioness, tiger and white cat using stable diffusion inpainting" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Image Segmentation with SAM and the Ikomia ecosystem
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we have explored the process of creating a workflow for image segmentation with SAM, followed by stable diffusion inpainting.&lt;/p&gt;

&lt;p&gt;The Ikomia API simplifies the development of Computer Vision workflows and provides easy experimentation with different parameters to achieve optimal results.&lt;/p&gt;

&lt;p&gt;To learn more about the API, refer to the &lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;documentation&lt;/a&gt;. You may also check out the list of state-of-the-art algorithms on &lt;a href="https://app.ikomia.ai/hub/"&gt;Ikomia HUB&lt;/a&gt; and try out &lt;a href="https://github.com/Ikomia-dev/IkomiaStudio"&gt;Ikomia STUDIO,&lt;/a&gt; which offers a friendly UI with the same features as the API.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Complete OpenPose guide</title>
      <dc:creator>gdemarcq</dc:creator>
      <pubDate>Tue, 26 Sep 2023 12:05:14 +0000</pubDate>
      <link>https://forem.com/gdemarcq/complete-openpose-guide-3nii</link>
      <guid>https://forem.com/gdemarcq/complete-openpose-guide-3nii</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TrdUu9yf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2400/0%2Aji63EJJ7N5-NNViX.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TrdUu9yf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2400/0%2Aji63EJJ7N5-NNViX.jpg" alt="Featured image" width="800" height="687"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OpenPose is one of the most popular pose estimation libraries. Its 2D and 3D keypoint detection features are widely used by data science researchers all over the world.&lt;/p&gt;

&lt;p&gt;Here is an analysis of its features, application fields, cost for commercial use and alternatives. This should help you decide whether OpenPose is the right choice for your project in artificial intelligence.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is OpenPose?
&lt;/h2&gt;

&lt;p&gt;OpenPose is a real-time multi-person keypoint detection library for body, face, and hand estimation. It is capable of detecting 135 keypoints.&lt;/p&gt;

&lt;p&gt;It is a deep learning-based approach that can infer the 2D location of key body joints (such as elbows, knees, shoulders, and hips), facial landmarks (such as eyes, nose, mouth), and hand keypoints (such as fingertips, wrist, and palm) from RGB images or videos.&lt;/p&gt;

&lt;p&gt;The library was created by a group of researchers from Carnegie Melon University and is now maintained by two of its initial creators.&lt;/p&gt;

&lt;p&gt;OpenPose is known for its robustness to multi person pose estimation settings and is the winner of the COCO 2016 Keypoints Challenge.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5bCGHb-I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2496/0%2ALZxJ38f128KBBkL8.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5bCGHb-I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2496/0%2ALZxJ38f128KBBkL8.jpeg" alt="Hand pose" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does OpenPose work?
&lt;/h2&gt;

&lt;p&gt;The initial step of the OpenPose library involves extracting features from an image by utilizing the initial layers.‍&lt;/p&gt;

&lt;p&gt;These extracted features are then fed into two separate divisions of convolutional neural network layers. One division is responsible for predicting 18 confidence maps, each representing a specific part of the human pose skeleton.&lt;/p&gt;

&lt;p&gt;Simultaneously, the other division predicts a set of 38 Part Affinity Fields (PAFs) that indicate the level of association between different body parts. The subsequent stages are utilized to refine the predictions generated by these divisions.‍&lt;/p&gt;

&lt;p&gt;Confidence map assist in constructing bipartite graphs between pairs of body parts, while Affinity Field PAF values help identify and eliminate weaker connections within these bipartite graphs.&lt;/p&gt;

&lt;p&gt;By following these steps, it becomes possible to estimate and allocate human pose skeletons to each individual depicted in the image.‍&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose Pipeline Steps
&lt;/h2&gt;

&lt;p&gt;So in summary, OpenPose will do these tasks in sequence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Initially, the entire image, whether it’s an image or a video frame, is taken as input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, two-branch Convolutional Neural Networks (CNNs) work together to predict confidence maps, which aid in body part detection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The estimation of Part Affinity Fields (PAFs) comes next, which enables the association of different body parts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A collection of bipartite matchings is then created to link body part candidates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, these matched body parts are assembled to form complete full-body poses for all individuals present in the image.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  OpenPose features
&lt;/h2&gt;

&lt;p&gt;OpenPose allows computer science professionals across the globe to use a vast selection of features for different computer vision applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  2D real-time multi-person keypoint detection
&lt;/h3&gt;

&lt;p&gt;2D human pose estimation is one of the most appreciated tasks that OpenPose model can do. Here’s a few frequently used estimations that can be achieved with OpenPose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;15, 18 or 25-keypoint body/foot keypoint estimation, including 6 foot key points. Runtime invariant to the number of detected people.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;2x21-keypoint hand key point estimation. Runtime depends on the number of detected people.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;70-keypoint face keypoint estimation. Runtime depends on the number of detected people. See OpenPose Training for a runtime invariant alternative.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w-HkXMGF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AjohVtgt5Z5ERWQm8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w-HkXMGF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AjohVtgt5Z5ERWQm8.png" alt="Body keypoints" width="800" height="1080"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3D real-time single-person keypoint detection
&lt;/h3&gt;

&lt;p&gt;3D pose estimation is another OpenPose feature that makes this a very powerful library of algorithms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;3D triangulation from multiple single views.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Synchronization of Flir cameras handled.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compatible with Flir/Point Grey cameras.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Calibration toolbox
&lt;/h3&gt;

&lt;p&gt;Estimation of distortion, intrinsic, and extrinsic camera parameters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Single-person tracking&lt;/strong&gt; for further speedup or visual smoothing.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenPose input
&lt;/h3&gt;

&lt;p&gt;Input can be image, video, webcam, Flir/Point Grey, IP camera, and support to add your own custom input source (e.g., depth camera). This means you can estimate human movement in real time as well as analyze still images.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenPose output
&lt;/h3&gt;

&lt;p&gt;Basic image + keypoint display/saving (PNG, JPG, AVI, …), keypoint saving (JSON, XML, YML, …), keypoints as array class, and support to add your own custom output code (e.g., some fancy UI).&lt;/p&gt;

&lt;p&gt;OpenPose can output the keypoints as 2D coordinates, 3D coordinates, or heatmap values, providing flexibility for different applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenPose OS
&lt;/h3&gt;

&lt;p&gt;Ubuntu (20, 18, 16, 14), Windows (10, 8), Mac OSX, Nvidia TX2.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenPose hardware compatibility
&lt;/h3&gt;

&lt;p&gt;CUDA (Nvidia GPU), OpenCL (AMD GPU), and non-GPU (CPU-only) versions.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenPose APIs
&lt;/h3&gt;

&lt;p&gt;OpenPose has APIs in several programming languages such as Python, C++, and MATLAB, and can be integrated with other machine learning libraries and frameworks such as TensorFlow, PyTorch, and Caffe.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose applications
&lt;/h2&gt;

&lt;p&gt;Before we jump into the areas of OpenPose human pose estimation algorithm uses, let’s first take a look at the most important tasks you can do with OpenPose.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multi-person pose estimation
&lt;/h3&gt;

&lt;p&gt;OpenPose can detect the poses of multiple people in the same image or video stream simultaneously, making it ideal for applications such as action recognition, gesture recognition, and human-computer interaction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ryCfuBpu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A7H5_hHbBrtiY0Qmu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ryCfuBpu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A7H5_hHbBrtiY0Qmu.png" alt="Firemen pose" width="512" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-time performance
&lt;/h3&gt;

&lt;p&gt;OpenPose can process images and videos in real-time on modern GPUs, making it suitable for real-time applications such as sports analysis, gaming, and virtual reality.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accurate keypoint detection
&lt;/h3&gt;

&lt;p&gt;OpenPose can detect key body, face, and hand keypoints with high accuracy, even in challenging scenarios such as occlusion and cluttered backgrounds.&lt;/p&gt;

&lt;p&gt;OpenPose has a wide range of applications in various fields. Here are some examples of OpenPose applications in different domains&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose in different industries
&lt;/h2&gt;

&lt;p&gt;Due to its outstanding ability to find and track human poses, OpenPose became a Computer Vision staple in many different industries.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose for sports Analysis
&lt;/h2&gt;

&lt;p&gt;OpenPose algorithm can be used for many different sports applications, such as injury prevention and gaming.&lt;/p&gt;

&lt;h3&gt;
  
  
  Human kinetics analysis
&lt;/h3&gt;

&lt;p&gt;Analyzing movements and techniques of athletes to improve their performance in sports like basketball, tennis, and golf.&lt;/p&gt;

&lt;h3&gt;
  
  
  Injury prevention
&lt;/h3&gt;

&lt;p&gt;Identifying improper posture or movement that could lead to injuries in sports like running, weightlifting, and football.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gaming
&lt;/h3&gt;

&lt;p&gt;Using motion tracking to control game characters using the player’s body movements, as seen in games like Kinect Sports and Just Dance.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose for robotics
&lt;/h2&gt;

&lt;p&gt;As you might imagine, OpenPose has multiple applications within the robotics industry.&lt;/p&gt;

&lt;h3&gt;
  
  
  Human-Robot interaction
&lt;/h3&gt;

&lt;p&gt;Developing robots that can interact with humans using natural body movements, like in personal assistance robots, factory automation, and social robots.&lt;/p&gt;

&lt;h3&gt;
  
  
  Object manipulation
&lt;/h3&gt;

&lt;p&gt;Controlling robotic arms using hand and finger movements detected by OpenPose, like in manufacturing and assembly line robots.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gesture recognition
&lt;/h3&gt;

&lt;p&gt;Detecting and recognizing human gestures, like waving, pointing, and hand signals, to control robots, like in home automation and virtual assistants.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose for healthcare
&lt;/h2&gt;

&lt;p&gt;Healthcare is another area that OpenPose can help with loads of tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Physical therapy
&lt;/h3&gt;

&lt;p&gt;Monitoring patients’ movements during rehabilitation exercises and providing real-time feedback to improve their posture and technique.&lt;/p&gt;

&lt;h3&gt;
  
  
  Elderly care
&lt;/h3&gt;

&lt;p&gt;Detecting falls and monitoring the activities of elderly people in their homes using OpenPose-based cameras.&lt;/p&gt;

&lt;h3&gt;
  
  
  Surgery
&lt;/h3&gt;

&lt;p&gt;Providing surgeons with real-time feedback on the positioning and movement of their hands during surgical procedures.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose for security and surveillance
&lt;/h2&gt;

&lt;p&gt;When it comes to security and surveillance, OpenPose finds many application fields for humans, objects and animals.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/T0xr48iULvc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Intrusion detection
&lt;/h3&gt;

&lt;p&gt;Detecting and tracking human movements in restricted areas or identifying suspicious activities in real-time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Crowd monitoring
&lt;/h3&gt;

&lt;p&gt;Analyzing crowd behavior, detecting anomalies, and providing insights for crowd management and public safety.&lt;/p&gt;

&lt;h3&gt;
  
  
  Perimeter security
&lt;/h3&gt;

&lt;p&gt;Monitoring and analyzing human presence along the perimeter of secure areas, detecting unauthorized entry attempts or potential breaches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Crowd behavior analysis
&lt;/h3&gt;

&lt;p&gt;Analyzing crowd dynamics, crowd density, and movement patterns in crowded public spaces, assisting in crowd management, event planning, and emergency response.&lt;/p&gt;

&lt;h3&gt;
  
  
  Traffic surveillance
&lt;/h3&gt;

&lt;p&gt;Tracking and analyzing pedestrian movements at intersections, crosswalks, or public transportation hubs, facilitating traffic management and improving pedestrian safety.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I5UXVybj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AaylS6wkxn8DiK69Q.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I5UXVybj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AaylS6wkxn8DiK69Q.jpeg" alt="Body pose" width="512" height="683"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose for Entertainment
&lt;/h2&gt;

&lt;p&gt;OpenPose is used by the entertainment industry for various applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Virtual reality
&lt;/h3&gt;

&lt;p&gt;Tracking body movements to provide an immersive experience in virtual reality environments, like in VR games and simulations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Animation
&lt;/h3&gt;

&lt;p&gt;Capturing the motion of actors’ bodies and facial expressions to create realistic and expressive animated characters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Film and TV
&lt;/h3&gt;

&lt;p&gt;Tracking actors’ movements during motion capture sessions and applying them to digital characters in movies and TV shows.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose for retail and e-commerce
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Virtual try-on
&lt;/h3&gt;

&lt;p&gt;Helping customers virtually try on clothes, accessories, or makeup, providing a more personalized and engaging shopping experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Customer behavior analysis
&lt;/h3&gt;

&lt;p&gt;Track and analyzing customers’ movements within a store, allowing retailers to optimize store layouts and product placements.&lt;/p&gt;

&lt;h2&gt;
  
  
  How much does OpenPose cost?
&lt;/h2&gt;

&lt;p&gt;OpenPose is freely available for free non-commercial use, and may be redistributed under these conditions.&lt;/p&gt;

&lt;p&gt;The license agreement can be used for academic or non-profit organization noncommercial research only.‍&lt;/p&gt;

&lt;p&gt;There is a non-exclusive commercial license. It requires a non-refundable $25,000 USD annual royalty.&lt;/p&gt;

&lt;p&gt;Note that the commercial license cannot be used in the field of sports.‍&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use OpenPose?
&lt;/h2&gt;

&lt;p&gt;The code base is open-sourced on &lt;a href="https://github.com/CMU-Perceptual-Computing-Lab/openpose"&gt;Github&lt;/a&gt; and is very well documented.&lt;/p&gt;

&lt;p&gt;You can read the &lt;a href="https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/installation/0_index.md"&gt;official installation documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install OpenPose
&lt;/h2&gt;

&lt;p&gt;The first step is to install OpenPose on your system. OpenPose is available for various platforms, including Windows, Linux, and macOS.&lt;/p&gt;

&lt;p&gt;You can download the latest version of the OpenPose package from the official website.‍&lt;/p&gt;

&lt;p&gt;The package includes pre-trained models and configurations that are ready to use, but can also be further customized according to your application needs.‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Prepare the input data
&lt;/h2&gt;

&lt;p&gt;OpenPose requires input data in the form of images or video streams. The input data can be captured using a camera or loaded from a file.&lt;/p&gt;

&lt;p&gt;Preprocessing the data before inputting it into OpenPose is necessary to ensure the best performance and accuracy of the model. This can be done through resizing, cropping, and filtering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure OpenPose
&lt;/h2&gt;

&lt;p&gt;Configuring OpenPose is an essential step in optimizing the model’s performance and accuracy. OpenPose provides various configuration options that can be adjusted.&lt;/p&gt;

&lt;p&gt;The configuration options include model type, output format, resolution, and keypoint detection threshold. These options can be selected according to your application’s specific requirements to achieve the best results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run OpenPose
&lt;/h2&gt;

&lt;p&gt;Once the input data is prepared and the configuration options are set, OpenPose can be run on the data. OpenPose will analyze the input data and detect the keypoints of the human body, including the position, orientation, and movement of various body parts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Visualize the output
&lt;/h2&gt;

&lt;p&gt;The final step is to visualize the output of OpenPose. OpenPose provides various output formats, including JSON, XML, and CSV, which can be used to display the detected keypoints in real-time or post-processing analysis The output can be visualized using various tools, such as OpenCV, Matplotlib, or Unity.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose Alternatives and Comparisons
&lt;/h2&gt;

&lt;p&gt;As powerful as OpenPose is, it’s always worth exploring alternative pose estimation algorithms to determine which is best suited for your use case.‍&lt;/p&gt;

&lt;p&gt;Here are a few OpenPose alternatives to consider.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs Mediapipe
&lt;/h2&gt;

&lt;p&gt;Lightweight, cross-platform framework for mobile devices and desktops that enables real-time, high-accuracy hand, facial, and pose tracking.&lt;/p&gt;

&lt;p&gt;One of the major advantages of MediaPipe is that it is optimized for mobile devices and can run on resource-constrained devices.&lt;/p&gt;

&lt;p&gt;However, it has limited support for 3D pose estimation and requires a significant amount of preprocessing for input data.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs Detectron2
&lt;/h2&gt;

&lt;p&gt;Provides pre-trained models for keypoint detection and pose estimation. Detectron2 is highly customizable and supports a wide range of models, including Mask R-CNN and RetinaNet.&lt;/p&gt;

&lt;p&gt;However, it is more complex than other libraries, and its performance may be affected by hardware limitations.‍&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs MMPose
&lt;/h2&gt;

&lt;p&gt;A high-accuracy pose estimation framework that includes support for multi-person, 3D, and hand pose estimation. It also includes a variety of pre-trained models and data augmentation techniques for improved performance.&lt;/p&gt;

&lt;p&gt;However, it may require more computational resources than some of the other algorithms, and it is currently only available in PyTorch.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs Lightweight-human-pose-estimation.pytorch
&lt;/h2&gt;

&lt;p&gt;PyTorch-based pose estimation algorithm that is designed to be lightweight and fast. It uses a human pose estimation model that has been optimized for running on devices with limited computational resources, such as mobile devices and Raspberry Pi boards.&lt;/p&gt;

&lt;p&gt;It can achieve real-time performance, making it suitable for applications such as human-computer interaction and sports analysis.&lt;/p&gt;

&lt;p&gt;However, its accuracy may be lower than some of the more complex algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs Freemocap
&lt;/h2&gt;

&lt;p&gt;Open-source, markerless motion capture system that uses computer vision techniques to estimate the 3D position of a person’s joints from a video stream. It includes support for multi-person pose estimation, as well as body and facial expression recognition.&lt;/p&gt;

&lt;p&gt;It can be used for a variety of applications, including animation, gaming, and biomechanics research.&lt;/p&gt;

&lt;p&gt;‍However, it may require more computational resources than some of the other algorithms, and its accuracy may be lower in challenging lighting conditions or with occlusions.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs AlphaPose
&lt;/h2&gt;

&lt;p&gt;Offers faster performance than OpenPose and can detect multiple people in a single image or video stream.&lt;/p&gt;

&lt;p&gt;However, it may have lower accuracy for small or occluded body parts due to its reliance on bottom-up detection and clustering.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs DeeperCut
&lt;/h2&gt;

&lt;p&gt;Offers higher accuracy than OpenPose, making it a good choice for fine-grained pose estimation and occluded body parts.&lt;/p&gt;

&lt;p&gt;However, it is slower than OpenPose due to its reliance on graphical models and requires careful tuning of its hyperparameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs HRNet
&lt;/h2&gt;

&lt;p&gt;Boasts state-of-the-art accuracy and fast inference time, making it well-suited for real-time pose estimation and multi-person scenarios.&lt;/p&gt;

&lt;p&gt;However, it requires more computational resources than OpenPose due to its use of a deeper network architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs EfficientPose
&lt;/h2&gt;

&lt;p&gt;Offers efficient inference time and improved accuracy compared to other lightweight models, making it ideal for mobile and embedded applications.&lt;/p&gt;

&lt;p&gt;However, it may not be as accurate as some of the more complex algorithms due to its lightweight nature.&lt;/p&gt;

&lt;h2&gt;
  
  
  OpenPose vs DensePose
&lt;/h2&gt;

&lt;p&gt;Can handle more complex poses and motions and estimate detailed body part textures, making it a good choice for fashion and retail applications, virtual try-ons, and gaming and animation.&lt;/p&gt;

&lt;p&gt;However, it requires higher quality input images and is only available for non-commercial use due to licensing restrictions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare OpenPose to Other Human Pose Estimation Algorithms
&lt;/h2&gt;

&lt;p&gt;Here is a table with these OpenPose alternatives:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jPX9JIzK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Ad8wMjk490zByQ5JHChXXUA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jPX9JIzK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2Ad8wMjk490zByQ5JHChXXUA.png" alt="Comparison table" width="800" height="1186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: The license type and cost may vary depending on the specific use case and the terms of the license agreement. Please refer to the individual project websites for more information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best alternatives to OpenPose for commercial use
&lt;/h2&gt;

&lt;p&gt;If you are planning to create a solution for commercial use requiring multi-person keypoint detection, the Ikomia team advises choosing either Detectron2 or MMPose.&lt;/p&gt;

&lt;p&gt;Both of these alternatives are freely available for commercial use under the Apache 2.0 license and are actively maintained by a strong community. You can also discover these resources within the &lt;a href="https://app.ikomia.ai/hub/?task=KEYPOINTS_DETECTION"&gt;Ikomia HUB&lt;/a&gt; and leverage them through either the open-source &lt;a href="https://github.com/Ikomia-dev/IkomiaApi"&gt;Ikomia API&lt;/a&gt; or &lt;a href="https://github.com/Ikomia-dev/IkomiaStudio"&gt;Ikomia STUDIO&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🚀 Exciting News: Beta Launch of a SaaS for Computer Vision Projects! 🚀</title>
      <dc:creator>gdemarcq</dc:creator>
      <pubDate>Wed, 20 Sep 2023 15:44:14 +0000</pubDate>
      <link>https://forem.com/gdemarcq/exciting-news-beta-launch-of-a-saas-for-computer-vision-projects-c3i</link>
      <guid>https://forem.com/gdemarcq/exciting-news-beta-launch-of-a-saas-for-computer-vision-projects-c3i</guid>
      <description>&lt;p&gt;Hey there, AI developers and data scientists! The Ikomia team is thrilled to announce the Beta launch of our new SaaS platform for deploying Computer Vision projects. If you're into AI and Computer Vision, this might pique your interest.&lt;/p&gt;

&lt;p&gt;🔗 &lt;a href="https://github.com/Ikomia-dev/IkomiaApi"&gt;Python API&lt;/a&gt;: First, a quick intro for those who aren't familiar with us. We already have a powerful Python API and an desktop app that lets you prototype workflows across multiple frameworks at a lightning-fast 5x pace. This includes popular frameworks like HuggingFace🤗, OpenMMlab, YOLO, and more.&lt;/p&gt;

&lt;p&gt;🆓 What's in it for you? The Beta we are opening up allows you to deploy endpoint APIs for free while contributing to the platform's improvement. 💝&lt;/p&gt;

&lt;p&gt;In exchange for your valuable feedback, here's what we offer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;2 months of free serverless CPU deployment, letting you process up to 1000 images per month.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access to a collaborative workspace where you can share and collaborate on up to 10 projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A fantastic 30% lifetime discount on all your future SCALE deployments.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✏️ Ready to get started? You can register here: &lt;a href="https://www.ikomia.ai/plans#Beta"&gt;Ikomia Beta Registration&lt;/a&gt;. If you have any questions or need more information, feel free to contact me.&lt;/p&gt;

&lt;p&gt;🌟 Don't wait too long! Please note that this Beta program is limited to 100 users, so grab your spot while you can. Let's shape the future of Computer Vision together! 🌟&lt;/p&gt;

</description>
      <category>computervision</category>
      <category>saas</category>
      <category>ai</category>
      <category>startup</category>
    </item>
    <item>
      <title>How to train a classification model on a custom dataset</title>
      <dc:creator>gdemarcq</dc:creator>
      <pubDate>Tue, 19 Sep 2023 09:47:49 +0000</pubDate>
      <link>https://forem.com/gdemarcq/how-to-train-a-classification-model-on-a-custom-dataset-21ba</link>
      <guid>https://forem.com/gdemarcq/how-to-train-a-classification-model-on-a-custom-dataset-21ba</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qzE1csDu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4586/0%2AdS6Im1Ewpt6GXWTg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qzE1csDu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4586/0%2AdS6Im1Ewpt6GXWTg.jpg" alt="Featured image" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog post, we will cover the necessary steps to train a custom image classification model and test it on images.&lt;/p&gt;

&lt;p&gt;The Ikomia API simplifies the development of Computer Vision workflows and provides an easy way to experiment with different parameters to achieve optimal results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started with Ikomia API
&lt;/h2&gt;

&lt;p&gt;You can train a custom classification model with just a few lines of code. To begin, you will need to install the API within a virtual environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.ikomia.ai/blog/a-step-by-step-guide-to-creating-virtual-environments-in-python"&gt;How to install a virtual environment&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;ikomia
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;API documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Ikomia-dev/IkomiaApi"&gt;API repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we will use the &lt;a href="https://universe.roboflow.com/ds/48QIfZoFjO?key=NTZLzFA0Q2"&gt;Rock, Paper, Scissor dataset from Roboflow&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Ensure that the dataset is organized in the correct format, as shown below:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Note: The “validation” folder should be renamed to “val”.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jdh0RsTq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AytoXxXZtouFjcBTY.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jdh0RsTq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AytoXxXZtouFjcBTY.jpg" alt="Folder tree" width="357" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ‍Run the train ResNet algorithm
&lt;/h2&gt;

&lt;p&gt;You can also charge directly the open-source &lt;a href="https://github.com/Ikomia-dev/notebooks/blob/main/examples/HOWTO_train_Classification_Model_with_Ikomia_API.ipynb"&gt;notebook&lt;/a&gt; we have prepared.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ik&lt;/span&gt;

&lt;span class="c1"&gt;# Init your workflow
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;# Add the training task to the workflow
&lt;/span&gt;&lt;span class="n"&gt;resnet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;train_torchvision_resnet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"resnet34"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;batch_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"16"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;epochs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;output_folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Path/To/Output/Folder"&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set the input path of your dataset
&lt;/span&gt;&lt;span class="n"&gt;dataset_folder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Path/To/Rock Paper Scissors.v1-hugggingface.folder"&lt;/span&gt;
&lt;span class="c1"&gt;# Launch your training on your data
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;dataset_folder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After 5 epochs of training, you will see the following metrics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;train Loss: 0.3751 Acc:0.8468&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;val Loss: 0.5611 Acc:0.7231&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;val per class Acc:tensor([0.75806, 1.00000, 0.41129])&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Training complete in 1m57s&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Best accuracy: 0.838710&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Image Classification
&lt;/h2&gt;

&lt;p&gt;Before experimenting with TorchVision ResNet, let’s dive deeper into image classification and the characteristics of this particular algorithm.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Image Classification?
&lt;/h2&gt;

&lt;p&gt;Image classification is a fundamental task in Computer Vision that involves categorizing images into predefined classes based on their visual content. It enables computers to recognize objects, scenes, and patterns within images. The importance of image classification lies in its various applications:&lt;/p&gt;

&lt;h3&gt;
  
  
  Object Recognition
&lt;/h3&gt;

&lt;p&gt;It allows computers to identify and categorize objects in images, essential for applications like autonomous vehicles and surveillance systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Image Understanding
&lt;/h3&gt;

&lt;p&gt;Classification helps machines interpret image content and extract meaningful information, enabling advanced analysis and decision-making based on visual data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Visual Search and Retrieval‍
&lt;/h3&gt;

&lt;p&gt;By assigning tags or labels to images, classification models facilitate efficient searching and retrieval of specific images from large databases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Content Filtering and Moderation‍
&lt;/h3&gt;

&lt;p&gt;Image classification aids in automatically detecting and flagging inappropriate or offensive content, ensuring safer online environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Medical Imaging and Diagnosis‍
&lt;/h3&gt;

&lt;p&gt;Classification assists in diagnosing diseases and analyzing medical images, enabling faster and more accurate diagnoses.&lt;/p&gt;

&lt;h3&gt;
  
  
  Quality Control and Inspection‍
&lt;/h3&gt;

&lt;p&gt;By classifying images, defects or anomalies in manufactured products can be identified, ensuring quality control in various industries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Visual Recommendation Systems‍
&lt;/h3&gt;

&lt;p&gt;Image classification enhances recommendation systems by analyzing visual content and suggesting related items or content.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security and Surveillance‍
&lt;/h3&gt;

&lt;p&gt;Classification enables the identification of objects or individuals of interest in security and surveillance applications, enhancing threat detection and public safety.&lt;/p&gt;

&lt;p&gt;In summary, image classification is essential for object recognition, image understanding, search and retrieval, content moderation, medical imaging, quality control, recommendation systems, and security applications in computer vision.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is TorchVision ResNet?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A DCNN architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://pytorch.org/vision/stable/index.html"&gt;TorchVision&lt;/a&gt; is a popular Computer Vision library in PyTorch that provides pre-trained models and tools for working with image data. One of the widely used models in TorchVision is &lt;a href="https://pytorch.org/vision/main/models/resnet.html"&gt;ResNet&lt;/a&gt;. ResNet, short for Residual Network, is a deep convolutional neural network architecture introduced by &lt;a href="https://arxiv.org/abs/1512.03385"&gt;Kaiming He et al. in 2015&lt;/a&gt;. It was designed to address the challenge of training deep neural networks by introducing a residual learning framework.&lt;/p&gt;

&lt;h3&gt;
  
  
  Residual blocks to train deeper networks
&lt;/h3&gt;

&lt;p&gt;ResNet uses residual blocks with skip connections to facilitate information flow between layers, mitigating the &lt;a href="https://towardsdatascience.com/the-vanishing-gradient-problem-69bf08b15484"&gt;vanishing gradient&lt;/a&gt; problem and enabling the training of deeper networks.&lt;/p&gt;

&lt;p&gt;The key idea behind ResNet is the use of &lt;a href="https://paperswithcode.com/method/residual-block"&gt;residual blocks&lt;/a&gt;, which allow the network to learn residual mappings. These residual blocks contain &lt;strong&gt;skip connections&lt;/strong&gt; that bypass one or more layers, enabling the flow of information from earlier layers to later layers.&lt;/p&gt;

&lt;p&gt;This helps alleviate the vanishing gradient problem and facilitates the training of deeper networks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zl4-a5S8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AtkpvhjyQGWqXQOfU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zl4-a5S8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AtkpvhjyQGWqXQOfU.png" alt="Skip connections" width="385" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The residual connection creates a shortcut path by adding the value at the beginning of the block, x, directly to the end of the block (F(x) + x) [&lt;a href="https://paperswithcode.com/method/residual-connection"&gt;Source&lt;/a&gt;].&lt;/p&gt;

&lt;p&gt;This allows information to pass through multiple layers without degradation, making training and optimization easier.‍&lt;/p&gt;

&lt;p&gt;The Microsoft Research team won the ImageNet 2015 competition using these deep residual layers, which use skip connections. They used ResNet-152 convolutional neural network architecture, comprising a total of 152 layers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZSez2Dlp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2754/0%2Ayxf0R2B_O1dGgCFJ.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZSez2Dlp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2754/0%2Ayxf0R2B_O1dGgCFJ.jpg" alt="ResNet34 architecture" width="800" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ResNet34 Architecture [&lt;a href="https://arxiv.org/pdf/1512.03385.pdf"&gt;Source&lt;/a&gt;].&lt;/p&gt;

&lt;h3&gt;
  
  
  Various ResNet models
&lt;/h3&gt;

&lt;p&gt;ResNet models are available in torchvision with different depths, including ResNet-18, ResNet-34, ResNet-50, ResNet-101, and ResNet-152. These pre-trained models have been trained on large-scale image classification tasks, such as the ImageNet dataset, and achieved state-of-the-art performance.&lt;/p&gt;

&lt;p&gt;By using pre-trained ResNet models from torchvision, researchers and developers can leverage the learned representations for various Computer Vision tasks, including image classification, object detection, and feature extraction.‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Step by step: Train ResNet Image Classification Model using Ikomia API
&lt;/h2&gt;

&lt;p&gt;With the dataset of Rock, Paper &amp;amp; Scissor images that you have downloaded, you can easily train a custom ResNet model using the Ikomia API. Let’s go through the process together:&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: import
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; 
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflowfrom&lt;/span&gt; &lt;span class="n"&gt;ikomia&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;ik&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Workflow&lt;/strong&gt; is the base object to create a workflow. It provides methods for setting inputs such as images, videos, and directories, configuring task parameters, obtaining time metrics, and accessing specific task outputs such as graphics, segmentation masks, and texts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ik&lt;/strong&gt; is an auto-completion system designed for convenient and easy access to algorithms and settings.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: create workflow
&lt;/h2&gt;

&lt;p&gt;Initialize a workflow instance by creating a ‘&lt;strong&gt;wf&lt;/strong&gt;’ object. This object will be used to add tasks to the workflow, configure their parameters, and run them on input data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: add the torchvision ResNet algorithm and set the parameters
&lt;/h2&gt;

&lt;p&gt;Now, let’s add the train_torchvision_resnet task to train our custom image classifier. We also need to specify a few parameters for the task:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;resnet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;train_torchvision_resnet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"resnet34"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;batch_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"16"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;epochs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"5"&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;model_name&lt;/strong&gt;: name of the pre-trained model&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;batch_size&lt;/strong&gt;: Number of samples processed before the model is updated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;epochs&lt;/strong&gt;: Number of complete passes through the training dataset.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;input_size&lt;/strong&gt;: Input image size during training.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;learning_rate&lt;/strong&gt;: Step size at which the model’s parameters are updated during training.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;momentum&lt;/strong&gt;: Optimization technique that accelerates convergence&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;weight_decay&lt;/strong&gt;: Regularization technique that reduces the magnitude of the model’s&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;output_folder&lt;/strong&gt;: Path to where the trained model will be saved.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: set the input path of your dataset
&lt;/h2&gt;

&lt;p&gt;Next, provide the path to the dataset folder for the task input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dataset_folder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Path/To/Rock Paper Scissors.v1-raw-300x300.folder"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: run your workflow
&lt;/h2&gt;

&lt;p&gt;Finally, it’s time to run the workflow and start the training process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;dataset_folder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Test your custom ResNet image classifier
&lt;/h2&gt;

&lt;p&gt;First, we can run a rock/paper/scissor image on the pre-trained ResNet34 model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils.displayIO&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ik&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the workflow
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;# Add the image classification algorithm  
&lt;/span&gt;&lt;span class="n"&gt;resnet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_torchvision_resnet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"resnet34"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Run on your image
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Path/To/Rock Paper Scissors/Dataset/test/rock/rock8_png.rf.8b06573ed8208e085c3b2e3cf06c7888.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Inspect your results
&lt;/span&gt;&lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_image_with_graphics&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tbC_vAeZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AjfujAg8VsaX7G6Vp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tbC_vAeZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AjfujAg8VsaX7G6Vp.PNG" alt="Result knee pod" width="300" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can observe that ResNet34 pre-trained model doesn’t detect rock signs. This is because the model has been trained on the ImageNet dataset, which does not contain images of rock/paper/scissor hand signs.&lt;/p&gt;

&lt;p&gt;To test the model we just trained, we specify the path to our custom model and class names using the &lt;strong&gt;’model_weight_file’&lt;/strong&gt; and “&lt;strong&gt;class_file&lt;/strong&gt;” parameters. We then run the workflow on the same image we used previously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Add the custom ResNet model  
&lt;/span&gt;&lt;span class="n"&gt;resnet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_torchvision_resnet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"resnet34"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;model_weight_file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/output_folder/timestamp/06-06-2023T14h32m40s/resnet34.pth"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;class_file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/output_folder/timestamp/classes.txt"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--451xx2iv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AcEffp4fCnW4W_DZz.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--451xx2iv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AcEffp4fCnW4W_DZz.PNG" alt="Result rock" width="300" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are some more examples of image classification using the pre-trained (left) and our custom model (right):‍&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---IX6mDoL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4126/0%2ATOtvc0nP0TWdd0yJ.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---IX6mDoL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4126/0%2ATOtvc0nP0TWdd0yJ.jpg" alt="Result scissors" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x4KwwDSV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4126/0%2AbZcZdFrqaoYeU4i-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x4KwwDSV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/4126/0%2AbZcZdFrqaoYeU4i-.png" alt="paper" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Build your own Computer Vision workflow
&lt;/h2&gt;

&lt;p&gt;To learn more about the API, refer to the &lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;documentation&lt;/a&gt;. You may also check out the list of state-of-the-art algorithms on &lt;a href="https://app.ikomia.ai/hub/"&gt;Ikoma HUB&lt;/a&gt; and try out &lt;a href="https://github.com/Ikomia-dev/IkomiaStudio"&gt;Ikomia STUDIO,&lt;/a&gt; which offers a friendly UI with the same features as the API.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to train YOLOv8 instance segmentation on a custom dataset</title>
      <dc:creator>gdemarcq</dc:creator>
      <pubDate>Mon, 11 Sep 2023 14:12:01 +0000</pubDate>
      <link>https://forem.com/gdemarcq/how-to-train-yolov8-instance-segmentation-on-a-custom-dataset-3ipm</link>
      <guid>https://forem.com/gdemarcq/how-to-train-yolov8-instance-segmentation-on-a-custom-dataset-3ipm</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0OjqElKI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AxA5VryZMXWJ7SKtP8oOHDg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0OjqElKI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AxA5VryZMXWJ7SKtP8oOHDg.jpeg" alt="YOLOv8 segmentation illustration" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case study, we will cover the process of fine-tuning the YOLOv8-seg pre-trained model to improve its accuracy for specific object classes. The &lt;a href="https://www.ikomia.ai/api"&gt;Ikomia API&lt;/a&gt; simplifies the development of Computer Vision workflows and allows for easy experimentation with different parameters to achieve the best results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started with Ikomia API
&lt;/h2&gt;

&lt;p&gt;With the Ikomia API, we can train a custom YOLOv8 Instance Segmentation model with just a few lines of code. To get started, you need to install the API in a virtual environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/bonus/virtual_env.html"&gt;How to install a virtual environment&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install ikomia
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;API documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;API repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we will use the coral dataset from Roboflow. You can download this dataset by following this link: &lt;a href="https://universe.roboflow.com/ds/Ap7v6sRXMc?key=ecveMLIdNa"&gt;Dataset Download Link&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the train YOLOv8 instance segmentation algorithm with a few lines of code
&lt;/h2&gt;

&lt;p&gt;You can also charge directly the open-source &lt;a href="https://github.com/Ikomia-dev/notebooks/blob/main/examples/HOWTO_train_YOLO_v7_with_Ikomia_API_aerial_plane_dataset.ipynb"&gt;notebook&lt;/a&gt; we have prepared.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the workflow
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Add the dataset loader to load your custom data and annotations
&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;dataset_coco&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set the parameters of the dataset loader
&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_parameters&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;json_file&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Path/To/Mesophotic Coral/Dataset/train/_annotations.coco.json&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;image_folder&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Path/To/Mesophotic Coral/Dataset/train&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;task&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;instance_segmentation&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;# Add the YOLOv8 segmentation algorithm
&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;train_yolo_v8_seg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set the parameters of the YOLOv8 segmentation algorithm
&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_parameters&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;model_name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;yolov8m-seg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;batch_size&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;4&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;epochs&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;50&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;input_size&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;640&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;dataset_split_ratio&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;output_folder&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Path/To/Folder/Where/Model-weights/Will/Be/Saved&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The training process for 50 epochs was completed in approximately 1h using an NVIDIA GeForce RTX 3060 Laptop GPU with 6143.5MB.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is YOLOv8 instance segmentation?
&lt;/h2&gt;

&lt;p&gt;Before going through a step by step approach with all parameters details, let's dive deeper into instance segmentation and YOLOv8.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is instance segmentation?
&lt;/h2&gt;

&lt;p&gt;Instance segmentation is a Computer Vision task that involves identifying and delineating individual objects within an image. Unlike semantic segmentation, which classifies each pixel into pre-defined categories, instance segmentation aims to differentiate and separate instances of objects from one another.&lt;/p&gt;

&lt;p&gt;In instance segmentation, the goal is to not only classify each pixel but also assign a unique label or identifier to each distinct object instance. This means that objects of the same class are treated as separate entities. For example, if there are multiple instances of cars in an image, instance segmentation algorithms will assign a unique label to each car, allowing for precise identification and differentiation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uq1Sr5cO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2ANRybCMtuJHh2z13k" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uq1Sr5cO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2ANRybCMtuJHh2z13k" alt="*Comparison between Object Detection, Semantic Segmentation and Instance Segmentation.*" width="704" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instance segmentation provides more detailed and granular information about object boundaries and spatial extent compared to other segmentation techniques. It is widely used in various applications, including autonomous driving, robotics, object detection, medical imaging, and video analysis.&lt;/p&gt;

&lt;p&gt;Many modern instance segmentation algorithms, like YOLOv8-seg, employ deep learning techniques, particularly convolutional neural networks (CNNs), to perform pixel-wise classification and object localization simultaneously. These algorithms often combine the strengths of object detection and semantic segmentation to achieve accurate instance-level segmentation results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview of YOLOv8
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Release and benefits
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/ultralytics/ultralytics"&gt;YOLOv8&lt;/a&gt;, developed by &lt;a href="https://docs.ultralytics.com/"&gt;Ultralytics&lt;/a&gt;, is a model that specializes in object detection, image classification, and instance segmentation tasks. It is known for its accuracy and compact model size, making it a notable addition to the YOLO series, which has seen success with &lt;a href="https://github.com/ultralytics/yolov5"&gt;YOLOv5&lt;/a&gt;. With its improved architecture and user-friendly enhancements, YOLOv8 offers a great option for Computer Vision projects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JgtyqHho--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2Aq4tR6lbtWZLXArhO" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JgtyqHho--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3200/0%2Aq4tR6lbtWZLXArhO" alt="Comparison with other real-time object detectors: YOLOv8 achieves state-of-the-art (SOTA) performance [[Source](https://github.com/ultralytics/ultralytics)]" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Architecture and innovations
&lt;/h3&gt;

&lt;p&gt;While an official research paper for YOLOv8 is currently unavailable, an analysis of the repository and available information provide insights on its architecture. YOLOv8 introduces anchor-free detection, which predicts object centers instead of relying on anchor boxes. This approach simplifies the model and improves post-processing steps like Non-Maximum Suppression.&lt;/p&gt;

&lt;p&gt;The architecture also incorporates new convolutions and module configurations, leaning towards a ResNet-like structure. For a detailed visualization of the network's architecture, refer to the image created by GitHub user RangeKing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NBqY_C-3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2758/0%2AbS3JqYHRO5SJFycA" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NBqY_C-3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2758/0%2AbS3JqYHRO5SJFycA" alt="YOLOv8 model structure (non-official) [[Source](https://github.com/ultralytics/ultralytics/issues/189)]" width="800" height="838"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Training routine and augmentation
&lt;/h3&gt;

&lt;p&gt;The training routine of YOLOv8 incorporates mosaic augmentation, where multiple images are combined to expose the model to variations in object locations, occlusion, and surrounding pixels. However, this augmentation is turned off during the final training epochs to prevent performance degradation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accuracy and performance
&lt;/h3&gt;

&lt;p&gt;The accuracy improvements of YOLOv8 have been validated on the widely used COCO benchmark, where the model achieves impressive mean Average Precision (mAP) scores. For instance, the YOLOv8m-seg model achieves a remarkable 49.9% mAP on COCO. The following table provides a summary of the model sizes, mAP scores, and other performance metrics for different variants of YOLOv8-seg:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hpeihz0N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AV59Hv1ACwrnNRnYSBayKbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hpeihz0N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/1%2AV59Hv1ACwrnNRnYSBayKbg.png" alt="Comparison table" width="628" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is an example of outputs using YOLOv8x detection and instance segmentation models:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7XBKPIbp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AVdp5JUHIxcfELomN" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7XBKPIbp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AVdp5JUHIxcfELomN" alt="YOLOv8x detection and instance segmentation models [[Source](https://learnopencv.com/ultralytics-yolov8/)]" width="600" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step by step: Fine tune a pre-trained YOLOv8-seg model using Ikomia API
&lt;/h2&gt;

&lt;p&gt;With the dataset of aerial images that you downloaded, you can train a custom YOLO v7 model using the Ikomia API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: import and create workflow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;

&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Workflow&lt;/strong&gt; is the base object to create a workflow. It provides methods for setting inputs such as images, videos, and directories, configuring task parameters, obtaining time metrics, and accessing specific task outputs such as graphics, segmentation masks, and texts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We initialize a workflow instance. The “&lt;strong&gt;wf&lt;/strong&gt;” object can then be used to add tasks to the workflow instance, configure their parameters, and run them on input data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: add the dataset loader
&lt;/h2&gt;

&lt;p&gt;The downloaded COCO dataset includes two main formats: .JSON and image files. Images are split into train, val, test folders, with each associated a .json file containing the images annotations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Image file name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Image size (width and height)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;List of objects with the following information: Object class (e.g., "person," "car"); Bounding box coordinates (x, y, width, height) and Segmentation mask (polygon)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will use the dataset_coco module provided by Ikomia API to load the custom data and annotations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Add the dataset loader to load your custom data and annotations
&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;dataset_coco&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set the parameters of the dataset loader
&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_parameters&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;json_file&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Path/To/Mesophotic Coral/Dataset/train/_annotations.coco.json&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;image_folder&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Path/To/Mesophotic Coral/Dataset/train,
                    &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;instance_segmentation&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;
})
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: add the YOLOv8 segmentation model and set the parameters
&lt;/h2&gt;

&lt;p&gt;We add the ‘**train_yolo_v8_seg’ **task to our workflow for training our custom YOLOv8-seg model. To customize our training, we specify the following parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Add the YOLOv8 segmentation algorithm
&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;train_yolo_v8_seg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set the parameters of the YOLOv8 segmentation algorithm
&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_parameters&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;model_name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;yolov8m-seg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;batch_size&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;4&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;epochs&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;50&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;input_size&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;640&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;dataset_split_ratio&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;output_folder&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Path/To/Folder/Where/Model-weights/Will/Be/Saved&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here are the configurable parameters and their respective descriptions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;batch_size&lt;/strong&gt;: Number of samples processed before the model is updated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;epochs&lt;/strong&gt;: Number of complete passes through the training dataset.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;input_size&lt;/strong&gt;: Input image size during training and validation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;dataset_split_ratio&lt;/strong&gt;: the algorithm automatically divides the dataset into train and evaluation sets. A value of 0.8 means the use of 80% of the data for training and 20% for evaluation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You also have the option to modify the following parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;workers&lt;/strong&gt;: Number of worker threads for data loading. Currently set to '0'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;optimizer&lt;/strong&gt;: The optimizer to use. Available choices include SGD, Adam, Adamax, AdamW, NAdam, RAdam, RMSProp, and auto.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;weight_decay&lt;/strong&gt;: The weight decay for the optimizer. Currently set to '5e-4'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;momentum&lt;/strong&gt;: The SGD momentum/Adam beta1 value. Currently set to '0.937'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;lr0&lt;/strong&gt;: Initial learning rate. For SGD, it is set to 1E-2, and for Adam, it is set to 1E-3.&lt;strong&gt;‍&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;lrf&lt;/strong&gt;: Final learning rate, calculated as lr0 * lrf. Currently set to '0.01'.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: run your workflow
&lt;/h2&gt;

&lt;p&gt;Finally, we run the workflow to start the training process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can monitor the progress of your training using tools like Tensorboard or MLflow.&lt;/p&gt;

&lt;p&gt;Once the training is complete, the train_yolo_v8_seg task will save the best model in a folder named with a timestamp inside the output_folder. You can find your best.pt model in the weights folder of the time-stamped folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test your fine-tuned YOLOv8-seg model
&lt;/h2&gt;

&lt;p&gt;First, can we run a coral image on the pre-trained YOLOv8-seg model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;ikomia.utils.displayIO&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the workflow
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Add the YOLOv8 segmentation alrogithm
&lt;/span&gt;&lt;span class="n"&gt;yolov8seg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;infer_yolo_v8_seg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set the parameters of the YOLOv8 segmentation algorithm
&lt;/span&gt;&lt;span class="n"&gt;yolov8seg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_parameters&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;model_name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;yolov8m-seg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;conf_thres&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;iou_thres&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.7&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="c1"&gt;# Run on your image
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Path/To/Mesophotic Coral Identification.v1i.coco-segmentation/valid/TCRMP20221021_clip_LBP_T109_jpg.rf.a4cf5c963d5eb62b6dab06b8d4b540f2.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Inspect your results
&lt;/span&gt;&lt;span class="nf"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;yolov8seg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_image_with_mask_and_graphics&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0IJWtKT7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A_NZHJcaJkXsBzi6l" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0IJWtKT7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2A_NZHJcaJkXsBzi6l" alt="Coral detection using YOLOv8-seg pre-trained model" width="640" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can observe that the infer_yolo_v8_seg default pre-trained mistake a coral for a bear. This is because the model has been trained on the COCO dataset, which does not contain any coral objects.&lt;/p&gt;

&lt;p&gt;To test the model we just trained, we specify the path to our custom model using the &lt;strong&gt;’model_weight_file’&lt;/strong&gt; argument. We then run the workflow on the same image we used previously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Set the path of you custom YOLOv8-seg model to the parameter
&lt;/span&gt;&lt;span class="n"&gt;yolov8seg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_parameters&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;model_weight_file&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Path/To/Output_folder/[timestamp]/train/weights/best.pt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;conf_thres&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.5&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;iou_thres&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.7&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2FB8LqI4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AzPf_-wkqKUhFXSy-" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2FB8LqI4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AzPf_-wkqKUhFXSy-" alt="Coral detection using custom model" width="640" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Comparing our results to the &lt;a href="https://universe.roboflow.com/uvi/mesophotic-coral-identification/dataset/1/images/a4cf5c963d5eb62b6dab06b8d4b540f2"&gt;ground truth&lt;/a&gt;, we successfully identified the species &lt;em&gt;Orbicella spp&lt;/em&gt;. Nevertheless, we did observe some instances of false negatives. To enhance the performance of our custom model, further training for additional epochs and augmenting our dataset with more images could be beneficial.&lt;/p&gt;

&lt;p&gt;Another example showcasing effective detection results is demonstrated with the &lt;em&gt;Agaricia agaricites&lt;/em&gt; species:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QQJzUXKO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3120/0%2AnlMPw36loUJxBa4J" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QQJzUXKO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3120/0%2AnlMPw36loUJxBa4J" alt="YOLOv8 detectin of the coral species: Agaricia agaricites" width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Start training easily with Ikomia
&lt;/h2&gt;

&lt;p&gt;To learn more about the API, you can refer to the documentation. Additionally, you can explore the list of state-of-the-art algorithms on &lt;a href="https://app.ikomia.ai/hub/"&gt;Ikomia HUB&lt;/a&gt; and try out&lt;a href="https://www.ikomia.ai/studio"&gt; Ikomia STUDIO&lt;/a&gt;, which provides a user-friendly interface with the same features as the API.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>YOLOv7 real-time object detection</title>
      <dc:creator>gdemarcq</dc:creator>
      <pubDate>Mon, 04 Sep 2023 08:53:29 +0000</pubDate>
      <link>https://forem.com/gdemarcq/yolov7-real-time-object-detection-312j</link>
      <guid>https://forem.com/gdemarcq/yolov7-real-time-object-detection-312j</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XmKNnP-r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2462/0%2AtRPs4vhOtJcozj3m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XmKNnP-r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2462/0%2AtRPs4vhOtJcozj3m.jpg" alt="YOLOv7 illustration" width="800" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog post, we will outline the essential steps for achieving real-time object detection alongside your webcam.&lt;/p&gt;

&lt;p&gt;To this end, I will use the &lt;a href="https://github.com/Ikomia-dev/IkomiaApi"&gt;Ikomia API&lt;/a&gt; which enables you to utilize a ready-to-use detection model for real-time object detection in a video stream captured from your camera. To begin, you’ll need to install the API within a virtual environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/bonus/virtual_env.html"&gt;How to install a virtual environment&lt;/a&gt;‍&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;ikomia
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;API documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;API repo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Running YOLOv7 algorithm on your webcam using Ikomia API
&lt;/h2&gt;

&lt;p&gt;Alternatively, you can directly access the open-source &lt;a href="https://github.com/Ikomia-dev/notebooks/blob/main/examples/HOWTO_run_Camera_Stream_Processing_with_Ikomia_API.ipynb"&gt;notebook&lt;/a&gt; that we have prepared.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ik&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils.displayIO&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;cv2&lt;/span&gt;

&lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;VideoCapture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Init the workflow
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Add color conversion
&lt;/span&gt;&lt;span class="n"&gt;cvt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ocv_color_conversion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Add YOLOv7 detection
&lt;/span&gt;&lt;span class="n"&gt;yolo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_yolo_v7&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;conf_thres&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"0.7"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Test if streaming is OK
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;

    &lt;span class="c1"&gt;# Run workflow on image
&lt;/span&gt;    &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Display results from "yolo"
&lt;/span&gt;    &lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;yolo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_image_with_graphics&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Object Detection - press 'q' to quit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;viewer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"opencv"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Press 'q' to quit the streaming process
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;waitKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0xFF&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nb"&gt;ord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'q'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;

&lt;span class="c1"&gt;# After the loop release the stream object
&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Destroy all windows
&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;destroyAllWindows&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/P4DJ7vFnR1c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Camera stream processing
&lt;/h2&gt;

&lt;p&gt;Camera stream processing involves the real-time analysis and manipulation of images and video streams captured from a camera. This technique finds widespread application in diverse fields such as Computer Vision, surveillance, robotics, and entertainment.&lt;/p&gt;

&lt;p&gt;In Computer Vision, camera stream processing plays a pivotal role in tasks like object detection and recognition, face detection, motion tracking, and image segmentation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For &lt;strong&gt;surveillance&lt;/strong&gt; purposes, camera stream processing aids in detecting anomalies and events such as intrusion detection and crowd behavior analysis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the realm of &lt;strong&gt;robotics&lt;/strong&gt;, camera stream processing facilitates autonomous navigation, object detection, and obstacle avoidance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;entertainment&lt;/strong&gt; industry leverages camera stream processing for exciting applications like augmented reality, virtual reality, and gesture recognition.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Camera stream processing assumes a critical role across various domains, enabling the realization of numerous exciting applications that were once considered unattainable.&lt;/p&gt;

&lt;p&gt;To embark on camera stream processing, we will make use of OpenCV and VideoCapture with the YOLOv7 algorithm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_X4c7k9s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2048/0%2A9IaJY_W-xY2GxUPv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_X4c7k9s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2048/0%2A9IaJY_W-xY2GxUPv.jpg" alt="YoloV7 detection (Original [photo](https://www.pexels.com/photo/people-in-motion-on-platform-of-train-station-4485867/source) by Gustavo Juliette)" width="800" height="1066"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step by step: camera stream processing for object detection using Ikomia API
&lt;/h2&gt;

&lt;p&gt;Here are the detailed steps followed in the first code snippet with all parameters explained.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: import dependencies
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ik&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils.displayIO&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;cv2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;‘Workflow’&lt;/strong&gt; class is the base object for creating a workflow. It provides methods for setting inputs (image, video, directory), configuring task parameters, obtaining time metrics, and retrieving specific task outputs, such as graphics, segmentation masks, and texts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;‘ik’&lt;/strong&gt; is an auto-completion system designed for convenient and easy access to algorithms and settings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;‘display’&lt;/strong&gt; function offers a flexible and customizable way to display images (input/output) and graphics, such as bounding boxes and segmentation masks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;‘cv2’&lt;/strong&gt; corresponds to the popular OpenCV library.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: define the video stream
&lt;/h2&gt;

&lt;p&gt;Initialize a video capture object to retrieve frames from a camera device. Use the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;VideoCapture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The parameter &lt;code&gt;0&lt;/code&gt; passed to VideoCapture indicates that you want to capture video from the default camera device connected to your system. If you have multiple cameras connected, you can specify a different index to capture video from a specific camera (e.g., &lt;code&gt;1&lt;/code&gt; for the second camera), or you can give the path to a video.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: create workflow
&lt;/h2&gt;

&lt;p&gt;We initialize a workflow instance using the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;‘wf’&lt;/strong&gt; object can then be used to add tasks to the workflow instance, configure their parameters, and run them on input data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: add the OpenCV color conversion algorithm
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;cvt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ocv_color_conversion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, OpenCV uses the BGR color format, whereas Ikomia works with RGB images. To display the image output with the right colors, we need to flip the blue and red planes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: add the YOLOv7 Object Detection Model
&lt;/h2&gt;

&lt;p&gt;Add the &lt;strong&gt;‘infer_yolo_v7’&lt;/strong&gt; task, setting the pre-trained model and the confidence threshold parameter using the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;yolo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_yolo_v7&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'yolov7'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;conf_thres&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"0.7"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: run the workflow on the stream
&lt;/h2&gt;

&lt;p&gt;We read the frames from a video stream using a continuous loop. If there is an issue reading a frame, it skips to the next iteration.&lt;/p&gt;

&lt;p&gt;It then runs the workflow on the current frame and displays the results using OpenCV. The displayed image includes graphics generated by the "YOLO" object detection system.&lt;/p&gt;

&lt;p&gt;The displayed window allows the user to quit the streaming process by pressing the 'q' key. If the 'q' key is pressed, the loop is broken, and the streaming process ends.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Test if streaming is OK
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;

    &lt;span class="c1"&gt;# Run workflow on image
&lt;/span&gt;    &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Display results from "yolo"
&lt;/span&gt;    &lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;yolo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_image_with_graphics&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Object Detection - press 'q' to quit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;viewer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"opencv"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Press 'q' to quit the streaming process
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;waitKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mh"&gt;0xFF&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nb"&gt;ord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'q'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 7: end the video stream
&lt;/h2&gt;

&lt;p&gt;After the loop, release the stream object and destroy all windows created by OpenCV.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# After the loop release the stream object
&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Destroy all windows
&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;destroyAllWindows&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/f-jhZ2A9RBM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Perform real-time object detection from your own video stream
&lt;/h2&gt;

&lt;p&gt;By leveraging Ikomia API, developers can streamline the creation of Computer Vision workflows and explore various parameters to attain the best possible outcomes.&lt;/p&gt;

&lt;p&gt;For additional insights into the API, we recommend referring to the comprehensive &lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;documentation&lt;/a&gt;. Additionally, you can explore the selection of cutting-edge algorithms available on &lt;a href="https://github.com/Ikomia-hub"&gt;Ikomia HUB&lt;/a&gt; and experiment with &lt;a href="https://github.com/Ikomia-dev/IkomiaStudio"&gt;Ikomia STUDIO&lt;/a&gt;, a user-friendly interface that encompasses the same functionality as the API. Take advantage of these resources to further enhance your Computer Vision endeavors.&lt;/p&gt;

&lt;p&gt;Source of the illustration image: &lt;a href="https://www.freepik.com/free-photo/young-happy-businesswoman-wearing-headset-waving-while-video-conference-office_26346501.htm"&gt;Photo by Drazen Zigic.&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to train YOLOv7 object detection on a custom dataset</title>
      <dc:creator>gdemarcq</dc:creator>
      <pubDate>Wed, 30 Aug 2023 13:27:39 +0000</pubDate>
      <link>https://forem.com/gdemarcq/how-to-train-yolov7-object-detection-on-a-custom-dataset-g21</link>
      <guid>https://forem.com/gdemarcq/how-to-train-yolov7-object-detection-on-a-custom-dataset-g21</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wkwp0Y8f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2630/0%2AHnpwl4Ecbg7Qw5xl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wkwp0Y8f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2630/0%2AHnpwl4Ecbg7Qw5xl.jpg" alt="Featured image" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to train YOLOv7 object detection on a custom dataset using Ikomia API
&lt;/h2&gt;

&lt;p&gt;With the Ikomia API, we can train a custom YOLOv7 model with just a few lines of code. To get started, you need to install the API in a virtual environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/bonus/virtual_env.html"&gt;How to install a virtual environment&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install ikomia
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;API documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;API repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we will use the aerial airport dataset from Roboflow. You can download this dataset by following this link: &lt;a href="https://universe.roboflow.com/ds/W8grf6DmCF?key=QkQVA4pg66"&gt;Dataset Download Link&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the train YOLOv7 algorithm with a few lines of code using Ikomia API
&lt;/h2&gt;

&lt;p&gt;You can also charge directly the open-source &lt;a href="https://github.com/Ikomia-dev/notebooks/blob/main/examples/HOWTO_train_YOLO_v7_with_Ikomia_API_aerial_plane_dataset.ipynb"&gt;notebook&lt;/a&gt; we have prepared.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ik&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the workflow
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Add the dataset loader to load your custom data and annotations
&lt;/span&gt;&lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dataset_yolo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;dataset_folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/aerial/dataset/train"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;class_file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/aerial/dataset/train/_darknet.labels"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Add the Yolov7 training algorithm
&lt;/span&gt;&lt;span class="n"&gt;yolo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;train_yolo_v7&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;batch_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;epochs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;output_folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/output/folder"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Launch your training on your data
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The training process for 10 epochs was completed in approximately 14 minutes using an NVIDIA GeForce RTX 3060 Laptop GPU with 6143.5MB.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is YOLOv7?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What Makes YOLO popular for object detection?
&lt;/h3&gt;

&lt;p&gt;YOLO stands for “You Only Look Once”; it is a popular family of real-time object detection algorithms. The original YOLO object detector was first &lt;a href="https://arxiv.org/pdf/1506.02640.pdf"&gt;released &lt;/a&gt;in 2016. It was created by Joseph Redmon, Ali Farhadi, and Santosh Divvala. At release, this architecture was much faster than other object detectors and became state-of-the-art for real-time Computer Vision applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  High mean Average Precision (mAP)
&lt;/h3&gt;

&lt;p&gt;YOLO (You Only Look Once) has gained popularity in the field of object detection due to several key factors. making it ideal for real-time applications. Additionally, YOLO achieves higher mean Average Precision (mAP) than other real-time systems, further enhancing its appeal.&lt;/p&gt;

&lt;h3&gt;
  
  
  High detection accuracy
&lt;/h3&gt;

&lt;p&gt;Another reason for YOLO's popularity is its high detection accuracy. It outperforms other state-of-the-art models with minimal background errors, making it reliable for object detection tasks.&lt;/p&gt;

&lt;p&gt;YOLO also demonstrates good generalization capabilities, especially in its newer versions. It exhibits better generalization for new domains, making it suitable for applications that require fast and robust object detection. For example, studies comparing different versions of YOLO have shown improvements in mean average precision for specific tasks like the &lt;a href="https://ieeexplore.ieee.org/document/8970033"&gt;automatic detection of melanoma disease&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  An open-source algorithm
&lt;/h3&gt;

&lt;p&gt;Furthermore, YOLO's open-source nature has contributed to its success. The community's continuous improvements and contributions have helped refine the model over time.&lt;/p&gt;

&lt;p&gt;YOLO's outstanding combination of speed, accuracy, generalization, and open-source nature has positioned it as the leading choice for object detection in the tech community. Its impact in the field of real-time Computer Vision cannot be understated.‍&lt;/p&gt;

&lt;h2&gt;
  
  
  YOLO architecture
&lt;/h2&gt;

&lt;p&gt;The YOLO architecture shares similarities with &lt;a href="https://arxiv.org/pdf/1409.4842.pdf"&gt;GoogleNet&lt;/a&gt;, featuring convolutional layers, max-pooling layers, and fully connected layers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--toFb3X3o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2614/0%2AP2UBhFj_oTtoVup-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--toFb3X3o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2614/0%2AP2UBhFj_oTtoVup-.png" alt="GoogLeNet CNN based YOLO network architecture ([Source](https://arxiv.org/pdf/1506.02640.pdf))." width="800" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The architecture follows a streamlined approach to object detection and work as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Starts by resizing the input image to a fixed size, typically 448x448 pixels.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This resized image is then passed through a series of convolutional layers, which extract features and capture spatial information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The YOLO architecture employs a 1x1 convolution followed by a 3x3 convolution to reduce the number of channels and generate a cuboidal output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Rectified Linear Unit (ReLU) activation function is used throughout the network, except for the final layer, which utilizes a linear activation function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To improve the model's performance and prevent overfitting, techniques such as batch normalization and dropout are employed. Batch normalization normalizes the output of each layer, making the training process more stable. Dropout randomly ignores a portion of the neurons during training, which helps prevent the network from relying too heavily on specific features.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does YOLO object detection work?
&lt;/h2&gt;

&lt;p&gt;In terms of how YOLO performs object detection, it follows a four-step approach:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ytmJ9tqd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2216/0%2A3PIFIVlYFD0iWfaa.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ytmJ9tqd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2216/0%2A3PIFIVlYFD0iWfaa.jpg" alt="YOLO model ([source](https://www.ikomia.ai/blog/how-to-train-a-custom-yolov7-model-with-the-ikomia-api#))" width="800" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First, the image is divided into grid cells (SxS) responsible for localizing and predicting the object's class and confidence values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, bounding box regression is used to determine the rectangles highlighting the objects in the image. The attributes of these bounding boxes are represented by a vector containing probability scores, coordinates, and dimensions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Intersection Over Unions (IoU) is then employed to select relevant grid cells based on a user-defined threshold.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, Non-Max Suppression (NMS) is applied to retain only the boxes with the highest probability scores, filtering out potential noise.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Overview of the YOLOv7 model
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NX_xer9z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2474/0%2AwaxMUWhVpJpF8DNV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NX_xer9z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2474/0%2AwaxMUWhVpJpF8DNV.png" alt="Overview" width="800" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cuRO3hXR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AS9d2tHHY0egJkD_n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cuRO3hXR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AS9d2tHHY0egJkD_n.png" alt="YOLOv7 performance comparison with other real-time object detectors ([Source](https://github.com/WongKinYiu/yolov7))" width="800" height="597"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Compared to its predecessors, YOLOv7 introduces several architectural reforms that contribute to improved performance. These include:&lt;/p&gt;

&lt;p&gt;● Architectural reform:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Model scaling for concatenation-based models allows the model to meet the needs of different inference speeds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;E-ELAN (Extended Efficient Layer Aggregation Network) which allows the model to learn more diverse features for better learning.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;● Trainable Bag-of-Freebies (BoF) improving the model’s accuracy without increasing the training cost using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Planned re-parameterized convolution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Coarse for auxiliary and fine for lead loss.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;YOLO v7 introduces a notable improvement in resolution compared to its predecessors. It operates at a higher image resolution of 608 by 608 pixels, surpassing the 416 by 416 resolution employed in YOLO v3. By adopting this higher resolution, YOLO v7 becomes capable of detecting smaller objects more effectively, thereby enhancing its overall accuracy.&lt;/p&gt;

&lt;p&gt;These enhancements result in a 13.7% higher Average Precision (AP) on the COCO dataset compared to YOLOv6.‍&lt;/p&gt;

&lt;h2&gt;
  
  
  Parameters and FPS
&lt;/h2&gt;

&lt;p&gt;The YOLOv7 model has six versions with varying parameters and FPS (Frames per Second) performance. Here are the details:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y7uzzIQ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2330/0%2A5wMqp-7mpxnC8dYl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y7uzzIQ0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2330/0%2A5wMqp-7mpxnC8dYl.png" alt="* FPS comparisons were done on Tesla V100 GPU." width="800" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step by step: Fine tune a pre-trained YOLOv7 model using Ikomia API
&lt;/h2&gt;

&lt;p&gt;With the dataset of aerial images that you downloaded, you can train a custom YOLO v7 model using the &lt;a href="https://github.com/Ikomia-dev/IkomiaApi"&gt;Ikomia API&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: import
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflowfrom&lt;/span&gt; &lt;span class="n"&gt;ikomia&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;ik&lt;/span&gt;&lt;span class="err"&gt;‍&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“Workflow”&lt;/strong&gt; is the base object to create a workflow. It provides methods for setting inputs such as images, videos, and directories, configuring task parameters, obtaining time metrics, and accessing specific task outputs such as graphics, segmentation masks, and texts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;“ik”&lt;/strong&gt; is an auto-completion system designed for convenient and easy access to algorithms and settings.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: create workflow
&lt;/h2&gt;

&lt;p&gt;We initialize a workflow instance. The &lt;strong&gt;“wf”&lt;/strong&gt; object can then be used to add tasks to the workflow instance, configure their parameters, and run them on input data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: add the dataset loader
&lt;/h2&gt;

&lt;p&gt;The downloaded dataset is in YOLO format, which means that for each image in each folder (test, val, train), there is a corresponding .txt file containing all bounding box and class information associated with airplanes. Additionally, there is a _darknet.labels file containing all class names. We will use the dataset_yolo module provided by Ikomia API to load the custom data and annotations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dataset_yolo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;dataset_folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/aerial/dataset/train"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;class_file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to//aerial/dataset/train/_darknet.labels"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: add the YOLOv7 model and set the parameters
&lt;/h2&gt;

&lt;p&gt;We add a &lt;strong&gt;train_yolo_v7&lt;/strong&gt; task to train our custom YOLOv7 model. We also specify a few parameters:‍&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;yolo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;train_yolo_v7&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;batch_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;epochs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;output_folder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/output/folder"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;batch_size&lt;/strong&gt;: Number of samples processed before the model is updated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;epochs&lt;/strong&gt;: Number of complete passes through the training dataset.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;train_imgz&lt;/strong&gt;: Input image size during training.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;test_imgz&lt;/strong&gt;: Input image size during testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;dataset_spilt_ratio&lt;/strong&gt;: the algorithm divides automatically the dataset into train and evaluation sets. A value of 0.9 means the use of 90% of the data for training and 10% for evaluation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;“auto_connect=True ”&lt;/strong&gt; argument ensures that the output of the dataset_yolo task is automatically connected to the input of the train_yolo_v7 task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: apply your workflow to your dataset
&lt;/h2&gt;

&lt;p&gt;Finally, we run the workflow to start the training process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can monitor the progress of your training using tools like Tensorboard or MLflow.&lt;/p&gt;

&lt;p&gt;Once the training is complete, the &lt;strong&gt;train_yolo_v7&lt;/strong&gt; task will save the best model in a folder named with a timestamp inside the output_folder. You can find your best.pt model in the weights folder of the timestamped folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test your fine-tuned YOLOv7 model
&lt;/h2&gt;

&lt;p&gt;First, we can run an aerial image on the pre-trained YOLOv7 model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.dataprocess.workflow&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils.displayIO&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;display&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;ikomia.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ik&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the workflow
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Workflow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Add an Object Detection algorithm  
&lt;/span&gt;&lt;span class="n"&gt;yolo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_yolo_v7&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;thr_conf&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"0.4"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Run on your image
&lt;/span&gt;&lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/path/to/aerial/dataset/test/airport_246_jpg.rf.3d892810357f48026932d5412fa81574.jpg"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Inspect your results
&lt;/span&gt;&lt;span class="n"&gt;display&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;yolo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_image_with_graphics&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OGSsZdXW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2ASv1ldDSgVEGTQ-Gf.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OGSsZdXW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2ASv1ldDSgVEGTQ-Gf.jpeg" alt="Original image" width="600" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can observe that the infer_yolo_v7 default pre-trained model doesn’t detect any plane. This is because the model has been trained on the COCO dataset, which does not contain aerial images of airports. As a result, the model lacks knowledge of what an airplane looks like from above.&lt;/p&gt;

&lt;p&gt;To test the model we just trained, we specify the path to our custom model using the &lt;strong&gt;’model_weight_file’&lt;/strong&gt; argument. We then run the workflow on the same image we used previously.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Use your custom YOLOv7 model  
&lt;/span&gt;&lt;span class="n"&gt;yolo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;infer_yolo_v7&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_weight_file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"path/to/output_folder/timestamp/weights/best.pt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;thr_conf&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"0.4"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
    &lt;span class="n"&gt;auto_connect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sDX5WEcb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AkTNz9KQFzz8oxEr3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sDX5WEcb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2000/0%2AkTNz9KQFzz8oxEr3.png" alt="Planes detection on the image" width="600" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this comprehensive guide, we have dived into the process of fine-tuning the YOLOv7 pre-trained model, empowering it to achieve higher accuracy when identifying specific object classes.&lt;/p&gt;

&lt;p&gt;The Ikomia API serves as a game-changer, streamlining the development of Computer Vision workflows and enabling effortless experimentation with various parameters to unlock remarkable results.&lt;/p&gt;

&lt;p&gt;For a deeper understanding of the API's capabilities, we recommend referring to the &lt;a href="https://ikomia-dev.github.io/python-api-documentation/getting_started.html"&gt;documentation&lt;/a&gt;. Additionally, don't miss the opportunity to explore the impressive roster of advanced algorithms available on &lt;a href="https://app.ikomia.ai/hub/"&gt;Ikomia HUB&lt;/a&gt;, and take a spin with &lt;a href="https://github.com/Ikomia-dev/IkomiaStudio"&gt;Ikomia STUDIO&lt;/a&gt;, a user-friendly interface that mirrors the API's features.&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>datascience</category>
      <category>showdev</category>
    </item>
    <item>
      <title>A new open source tool for Computer Vision developers</title>
      <dc:creator>gdemarcq</dc:creator>
      <pubDate>Thu, 27 Oct 2022 09:59:22 +0000</pubDate>
      <link>https://forem.com/gdemarcq/a-new-open-source-tool-for-computer-vision-developers-101k</link>
      <guid>https://forem.com/gdemarcq/a-new-open-source-tool-for-computer-vision-developers-101k</guid>
      <description>&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;Here is the news we’ve been eager to share with you for weeks: we just released our Open Source Python API for Computer Vision! ✨&lt;/p&gt;

&lt;p&gt;Why is this a big step for all Computer Vision developers and data scientists?&lt;/p&gt;

&lt;p&gt;Too often, scientific and technological knowledge represent a barrier to building solutions based on AI. And yet a lot of fields would benefit from the numerous positive innovations it enables. &lt;/p&gt;

&lt;p&gt;That’s why we have been working on the Ikomia API these last months and can’t wait to receive your feedback 😀.&lt;/p&gt;

&lt;p&gt;Is it for you? You might wonder. It is if (multiple answers possible 😅):&lt;/p&gt;

&lt;p&gt;✅ you have a basic to average knowledge of Python and image analysis and need to build a Computer Vision solution,&lt;/p&gt;

&lt;p&gt;✅ you are fed up of searching endlessly for the right model,&lt;/p&gt;

&lt;p&gt;✅ you spend days testing algorithms and want to reduce this time tenfold,&lt;/p&gt;

&lt;p&gt;✅ you can’t wait to use several models together and chain them in a workflow,&lt;/p&gt;

&lt;p&gt;✅ you would like to benchmark your algorithm with others on your dataset and compare the results in real time,&lt;/p&gt;

&lt;p&gt;✅ you want to be able to switch easily between training models,&lt;/p&gt;

&lt;p&gt;✅ you are eager to finally share your work easily.&lt;/p&gt;

&lt;p&gt;Checked any box? Here is your next step:&lt;/p&gt;

&lt;p&gt;Go to our repo &lt;a href="https://github.com/Ikomia-dev/IkomiaApi"&gt;GitHub&lt;/a&gt; and &lt;code&gt;pip install ikomia&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As simple as that ! 😎&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>machinelearning</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
