{'fraction_non_alphanumeric': 0.03809447106672573, 'fraction_numerical': 0.012966617001570492, 'mean_word_length': 4.690650779101741, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Semi-Online Knowledge Distillation

Knowledge distillation is an effective and stable method for model compression via knowledge transfer. Conventional knowledge distillation (KD) is to transfer knowledge from a large and well pre-trained teacher network to a small student network, which is a one-way process. Recently, deep mutual learning (DML) has been proposed to help student networks learn collaboratively and simultaneously. However, to the best of our knowledge, KD and DML have never been jointly explored in a unified framework to solve the knowledge distillation problem. In this paper, we investigate that the teacher model supports more trustworthy supervision signals in KD, while the student captures more similar behaviors from the teacher in DML. Based on these observations, we first propose to combine KD with DML in a unified framework. Furthermore, we propose a Semi-Online Knowledge Distillation (SOKD) method that effectively improves the performance of the student and the teacher. In this method, we introduce the peer-teaching training fashion in DML in order to alleviate the student's imitation difficulty, and also leverage the supervision signals provided by the well-trained teacher in KD. Besides, we also show our framework can be easily extended to feature-based distillation methods. Extensive experiments on CIFAR-100 and ImageNet datasets demonstrate the proposed method achieves state-of-the-art performance.


Introduction
In recent years, deep learning has demonstrated great success in many computer vision tasks such as image classification [10,15,24], object detection [18,22,33] and image generation [7,19,44], which mainly benefits from deeper and larger convolutional neural network architectures. However, these architectures require huge computation and massive storage, which makes them hard to deploy on resource-limited devices such as mobile phones and drones. Therefore, many recent studies have focused on network compression methods, including network pruning [6,11,45], network quantization [29,30,31], and knowledge distillation [12,23,35].
Knowledge distillation is a simple yet effective technology, which is orthogonal to other model compression methods. Existing distillation methods can be roughly divided into offline knowledge distillation and online knowledge distillation [9]. Without loss of generality, in this paper we investigate the typical offline and online knowledge distillation methods, namely KD [12] and deep mutual learning (DML) [42]. The key idea of KD is to improve the performance of a compact network (student) via the knowledge transfer from a large and well-trained network (teacher). Specifically, Hinton et al. [12] regard the softened output probabilities of the teacher as knowledge and propose that the student absorbs this knowledge by approximating the teacher's outputs. Whereas, the student is generally hard to fully absorb the knowledge provided by the teacher in practice (i.e., fully match the outputs of the teacher). The main reason is that there exists a large performance gap between the converged large network and untrained small network [16]. On the contrary, the networks in DML are easier to approach and learn from each other because they are regarded as students and trained simultaneously. Such peer-teaching training fashion makes the networks easily imitate the behaviors (i.e., representations and outputs) of each other. However, since all networks in DML are trained from scratch and their optimization directions seem unstable in the early training phase, there exist many unreliable supervision signals, which might lead to conflicts of networks' optimization [9]. Although both KD and DML exist some shortcomings, we argue that they are complementary to each other for knowledge distillation problem.
To verify the above viewpoint, we evaluate the imitation ability of the student 1 based on CKA similarity [17] and two well-defined metrics which are imitation error rate (IER) and misleading rate (MR). We empirically found that 1) The peer-teaching training fashion in DML is a more effective way than one-way flow in KD for the student to learn similar behaviors of the teacher. 2) The well-trained teacher in KD can provide more trustworthy and stable supervision signals for the student than the teacher in DML. (See discussion in detail in section 3.2).
Based on the above observations, in this paper we first propose a unified framework combining KD with DML, which effectively leverages the teacher's supervision signals in KD and alleviates the imitation difficulty via the peer-teaching training fashion in DML. To this end, we further propose a Semi-Online Knowledge Distillation (SOKD) method. In this method, we build a simple yet effective knowledge bridge module (KBM) to exploit the knowledge from the offline teacher and transfer it to the student online. Specifically, the KBM is the same as the high-level layers of the teacher while taking the output of the lowlevel layers as input. In the training phase, inspired by DML, we update the KBM and the student simultaneously while fixing the teacher. In the inference phase, we replace high-level layers with KBM to construct a new teacher. As a result, we obtain a compact but effective student as well as, surprisingly, a more powerful teacher.
Our contributions are summarized as follows: • We discover that KD and DML are complementary to each other on knowledge distillation task. Based on this observation, we propose a novel distillation method combining KD with DML. To the best of our knowledge, we are the first to jointly integrate KD with DML in a unified framework.
• We propose a Semi-Online Knowledge Distillation (SOKD) method that significantly improves the performance of the student and the teacher. To leverage the well-trained teacher's supervision signals and alleviate the imitation difficulty of the student, we propose a simple yet effective knowledge bridge module (KBM).
• We further extend our proposed framework to feature-based distillation methods. Extensive experiments on CIFAR-100 and ImageNet datasets demonstrate that the proposed SOKD not only outperforms state-of-the-art model distillation methods but also can be easily extended to feature-based distillation methods for improved learning accuracy.

Related Work
Offline Knowledge Distillation. The training process of traditional offline knowledge distillation can be split into two stages: 1) pre-training a teacher; and 2) distilling the knowledge of teacher into student. Most existing work mainly concentrate on how to define and transfer knowledge. For example, Hinton et al. [12] first propose to mimic softened logits of teacher. Romero et al. [23] propose to match the intermediate representations of the teacher and the student. After that, many studies investigate how to clearly define the knowledge based on the intermediate feature maps [27,38]. However, most feature-based distillation methods are sensitive to the structures of the teacher and the student [26,32]. Instead, in this paper we focus on improving the student's capacity to imitate the logits of the teacher. Such logit-based knowledge distillation can be well generalized to different teacher-student combinations.
Online Knowledge Distillation. Zhang et al. [42] propose an online distillation scheme called deep mutual learning (DML), in which all networks are treated as students and updated simultaneously. To reduce the computational cost, Lan et al. [43] propose a multibranch network. Recently, Chen et al. [4] introduce the self-attention mechanism to improve the diversity of students. However, the different outputs of students will conflict with each other, which may harm the convergence of training [9]. To improve the ability of converging with higher generalization, Guo et al. [9] generate a high-quality soft target via ensembling the output of students. Besides, some studies [13,36,40] propose self-distillation methods, the special cases of online knowledge distillation, in which the teachers and students are the same networks. In this paper, we introduce the peer-teaching training fashion in DML into KD to simplify the difficulty for student to imitate teacher's behaviors.

Preliminary
Knowledge Distillation. The key idea of KD is that the student uses the softened output of the teacher as supervised signal for network training. Given the i th sample, we can get the logits z i = (z 1 i , z 2 i , ..., z C i ) before softmax function. Then the softened output probability of the teacher network is computed as: where τ is a temperature factor. Similarly, the student produces a softened target p s i . The student mimics outputs of the teacher by minimizing Kullback-Leibler (KL) Divergence KL(p s , p t ). The total loss for the student network consists of the typical cross entropy loss L s ce and the KL Divergence: λ 1 and λ 2 are hyperparameters. Deep Mutual Learning. Zhang et al. [42] propose an online knowledge distillation method named deep mutual learning, in which the teacher and the student networks are updated simultaneously. Specifically, the teacher and the student optimize their networks with their respective loss functions L t and L s . The formulations are as follows: λ 1 and λ 2 are hyperparameters.

Analysis on Imitation Ability of Student
In distillation methods, the student is expected to imitate the behaviors of the teacher, which means that the performance of the student largely depends on its imitation. To investigate the mimic ability of the student in KD and DML, we conduct experiments with the teacherstudent pair of WRN-28-4 and WRN-16-2 on CIFAR-100 dataset. Specifically, we use CKA [17] to measure the representational similarity between the teacher and the student. The larger the CKA, the more similar the representations between teacher and student. Besides, we define the imitation error rate (IER) and the misleading rate (MR) as the metrics to measure the ability to imitate the final output. IER refers to the rate of different outputs between the teacher and the student. MR represents the rate of wrong outputs learned from the teacher. Let D st be the samples with the same prediction results between the teacher and the student in the training data D, D sg be the samples with the same prediction results between the ground-truth and the student in D st . IER and MR are computed as (1 − |D st |/|D|) × 100 and (1 − |D sg |/|D st |) × 100, respectively. | · | denotes number of samples. From table 5, DML achieves much higher CKA and lower IER than KD, which means that the student in DML has stronger abilities to capture the representations of the teacher and mimic the output probabilities of the teacher effectively. However, DML achieves highest MR, meaning that the student in DML has learned much more wrong information from the teacher. The main reason is that in the early training phase the optimization direction of the teacher is unstable. The supervision signals provided by the teacher might be inaccurate and changing. Fortunately, we are able to easily obtain reliable supervision signals from the well-trained teacher in KD. Therefore, it is possible for the student to learn similar and accurate behaviors from the teacher and effectively improve its performance.

Semi-Online Knowledge Distillation
Based on above analysis, the training mechanism that the teacher and the student are updated simultaneously in DML is an effective way for the student to learn similar behaviors of the teacher. Besides, the well-trained teacher in KD provides reliable and stable signals for the student. In this paper, we propose to integrate KD with DML in a unified framework. To this end, we propose a Semi-Online Knowledge Distillation (SOKD) framework that effectively improves the performance of the student and the teacher. The overview of our framework  Figure 1: An overview of the proposed SOKD. In the training phase, the teacher is fixed. The knowledge bridge module (KBM) is trained under the supervision of both the teacher and the student. The student is to mimic the output of the KBM. In the inference phase, we reconstruct the teacher network with low-level layers and KBM. In this way, we obtain a well-trained student network as well as a retrained teacher network.
is shown in figure 1, which consists of three parts, well-trained teacher (low-level and highlevel layers), knowledge bridge module (KBM), and student. The KBM is proposed to build a knowledge bridge between the teacher and the student. We take the outputs of low-level layers as the inputs of KBM. More details about KBM will be discussed in section 3.4.
In the training phase, the KBM tries to fully exploit the knowledge of the teacher and transfer it to the student. Meanwhile, the KBM also gains the feedback from the student. Specifically, we do not update the parameters of the teacher since it would destroy the inherent knowledge of the teacher. Instead, we update the parameters of the KBM and the student simultaneously, which is a more tolerant way for the student to approach what the teacher expresses. The training objectives of the KBM and the student can be written as: where α 1 , α 2 , α 3 , λ 1 , λ 2 are balanced hyperparameters. KL divergence is computed by Eqn. 2. In this sense, we are able to obtain a compact but effective student network. Besides, we also get a more powerful teacher by reconstructing the teacher network with low-level layers and KBM.

Knowledge Bridge Module
In this subsection, we discuss how to build the KBM, the structure of which is motivated by characteristics of Convolutional Neural Network (CNN). CNN can be roughly composed of low-level and high-level layers. Given a face image, the features detected by low-level layers are usually some fundamental patterns, e.g., edge, corner, and color, which are not sensitive to classes [2]. By contrast, the features extracted by high-level layers may be a full face, which is class-specific and related to the output closely. In other words, the discriminative power of a CNN is mainly reflected in the high-level layers [39].  Table 2: Comparison with state-of-the-art online methods on CIFAR-100 dataset. We refer to the smaller network in online methods as student, otherwise as teacher.
Based on the above theoretical analyses, we design the KBM to be the same as the teacher's high-level layers while using its low-level layer's output as input. Formally, given a pre-trained teacher model M t , our main goal is to obtain a compact yet efficient student model M s . For simplicity, low-level and high-level layers are denoted by {M t i } l i=1 and {M t i } L i=l+1 , respectively. To build a knowledge bridge between M t and M s , we propose the KBM M kbm . The KBM is the same as {M t i } L i=l+1 and takes the output of {M t i } l i=1 as input. The main characteristics of the KBM are: 1) Since KBM is the same as high-level layers of the teacher, it has the ability to approach what the teacher expresses. 2) Since different networks have similar representations in low-level layers, sharing the low-level layers would not greatly affect the performance of the KBM. Conversely, it is similar to layer-wise training [3,28], which boosts training stability. Besides, it only brings a small amount of extra calculations.

Extension to Feature-Based Methods
In this subsection, we investigate the possibility of extending our method to feature-based methods. The main differences between feature-based and logit-based methods lie in the definition of the knowledge and learning objectives of the student. Feature-based methods learn from the teacher by minimizing the distance (e.g.,    Table 4: Test error (%) of different online methods on ImageNet. We refer to the smaller network in online methods as student, otherwise as teacher.

Experimental Details
Choices of Teacher and Student. We consider six types of networks, including WideRes-Net [37], resnet [10], vgg [25], MobileNet [14], MobileNetV2 [24], and ShuffleNetV1 [41]. For convenience, we use WRN-d-w to denote the WideResNet with depth d and width factor w and MBNV2 (w) to denote MobileNetV2 with a width multiplier of w. We use resnetd and ResNetd to represent CIFAR-style and ImageNet-style resnet with depth d, respectively. Besides, we use the following rules to construct teacher-student pairs: 1) the teacher and the student have the same architectural style (e.g., vgg13 and vgg8); 2) the teacher and the student are different architectures (e.g., WRN-28-4 and resnet56). Implementation Details. We implement our methods on PyTorch [20]. We run compared methods based on two knowledge distillation benchmarks 2 and author-provided codes. 1) For CIFAR-100 dataset, we train all networks for 200 epochs. We use an SGD optimizer with a mini-batch size of 128, the momentum of 0.9, and the weight decay of 5e-4. The learning rate is initialized by 0.1 (MobileNetV2 and ShuffleNetV1 by 0.05) and divided by 10 at both 100 and 150 epochs. 2) For ImageNet dataset, we follow the standard ImageNet parallel training practice on PyTorch. We set the batch size to 256 and train the student model for 100 epochs. The initial learning rate is 0.1 and decayed by 10 at 30, 60 and 90 epochs, respectively. We set λ 1 = λ 2 = α 1 = α 2 = α 3 = 1, τ = 3 for our SOKD on both CIFAR-100 and ImageNet. Code can be found at https://github.com/swlzq/Semi-Online-KD.  Table 5: CKA similarity [17], imitation error rate (IER), and misleading rate (MR) on CIFAR-100 dataset. We take WRN-28-4 and WRN-16-2 as the teacher and the student, respectively.

Comparisons with Offline Methods
Results on CIFAR-100. In this experiment, we compare our proposed SOKD with KD [12], AT [38], SP [27], CC [21], VID [1], CRD [26], SSKD [32] and SemCKD [5] on eight teacher-student combinations. From Table 1, our SOKD outperforms all of compared methods by a large margin on all teacher-student pairs, which demonstrates the effectiveness and generalization of our method. It is worth noting that our SOKD not only achieves high performance in terms of the student's accuracy, but also improves the performance of the teacher. Specifically, the teacher of our SOKD outperforms the vanilla pretrained teacher by 1.87% Top-1 accuracy, ranging from 1.54% to 2.32%. Similar to Vanilla KD method, our SOKD only leverages logit-based knowledge while showing superior performance than existing state-of-the-art feature-based methods. We show that the knowledge of logit still has huge room for improvement, which is usually underestimated by existing methods. Results on ImageNet. In this experiment, we evaluate our proposed SOKD on Ima-geNet dataset. Constrained by limited computational resources, we only use ResNet34 and ResNet18 as teacher and student network, respectively. As shown in Table 3, our proposed SOKD outperforms other state-of-the-art methods. Specifically, our SOKD outperforms KD of 1.30% in terms of Top-1 accuracy. Besides, the teacher of SOKD achieves 0.84% higher Top-1 accuracy than vanilla teacher. These results show the generalization of our proposed SOKD in the large-scale dataset.

Comparisons with Online Methods
Results on CIFAR-100. In this experiment, we compare our SOKD with three state-of-theart online KD methods (i.e., DML [42], KDCL [8], DCM [34]). We consider two training scenarios: 1) training two models with same backbone; 2) training two models with different backbones. We show the results in Table 2. From this table, we have the following observations: First, our SOKD gains the best student models. Second, it is interesting to find that SOKD further improves the accuracy of the teacher models, which never occurs in traditional offline KD methods. Specifically, our SOKD evenly achieves 1.96% higher Top-1 accuracy on four teacher-student pairs. Furthermore, although our main goal is to obtain a small and effective student model, we can further improve teacher by simply adjusting the structure of KBM, which will be discussed in section 4.4.
Results on ImageNet. In this experiment, we conduct experiments with two teacherstudent pairs. We do not compare with KDCL [8] due to unavailable code on ImageNet. As shown in Table 4, our SOKD performs better than all compared methods. Specifically, for ResNet50-ResNet18 pair, SOKD has increased the accuracy of vanilla student and teacher by 1.81% and 0.38%, respectively. These results show effectiveness of our SOKD.

Method
Vanilla AT DML-AT SO-AT SP DML-SP SO-SP CRD DML-CRD SO-CRD   Table 7: Effect of different KBMs on CIFAR-100 dataset. The last row "whole network" means the KBM is the same as the whole teacher network (It refers to WRN-28-4 here).

Further Experiments
Imitation Ability of Student. In this experiment, we try to analyze the degree to which the student imitates the teacher. From Table 5, we observe that 1) online methods (i.e., DML, KDCL, DCM) generally have learned similar representations to the teacher (higher CKA and lower IER) while suffering more serious misleading (higher MR). 2) our SOKD achieves much higher CKA and lower IER than all of compared methods, revealing that our SOKD has stronger ability to capture the behaviors of the teacher. Meanwhile, the supervision signals provided by the teacher in SOKD are much more accurate (lower MR) than that in DML. The main reason is that the KBM is able to obtain valuable information from the well-trained teacher.
Extensions to Feature-Based Methods. To investigate the scalability of our SOKD, we extend it to feature-based methods. Since feature information is related to network structure, we choose two different combinations of the teacher and the student in this experiment. Meanwhile, we also try to apply the training framework of DML into different methods. For simplicity, we use "DML/SO-M" to denote training M method with DML/SOKD framework. From Table 6, the performance of feature-based methods significantly decreases when applied with DML framework on most cases but our SOKD performs better than baselines. One possible reason is that in the early training of DML the representations might be meaningless, which would mislead the optimization directions of the teacher and the student. Instead, the training of SOKD is supervised by a well-trained teacher, which has learned powerful representations.
Effect of Different KBMs. In this experiment, we investigate the effect of different KBMs. We design the KBM with last classifier layers and last n feature extractor blocks of the teacher. As shown in Table 7, all KBMs achieve better performance than KD, which demonstrates the effectiveness and flexibility of our SOKD. The KBM can be changed according to different demands while maintaining the performance. However, the KBM with only classifier performs much worse than those with several extractor blocks, which means that it is necessary to adjust the parameters of intermediate layers such that the student is easier to learn similar representations from the teacher. However, taking the whole WRN-28-4 as KBM does not lead to further improvement, which shows the necessity of sharing teacher's low-level layers. For the purpose of reducing computational cost, in this paper, we set the structure of KBM to be the same as the last feature extractor block and last classifier in most cases.
Effect of Different Losses for KBM. We investigate the effect of different losses for  KBM. The results are shown in table 8. When only equipped with L kbm ce , the performance of the student is improved. The main reason is that KBM and student are trained simultaneously, the student is easier to imitate the KBM than the well-trained teacher. However, only adding the supervision of the teacher (i.e., w/o KL(p kbm , p s )) or only obtaining the feedback from the student (i.e., w/o KL(p kbm , p t )) both lead to performance degradation, which shows the indispensability of reliable signals and real-time feedback. Equipped with all losses, both teacher and student achieve highest accuracy, which shows the effectiveness of proposed losses for the KBM.

Conclusion
In this paper, we have discovered that KD and DML are complementary to each other on knowledge distillation task. Inspired by this observation, we have proposed a Semi-Online Knowledge Distillation (SOKD) method that integrates KD with DML. Our SOKD have effectively leveraged the well-trained teacher's supervision signals and alleviated the imitation difficulty of the student. Moreover, we have extended the proposed framework to feature-based distillation methods, which also achieved competitive performance. Extensive experiments on two benchmarks have shown that our method consistently outperforms state-of-the-art methods on knowledge distillation tasks with different teacher-student pairs.