1. object detection이란

 

한 이미지에서 물체를 둘러싼 사각형(bounding box)를 탐지하는 것으로 
일반적으로 이미지를 입력으로 받고, bounding box와 그에 대응하는 예측 클래스와 클래스의 신뢰도(confidence)를 출력한다. 

 

출처 : https://deep-eye.tistory.com/6

2. IOU (intersection over union)

 

출처 : https://pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/

정답 값과 모델이 예측한 사각형이 얼마나 겹치는 지를 나타내는 지표이며 높을수록 잘 예측한 모델이다.

import numpy as np

def compute_iou(pred_box, gt_box):
  x1 = np.maximum(pred_box[0], gt_box[0]) 
  y1 = np.maximum(pred_box[1], gt_box[1])
  x2 = np.maximum(pred_box[2], gt_box[2])
  x2 = np.maximum(pred_box[3], gt_box[3])

  intersection = np.maximum(x2 - x1, 0 ) * np.maximum(y2 - y1, 0)

  pred_box_area = (pred_box[2] - pred_box[0]) * (pred_box[3]- pred_box[1])
  gt_box_area = (gt_box[2] - gt_box[0]) * (gt_box[3]- gt_box[1])

  union = pred_box_area + gt_box_area - intersection

  iou = intersection / union
  return iou

pred_box와 gt_box 는 각각 

 

 

3. NMS(non maximum suppression, 비최댓값 억제)

 

한가지 object에 여러가지 bbox가 겹쳤을 경우

확률이 가장 높은 상자와 겹치는 상자들을 제거하는 과정

 

1) 확률 기준으로 모든 상자를 정렬하고 먼저 가장 확률이 높은 상자를 취함
2) 각 상자에 대해 다른 모든 상자와의 IOU를 계산
3) 특정 임곗값을 넘는 상자는 제거 (너무 겹치는 녀석을 없앤다)

 

위와 같은 과정으로 이루어진다.

https://pyimagesearch.com/2015/02/16/faster-non-maximum-suppression-python/

def non_max_suppression_fast(boxes, overlap_thresh):
  if len(boxes) ==0:
    return []
  if boxes.dtype.kind == 'i':
    boxes = boxes.astype('float')

  pick = []
  x1, y1, x2, y2 = boxes[:,0], boxes[:,1], boxes[:,2], boxes[:,3]

  area = (x2 -x1 + 1) - (y2 - y1 +1)
  idxs = np.argsort(y2)

  while len(idxs) > 0:
    last = len(idxs) - 1
    i = idxs[last]
    pick.append(i)

    xx1 = np.maximum(x1[i], x1[idxs[:last]])
    yy1 = np.maximum(y1[i], y1[idxs[:last]])
    xx2 = np.maximum(x2[i], x2[idxs[:last]])
    yy2 = np.maximum(y2[i], y2[idxs[:last]])

    w = np.maximum(0, xx2 - xx1 +1)
    h = np.maximum(0, yy2 - yy1 +1)

    overlap = (w*h) / area[idxs[last]]

    idxs = np.delete(idxs, np.concatenate(([last], np.where(overlap > overlap_thresh)[0])))

  return boxes[pick].astype('int')

 

4. 모델 성능평가

 

4-1. 정밀도와 재현율

https://towardsdatascience.com/precision-and-recall-made-simple-afb5e098970f

 

모델이 객체 존재를 엄격하지 않게하면 FP가 커져 precision(정밀도)이 낮아지고

너무 엄격해서 FN이커져 recall(재현율)이 낮아지게된다.

 

 

 

4-2 정밀도 재현율 곡선

 

https://github.com/ultralytics/yolov3/issues/898

 

T이하는 제거하는 임계값 T에 따라 정밀도와 재현율이 달라지게 된다.

- 0 < T < 1 

- T가 1에 가까우면 놓치는 객체가 많아져 재현율이 낮아지고 신뢰도가 높은 예측만 유지하여 정밀도는 높아진다.

- T가 0에 가까우면 대부분의 예측을 유지하기에 재현율은 높어자고 정밀도는 낮아진다.

 

예를 들어 모델이 보행자를 참지하면 이유없이 차를 세우더라도 보행자를 놓지지않도록 재현율을 높여야한다.

 

 

4-3 AP, mAP

 

위 그래프의 곡선 아래영역의 넓이이다. 

항상 0~1사이 값을 가지며

단일 클래스에 대한 모델성능 정보를 제공한다.

데이터셋이 10개의 클래스로 구성된다면 각 클래스에 대한 ap를 계산하고 그의 평균인 map를 구한다.

 

 

'CV > object detection' 카테고리의 다른 글

[CV] fast-R-cnn  (0) 2022.06.01
[cv] SPP-net  (0) 2022.06.01
[CV] R-CNN  (0) 2022.06.01

+ Recent posts