Cookie Consent by Free Privacy Policy Generator Aktuallisiere deine Cookie Einstellungen ๐Ÿ“Œ YOLOv9 vs. YOLOv8: Segmentation & Fine-Tuning Guide


๐Ÿ“š YOLOv9 vs. YOLOv8: Segmentation & Fine-Tuning Guide


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Introduction

The YOLOv9 model for object segmentation was released recently, offering superior performance to the previous YOLOv8 model. This article will compare YOLOv8 and YOLOv9, showcase YOLOv9 segmentation, and include a guide for fine-tuning YOLOv9 on your own datasets.

Comparison and Showcase

In this section, we will compare YOLOv8 and YOLOv9 performance and quickly showcase YOLOv9 segmentation.

YOLOv8 vs. YOLOv9

The new YOLO model uses techniques such as Programmable Gradient Information (PGI) and Generalized Efficient Layer Aggregation Network (GELAN) to improve performance.

YOLOv8 vs YOLOv9 Performance Comparison

YOLOv9 demonstrates improved accuracy and efficiency for object segmentation, achieving higher precision and recall rates compared to YOLOv8ใ€12โ€ sourceใ€‘ใ€13โ€ sourceใ€‘.

Demo

YOLOv9e segmentation demo:

![YOLOv9 Training on Custom Data using Ultralytics]

Training

Itโ€™s possible to train YOLOv9 on your own segmentation data. The process can be divided into three steps: (1) Installation, (2) Dataset Creation, and (3) Fine-tuning/Training.

Installation

Begin by installing the Ultralytics framework:

pip install ultralytics

Dataset

Choose or create the dataset you need. The dataset needs to be in YOLO segmentation format, meaning each image shall have a corresponding text file (.txt) with the following content:

<class-index> <x1> <y1> <x2> <y2> ... <xn> <yn>
...
<class-index> <x1> <y1> <x2> <y2> ... <xn> <yn>

After finding a dataset and completing the image annotations, organize the dataset in the following way:

path/to/dataset/
โ”œโ”€ train/
โ”‚  โ”œโ”€ img_0000.jpg
โ”‚  โ”œโ”€ img_0000.txt
โ”‚  โ”œโ”€ ...
โ”‚  โ”œโ”€ img_0999.jpg
โ”‚  โ”œโ”€ img_0999.txt
โ”œโ”€ val/
โ”‚  โ”œโ”€ img_1000.jpg
โ”‚  โ”œโ”€ img_1000.txt
โ”‚  โ”œโ”€ ...
โ”‚  โ”œโ”€ img_1099.jpg
โ”‚  โ”œโ”€ img_1099.txt

Fine-Tuning

This section is for you if you want to train YOLOv9 on your custom data. If youโ€™re just looking to use the model, skip ahead to the section Inference and Segmentation.

First, begin by creating a training configuration file:

# train.yaml
path: path/to/dataset
train: train
val: val

names:
  0: person
  1: bicycle
  2: car
  # ...
  77: teddy bear
  78: hair drier
  79: toothbrush

The configuration file shall contain the paths to the training and validation sets, class names, and class mapping.

Finally, train the model using the Ultralytics framework:

from ultralytics import YOLO

model = YOLO("yolov9c-seg.yaml")
model.train(data="path/to/train.yaml", epochs=100)

Make sure to use the correct segmentation model depending on your time constraints and hardware:

  • yolov9c-seg.yaml
  • yolov9e-seg.yaml

Best Practices

If you want to optimize the training performance, read this guide:

YOLOv8: Best Practices for Training

Inference and Segmentation

Run inference:

results = model("images/sofa.jpg")

Plot segmented masks:

import numpy as np
import matplotlib.pyplot as plt
import cv2

for result in results:
    height, width = result.orig_img.shape[:2]
    background = np.ones((height, width, 3), dtype=np.uint8) * 255

    masks = result.masks.xy
    for mask in masks:
        mask = mask.astype(int)
        cv2.drawContours(background, [mask], -1, (0, 255, 0), thickness=cv2.FILLED)

    plt.imshow(background)
    plt.title('Segmented objects')
    plt.axis('off')
    plt.show()

    plt.imsave('segmented_objects.jpg', background)

Plot segmentation mask with original colors:

import cv2
import numpy as np
import matplotlib.pyplot as plt

for result in results:
    height, width = result.orig_img.shape[:2]
    background = np.ones((height, width, 3), dtype=np.uint8) * 255
    masks = result.masks.xy
    orig_img = result.orig_img

    for mask in masks:
        mask = mask.astype(int)
        mask_img = np.zeros_like(orig_img)

        cv2.fillPoly(mask_img, [mask], (255, 255, 255))
        masked_object = cv2.bitwise_and(orig_img, mask_img)
        background[mask_img == 255] = masked_object[mask_img == 255]

    background_rgb = cv2.cvtColor(background, cv2.COLOR_BGR2RGB)

    plt.imshow(background_rgb)
    plt.title('Segmented objects')
    plt.axis('off')
    plt.show()

    cv2.imwrite('segmented_objects.jpg', background)

Bonus: Comparison with Other Technologies

Let's briefly compare YOLO with another popular computer vision technology, such as Mask R-CNN, in terms of performance and ease of use.

  • Performance: YOLO models are generally faster but might be less accurate for complex segmentation tasks compared to Mask R-CNN.
  • Ease of Use: YOLO is simpler to set up and use for real-time applications, while Mask R-CNN can be more complex but offers finer segmentation.

Mask R-CNN vs YOLO

Word of the Day

Generalized Efficient Layer Aggregation Network (GELAN) - A technique used in YOLOv9 to enhance model performance by efficiently aggregating information across layers.

Conclusion

YOLOv9 offers significant improvements over YOLOv8, particularly in accuracy and efficiency for object segmentation tasks. Training and fine-tuning your own YOLOv9 model can be straightforward with the right dataset and tools. Don't hesitate to experiment and share your results!

Limitations:

The limitation of YOLO algorithm is that it struggles with small objects with in the image. The algorithm might not be able to detect very small object in the image, due to spatial constraints of the algorithm.

Courses & Projects

Feel free to ask any questions in the comments or reach out to me on Medium. Your feedback is valuable and helps me create better content for you.

Happy learning and coding!

...



๐Ÿ“Œ Train YOLOv8 Instance Segmentation on Your Data


๐Ÿ“ˆ 44.28 Punkte

๐Ÿ“Œ What is Network Segmentation? Virtual & Physical Segmentation | UpGuard


๐Ÿ“ˆ 30.77 Punkte

๐Ÿ“Œ Hosting YOLOv8 PyTorch models on Amazon SageMaker Endpoints


๐Ÿ“ˆ 29.95 Punkte

๐Ÿ“Œ Enhanced Object Detection: How To Effectively Implement YOLOv8


๐Ÿ“ˆ 29.95 Punkte

๐Ÿ“Œ Teeth caries detection using YOLOv8 neural network


๐Ÿ“ˆ 29.95 Punkte

๐Ÿ“Œ t3n Daily: Adobe &amp;amp; Figma, Ethereum &amp;amp; NFT, Steuer &amp;amp; Homeoffice, KI &amp;amp; Gruselfrau


๐Ÿ“ˆ 25.2 Punkte

๐Ÿ“Œ To Fine Tune or not Fine Tune? That is the question


๐Ÿ“ˆ 21.61 Punkte

๐Ÿ“Œ To Fine Tune or Not Fine Tune? That is the question


๐Ÿ“ˆ 21.61 Punkte

๐Ÿ“Œ Micro-Segmentation Zero Trust: Your Guide To The Fundamentals


๐Ÿ“ˆ 20.13 Punkte

๐Ÿ“Œ Micro-Segmentation Zero Trust: Your Guide To The Fundamentals


๐Ÿ“ˆ 20.13 Punkte

๐Ÿ“Œ http://umkm.padang.go.id/index.php?option=com_content&amp;amp;view=article&amp;amp;id=46&amp;amp;Itemid=78


๐Ÿ“ˆ 18.9 Punkte

๐Ÿ“Œ http://swat.sragenkab.go.id/index.php?option=com_content&amp;amp;view=article&amp;amp;id=76&amp;amp;Itemid=27


๐Ÿ“ˆ 18.9 Punkte

๐Ÿ“Œ #0daytoday #Ruby &amp;lt; 2.2.8 / &amp;lt; 2.3.5 / &amp;lt; 2.4.2 / &amp;lt; 2.5.0- [#0day #Exploit]


๐Ÿ“ˆ 16.8 Punkte

๐Ÿ“Œ #0daytoday #Drupal &amp;lt; 7.58 / &amp;lt; 8.3.9 / &amp;lt; 8.4.6 / &amp;lt; 8.5.1 [#0day #Exploit]


๐Ÿ“ˆ 16.8 Punkte

๐Ÿ“Œ #0daytoday #Linux/ARM - execve(&amp;quot;/bin/sh&amp;quot;, [&amp;quot;/bin/sh&amp; [#0day #Exploit]


๐Ÿ“ˆ 16.8 Punkte

๐Ÿ“Œ Neu bei Amazon Prime Video im April: &quot;Bibi &amp; Tina&quot; &quot;Tales from the Loop&quot; und &quot;Falling Snow&quot; starten


๐Ÿ“ˆ 16.8 Punkte

๐Ÿ“Œ Neu im TV und bei Sky: &quot;Suits&quot;, &quot;Das Boot&quot;, &quot;Better Call Saul&quot; und &quot;What We Do in the Shadows&quot;


๐Ÿ“ˆ 16.8 Punkte

๐Ÿ“Œ &quot;The Batman&quot;, &quot;Avatar&quot;, &quot;The Witcher&quot; &amp; Co.: Die Dreharbeiten gehen nach Corona-Pause wieder weiter!


๐Ÿ“ˆ 16.8 Punkte

๐Ÿ“Œ Samsung-Geheimsprache geknackt: Das bedeuten &quot;Water&quot;, &quot;Merlot&quot;, &quot;Wise&quot; und &quot;Fresh&quot;


๐Ÿ“ˆ 16.8 Punkte

๐Ÿ“Œ Super Bowl 2024: &quot;Deadpool &amp; Wolverine&quot;, &quot;Planet der Affen&quot;, &quot;Wicked&quot; und mehr - alle neuen Film-Trailer


๐Ÿ“ˆ 16.8 Punkte

๐Ÿ“Œ How To Fine-Tune Large Language Models: A Step-By-Step Guide


๐Ÿ“ˆ 16.6 Punkte

๐Ÿ“Œ ML Kit is now in GA & Introducing Selfie Segmentation


๐Ÿ“ˆ 16.43 Punkte

๐Ÿ“Œ AT&amp;T Hit With $23 Million Fine For Bribing Illinois Lawmaker


๐Ÿ“ˆ 15 Punkte

๐Ÿ“Œ #0daytoday #Nutanix AOS &amp;amp; Prism &amp;lt; 5.5.5 (LTS) / &amp;lt; 5.8.1 (STS) - S [#0day #Exploit]


๐Ÿ“ˆ 14.7 Punkte

๐Ÿ“Œ Die Kino-Flaute geht weiter: &quot;Top Gun&quot;, &quot;Avatar&quot;, Mulan&quot; und &quot;Spider-Man&quot; werden verschoben


๐Ÿ“ˆ 14.7 Punkte

๐Ÿ“Œ Brie Larson aus &quot;Captain Marvel&quot;: Wird sie in &quot;Fast &amp; Furious 10&quot; zur Schwester von Brian O&#039;Conner?


๐Ÿ“ˆ 14.7 Punkte

๐Ÿ“Œ 1899 - Kritik: Spannender Mix aus &quot;Dark&quot;, &quot;Lost&quot; und &quot;Westworld&quot; - So gut ist Netflix&#039; neue Mystery-Serie


๐Ÿ“ˆ 14.7 Punkte











matomo