နားလည်ထားရမယ့် အချက်
Classification model ကို evaluate လုပ်တာက ရိုးရှင်းသည် — predicted label သည် true label နှင့် အတိအကျ ကိုက်ညီသလား ('correct' ဟုတ်/မဟုတ်) ဆိုတဲ့ binary question တစ်ခုသာ ဖြစ်သည်။ Object detection ကတော့ ဒီလို binary ပြဿနာ မဟုတ်တော့ပါ — predicted box သည် ground-truth box နှင့် အတိအကျ ကိုက်ညီဖို့ (pixel-perfect) မျှော်လင့်ထားလို့ မရနိုင်သောကြောင့် (annotator လူတစ်ဦးချင်းစီ ဆွဲထားတဲ့ box တောင် အနည်းငယ် ကွာနိုင်သည်), 'ဘယ်လောက် ကောင်းကောင်း ကိုက်ညီမှ correct လို့ ယူဆမလဲ' ဆိုတဲ့ threshold တစ်ခု လိုအပ်လာသည်။ ဒီနေရာမှာ IoU က threshold-based decision အတွက် metric ကို ပေးထားသည် — IoU ≥ 0.5 (ဥပမာ) ရှိမှသာ ဒီ prediction ကို 'true positive' ဟု ယူဆမည်၊ IoU ဒီထက် နိမ့်ရင် (box ရှိသော်လည်း misaligned) ၎င်းကို 'false positive' အဖြစ် treat လုပ်မည်။
Threshold တစ်ခုတည်းသာ မကျေနပ်ဘဲ IoU threshold မတူညီ (0.5, 0.75, စသည်) များအလိုက် precision/recall တွက်ချက်ကာ average ချ ယူလိုက်ခြင်းသည် mAP (mean Average Precision) ၏ core idea ဖြစ်သည် — model တစ်ခုသည် loose threshold (0.5) မှာ ကောင်းစွာ perform လုပ်ပေမယ့် strict threshold (0.9) မှာ performance ကျဆင်းသွားခြင်းဖြင့် bounding box localization ၏ precision level ကို ပိုမိုအသေးစိတ် သိရှိနိုင်သည်။ ဒီလိုနည်းလမ်းက classification accuracy ထက် ပိုမိုနက်ရှိုင်းသော information ကို ပေးသည် — classification တွင် 'correct/incorrect' ကလွဲလို့ intermediate quality level ဆိုတာ မရှိသလောက်ဖြစ်ပြီး, detection တွင်တော့ localization quality သည် continuous spectrum တစ်ခု ဖြစ်နေသောကြောင့်ပင်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Tutorial Platform တွင် course video ထဲက slide screenshot ပေါ်ရှိ watermark/logo area ကို auto-detect လုပ်မည့် feature တစ်ခု ship လုပ်ဖို့ ပြင်ဆင်နေသည်ဆိုပါစို့။ Production သို့ deploy မလုပ်မီ, hand-labeled test set တစ်ခုပေါ်တွင် model ၏ predicted watermark box များကို IoU ≥ 0.5 threshold ဖြင့် correct/incorrect စစ်ဆေးကာ detection rate ရာနှုန်းသတ်မှတ်ချက် (ဥပမာ 90%) ကို ကျော်မှသာ feature ကို ship လုပ်ရန် decision gate တစ်ခုအဖြစ် သုံးနိုင်သည်။
အတူတူ စမ်းရေးကြည့်မယ်
import torch
def compute_iou(box1, box2):
x1 = torch.max(box1[0], box2[0])
y1 = torch.max(box1[1], box2[1])
x2 = torch.min(box1[2], box2[2])
y2 = torch.min(box1[3], box2[3])
inter_width = (x2 - x1).clamp(min=0)
inter_height = (y2 - y1).clamp(min=0)
intersection = inter_width * inter_height
area1 = (box1[2] - box1[0]) * (box1[3] - box1[1])
area2 = (box2[2] - box2[0]) * (box2[3] - box2[1])
union = area1 + area2 - intersection
return intersection / union
def is_correct_detection(pred_box, gt_box, iou_threshold=0.5):
iou = compute_iou(pred_box, gt_box)
return iou.item() >= iou_threshold
ground_truth = torch.tensor([0.0, 0.0, 10.0, 10.0])
good_prediction = torch.tensor([1.0, 1.0, 11.0, 11.0])
bad_prediction = torch.tensor([8.0, 8.0, 18.0, 18.0])
for name, pred in [("good_prediction", good_prediction), ("bad_prediction", bad_prediction)]:
iou = compute_iou(pred, ground_truth)
correct = is_correct_detection(pred, ground_truth, iou_threshold=0.5)
print(f"{name}: IoU={iou.item():.4f}, correct={correct}")
'good_prediction: IoU=0.6807, correct=True' နှင့် 'bad_prediction: IoU=0.0204, correct=False' ဟု line နှစ်ကြောင်း print ထုတ်မည်။ good_prediction ([1,1,11,11]) သည် ground_truth ([0,0,10,10]) နှင့် overlap area 81 ရှိပြီး union 119 ဖြစ်ကာ IoU=81/119≈0.6807 (threshold 0.5 ထက် ကျော်သောကြောင့် correct); bad_prediction ([8,8,18,18]) သည် overlap area 4 သာရှိပြီး union 196 ဖြစ်ကာ IoU=4/196≈0.0204 (threshold ထက် နိမ့်သောကြောင့် incorrect) ဖြစ်သည်။၅ မိနစ် စမ်းကြည့်
predicted box အစုအဝေးတစ်ခု (list of tensors) နှင့် corresponding ground-truth box list ကို လက်ခံပြီး, correct detection အရေအတွက်ကို total prediction အရေအတွက်ဖြင့် စားလိုက်သော 'detection accuracy' ကို ပြန်ပေးမည့် function တစ်ခု ရေးပါ၊ ပြီးလျှင် iou_threshold ကို 0.5 မှ 0.75 သို့ ပြောင်းလိုက်လျှင် detection accuracy ဘယ်လို ပြောင်းလဲသွားသလဲ observe လုပ်ပါ။
သတိလေးတစ်ချက်
Classification accuracy ကို object detection မှာ တိုက်ရိုက် သုံးမိလျှင် (localization quality ကို လုံးဝ ထည့်မတွက်ဘဲ class label တစ်ခုတည်း ကိုက်/မကိုက်ကိုသာ ကြည့်ခြင်း) box position လွဲနေသော်လည်း class label မှန်ရင် 'correct' ဟု အလွဲသုံးစားခံရနိုင်သည်။
iou_threshold ကို task requirement နှင့် မလိုက်ဘဲ 0.5 ကို default value အဖြစ် အမြဲတမ်း သုံးမိလျှင် (ဥပမာ precise auto-crop လိုအပ်သော feature အတွက်) loose threshold ကြောင့် အမှန်တကယ် misaligned box များကို 'correct' ဟု အလွဲသတ်မှတ်နိုင်သည်။
Wikipedia — Jaccard index — Computer Vision