Object detection 예시
입력 이미지에 포함된 객체의 위치 및 크기와 종류를 추론하는 작업
하나의 입력 이미지에 여러 개의 객체가 포함될 수 있음
모델의 output은 보통 3가지
Bounding box는 객체의 위치와 크기를 의미
객체의 존재 유무는 binary classification과 비슷
객체의 종류에 대한 output은 multi-class classification과 비슷
Mean Average Precision(mAP) : 각 class 별 Average Precision(AP)를 구하고, 평균을 구함
mAP를 구하는 과정
1. Detection model output 취득
2. Non-Maximum Suppression (NMS) 적용
Detection model은 구조상 하나의 객체에 대해서 여러 개의 bounding box를 예측할 수도 있음 (아래 "주요 연구" 파트 참조)
따라서 bounding box들의 IoU를 계산하여 과도하게 겹쳐있는 bounding box들은 하나의 객체에 대한 예측이라고 생각하고, 가장 높은 confidence score를 가진 bounding box만 남기고 나머지는 제거
IoU: 두 bounding box가 겹친 영역과 두 bounding box의 전체 영역 사이의 비율
Sample code: bounding box는 (cx, cy, w, h)로 표현
def batch_iou(boxes, box):
# 겹치는 부분의 너비 계산
lr = np.maximum(
np.minimum(boxes[:,0]+0.5*boxes[:,2], box[0]+0.5*box[2]) - \
np.maximum(boxes[:,0]-0.5*boxes[:,2], box[0]-0.5*box[2]),
0
)
# 겹치는 부분의 높이 계산
tb = np.maximum(
np.minimum(boxes[:,1]+0.5*boxes[:,3], box[1]+0.5*box[3]) - \
np.maximum(boxes[:,1]-0.5*boxes[:,3], box[1]-0.5*box[3]),
0
)
inter = lr*tb
union = boxes[:,2]*boxes[:,3] + box[2]*box[3] - inter
return inter/union
def nms(boxes, confidence, threshold):
# 내림차순으로 정렬
order = confidence.argsort()[::-1]
# 개수 대로 true 리스트 생성
keep = [True]*len(order)
for i in range(len(order)-1):
# IOU 계산 (특정 bounding box와 그 이하의 confidence를 가진 bounding box들)
ovps = batch_iou(boxes[order[i+1:]], boxes[order[i]])
for j, ov in enumerate(ovps):
if ov > threshold:
# IOU가 특정 threshold 이상인 box를 False로 세팅
keep[order[j+i+1]] = False
return boxes[keep]
3. Class 별 AP 계산
AP를 계산할 class를 선택하고 해당하는 class에 대한 bounding box와 confidence 값을 추출 (각 bounding box의 class 예측 결과 중 해당 선택 class의 수치가 가장 높은 경우)
예측된 bounding box들과 precision, recall 계산 결과
Bounding box를 confidence score에 따라 정렬
각 confidence를 confidence threshold로 설정하여 각 threshold 마다의 precision, recall을 계산 : 위 표에 따라 처음에는 threshold를 95% 두고 계산, 그 다음은 91%, 그 다음은 88%, ...
TP: confidence threshold 이상의 확률을 갖는 예측 bounding box들 중 일정 수치(IoU threshold) 이상의 IoU를 갖는 ground-truth bounding box가 존재하는 것의 개수
FP: confidence threshold 이상의 확률을 갖는 예측 bounding box들 중 일정 수치(IoU threshold) 이상의 IoU를 갖는 ground-truth bounding box가 없는 것의 개수
FN: ground-truth bounding box 중 일정 수치(IoU threshold) 이상의 예측 bounding box가 없는 것의 개수
Precision = TP/(TP+FP), Recall = TP/(TP+FN)
모든 confidence threshold에 대해 반복하고, 이를 이용하여 다음과 같은 그래프 작성
Precision-Recall(PR) curve
해당 그래프의 아래 면적(AUC)이 AP
다만 그래프의 모양이 부드러운 곡선이 아닌 지그재그 모양이기 때문에 계산의 용의성을 위해 N-point interpolation, All-point interpolation 등을 사용(dataset마다 공식적으로 사용하는 방법이 다름)
11-point interpolation: recall을 11개의 간격(0, 0.1, 0.2, ..., 1)으로 나누고, 각 위치마다 현재 Recall보다 큰 Recall의 precision 중 가장 큰 값(max)을 취하여 얻은 모든 precision을 평균내어 AP를 구함
11-point interpolation 예시
All-point interpolation: 위와 원리는 같으나 일정 간격마다 interpolation 하는 것이 아니라 그래프의 각 점에서 interpolation하여 아래 그림과 같이 그래프를 단순화하고, 아래 면적을 구함
All-point interpolation 예시
4. mAP 계산
(R-CNN)1. R-CNN구조
(R-CNN)2. Selective Search
목표
Method
Selective search는 <(R-CNN)2>와 같이 입력 영상의 색상, 명암 등의 정보를 기반으로 픽셀을 군집화하여 각 객체의 위치를 찾음. 이러한 방법을 사용하여 입력 영상 내 관심 객체가 존재할 것 같은 위치(초록색 box)를 다수 추출하고, 일정한 크기로 resizing 한 후, 다음의 CNN 모듈로 전달함. Region proposal 단계라고도 함.
Feature extraction을 위한 CNN 모듈을 각 region proposal에 적용하며, R-CNN 논문에서는 pretrain된 AlexNet을 detection 데이터셋에서 fine tune하여 사용
추출된 Feature에 SVM에 적용하여 입력된 영역에 포함된 관심 객체의 종류를 구분하는 classifier 학습
추출된 Feature에 Bounding box regressor를 적용하여 selective search의 결과를 보정하고, 더욱 정확한 bounding box를 추출함
NMS를 적용하여 대표 bounding box만 남김
특징
목표
Method
(Fast R-CNN)1. Fast R-CNN구조
(Fast R-CNN)2. RoI Pooling 방법
Selective search를 사용하여 region proposal 추출
VGG16 등의 모델에 전체 이미지를 입력하여 feature map 추출
원본 이미지 크기와 feature map의 크기 간 비율을 이용하여, 1단계에서 추출된 region proposal을 feature map에 projection. 이를 통해 feature map 상에서의 region proposal을 추출함
Feature map 상에서 추출된 region proposal에 RoI Pooling을 적용하여 모두 같은 크기의 feature가 되도록 함.
추출된 각 RoI에 대해서 FC layer 등을 적용하여 classfication 및 bounding box regression을 수행
NMS를 적용하여 대표 bounding box만 남김
특징
목표
Method
(Faster R-CNN)1. Faster R-CNN구조
(Faster R-CNN)2. Anchor Box 예시
(Faster R-CNN)3. RPN(Region Proposal Network)
전체 이미지를 CNN 네트워크에 입력하여 feature를 추출
1번 단계에서 추출한 feature map을 RPN에 입력하여 region proposal 추출
추출된 region proposal를 사용하여 1번 단계에서 추출한 feature map에 대해 RoI projection, RoI pooling을 적용
각 RoI에 대해서 classfication 및 bounding box regression을 수행
NMS를 적용하여 대표 bounding box만 남김
특징
목표
Method
특징
목표
Method
특징