[OCR] PixelLink
[2022.11월 OCR 개발 관련 survey]
<PixelLink: Detecting Scene Text via Instance Segmentation>
최신 STD(Scene Text Detection) 알고리즘은 bounding box regression을 기반으로 하는 딥러닝으로, 두가지 예측을 수행한다.
1. text/non-text classification
2. location regression
그러나 text/non-text classification 예측 수행만으로도 semantic segmentation 역할을 할 수 있어 location regression이 필수적이지 않다. 다만 이미지 속 text가 서로 가까워 semantic segmentation으로 분리하는 것이 어려울 때가 있다.
이 문제를 instance segmentation으로 해결하고자 하는데, 방식은 다음과 같다.
먼저 text instance를 같은 instance 내의 픽셀을 link하여 나누고, location regression은 따로 수행할 필요 없이 segmentaion 결과로부터 text bounding box를 추출한다.
instance segmentation를 기반으로 한 STD알고리즘이 PixelLink이다.
location regression 기반 방법과 비교하면 PixelLink는 비슷하거나 더 나은 성능을 가지며 훨씬 더 적은 training iteration과 training data를 필요로 한다.
https://arxiv.org/pdf/1801.01315v1.pdf
1. how to detect text
대표적인 text detection 알고리즘으로는 CTPN, TextBoxes, SegLink, EAST 등이 있다. 이러한 대부분의 최신 알고리즘은 FCN을 기반으로 하고, text/non-text classificaton와 Location regression 2가지를 예측함으로써 text의 위치를 추출한다.
하지만 위에서 언급했듯이 location regression은 필수적이지 않다. text/non-text 예측으로 regression 결과의 confidence뿐만 아니라 bounding box를 구할 수 있는 segementation score map으로 사용될 수 있기 때문이다.
따라서 text/non-text prediction만 수행하여 text detection을 구현할 수 있는데,
문제는 text가 서로 가깝게 위치해 있어 instance 단위로 segementation 하는 것이 어렵다는 것이다.
PixelLink는 pixel 단위의 두 가지 학습을 통해 이 문제를 해결한다!
1. text/non-text prediction
해당 pixel이 text instance에 속하면 positive(text pixels)로 라벨링 되고, 속하지 않으면 negative(non-text pixels)로 라벨링 된다.
2. link prediction
모든 pixel은 8개의 neighbor이 존재한다. 주어진 pixel과 그 neighbor이 같은 instance 내에 있으면 pixel 사이 link를 positive로 설정하고, 그렇지 않으면 negative로 설정한다.
예측된 positive pixel은 예측된 positive link를 통해 CC(Connected Components)로 결합된다.
이러한 방식으로 instance segmentation이 이루어지고, 각각의 CC는 text가 된다.
2. What is segmentation
이미지의 pixel 단위로 라벨링을 하는 것으로, 크게 두 가지로 구분된다.
object의 카테고리만 고려된다! --> "Semantic segmentation"
object의 카테고리 뿐만 아니라 instance의 구별도 해야한다! --> "Instance segmentaion"
Instance segmenation은 동일한 클래스라도 서로 다른 물체면 다른 instance 인식해야 하기 때문에 semantic segmentation보다 더 어려운데, 일반적인 object detection과 관련이 있어 이 시스템을 많이 사용하여 해결한다.
예를 들어, FCIS는 R-FCN의 position-sensitive 예측 개념을 확장하고, Mask R-CNN은 Faster R-CNN의 ROI Pooling을 ROI Align으로 바꾸어 한 모델에서 detection과 instance segmentation을 수행한다.
3. Regression-based Text Detection
이 방법은 일반적인 object detection의 장점을 활용한다.
CTPN | object detection의 anchor box 개념을 확장하여 text 조각을 예측하고, heuristic방법을 통해 조각들을 연결 |
TextBoxes | scene text가 가지는 큰 aspect ratio 특징에 맞게, 큰 aspect ratio의 anchor와 불규칙한 모양의 kernel을 사용하는 text-specific SSD를 사용 |
RRPN | scene text의 방향을 다루기 위해 anchor와 Fast R-CNN의 RoI Pooling에 rotation을 추가 |
SegLink | text segemen들을 예측하기 위해 SSD를 사용 |
EAST | locality를 인식하는 NMS를 사용하는 조밀한 예측 수행 |
이 모든 Regression-based Text Detection 알고리즘은 confidence와 location을 동시에 예측한다.
4. Detecting Text via Instance Segmentation
4.1) Instance Segmentation 방식
예측한 positive pixel + 예측한 positive link --> 동일한 text instance로 묶임 --> bounding box 추출
4.2) Network Architecture
다음은 각 Model들의 Architecture들과 사용한 Backbone을 나타낸 표이다.
PixelLink는 feature extractor로 아키텍쳐는 FCN이고, fully connected layer를 convolutional layer로 바꾼 VGG16를 사용했다.
모델은 text/non-text prediction과 link prediction을 위한 2개의 헤더를 가진다.
channel의 수는 다음과 같다.
- text/non-text prediction channel: 1*2 = 2
- link prediction channel: 8*2 = 16
4.3) Linking Pixels Together
주어진 pixel과 link에 대한 예측해는 threshold가 각각 적용된다.
두 개의 이웃한 positive pixel이 주어지면, 두 pixel들 간의 link가 예측되고, 예측된 두 link 중 하나라도 positive이면 연결된다.
이러한 linking process는 disjoint-set data structure을 사용하여 구현한다.
4.4) Extraction of Bounding Boxes
PixelLink는 위치 regression이 아니라 instance segmentation으로부터 bounding box를 얻을 수 있다.
이 점이 PixeLink와 regression-based text detection 방법 간의 차이점이라고 할 수 있다.
5. Ground Truth Calculation
주어진 pixel과 주변 8개의 neighbor pixel이 같은 instance에 속한다면, 그들 사이의 link는 positive이고, 속하지 않는다면 negative이다.
pixel 예측이 overlap되어 존재한다면 overlap되지 않는 pixel만 positive이고, 나머지는 negative이다.
ground truth 계산은 예측 레이어의 resize된 입력 이미지에 따라 수행된다.
6. Loss Function
PixelLink의 Loss는 pixel loss와 link loss의 합으로 이루어진다.
link loss는 positive인 pixel에서만 존재하기 때문에 classification 문제가 link보다 더 중요하다. 따라서 pixel loss가 더 중요하므로 보통 λ를 2.0으로 설정한다.
6.1) Pixel Loss
단어들마다 instance의 크기가 다르다.
크기가 작은 단어에는 적은 pixel이 포함되고, 크기가 큰 단어에는 많은 pixel이 포함될 것이다.
그런데 만약 모든 positive pixel에 대해 같은 weight를 부여한다면 크기가 제각각인 모든 instance에 대하여 불공평하게 weight가 설정되어 크기가 작은 단어에는 작은 weight가 부여된다.
이런 불공평한 weight 설정으로 인한 성능 저하를 막기 위해 segmentation을 위한 새로운 weighted loss인 Instance-Balanced Cross-Entropy Loss가 제안된다.
Instance-Balanced Cross-Entropy Loss
(N: text instance의 개수 / Si: i번째 instance의 넓이)
Si의 넓이를 갖는 i번째 instance에 속하는 모든 positive pixel은 Wi= Bi/Si의 가중치를 갖는다.
OHEM(Online Hard Example Mining)은 negative pixel을 고르는 데에 적용된다.
OHEM(Online Hard Example Mining)
negative pixel을 고르는 데에 적용된다.
weight를 1로 설정하고 loss를 구해 가장 높은 loss를 갖는 r*S개의 negative pixel을 선택한다. 이 때. r은 negative-positive 비율로 보통 3으로 설정된다.
위 두 메커니즘을 통해 모든 positive pixel과 선택된 negative pixel이 표시된 W(weight matrix)를 생성한다.
그리고 최종 pixel classification에 대한 loss를 구한다.
(Lpixel_CE: text/non-text prediction에 대한 Cross Entropy Loss matrix)
결론적으로, 이 Lpixel_CE 행렬에 W/(S+rS)를 곱함으로써 작은 instance의 pixel은 큰 weight를 가지고 큰 instance의 pixel은 작은 weight를 가져 모든 instance가 loss에 동일하게 관여하게 한다.
또한 negative pixel의 weight는 1로 설정함으로써 모든 negative pixel이 loss에 동일하게 관여하게 한다.
6.2) Link Loss
link loss는 positive pixel에서만 계산된다.
positive link와 negative link에 대한 weight는 각각 계산하는데, 계산 방법은 다음과 같다.
(W: 위에서 언급했던 positive pixel과 선택된 negative pixel의 weight matrix / Ylink: link의 label matrix)
positive link loss와 negative link loss 또한 각각 계산하는데, 계산 방법은 다음과 같다.
(Llink_CE: link prediction에 대한 Cross Entropy Loss matrix)
최종 link loss는 일종의 class-balanced cross entropy loss로 다음과 같이 구한다.
(rsum: reduce sum으로 tensor의 모든 요소를 scalar로 더한 것)
7. Data Augmentation