Image Segmentation made easy with YOLOv11-seg latest model
- Published on
- Vishal Maurya--3 min read
Overview
What in the hell is YOLO?
If you are reading this then it surely means you must have heard about yolo somewhere, I can surely assure you its not 'You only live once' 😆😆 Well in Computer science term its defined as You Only Look Once which is popular open source algorithm introuduced by Joseph Redmon. Just by reading it like you only look once, we get the gist of how this algorithm works, basically I will take a look at the image only one time i.e. during training after that I am confident enought find thing or objects in an image or video.
Now you got the gist of the Yolo, let's understand how this algorithm actually works there are various model that are currently present in yolo for the sake of this blog we will be focusing on the segmentation model.
What's new in YOLO11
- Enhanced Feature Extraction: Yolov11 architecture has deployed improvement in their backbone i.e. CNN for feature extraction. In a nut shell what CNN does is it takes an image as input and produces a series of output features it can be either edges, shapes, textures etc. They also improved their neck architecture which basically means combining the features generated by the backbone architecture to more precise predictions.
- Improved Speed and Perfomance: With the new 11 version we can see the bump of upto 25% increase in speed in comparison with last version, which is huge.
- Reduced number of parameters: With less number of parameters and same accuracy I think they did a great job for which we can say them Thank you!
- For more detailed information on changes you can visit YOLOV11 page.
Training Image Segmentation model
With YOLO models we can easily train state of the art image segmentation model with few lines of codes. Most difficult part is the data gathering and labelling, since that is not in the scope of this blog, we will use existing dataset from kaggle.
Once we have our dataset ready, we can prepare the environment like this:
Install ultralytics library:
pip install ultralytics
Import the methods and prepare the model:
import os
from ultralytics import YOLO
import yaml
# Loading the YOLO model
model = YOLO('yolo11n-seg.pt')
dataset_path = '/kaggle/input/pothole-image-segmentation-dataset/Pothole_Segmentation_YOLOv8'
# Set the path to the YAML file
yaml_file_path = os.path.join(dataset_path, 'data.yaml')
# Load the content of yaml file
with open(yaml_file_path, 'r') as file:
yaml_content = yaml.load(file, Loader=yaml.FullLoader)
To train the model we will use model.train method
results = model.train(
data=yaml_file_path, # Path to the dataset configuration file
epochs=150, # Number of epochs to train for
imgsz=640, # Size of input images as integer
patience=15, # Epochs to wait for no observable improvement for early stopping of training
batch=16, # Number of images per batch
optimizer='auto', # Optimizer to use, choices=[SGD, Adam, Adamax, AdamW, NAdam, RAdam, RMSProp, auto]
lr0=0.0001, # Initial learning rate
lrf=0.01, # Final learning rate (lr0 * lrf)
dropout=0.25, # Use dropout regularization
device=0, # Device to run on, i.e. cuda device=0
seed=42 # Random seed for reproducibility
)
This is as simple as that no need to manually define the Neural network architecture and all, just with few lines of code you can have a working neural network for pothole detection.
Here is the link to full kaggle notebook which has in depth knowledege on how each step is done: Kaggle Notebook.