অধ্যায়Phase 8 · রিয়েল-ওয়ার্ল্ড প্রজেক্ট
8.5 12 মিনিট পড়া

Industrial Defect Detection

Manufacturing QA।

🎬 গল্প দিয়ে শুরু
কারখানার production line-এ মানুষ চোখে দেখে defect খোঁজা — ক্লান্তি, inconsistency, miss rate। AI ক্যামেরা ২৪/৭ একই accuracy-তে কাজ করে। Garments, PCB, bottle, tile — সবখানে use।

Defect categories ও approach

  • Surface defect (crack, scratch, stain) → segmentation।
  • Shape/dimension mismatch → classical CV (contour, measure)।
  • Missing component (PCB chip, bottle cap) → object detection।
  • Color/print defect → color histogram + classification।
  • Unknown anomaly (যেকোনো অস্বাভাবিকতা) → Anomaly Detection।

দুটি training strategy

Supervised vs Anomaly
Supervised: defect-এর হাজারো labelled sample থাকলে YOLO/Unet।
Anomaly Detection: defect rare — শুধু "good" sample দিয়ে train, unusual সব flag। Industrial reality-তে এটাই বেশি practical।

Approach A — YOLOv8-seg দিয়ে scratch detect

text
Dataset: 800 good + 200 defect image, polygon-annotated (Roboflow)
Train:   yolo segment train model=yolov8n-seg.pt data=defect.yaml epochs=100
Deploy:  yolov8n-seg.engine on Jetson @ line camera
python
from ultralytics import YOLO
m = YOLO("defect_seg.engine")
res = m(frame)[0]
for mask, cls, conf in zip(res.masks.xy, res.boxes.cls, res.boxes.conf):
    if conf > 0.5:
        defect_area = cv2.contourArea(mask.astype("int32"))
        if defect_area > MIN_AREA:
            reject(frame, mask, cls)

Approach B — Anomaly Detection (PaDiM / PatchCore)

bash
pip install anomalib
python
from anomalib.data import Folder
from anomalib.models import Patchcore
from anomalib.engine import Engine

data = Folder(root="dataset", normal_dir="good", abnormal_dir="defect",
              image_size=(256, 256))
model = Patchcore()
Engine().fit(model=model, datamodule=data)
# inference: anomaly map (pixel-wise) + score
MVTec AD benchmark
PatchCore SOTA — শুধু good image দিয়ে train, AUROC ≈ 99%।

Approach C — Classical CV (cheap, fast)

python
# Template-based comparison
import cv2
ref = cv2.imread("good.jpg", 0)
def check(img):
    g = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    g = cv2.warpPerspective(g, align(g, ref), ref.shape[::-1])
    diff = cv2.absdiff(g, ref)
    _, th = cv2.threshold(diff, 30, 255, cv2.THRESH_BINARY)
    return cv2.countNonZero(th) > AREA_THRESHOLD
যখন কার্যকর
fixed jig + same lighting + same orientation — যেমন bottle cap inspection।

Lighting — সবচেয়ে underrated factor

  • Diffuse dome light — reflective surface (metal, glass)।
  • Backlight — silhouette / dimension।
  • Coaxial — scratch on shiny part।
  • Polarizer — glare কমাতে।
  • Strobe + global shutter camera — motion blur free।
Reality check
খারাপ lighting-এ best model-ও ফেল করে। ৫০% সফলতা lighting + mechanical setup-এ, ৩০% data quality-এ, ২০% model-এ।

System integration (PLC ↔ AI)

text
Conveyor encoder ─► PLC ─MQTT/Modbus─► AI station
                                       (capture trigger)
        ◄───── Reject signal (good/bad) ─────
  • Trigger-based capture (encoder pulse) — frame timing precise।
  • Result < 50 ms latency → PLC pneumatic rejector।
  • All decision log + image archive (audit trail)।
  • Periodic model retraining loop।

QC Dashboard metrics

  • Defect rate per hour / shift।
  • Top defect class Pareto chart।
  • False positive rate (operator override count)।
  • OEE — Overall Equipment Effectiveness।
প্র্যাকটিস টাস্ক
  1. MVTec AD dataset-এ anomalib PatchCore train ও AUROC মাপুন।
  2. ফোনের photo-তে template diff দিয়ে bottle cap missing detect করুন।
  3. Roboflow-এ scratch dataset annotate করে YOLOv8-seg train করুন।