{'fraction_non_alphanumeric': 0.030991131468667773, 'fraction_numerical': 0.01439106000064971, 'mean_word_length': 4.97747572815534, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
FedOCR: Communication-Efficient Federated Learning for Scene Text Recognition

While scene text recognition techniques have been widely used in commercial applications, data privacy has rarely been taken into account by this research community. Most existing algorithms have assumed a set of shared or centralized training data. However, in practice, data may be distributed on different local devices that can not be centralized to share due to the privacy restrictions. In this paper, we study how to make use of decentralized datasets for training a robust scene text recognizer while keeping them stay on local devices. To the best of our knowledge, we propose the first framework leveraging federated learning for scene text recognition, which is trained with decentralized datasets collaboratively. Hence we name it FedOCR. To make FedCOR fairly suitable to be deployed on end devices, we make two improvements including using lightweight models and hashing techniques. We argue that both are crucial for FedOCR in terms of the communication efficiency of federated learning. The simulations on decentralized datasets show that the proposed FedOCR achieves competitive results to the models that are trained with centralized data, with fewer communication costs and higher-level privacy-preserving.


Introduction
Text in scene images contains valuable semantic information for text reading and has become one of the most popular research topics in academia and industry for a long time (Goel et al. 2013;Almazán et al. 2014;Su and Lu 2014;Luo, Jin, and Sun 2019;Li et al. 2019;Yu et al. 2020). In practice, scene text recognition has been applied to various real-world scenarios, such as autonomous navigation, photo transcription, and scene understanding. With the development of deep learning and the emergence of public text datasets, significant progress on scene text recognition has been made in recent years.
However, most of the existing scene text recognition algorithms assume that a large scale set of training images is easily accessible. As shown in Fig. 1(a), in real conditions, algorithms may achieve sub-optimal performance and be unable to model the data variations or diversity owing to the lack of sufficient images. To remedy this, some works (Bartz et al. 2019;Hu et al. 2020) merge different Copyright © 2022, Association for the Advancement of Artificial Intelligence (www.aaai.org). All rights reserved. public datasets to build a more robust text recognizer, as illustrated in Fig. 1(b). However, centralizing data in this way is simply problematic in many real-world scenarios. For example, many laws and regulations strengthening the data privacy constrain the use of data stored on local devices, such as General Data Protection Regulation (GDPR) (Voigt and Von dem Bussche 2017). Besides, centralizing tremendous image data from different local devices incurs heavy communication loads. That means it is simply intractable to centralize large amounts of data for scene text recognition training in practice. Our solution, which works within the framework of federated learning, is illustrated in Fig. 1(c).
Federated Learning (FL), a new concept first proposed by McMahan et al. (McMahan et al. 2016), allows data owners to train a shared model collaboratively while keeping data stored on different local devices. However, directly applying FL to scene text recognition faces two inevitable difficulties. First, in most scene text recognition algorithms, a heavyweight backbone model is usually adopted for the sake of better performance. Hence, it results in heavy burdens of the parameter transmission while doing federated learning. Second, there is an extra computational cost from a privacy-preserving module to handle privacy leakage due to the honest-but-curious global server in general federated learning frameworks.
In this paper, to the best of our knowledge, we propose the first federated learning framework for scene text recognition, which we name FedOCR. In our FedOCR (a schematic is given in Fig. 2), all participants train a shared model collaboratively without centralizing the training images. In this manner, datasets on different local devices have an indirect influence on the training of the global model, which leads to a competitive performance to the model trained with a centralized set of data. To improve the communication efficiency between the global server and local clients, we argue two important aspects in FedOCR, i.e., lightweight models and hashing techniques. Moreover, benefited from the hashing technique, we can avoid privacy leakage to the global server by a specific hashing function and the random seeds, which saves an extra computational cost for a privacy-preserving module. As a consequence, the proposed FedOCR is readily to be deployed in practical applications for scene text recognition.
Compared with existing scene text recognition meth-  ods (Luo, Jin, and Sun 2019;Li et al. 2019;Bartz et al. 2019;Zhan and Lu 2019;Yue et al. 2020;Bhunia et al. 2021) without federated learning, the proposed framework has the following intriguing merits. First, FedOCR can make use of more abundant image data from different local devices. Particularly, there are billions of end devices with tremendous text images benefiting scene text recognition. Therefore, our framework may have great potential in real-world applications of scene text reading. Second, by design, our framework has a superior trade-off between parameter transmission efficiency and performance. The proposed text recognizer has much fewer parameters than existing scene text recognition algorithms but encouragingly reaches a comparable performance. Last, it can encrypt and decrypt with the hashing technique, which provides higher-level privacypreserving without an extra computational cost.
In summary, the main contributions of this paper are three-fold.
• We reveal the problem of data privacy in scene text recognition, which is somehow overlooked by the existing methods. • We propose the first federated scene text recognition framework called FedOCR for training a recognizer with decentralized datasets distributed on different local devices. • FedOCR is a highly communication-efficient as well as privacy-preserving framework by incorporating lightweight backbones and hashing techniques, which makes it suitable to be deployed in real privacy-sensitive applications and edge devices.

Related Work
Scene text recognition has attracted great interest for a long time. According to Long et al. (Long, He, and Yao 2018), representative methods can be roughly divided into two mainstreams, i.e., Connectionist Temporal Classification (CTC) based and attention-based methods. Generally, the CTC-based methods model scene text recognition as a sequence recognition task. For example, Shi et al. (Shi, Bai, and Yao 2016) combine the convolutional neural network (CNN) with the recurrent neural network (RNN) to extract sequence features from input images, and decode the features with a CTC layer. Different from Shi et al. (Shi, Bai, and Yao 2016), Gao et al. (Gao et al. 2019) use stacked convolutional layers to extract contextual information from inputs without RNN, and show advantages with low computational costs. Zhang et al. (Zhang, Gupta, and Zisserman 2020) turn text recognition into a visual matching problem by exploiting the repetition of glyphs in language, and build this similarity between units into the proposed architecture. Meanwhile, attention-based methods extract features more effectively via the attention mechanism. For instance, Liu et al. ) propose a binary convolutional encoderdecoder network to provide real-time scene text recognition. Liu et al. (Liu, Chen, and Wong 2018) propose a characteraware neural network with a hierarchical attention mechanism, which adopts a local transformation to rectify characters individually. Unlike other attention-based algorithms, Bai et al.  propose Edit Probability (EP) to handle the misalignment between the output sequence of probability distribution and the ground-truth sequence. Nguyen et al. (Nguyen et al. 2021) incorporate a dictionary in both the training and inference stage to make a more robust scene text recognition system.
Undoubtedly, large amounts of real-world data are needed in practical applications of those scene text recognition methods. However, tremendous image datasets are distributed on different companies, communities or local devices, and can not be centralized to share.  (Gao, Xu, and Huang 2021) propose the error-compensated double compression mechanism to significantly reduce the communication cost. Especially very recently, the computer vision community starts to pay attention to federated learning, thus arising several pioneering works. For example, Luo et al. ) implement object detection algorithms with federated learning and release a reliable benchmark framework. In the medical field, Zhu et al. (Zhu et al. 2019) implement a privacy-preserving federated learning system with the differential privacy for brain tumor segmentation. Li et al. (Li, He, and Song 2021) conduct contrastive learning in model-level to correct the local training of individual parties to achieve high performance in image classification tasks. To the best of our knowledge, we propose the first federated scene text recognition framework, which is more efficient in communication and provides higher-level privacy-preserving.

Methodology
In this section, we first introduce the pipeline of our federated scene text recognition framework. Then, we describe the details of local training and global aggregation, which are the two main steps in federated learning. Finally, we elaborate on how to improve communication efficiency and preserve data privacy in our framework.

Pipeline of FedOCR
According to Yang et al. (Yang et al. 2019), our framework is a kind of horizontal federated learning, where datasets of different participants share the same feature space but differ in samples. Suppose we have C data owners, which have different sets of training images {D 1 , ..., D C }. We denote the accuracy of the text recognizer trained with decentralized datasets {D 1 , ..., D C } as Acc F ED . Note that these decentralized datasets are not shared or transferred to other participants during training. We denote the accuracy of the text recognizer trained with a centralized dataset D = D 1 ∪ ... ∪ D C as Acc SU M . Basically, the objective of FedOCR is to minimize the difference between Acc F ED and Acc SU M . A smaller difference between Acc F ED and Acc SU M means a better performance of our federated learning for scene text recognition. Fig. 2 illustrates the pipeline of our federated scene text recognition framework. There are C participants, each of which has a set of data containing cropped text word images and transcriptions, and a global server for local model parameter aggregation. We assume all participants agree in advance on the same network architecture and the same training objective but do not share their datasets. The whole learning process can be decomposed into four steps: (1) Before each round of local training, all participants start with the same parameters, which are initialized randomly in the first round and downloaded from the global server in the next rounds.
(2) Each participant trains the model with its dataset for E l epochs individually. (3) All participants calculate parameter increments compared to the original parameters in a round, and all parameter increments are sent to the global server. (4) The global server aggregates all parameter increments by average, and updates a set of global parameters. Before the next local training, the global parameters are downloaded for local model updating.
Sample a minibatch B s 8: Compute gradients: Update local parameters: Send ∆W i t and data size S i to the global server 15: end for Following this pipeline, our federated training continues until convergence.
Local Training. In our FedOCR, each participant i and the global server maintain a set of local model parameters W i and W global , respectively. Algorithm 1 describes the local training process of our framework. As shown, all participants first download the latest global parameters from the global server and overwrite their local parameters. Then, participants train local models with their datasets independently for E l epochs and send parameter increments to the global server. During local training, all participants do not share any image data with others. To update the global parameters efficiently, all participants should train their models enough before parameter transmission. McMahan et al. (McMahan et al. 2016) demonstrate that sufficient epochs of local training can bring a dramatic increase in parameter update efficiency. Detailed experiment settings of our FedOCR are provided in the next section.
Global Aggregation. To aggregate parameter increments from different local participants, McMahan et al. (McMahan et al. 2016) propose a straightforward approach to aggregate all local participants' parameters by average. Following steps in Algorithm 2, we adapt the federated average method (McMahan et al. 2016) to our federated scene text recognition framework. In the global aggregation step of our FedOCR, we average all parameter increments and update former global parameters, which are available for all participants' downloading.

Communication Efficiency
Communication efficiency is an essential property in federated learning. For instance, if the size of one participant's model is one hundred megabytes, tens of gigabytes will be required to transmit in a round, when hundreds of clients participate in a federated learning framework. Under such a circumstance, plenty of parameters result in huge communication costs, which lead to a training bottleneck. To reduce Algorithm 2: Global Aggregation Assume the total size of weight matrix W l is T l 3: Generate a real weight vector R l with a size T l * γ 4: Generate a random sort RS l of numbers from 0 to T l − 1 with a hashing function and a seed seed l

5:
Generate an index vector I l : [ e · γ , for e in RS l ]

6:
Reshape I l as the shape of W l 7: Generate a virtual weight matrix: V l = R l [I l ] 8: end for 9: Initialize our network with R l , l ∈ [0, L − 1], and the total parameter size is compressed to γ · L−1 l=0 T l communication burdens, we replace the heavyweight backbone, such as ResNet (He et al. 2016), for feature extraction in text recognizers with a lightweight neural network.
To further decrease the parameter size, we extend a hashing technique (Chen et al. 2015) to compress the parameters of CNN and RNN, which makes it applicable for any text recognizer. In this way, the text recognizer in our FedOCR has much fewer parameters compared with existing text recognition algorithms, which shows great potential in practical federated learning deployment.
Hashing Technique. In fact, any well-designed scene text recognition model can be applied in our federated learning framework. However, considering the communication efficiency, the network with fewer parameters is more appropriate and practical. Therefore, we propose to compress model parameters by a hashing technique. Specifically, we compress network parameters in a weight sharing manner that a random subset of parameters in a layer share the same parameter. Following Algorithm 3, we can compress the parameters in a scene text recognition network with a hyperparameter γ to control the compression ratio, and it can reduce the parameter size to a large extent. It should be noted that e · γ means the largest integer that is smaller than e · γ in Algorithm 3. Notably, the specific hashing function and the random seeds are shared among all local participants to keep the same relationship between real weight vectors and virtual weight matrices of all local models.
Text Recognizer. Following the above methods, we can improve any existing text recognition algorithms to construct a lightweight text recognizer. Specifically, in our experiments, we optimize a classical text recognizer, ASTER (Shi et al. 2018). We replace the encoder in ASTER with ShuffleNetV2 (Ma et al. 2018) and apply the hashing technique to the entire model parameters. Benefited from hashing techniques and lightweight networks, we successfully decrease communication costs to a large extent in our federated learning framework. Moreover, we keep the network structure and experiment settings the same with ASTER as much as possible. Similar to ASTER, the text recognizer in our experiments consists of a rectification network, a lightweight convolutional encoder, and an attentional sequence-to-sequence model. We briefly introduce the method of scene text recognition as follows: Firstly, an input image is rectified by a rectification network before being sent into a recognition network. The rectification network based on the Spatial Transformer Network (STN) aims to rectify perspective or curved texts. Secondly, we use a lightweight neural network as the encoder to extract the feature sequence from the rectified image. Lastly, we use an attentional sequence-to-sequence model as the decoder to translate the feature sequence. During inference, we use beam searching by holding five candidates with the highest accumulative scores at every step.
Network Training. After neural network initialization, the mapping relationship between real weight vectors and virtual weight matrices is fixed, which is defined in Algorithm 3. In the forward computation, it is the virtual weight matrices that participate in calculation with input features. In the backward propagation, the gradients of all parameters in real weight vectors are calculated based on virtual weight matrices' parameter gradients.
Let V l i,j denote the i-th row and j-th column element of a virtual weight matrix at layer l, and let R l k denote the k-th element in the corresponding real weight vector. Assuming that where g l i,j is computed from the loss. Moreover, Based on the above equations, we can obtain any parameter's gradient in the real weight vector as follows: (3)

Privacy Preserving
Federated learning can provide training procedures at a high level of security, but the global server still has a chance to compromise data privacy, such as model inversion (Fredrikson, Jha, and Ristenpart 2015) and GAN-based attacks (Hitaj, Ateniese, and Perez-Cruz 2017). Usually, local network parameters or their increments are sent to the global server in each communication round, which gives the honest-butcurious server a chance to spy on local sets of data. In recent works, Geiping et al. (Geiping et al. 2020) and Phong et al. (Phong et al. 2018) show that the gradients may reveal information of training samples and apply an additively homomorphic encryption scheme to their federated framework. Shokri et al. (Shokri and Shmatikov 2015) propose to upload partially gradients added with noise to avoid information leakage, and apply differential privacy to parameter updates for a higher level of security. However, the above methods bring more computational costs or a dramatic decrease in accuracy because of the privacy-preserving module.
In our FedOCR, we adopt the hashing technique to compress the entire model parameters with a hashing function and random seeds. They are equivalent to an encryptiondecryption module and the keys, but it can save much computational costs without the encryption-decryption step. For the parameter aggregation in the global server, we only upload increments of the parameters in real weight vectors, which can not be used to reconstruct the complete network without the specific hashing function and the random seeds. As for all local participants, they share the same hashing function and random seeds, so the average operation in the global aggregation can be directly applied to these parameter increments. Therefore, the global server can not compromise the private data, while it can finish its global aggregation task. Moreover, the other attackers also can not do anything with the compressed parameter increments, because they mean nothing without hashing functions and seeds. In this way, we enhance the privacy-preserving in our FedOCR without introducing an extra computational cost.

Experiments Datasets
Two synthetic datasets (Jaderberg et al. 2014;Gupta, Vedaldi, and Zisserman 2016) and six public real-world datasets are used to train local models, and our models are evaluated on seven general datasets. In our federated settings, we construct different local datasets with the public real-world datasets. These datasets are briefly introduced as follows: Synth90k (Jaderberg et al. 2014) contains 9 million images generated from a set of 90k English words. Words are rendered onto natural images with random transformations and effects.
SynthText (Gupta, Vedaldi, and Zisserman 2016) contains 0.8 million images for end-to-end text detection and recognition tasks. Therefore, we crop word images using the ground-truth word bounding boxes.
ICDAR 2003 (IC03) (Lucas et al. 2005) contains 860 cropped word images for evaluation after discarding images that contain non-alphanumeric characters or have fewer than three characters, which follows (Mishra, Alahari, and Jawahar 2012). For training, we use 1150 cropped images after filtering.
ICDAR 2013 (IC13) (Karatzas et al. 2013), which inherits most images from IC03 and extends it with new images, contains 1015 cropped word images for evaluation after filtering. For training, we use 848 cropped images after filtering.
ICDAR 2015 (IC15) (Karatzas et al. 2015) contains images captured by a pair of Google Glasses casually, and many images are severely distorted or blurred. For a fair comparison, we evaluate models on 1811 cropped word images after filtering. For training, we use 4426 cropped images after filtering.
IIIT5K-Words (IIIT5K) (Mishra, Alahari, and Jawahar 2012) contains 3000 word images collected for evaluation and 2000 word images for training, which are mostly horizontal text images.
Street View Text (SVT) (Wang, Babenko, and Belongie 2011) is collected from the Google Street View, and it contains 647 images of cropped words, many of which are severely corrupted by noise, blur, or low resolution.
Street View Text Perspective (SVTP) (Quy Phan et al. 2013), which is collected from Google StreetView and contains many distorted images, contains 645 word images for evaluation. (Risnumawan et al. 2014) contains 80 real-world curved text images with high quality. For evaluation, we crop 288 word images according to its ground-truth.

CUTE80 (CUTE)
ArT (Chng et al. 2019) is a combination of Total-Text, SCUT-CTW1500, and Baidu Curved Scene Text, which contains images with arbitrary-shaped texts. For training, we use 30271 word images after discarding images that contain non-alphanumeric characters and vertical texts. (Veit et al. 2016) is based on the MS COCO dataset, which contains images of complex everyday scenes. For training, we use 31943 cropped images after discarding images that contain non-alphanumeric characters and vertical texts.

Experiment settings
Decentralized Datasets for Federated Learning Different local datasets are constructed by public real-world datasets in our experiment settings. We use the training images from IC03 (Lucas et al. 2005), IC13 (Karatzas et al. 2013), IC15 (Karatzas et al. 2015), IIIT5K (Mishra, Alahari, and Jawahar 2012), ArT (Chng et al. 2019), and COCO-Text (Veit et al. 2016). As a sequence, we have 70638 realword text images in total. To simulate the decentralized datasets distributed on local devices in federated learning, we, as an honest server, should not known the data distribution and whether there is a data bias. Hence, we randomly split all training images into different sets of image data for C participants, It should be mentioned that these different sets of image data should not be shared or transferred to other participants during the training procedures.
Federated Settings. Some hyper-parameters should be noted in our federated settings: C, the number of participants in our federated scene text recognition framework; γ, the compression ratio of the hashing technique; E l , the number of epochs that each local participant trains the model with its dataset before communication with the global server; B, the batch size in local training. In our experiments, we set C = 5, E l = 3, B = 512 and γ ∈ {1/2, 1/4, 1/8}.
Baseline and FedOCR-Hash. In our experiments, we adopt ASTER 1 (Shi et al. 2018) as the text recognition baseline in our FedOCR, which is denoted as ASTER-FL. Then, we replace the encoder in ASTER-FL with Shuf-fleNetV2 (Ma et al. 2018), and this variant of ASTER-FL in our FedOCR is denoted as FedOCR-Hash 1 . To further reduce the parameter size, we apply the hashing technique to compress FedOCR-Hash 1 with different ratios γ ∈ {1/2, 1/4, 1/8}, and these models are denoted as FedOCR-Hash γ in the following paper.
Implementation Details. Following the federated settings, we construct C = 5 participants in our FedOCR for experiments. In each local training, all models are locally trained via Adadelta (Zeiler 2012) with an initialization learning rate of 1.0, and each participant trains the scene text recognition model with its dataset individually for E l = 3 epochs in each round. All word images are trained directly without data argumentation. As for the complete federated training process of our FedOCR, each participant trains its model with the two synthetic datasets for 4 rounds, then trains on its real-world dataset for 40 rounds.
The learning rate is decayed to 0.1 and 0.01 at the 5-th round and the 30-th round, respectively. Following Algorithm 2, in the global aggregation step, the global server aggregates the parameter increments from all participants by average. To simply simulate the communication procedure of federated learning, we replace the parameter transmission between participants and the global server with saving and restoring checkpoints on the hard-disk.
Evaluation Metric. In our experiments, we use the caseinsensitive word accuracy for evaluation. If the word prediction and the ground-truth are the same in the lower case, the prediction is correct. The recognition accuracy is the percentage of the correct number of total. Furthermore, the objective of FedOCR is to minimize the difference between the accuracy of the text recognizer trained with decentralized datasets and trained with a centralized dataset. A smaller difference means a better performance of our FedOCR.

Experiments on FedOCR
In this subsection, we first compare the parameter reduction and the accuracy decrease of different models in our Fe-dOCR. Then, we analyze the performance of our FedOCR compared with the other two training manners and show that   training means that the model is trained with a centralized set of image data. Third, "federated" training means that the model is trained with decentralized sets of image data in a federated manner. As shown in Tab. 2, "federated" and "centralized" training results of all models are similar to each other and better than "single" training results. In the "single" training manner, scene text recognition faces the problem in practice that the image data for training is limited, which causes poor performance in scene text recognition. However, we succeed in training a shared model with decentralized sets of image data collaboratively in the "federated" training manner, and we do not exchange or expose any image data to other participants. Expectantly, our Fe-dOCR achieves comparable results, which are very close to the results of the "centralized" training manner. Therefore, our FedOCR is effective to train a more robust model without centralizing datasets on different local devices.
Communication Efficiency Improvement. In Tab. 2, FedOCR-Hash 1 shows comparable accuracy with ASTER-FL in the "federated" training manner. Owing to the lightweight backbone in FedOCR-Hash 1 , it has fewer parameters than ASTER-FL, which benefits communication efficiency in federated learning. As shown in Fig. 3, FedOCR-Hash 1 has a higher accuracy than ASTER-FL when little communication bytes are uploaded. Fig. 3 illustrates the accuracy curves of different models on IIIT5k versus uploaded bytes in federated training procedures. FedOCR-Hash γ with a smaller compression ratio γ achieves higher accuracy when limited communication bytes are uploaded, and it shows greater advantages in communication efficiency. The advantage of our FedOCR-Hash γ will be more distinctive when more local clients participate in our FedOCR. Considering both Tab. 1 and 2, FedOCR-Hash 1/4 with an appropriate compression ratio γ shows a significant overall performance in communication efficiency and accuracy of federated learning. Only 13.38 megabytes are required to be transmitted by each participant, which results in a faster parameter transmission with the same communication bandwidth.
Benefited from lightweight models and hashing techniques, our federated scene text recognition framework shows a comparable performance and advantages in communication efficiency. Considering plenty of participants and the unstable data transmission network in the real world, our FedOCR has great potential in practical application deployment.

Conclusion and Future Work
In this paper, we reveal the problem of data privacy in scene text recognition and address the difficulty in utilizing decentralized datasets distributed on local devices with federated learning. To the best of our knowledge, we propose the first federated scene text recognition framework named FedOCR. In our FedOCR, we succeed in training a shared text recognizer collaboratively with decentralized datasets and avoid violating rules of data privacy. Benefited from lightweight models and hashing techniques, we reduce communication costs to a large extent and provide higher-level privacy-preserving against the honestbut-curious global server. In terms of taking advantage of tremendous decentralized real-world data in practice, our communication-efficient federated learning framework for scene text recognition shows intriguing merits.
Recently, the domain shift in scene text recognition has attracted great interest in academia, and some methods are proposed, such as GA-DAN (Zhan, Xue, and Lu 2019) and SSDAN . Notably, the domain shift occurs in federated learning for scene text recognition as well, which leads to a deterioration on the global accuracy. Hence, we are working on the domain adaptation of decentralized datasets within our framework.