본문 바로가기

프로그래밍/AI:ML:DL

[Yolo|번역] Yolo 에서 나오는 anchor box 개념에 대해 설명해 줄 수 있을까?

반응형

https://github.com/pjreddie/darknet/issues/568 의 타래 중에 도움이 되었던 몇 커멘트들을 번역해 보았다.

Yolo 에서 나오는 anchor box 개념에 대해 설명해 줄 수 있을까?

Can someone clarify the anchor box concept used in Yolo?


AlexeyAB

Anchor 는 검출객체 너비, 높이의 초기값으로 주어진 값들이다. 이 초기값이 리사이즈되서 실제 검출객체 크기가 된다.

// darknet/src/yolo_layer.c
// Lines 88 to 89 in 6f6e475

 b.w = exp(x[index + 2*stride]) * biases[2*n]   / w; 
 b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h; 
  • x[...] - 신경망 출력
  • biases[...] - anchor

b.w 와 b.h 결과가 바운딩박스의 너비와 높이가 되서 결과 이미지에서 보여질 것이다.

즉, 신경망은 물체의 최종 크기를 예측하는 것이 아니고, 가장 크기가 비슷한 anchor 에서 물체크기로의 조정값을 예측한다.

Yolo v3 anchor 는 이미지에서의 픽셀기준 물체 사이즈이고,
Yolo v2 anchor 는 최종 feature map 기준 사이즈이다. (Yolo v3 보다 32배 작은 값이 된다.)

AlexeyAB commented on 27 Mar 2018

Anchors are initial sizes (width, height) some of which (the closest to the object size) will be resized to the object size - using some outputs from the neural network (final feature map):

// darknet/src/yolo_layer.c
// Lines 88 to 89 in 6f6e475

 b.w = exp(x[index + 2*stride]) * biases[2*n]   / w; 
 b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h; 

x[...] - outputs of the neural network

biases[...] - anchors

b.w and b.h result width and height of bounded box that will be showed on the result image

Thus, the network should not predict the final size of the object, but should only adjust the size of the nearest anchor to the size of the object.

In Yolo v3 anchors (width, height) - are sizes of objects on the image that resized to the network size (width= and height= in the cfg-file).

In Yolo v2 anchors (width, height) - are sizes of objects relative to the final feature map (32 times smaller than in Yolo v3 for default cfg-files).


andyrey
아직도 이상한 게 있음.
Yolo v2 에서 anchor (width, height) 는 최종 feature map 에 상대적인 물체들의 크기다.
"최종 feature map" 크기란게 뭘 말하는 건가?
yolo-voc.2.0.cfg 에서 입력 이미지 사이즈는 416x416 이고,
anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52 이다.
각 쌍이 anchor의 너비와 높이인 것 같다.
그런데 마지막 anchor 의 16.62, 10.52 의 단위는 뭔가? 이 예에에 대해 설명해 줄 수 있나?
혹시 K-means 로 데이터셋에서 최적의 anchors 를 추출해 내는 코드를 올려줄 수 있을까?

fkoorc

내 생각엔 너의 anchor 값에 오류가 있는 것 같다. yolo2 에서 anchor 크기는 13x13 인 최종
feature map 이 기준이다. 그렇기 때문에, anchor 는 13x13 보다 작아야 한다.
하지만, yolo3 에서는 저자가 anchor 크기를 입력 이미지 크기 기준으로 단위를 바꾸었다.
저자가 써놓기를:
"YOLOv3 anchor 크기는 실제 픽셀값이다. 이렇게 하면 많은 것이 간단해지고, 구현이 약간 복잡해질 뿐이다.
내가 뭔가 놓치지 않았다면."

andyrey commented on 5 Nov 2018 •

Sorry, still unclear phrase
In Yolo v2 anchors (width, height) - are sizes of objects relative to the final feature map
What are "final feature map" sizes?
For yolo-voc.2.0.cfg input image size is 416x416,
anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52.
I got- each pair represents anchor width and height, centered in every of 13X13 cells.
The last anchor- 16.62 (width?), 10.52(height?)-what units they are? Can somebody explain litterally
with this example?
And, may be, someone uploaded the code for deducing best anchors from given dataset with K-means?

@fkoorc

fkoorc commented on 9 Nov 2018

I think maybe your anchor has some error. In yolo2 the anchor size is based on final feature map(13x13) as you said.
So the anchor aspect ratio must be smaller than 13x13
But in yolo3 the author changed anchor size based on initial input image size.
As author said:
"In YOLOv3 anchor sizes are actual pixel values. this simplifies a lot of stuff and was only a little bit harder to implement"
Hope I am not missing anything :)


ameeiyn

YOLO anchor 는 훈련하는 훈련셋 마다 다르게 정해진다. (디폴트 훈련셋은 PASECAL VOC 기반) ground truth 바운딩박스들의 너비와 높이를 정규화(normalize)하고 거기에 k-means 클러스터링을 해서, 5개의 값들을 얻는다.

최종값은 좌표가 아니라, 그리드기준 값이다. YOLO 디폴트 셋은:
anchors = 1.3221, 1.73145, 3.19275, 4.00944, 5.05587, 8.09892, 9.47112, 4.84053, 11.2364, 10.0071

이고, 이걸 다시 보면, 첫번째 anchor 인 [1.3221, 1.73145] 는 그리드셀 하나보다 조금 큰 것이고, 마지막 anchor 인 [11.2364, 10.0071] 는 거의 전체 이미지(13x13)를 차지하는 크기이다.

ameeiyn commented on 5 Mar

@AlexeyAB How do you get the initial anchor box dimensions after clustering? The width and height after clustering are all number s less than 1, but anchor box dimensions are greater of less than 1. How to get the anchor box dimensions?

YOLO's anchors are specific to dataset that is trained on (default set is based on PASCAL VOC). They ran a k-means clustering on the normalized width and height of the ground truth bounding boxes and obtained 5 values.

The final values are based on not coordinates but grid values. YOLO default set:
anchors = 1.3221, 1.73145, 3.19275, 4.00944, 5.05587, 8.09892, 9.47112, 4.84053, 11.2364, 10.0071
this means the height and width of first anchor is slightly over one grid cell [1.3221, 1.73145] and the last anchor almost covers the whole image [11.2364, 10.0071] considering the image is 13x13 grid.

Hope this gives you a bit clearer idea if not complete.

728x90