Chapter 24
YOLO
YOLO
🎬 You Only Look Once
YOLO পুরো ইমেজকে একটিমাত্র forward pass-এ গ্রিডে ভাগ করে — প্রতিটি cell-এ box ও class prediction। ফল: real-time detection, যা CCTV থেকে self-driving cars পর্যন্ত সর্বত্র ব্যবহার হয়।
YOLO-র মূল ধারণা
- ইমেজকে S×S গ্রিডে ভাগ — প্রতিটি cell B টি box predict করে।
- প্রতিটি box: (x, y, w, h, confidence) + class probabilities।
- Single network → end-to-end → real-time।
- NMS দিয়ে overlapping box ছাঁকা।
সংস্করণ-এ ক্রমবিকাশ
সংস্করণ
মূল পরিবর্তন
বছর
YOLOv1
Grid-based, একক network
2016
YOLOv3
Multi-scale, Darknet-53
2018
YOLOv4
CSPDarknet, Mosaic aug
2020
YOLOv5
PyTorch, ease-of-use
2020
YOLOv8
Anchor-free, multi-task
2023
YOLOv11
Improved backbone
2024
Ultralytics দিয়ে দ্রুত শুরু
pip install ultralytics
from ultralytics import YOLO
model = YOLO("yolov8n.pt") # nano — দ্রুত
results = model("street.jpg")
results[0].show()
results[0].save("out.jpg")নিজের ডেটায় Train (Custom)
# data.yaml
path: ./dataset
train: images/train
val: images/val
names: ["helmet", "no_helmet"]
# label ফাইল (per image .txt):
# class_id x_center y_center width height (সব normalized)
model = YOLO("yolov8s.pt")
model.train(data="data.yaml", epochs=50, imgsz=640, batch=16)
model.val()
model.predict("test.jpg", save=True)Multi-task — Detect, Segment, Pose, Classify
YOLO("yolov8n.pt") # detection
YOLO("yolov8n-seg.pt") # instance segmentation
YOLO("yolov8n-pose.pt") # keypoint / pose
YOLO("yolov8n-cls.pt") # classificationReal-time Webcam
import cv2
from ultralytics import YOLO
model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture(0)
while cap.isOpened():
ok, frame = cap.read()
if not ok: break
res = model(frame, verbose=False)
cv2.imshow("YOLO", res[0].plot())
if cv2.waitKey(1) == ord("q"): break
cap.release()🔑 Model size choice
n (nano) → s → m → l → x। ছোট model দ্রুত কিন্তু কম accurate। Edge device-এ n/s, সার্ভারে m/l/x সাধারণ পছন্দ।
Export — Deployment
model.export(format="onnx") # ONNX
model.export(format="engine") # TensorRT
model.export(format="coreml") # iOS
model.export(format="tflite") # Mobileঅনুশীলন
১. Pretrained YOLOv8n দিয়ে আপনার নেওয়া ১০টি ইমেজে inference চালান।
২. Roboflow থেকে ছোট dataset নিয়ে custom YOLOv8 train করুন।
৩. Webcam-এ real-time inference চালিয়ে FPS measure করুন।
সারসংক্ষেপ
✨ এই অধ্যায়ে যা শিখলাম
- YOLO = single-pass real-time detector।
- Ultralytics দিয়ে training/inference কয়েক লাইনে।
- Multi-task: detect, segment, pose, classify।