{'fraction_non_alphanumeric': 0.03927687506725492, 'fraction_numerical': 0.014096631873453136, 'mean_word_length': 4.813177648040034, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Weakly-Supervised Arbitrary-Shaped Text Detection with Expectation-Maximization Algorithm

Arbitrary-shaped text detection is an important and challenging task in computer vision. Most existing methods require heavy data labeling efforts to produce polygon-level text region labels for supervised training. In order to reduce the cost in data labeling, we study weakly-supervised arbitrary-shaped text detection for combining various weak supervision forms (e.g., image-level tags, coarse, loose and tight bounding boxes), which are far easier for annotation. We propose an Expectation-Maximization (EM) based weakly-supervised learning framework to train an accurate arbitrary-shaped text detector using only a small amount of polygon-level annotated data combined with a large amount of weakly annotated data. Meanwhile, we propose a contour-based arbitrary-shaped text detector, which is suitable for incorporating weakly-supervised learning. Extensive experiments on three arbitrary-shaped text benchmarks (CTW1500, Total-Text and ICDAR-ArT) show that (1) using only 10% strongly annotated data and 90% weakly annotated data, our method yields comparable performance to state-of-the-art methods, (2) with 100% strongly annotated data, our method outperforms existing methods on all three benchmarks. We will make the weakly annotated datasets publicly available in the future.


Introduction
Scene text detection has received increasing attention in recent years due to its wide applications in document analysis and scene understanding. Driven by the deep neural network, many previous methods have made great progress. The proposed detectors can detect not only horizontal texts [36,12], but also multi-oriented texts [8,38] and even more challenging arbitrary-shaped texts [6,13].
However, these methods usually require large scale polygon-level annotated data during training. According to 100%   [16], labeling one curve text consumes approximately triple time than labeling with quadrangle (13s vs 4s). Therefore, acquiring such a strongly annotated dataset is expensive and time consuming, which has impeded its application in largescale real problems. An alternative is to utilize weak annotations. In this paper, we propose four kinds of weak supervision for arbitrary-shaped texts, which are far easier to label compared with polygons. We introduce them from strong to weak according to the supervision hierarchy. The first one is tight bounding box, which is defined by the four extreme points of the text contour, and can enclose the text instance tightly. The second one is loose bounding box, whose sides are not required to be close to the text instance. The third one is coarse bounding box which locates a cluster of texts roughly. The last one is image-level tag, which indicates whether an image contains text or not. Fig. 2 gives an illustration of the four weak supervision forms as well as the traditional strong supervision of polygons.  To give a comparison of time costs of labeling an image with different annotation formats, we randomly selected 500 images, and annotated them with these annotation formats by ourselves. The average time cost of each annotation format is also shown in Fig. 2. We can see that it takes about 1 minutes for a annotator to label an image with polygons, 39s with tight bounding boxes, 28s with loose bounding boxes, 15s with coarse bounding boxes, and only 2s with image-level tags. Based on this, we estimated the time consumptions for labeling the whole ICDAR-ArT [3] dataset with different annotation policies. As shown in Fig. 1, the time consumption can be greatly reduced by combining weak labels, which demonstrates the effectiveness and low costs of the proposed weak supervision forms. However, it still remains a challenging problem to use these weak labels to train text detectors.
In this paper, we develop an Expectation-Maximization (EM) based weakly-supervised framework for training arbitrary-shaped text detector from strong labels in combination with the proposed weak labels. Firstly, for arbitraryshaped text detection, we propose a contour-based method, which firstly locates the instance-level text proposals, then regresses contours of them. Due to the proposal mechanism is very similar to the proposed weak supervision forms (coarse, loose, and tight bounding boxes), the detector is very suitable for incorporating weakly-supervised learning. Secondly, in order to utilize the weakly-supervised data to boost the performance, we treat polygon-level labels as latent variables for weakly-supervised data, and use a EMlike optimization algorithm (See Fig. 4) to solve the latent variable learning problem. Specifically, the algorithm alternates between two steps: (1) E-step: estimate a probability distribution over all possible latent polygons of text instances; (2) M-step: update the weights of detection model using estimated polygon-level pseudo labels from the last E-step. In practice, the quality of the final extremum depends heavily on the initialization, since the whole optimization problem is highly non-convex. On this issue, we use the model pre-trained by a small set of strongly annotated data to initialize our learning algorithm.
In summary, this work has the following contributions: (1) We propose an EM-based framework, including a contour-based arbitrary-shaped text detector for weaklysupervised arbitrary-shaped text detection, which can accommodate various forms of weak supervision. (2) We propose four kinds of weak supervision for arbitrary-shaped text detection, which could cover most of the weaklysupervised scenarios. (3) Using only 10% strongly annotated data combined with 90% weakly annotated data, our model can almost match the performance of fullysupervised models, which demonstrates the superiority of our method. Meanwhile, under full supervision, our method outperforms existing methods on three public benchmarks (CTW1500 [16], Total-Text [2], and ICDAR-ArT [3]).

Related Work
In this section, we review the most relevant works on scene text detection and weakly-supervised text detection.

Scene Text Detection
Over the years, the traditional SWT [5,30] based methods and MSER [18,19] based methods have been replaced by deep learning inspired methods with simplified pipelines. These deep neural networks based methods [25,8,38] are mainly built on generic object detectors [21,14,10] with various text-specific modifications.
Recently, detecting texts with arbitrary shapes has gradually drawn the attention of researchers. TextSnake [17] describes the curved text as a series of ordered, overlapping  Figure 3. Illustration of the structure of the proposed text detector."TLN", "CIN", and "CDN" represent text localization network, contour initialization network and contour deformation network, respectively. disks centered at symmetric axes. MaskTextSpotter [11] regards the arbitrary-shaped text detection as an instance segmentation problem. CRAFT [1] detects individual characters, and connects them to get each text polygon. PSENet [27] adopts a progressive scale algorithm to gradually expand the predefined kernels. LOMO [35] regresses text geometry in a corarse-to-fine manner. TextMountain [40] generates text polygons after predicting text score, text center border probability, and text center direction. However, these methods usually require amounts of strongly annotated data during training. Different from these methods, we propose a novel EM-based framework, which can achieve good performance with only a small amount of fully-supervised data.

Weakly-Supervised Scene Text Detection
Some researchers proposed weakly-supervised learning based methods [24,9,32] to perform character-level text detection, due to most existing datasets do not provide character-level annotations. Usually, synthetic datasets are firstly used to initialize a character detector. Then the initial detector model could generate character candidates for the real datasets. However, such generated pseudo annotations may contain many false positives. To overcome this, the methods in [9] and [24] take the polygon-level annotations as filters, and mask false positives out. Besides, the method in [32] removes false positives by comparing the number of detected character bounding box inside the word polygon with the ground truth word. The disadvantage of these methods lies in the dependence on polygon-level annotations.
Besides, Sun et al. [22] published a large partially labeled dataset (Each image is only annotated with one dominant text) and proposed an algorithm to use these partially labeled data. However, because the supervision information is too weak, it will not greatly improve the detection performance.

Methodology
The weakly-supervised framework is based on the proposed four kinds of weak supervision, which consists of two major parts: a contour-based arbitrary-shaped text detector and an EM-based learning algorithm. Firstly, we introduce the generation methods of the four weak labels for public datasets. Then, we introduce these two major parts of the framework in detail.

Weak Labels Generation
Four kinds of weak labels can be generated from the polygon-level labels provided by public datasets. The tight bounding box can be obtained from the external bounding box of the polygon. The loose bounding box can be obtained by expanding the height and width of the tight bounding box by 0.1 to 0.2 times respectively. The coarse bounding box can be generated from the external bounding box of the text cluster. We adopt Mean Shift algorithm [4] to cluster centers of text regions, where the clustering radius is set to 0.3 times of the short side length of the image. The image-level tag indicates whether an image contains text or not, which can be easily obtained.
Our purpose is to evaluate the effectiveness of the weakly-supervised text detection, therefore, the weak supervisions are generated from the polygon-level supervision provided in the public datasets. In real applications, the annotation of these weak labels are much easier compared with polygons, which will then significantly reduce the labeling costs.

Contour-Based Text Detection
Inspired by [20], we propose a contour based arbitraryshaped text detector. An overview of the detector is illustrated in Fig. 3. After extracting original features by the backbone network, a text localization network is used to generate bounding-box-level text proposals. Then, we adopt a contour initialization network to produce the initial text contour for each text proposal. Finally, initial text contours together with original features are sent to the contour deformation network, which performs iterative contour regression to obtain the text instance boundary. Since the proposal mechanism in the pipeline is very similar to the proposed weak supervision forms (coarse, loose, and tight bounding boxes), the proposed method can fully utilize the weak labels to boost the detection performance. Text Localization Network. We adopt CenterNet [37] to generate text proposals, which reformulates the detection task as a keypoint detection problem. The detection head has two branches: (1) The classification branch calculates a heatmap, where the peaks are supposed to be the text instance centers; (2) The regression branch predicts the height and width of the proposal bounding box for each peak. Contour Initialization Network. Since the initial input has a non-ignorable influence on the contour deformation and the detected text proposals usually have some offsets or errors, we propose this network to produce more accurate and suitable initial contours for text instances. In [39] and [20], octagon enclose the arbitrary-shaped object much tighter than the rectangle. Therefore, we also choose it as the initial contour. In fact, the octagon could be formed by four extreme points, which are top, leftmost, bottom, rightmost pixels in an object, denoted by {z ex i |i = 1, 2, 3, 4}. Therefore, the problem is how to get the extreme points from the bounding box.
Given a bounding box, we could extract the four center points at the top, left, bottom, right box edges, denoted by {z bb i |i = 1, 2, 3, 4}, and then connect them to get a diamond contour. After that, we adopt the Deep Snake, a contour regression model proposed by [20]. It takes the diamond contour as input and outputs four offsets that point from each z bb i to the extreme point z ex i , namely z ex i −z bb i . Finally, we extend a line in both directions at each extreme point, whose length is 1/4 to the corresponding edge, and connect their endpoints to get the octagon. Contour Deformation Network. Contour deformation network is used to regress the offsets from points on the initial contour to the corresponding points on the groundtruth. We adopt the same regression method as the contour initialization. To make the output contour smoother, we sample 128 points along the octagon contour. Similarly, the ground-truth is generated by uniformly sampling 128 vertices along the polygon. In addition, in order to simplify the difficulty of regression, an iterative optimization strategy is adopted. Specifically, the output contour of the previous iteration is used as the initial contour of the next iteration. In our experiments, we set the number of iterations to 3.

EM-based Learning Algorithm
In this paper, x denotes the image values, y denotes the polygon-level labels of the image, and w denotes the weak labels of the image. As for the weakly annotated image, we can observe the image values x and the weak labels w, but the text instances polygons are latent variable. We have the following probabilistic graphical model: P (x, y, w; θ) = P (x)P (y|x; θ)P (w|y). (1) Then, in order to learn the model parameters θ from the weakly annotated data, we adopt an EM-based learning strategy as follows: E-step. The purpose of E-step is to estimate the completedata log likelihood. Given the previously estimated parameter θ , the expected complete-data log likelihood for weakly annotated image x and it's label w is given by where the latent variable can be estimated bŷ y = arg max y P (y|x, w; θ ). ( M-step. The M-step is to maximize the Q(θ; θ ) with respect to θ. According to Eq. 2, the key to maximize Q(θ; θ ) is maximizing logP (ŷ|x; θ). Here, we treatŷ as ground truth polygons, and optimize logP (ŷ|x; θ) by the minibatch SGD algorithm.
We integrate the detector in Sec. 3.2 into the learning algorithm, and obtain a pipeline for weakly-supervised text detection, which is shown in Fig. 4. The parameter θ is equivalent to the weights of the detection model. We use a small amount of strongly annotated data to train a model, which provide the initial state for the 1st M-step. And the estimated latent polygon-level labelŷ is given by the output of contour deformation network in the detection model. As shown in Eq. 3,ŷ is related to weak labels w. Different weak supervisions will provide different informations, so there are different approaches to estimate the latent variables. We introduce them separately as follows: Learning with Image-Level Tags. The whole pipeline is shown in Fig. 5(a). We send the text images to the detection model of the previous M-step, and obtain a candidate pseudo annotation set D I = {(b 1 , p 1 , s 1 ), (b 2 , p 2 , s 2 ), ..., (b n , p n , s n )}, where (b j , p j , s j ) corresponds to the bounding box, polygon, and confidence score of the j-th detected instance, respectively. For the issue of false positives, we adopt a filter, which use the confidence threshold to select the more reliable samples. This process can be formulated as: where D I is the final pseudo annotation set, and S is the confidence threshold. Learning with Coarse Bounding Boxes. Similarly, the detection model of previous M-step is applied to the weakly annotated images (See Fig. 5(a)), and a candidate pseudo annotation set D C is obtained. In the filtering process, in addition to the confidence threshold, we can utilize the coarse bounding box which can perform like a text filter. Specifically, we use the IoU between detection results and ground truths as a metric to filter out the false positives. This process can be formulated as: where D C is the final pseudo annotation set, G C is the ground-truth set, S and H is the confidence threshold and IoU threshold respectively. Learning with Tight Bounding Boxes. Given the tight bounding boxes, the text proposal localization in the detection pipeline is unnecessary. We replace the bounding boxes generated by text localization network with the bounding boxes from weak labels (See Fig. 5(b)). With the ground truth bounding boxes, the more accurate initial contour are generated. Accordingly, the contour deformation network can predict better final contours. Therefore, all the generated results can be taken into final candidate pseudo annotation set D T , and their confidence scores are all set to 1, which can be formulated as: where D T is the final pseudo annotation set, and G T is the ground truth set.
Learning with Loose Bounding Boxes. Almost the same approach as the tight bounding box is utilized in this case (See Fig. 5(b)). However, the loose bounding boxes contain more background noises than tight bounding boxes, which might deteriorate the performance of contour regression. Therefore, care must be taken during pre-training in this case, the generated bounding boxes of text proposals should be expanded randomly before sent to the contour initialization network, which can weaken the sensitivity of contour initialization network to the looseness of text bounding box. Similar to tight bounding boxes, all the generated results are taken into final candidate pseudo annotation set D L and their confidence scores are all set to 1. The final candidate pseudo annotation can be written as: where D L is the final pseudo annotation set, and G L is the ground truth set.
During network training, the same loss function as Cen-terNet [37] is adopted in text localization, which can be denoted as L det . And the smooth L1 loss is used to learn contour initialization and contour deformation, which can be denoted as L cin and L cdn , respectively. For the end-toend training of the three tasks, the whole loss function can be formulated as: where λ 1 and λ 2 are the hyper-parameters to control the balance among each task.
Inevitably, even if we filter the candidate pseudo annotation set generated in E-step, there are still negative samples in the final pseudo annotation set, especially for D I and D C . Once using these noisy labels to update the parameters in M-step, the performance of the model tends to deteriorate iteratively. To make the training focus more on reliable samples, a confidence weighted lossL is proposed as follows:L = sL, (9) where s is the confidence score of a sample obtained in the E-step, which ensures the stability of the training process.
CTW1500. The CTW1500 dataset contains 1000 training images and 500 test images. Each image has at least one curved text. Horizontal and multi-oriental texts are also contained in this dataset. Each text is labeled as a polygon with 14 vertexes in line-level.
Total-Text. The Total-Text dataset has 1255 training images and 300 test images, which contains curved texts, as well as horizontal and multi-oriental texts. Each text is labeled as a polygon with 10 vertexes in word-level.
ICDAR-ArT. The ICDAR-ArT dataset consits of 5603 training images and 4563 test images, which contains multilingual arbitrary-shaped texts. Each text is labeled with adaptive number of vertices.

Implementation Details
The whole algorithm is implemented with PyTorch 1.1, and we conduct all experiments on a regular workstation with 4 GeForceGRX Titan GPUs. We use the DLA-34 [34] as our backbone. For all models, we first pre-train them with the SynthText [7] dataset, then fine-tune the models on the corresponding real-world datasets. Each M-step consists of 200 epochs. And the batchsize is set to 36. We adopt the "multistep" strategy to adjust the learning rate. The initial learning rate is set to 1 × 10 −4 and is divided by 2 at 80th, 120th, 150th, and 170th epoch. For data labeled with coarse bounding boxes or image-level tags, we stop training after 3 M-steps. For data labeled with tight or loose bounding boxes, since the initial pseudo annotations are of high quality, it is unnecessary to iterate multiple rounds. Actually, data augmentation is important for training, especially when there is only a small amount of strongly annotated data: (1) the image is rescaled with ratio from 0.5 to 2.0 randomly. (2) the image is horizontally flipped and rotated in range [−10 • , 10 • ] randomly. (3) 640 × 640 random samples are cropped from the transformed image.
In the inference stage, the short side of the input image is scaled to a fixed length (460 for CTW1500, 640 for Total-Text, and 960 for ICDAR-ArT), with the maintained aspect ratio. Table 1. Detection results on CTW1500. "P", "R", and "F" represent the precision, recall and F-measure, respectively.

Experimental Results
For all three datasets, we randomly select 10% of original training images as strongly annotated data and take other 90% as weakly annotated data, resulting in a 100 and 900 split for CTW1500, a 125 and 1130 split for Total-Text, and a 560 and 5043 split for ICDAR-ArT. Based on the data division, we can get the following models: Figure 6. Examples of text detection results. First column: CTW1500; second column: Total-Text; third column: ICDAR-ArT. Table 4. The benefits of the confidence weighted loss on ICDAR-ArT. "WL" indicates confidence weighted loss. "P", "R", and "F" represent the precision, recall and F-measure, respectively. (1) 100%Poly: Model trained with all images, which are annotated with polygons.
(3) 10%Poly & 90%XXX: Model trained with all images, of which 10% are annotated with polygons, and 90% are annotated with a kind of weak annotation format.
Weakly-Supervised Detection Results. As shown in Tables 1, 2, and 3, the "10%Poly & 90%Tight" has gained the best performance among the four weakly-supervised models, and almost reaches the performance of the "100%Poly". Due to the loose bounding boxes contains more background noises, the performance of "10%Poly & 90%Loose" is slightly lower than that of "10%Poly & 90%Tight". Both "10%Poly & 90%Coarse" and "10%Poly & 90%Tag" outperform the baseline model "10%Poly", which demonstrates the effectiveness of the proposed weakly-supervised framework.
Fully-Supervised Detection Results. As shown in Tables 1, 2 and 3, our fully-supervised models have achieved state-of-the-art performance on all three datasets, which demonstrates the superiority of our method. Meanwhile, in terms of speed, our method also achieves good performance. Although not the highest, our method achieves an impressive trade-off between speed and accuracy. Some examples of text detection results are shown in Fig. 6  izontal, multi-oriented and curved texts.

Ablation Studies
Influence of the Proportion of Strongly Annotated Data. As illustrated above, the weakly-supervised model can almost match the performance of the fully-supervised model, using only 10% strongly annotated data. With less strongly annotated data, can the proposed method achieve such good results? We sample five proportions from 1% to 10% for the strongly annotated data, which are 1%, 3%, 5%, 8%, and 10%, and conduct experiments on ICDAR-ArT. As shown in Fig. 7, the performance gets better as the proportion of strongly annotated data increases. In addition, the four kinds of weak supervision show different sensitiveness about the amount of strongly annotated data. For tight or loose bounding boxes annotated data, combining with only 1% strongly annotated data, they can still get good performance. While, for the other two weak supervision forms, when the proportion of strongly annotated data is reduced, Table 5. Detection results of different annotation policies on ICDAR-ArT. "P", "R", and "F" represent the precision, recall and F-measure, respectively. In the "Labels" column, the "I", "C", "L", "T" and "Poly" represent the image-level tags, coarse bounding boxes, loose bounding boxes, tight bounding boxes and polygons, respectively.  the performance drops obviously. Influence of the Confidence Weighted Loss. We evaluate the influence of the weighted confidence loss (See Eq. 9) by experiments with or without it. We conduct two groups of comparative experiments on ICDAR-ArT. As shown in Table 4, the models trained with confidence weighted loss yield better results. The confidence weighted loss improves the two basic models by about 2.1% and 2.5% of F-measure respectively. It attributes to that with confidence weighting, the influence of noise samples on training can be limited, and the network learning tends to focus on reliable samples.
Influence of the Number of Training Rounds. The results of the weakly-supervised training within three rounds are shown in Fig. 8. The result of the 0 training round is the performance of the initial model. The performance of weakly-supervised models has improved in the first two rounds, which attributes to the improvement of pseudo label quality. Then the improvements stop at the third round, which lies in the error accumulation.
Budget-Aware Omni-Supervised Text Detection. In this part, we consider another scenario: given the annotation budget, how to design an annotation policy for better detection performance. For data annotation, the budget consumption is directly proportional to the time cost. Therefore, we just use the time cost as the budget consumption and ignore other factors.
The total budget is set to 43,200 seconds (12 hours). Then, we put forward three policies as list below: (1) Strong: all the budget is used to annotate polygons. (2) Equal Time: in addition to 560 strongly labeled images, the remaining time is equally divided into four weak supervision forms. (3) Equal Number: in addition to 560 strongly labeled images, the remaining time is used for the weak supervision forms, and make the image amount of each kind of weak supervision the same. In addition, in order to explore the cost-effectiveness of the four weak supervision forms, we conduct four comparative experiments, in which 80% budget is spent on polygons and the rest is spent on a kind of weak supervision.
The results are shown in Table 5, which show that both the "Equal Time" and "Equal Number" policy perform better than the "Strong" policy, and the "Equal Time" policy has gained the best results, outperforming the "Strong" policy over 3.9% on F-measure. These results suggest that spending a certain amount of budget to annotate more images with weak labels is better than commonly all adopted strong labels. For the "80% Poly" policy, the four weak supervision forms have achieved similar results, and "Loose Bounding Box" is slightly ahead of others, which can be regarded as the most cost-effective weak supervision form.

Conclusion
In this paper, we propose an EM-based framework for weakly-supervised arbitrary-shaped text detection, so as to take advantage of various forms of weak annotations in addition to polygon-level strong annotation. The proposed framework consists of a contour-based arbitrary-shaped text detector and an EM-based learning strategy. Extensive experiments have been conducted to demonstrate the effectiveness of the proposed framework. Using 10% strongly annotated data, our weakly-supervised model can match the performance of fully-supervised models. Meanwhile, under full supervision, our method outperforms existing methods. The results also reveal the effects of different kinds of weak supervision. How to better exploit weakly annotated data deserves further research.