{'fraction_non_alphanumeric': 0.04569818957501504, 'fraction_numerical': 0.021030465459716676, 'mean_word_length': 4.597275371192408, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
RepMLPNet: Hierarchical Vision MLP with Re-parameterized Locality

Compared to convolutional layers, fully-connected (FC) layers are better at modeling the long-range dependencies but worse at capturing the local patterns, hence usually less favored for image recognition. In this paper, we propose a methodology, Locality Injection, to incorporate local priors into an FC layer via merging the trained parameters of a parallel conv kernel into the FC kernel. Locality Injection can be viewed as a novel Structural Re-parameterization method since it equivalently converts the structures via transforming the parameters. Based on that, we propose a multi-layer-perceptron (MLP) block named RepMLP Block, which uses three FC layers to extract features, and a novel architecture named RepMLPNet. The hierarchical design distinguishes RepMLPNet from the other concurrently proposed vision MLPs. As it produces feature maps of different levels, it qualifies as a backbone model for downstream tasks like semantic segmentation. Our results reveal that 1) Locality Injection is a general methodology for MLP models; 2) RepMLPNet has favorable accuracy-efficiency trade-off compared to the other MLPs; 3) RepMLPNet is the first MLP that seamlessly transfer to Cityscapes semantic segmentation. The code and models are available at https://github.com/DingXiaoH/RepMLP.


Introduction
The locality of images (i.e., a pixel is more related to its neighbors than the distant pixels) makes Convolutional Besides, we also desire the ability to build up long-range dependencies, which is referred to as the global capacity in this paper. Traditional CNNs model the long-range dependencies by deep stacks of conv layers [40]. However, repeating local operations may cause optimization difficulties [1,20,40]. Some prior works enhance the global capacity with self-attention-based modules [18,39,40], which have no local prior. For example, due to the lack of local prior, ViT [18] requires an enormous amount of training data (3 × 10 8 images in JFT-300M) to converge. On the other hand, a fully-connected (FC) layer can also directly model the dependencies between any two input points, which is as simple as flattening the feature map as a vector, linearly mapping it into another vector, and reshaping the resultant vector back into a feature map. However, this process has no locality either. Without such an important inductive bias, the concurrently proposed MLPs [26,36,37,43] usually demand a huge amount of training data (e.g., JFT-300M), more training epochs (300 or 400 ImageNet [8] epochs) or special training techniques (e.g., a DeiT-style distillation method [37,38]) to learn the inductive bias from scratch. Otherwise, they may not reach a comparable level of performance with traditional CNNs.
We desire an MLP model that is 1) friendly to small-data, 2) trainable with ordinary training methods, and 3) effective in visual recognition. To this end, we make contributions in three aspects: methodology, component and architecture.
Methodology We propose a novel methodology, Locality Injection, to provide an FC layer with what it demands for effective visual understanding: the locality. Specifically, we place one or more conv layers parallel to the FC and add up their outputs. Though the FC simply views 1) The Global Perceptron aggregates the information across all the spatial locations and establishes the relations among channels. 2) In parallel, the input feature map is split into s share-sets and fed into the Channel Perceptron, which simply reshapes the features into vectors, linearly maps it to the output vectors, and reshapes them back.
3) The Local Perceptron takes the same inputs as the Channel Perceptron but convolve with small kernels to capture the local patterns. This example uses 1×1 and 3×3 so that the padding should be p = 0 and 1, respectively, to maintain the feature map size. Through batch normalization (BN) [22], the outputs of Local Perceptron and Channel Perceptron and added up. Finally, we combine the global and channel-wise information by merging the outcomes of the Global Perceptron. After training, the conv layers are absorbed into the FC3 kernel via Locality Injection, so that the training-time block is equivalently converted into a three-FC block and used for inference.
the feature maps as vectors, completely ignoring the locality, the conv layers can capture the local patterns. However, though such conv layers bring only negligible parameters and compute, the inference speed may be considerably slowed down because of the reduction of degree of parallelism on high-power computing devices like GPUs [30]. Therefore, we propose to equivalently merge the conv layers into the FC kernels after training to speed up the inference. By doing so, we obtain an FC layer that is structurally identical to a normally trained FC layer but is parameterized by a special matrix with locality. Since Locality Injection converts the training-time structure (FC + conv) to the inference-time (a single FC) via an equivalent transformation on the parameters, it can be viewed as a novel Structural Re-parameterization [11,[13][14][15][16] technique. In other words, we equivalently incorporate the inductive bias into a trained FC layer, instead of letting it learn from scratch.
The key to such an equivalent transformation is converting an arbitrary conv kernel to an FC kernel (i.e., a Toeplitz matrix). In this paper, we propose a simple, platform-agnostic and differentiable approach (Sec. 3). Component Based on Locality Injection, we propose RepMLP Block as an MLP building block. Fig. 1 shows a training-time RepMLP Block with FC, conv and batch normalization [22] (BN) layers can be equivalently converted into an inference-time block with only three FC layers. Architecture The hierarchical design has been shown to benefit visual understanding [20,27,34]. Therefore, we propose a hierarchical MLP architecture composed of RepMLP Blocks. In other words, as the feature map size reduces, the number of channels increases. We reckon that the major obstacle for adopting hierarchical design in a ResMLP- [37] or MLP-Mixer-style [36] model is that the number of parameters is coupled with the feature map size 1 , so that the number of parameters of the lower-level FC layers would be several orders of magnitude greater than the higher-level layers. For example, assume the lowest-level feature maps are of 56×56, an FC layer requires 56 4 = 9.8M parameters to map a channel to another, without any cross-channel correlations (i.e., like depth-wise convolution). We may let all the channels share the same set of parameters, so that the layer will have a total of 9.8M parameters. However, let the highest-level feature maps be of 7×7, the parameter count is only 7 4 = 2.4K but the number of channels is large. Predictably, sharing so few parameters among so many channels restricts the representational capacity hence results in inferior performance. We solve this problem by a set-sharing linear mapping (Sec. 4.1) so that we can independently control the parameter count of each layer by letting the channels share a configurable number of param-eter sets s. With a smaller s for the lower-level layers and a larger s for the higher-level ones, we can balance the model size and the representational capacity. Another drawback of the concurrently proposed MLPs is the difficulty of transferring to the downstream tasks like semantic segmentation. For example, MLP-Mixer [36] demonstrates satisfactory performance on ImageNet but does not qualify as the backbone of a segmentation framework like UperNet [41] as it aggressively embeds (i.e., downsamples) the images by 16× and repeatedly transforms the embeddings, so that it cannot produce multi-scale feature maps with different levels of semantic information. In contrast, our hierarchical design produces semantic information on different levels, so that it can be readily used as the backbone of the common downstream frameworks.
In summary, with Locality Injection, RepMLP Block and a hierarchical architecture, RepMLPNet achieves favorable accuracy-efficiency trade-off with only 100 training epochs on ImageNet, compared to the other MLP models trained in 300 or 400 epochs. We also show the universality of Locality Injection as it improves the performance of not only RepMLPNet but also ResMLP [37]. Moreover, RepMLP-Net shows satisfactory performance as the first attempt to transfer an MLP-style backbone to semantic segmentation.

From Vision Transformer to MLP
Vision Transformers [18,27,38] heavily adopt selfattention modules to capture the spatial patterns. A primary motivation for using Transformers on vision tasks is to reduce the inductive bias designed by human and let the model automatically learn a better bias from big data. Concurrent with our work, MLP-Mixer [36], ResMLP [37] and gMLP [26] are proposed. For example, MLP-Mixer alternatively mix the information across channels (channelmixing, implemented by 1×1 conv) and within channels (token-mixing). Specifically, the token-mixing component projects the feature maps along the spatial dimension (i.e., transpose the feature map tensor), feed them into a 1×1 conv, and transpose the outcomes back. Therefore, the token-mixing can be viewed as an FC layer that flattens every channel as a vector, linearly maps it into another vector, and reshapes it back into a channel, completely ignoring the positional information; and all the channels share the same kernel matrix. In this way, MLP-Mixer realizes the communications among spatial locations. ResMLP [37] and gMLP [26] present different architectures which mix the spatial information with a similar mechanism.

Structural Re-parameterization
The core of Locality Injection is to equivalently merge a trained conv kernel into a trained FC kernel to inject the locality, so it can be categorized into Structural Reparameterization, which is a methodology of converting structures via transforming the parameters. A representative of Structural Re-parameterization is RepVGG [15], which is a VGG-like architecture that uses only 3×3 conv and ReLU for inference. Such an inference-time architecture is equivalently converted from a training-time architecture with identity and 1×1 branches. Asymmetric Convolution Block (ACB) [11] and Diverse Branch Block (DBB) [14] are two replacements for regular conv layers. Via constructing extra training-time paths (e.g., 1×3, 3×1, or 1×1-3×3), they can improve a regular CNN without extra inference costs. ResRep [13] uses Structural Re-parameterization for channel pruning [9,10,12,25,28] and achieves state-ofthe-art results, which reduces the filters in a conv layer via constructing and pruning a following 1×1 layer. Re-pLKNet [16] heavily uses very large (e.g., 31×31) convolutional kernels, where Structural Re-parameterization with small kernels helps to make up the optimization issue.
Locality Injection is a remarkable attempt to generalize Re-parameterization beyond convolution. By merging a conv into an FC kernel, we bridge conv and FC with a simple, platform-agnostic and differentiable method (Sec. 3).

Locality Injection via Re-parameterization
This section derives the explicit formula (Eq. 12) to convert any given conv kernel into an FC kernel (a Toeplitz matrix), which is the key to further merging the conv into the parallel FC. The derivation can be safely skipped.

Formulation
In this paper, a feature map is denoted by a tensor M ∈ R n×c×h×w , where n, c, h, w are the batch size, number of channels, height and width, respectively. We use F and W for the kernel of conv and FC, respectively. For the ease of re-implementation, we formulate the computation in a PyTorch-like [32] pseudo-code style. For example, the data flow through a k × k conv is formulated as where M (out) ∈ R n×o×h ×w is the output, o is the number of output channels, p is the number of pixels to pad, F ∈ R o×c×k×k is the conv kernel (we temporarily assume the conv is dense, i.e., the number of groups is 1). From now on, we assume h = h, w = w for the simplicity.
For an FC, let p and q be the input and output dimensions, V (in) ∈ R n×p and V (out) ∈ R n×q be the input and output, respectively, the kernel is W ∈ R q×p and the matrix multiplication (MMUL) is formulated as We now focus on an FC that takes M (in) as input and outputs M (out) and assume the output shape is the same as the input. We use RS (short for "reshape") as the function that only changes the shape specification of tensors but not the order of data in memory, which is cost-free. The input is first flattened into n vectors of length chw, which is V (in) = RS(M (in) , (n, chw)), multiplied by the kernel W(ohw, chw), then the output V (out) (n, ohw) is reshaped back into M (out) (n, o, h, w). For the better readability, we omit the RS if there is no ambiguity, Obviously, such an FC cannot take advantage of the locality of images as it computes each output point according to every input point, unaware of the positional information.

Locality Injection
Assume there is a conv layer parallel to the FC (like the Channel Perceptron and Local Perceptron shown in Fig. 1), which takes M (in) as input, we describe how to equivalently merge it into the FC. In the following, we assume the FC kernel is W(ohw, chw), conv kernel is F(o, c, k, k), padding is p. Formally, we desire to construct W so that We note that for any kernel W (2) of the same shape as W (1) , the additivity of MMUL ensures that Therefore, we can merge F into W if we can construct W (F,p) of the same shape as W which satisfies Obviously, for any M (in) , F, p, the corresponding W (F,p) must exist, since a conv can be viewed as a sparse FC that shares parameters among spatial positions (i.e., a Toeplitz matrix), but it is nontrivial to construct it with a given F.
Then we seek for the explicit formula of W (F,p) . With the formulation used before (Eq. 2), we have We insert an identity matrix I (chw, chw) and use the associative law With explicit RS, we rewrite Eq. 8 as We note that W (F,p) is constructed with an existing conv kernel F, so that I · W (F,p) is exactly a convolution with F on a feature map M (I) which is reshaped from I. That is where M (I) is reshaped from a constructed identity matrix Comparing Eq. 7 with Eq. 9, Eq. 10, we have which is exactly the formula to construct W (F,p) with F, p.
In brief, the equivalent FC kernel of a conv kernel is the result of convolution on an identity matrix with proper reshaping. Better still, the conversion is efficient and differentiable, so one may derive the FC kernel during training and use it in the objective function (e.g., for penalty-based pruning [17,19]). The formulas for the group-wise case are derived similarly and the code is released on GitHub.
Why is this solution nontrivial? Given F, p, there is no existing generic method to construct the corresponding Toeplitz matrix W (F,p) as the existing conv implementations do not require such a step. As discussed above, though W (F,p) must exist, it is nontrivial to construct it in a platform-agnostic way. Modern platforms use different algorithms of conv, e.g., based on iGEMM [16] (for very large kernel), Winograd [24] (for 3×3), im2col [2] (converting the feature map, rather than the kernel, to a matrix), FFT [31], MEC [4] and sliding-window). Moreover, the memory allocation of data and implementations of padding may be different. Therefore, given F, p and the FC kernel W (F,p) , the equivalency (Eq. 6) may hold on a platform but break on another platform (e.g., the simplest case is the two platforms arrange the kernels in memory differently). Our method (Eq. 12) is platform-agnostic because its derivation does not rely on the concrete form of CONV. On any platform, the W (F,p) constructed with its specific CONV implementation must ensure Eq. 6 with the same CONV.

RepMLPNet
RepMLPNet is a hierarchical MLP-style architecture composed of RepMLP Blocks. We first introduce RepMLP Block (Fig. 1) in Sec. 4.1 and then describe the overall architecture (Fig. 2) in Sec. 4.2.

Components of RepMLP Block
A training-time RepMLP Block is composed of three parts termed as Global Perceptron, Channel Perceptron and Local Perceptron (Fig. 1), which are designed to model the information on different levels. Global Perceptron models the coarse global dependencies across spatial locations  Figure 2. Architecture of RepMLPNet. Apart from RepMLP Blocks, we also use a FFN-style block (1×1-GELU [21]-1×1) to increase the depth, which has been widely used in Vision Transformers [18,27], MLPs [36,37] and CNN (RepLKNet [16]). among all the channels; Channel Perceptron is designed for modeling the long-range spatial dependencies within each channel; Local Perceptron captures the local patterns. The outputs of the three components are combined to obtain a comprehensive transformation of the input features. Global Perceptron average-pools the inputs (n, c, h, w) into vectors (n, c, 1, 1) and feed them into two FC layers to obtain a vector that encodes the global information.
Channel Perceptron contains an FC layer that directly performs the feature transformation, where the key is the setsharing mechanism. We follow the formulation in Sec. 3 and assume o = c for the convenience. We note that a normal FC layer has (chw) 2 parameters. Taking a 64×64 feature map with 128 channels for example, the parameter count of a normal dense FC will be 2.1B, which is unacceptable. A natural solution is to make the FC "depth-wise" just like depth-wise conv, which will not be able to model cross-channel dependencies but has only 1/c parameters and FLOPs. However, even a parameter count of c(hw) 2 is too large. Our solution is to make multiple channels share a set of spatial-mapping parameters, so that the parameters are reduced to s(hw) 2 , where s is the number of share-sets of parameters. In other words, every c s channels share the same set of parameters, and there are s such share-sets in total. Specifically, we first evenly split the c channels into c/s groups, which means (n, c, h, w) → ( nc s , s, h, w), and then flatten them into nc s vectors each of length shw, feed the vectors into a "depth-wise" FC, and reshape the output back. Compared to "depth-wise" FC, set-sharing FC not only breaks the correlation between channels ((chw) 2 parameters → c(hw) 2 )), but reduces the parameters even further (c(hw) 2 ) → s(hw) 2 ); but it does not reduce the computations compared to a "depth-wise" FC. It should be noted that the spatial mappings in ResMLP and MLP-Mixer are implemented in a different way (transpose, 1×1 conv and transpose back) but are mathematically equivalent to a special case of set-sharing FC with s = 1, which means all the channels share the same (hw) 2 parameters. We will show increasing s can improve the performance with more parameters but no extra FLOPs, which is useful in scenarios where the model size is not a major concern (Table 4).
In practice, though set-sharing FC is not directly supported by some computing frameworks like PyTorch, it can be implemented by a group-wise 1×1 conv. Formally, let V (in) ( nc s , shw) be the vectors split in share-sets, the implementation is composed of three steps: 1) reshaping V (in) as a "feature map" with spatial size of 1×1, which is ( nc s , shw, 1, 1); 2) performing 1×1 conv with s groups (so that the parameters are (shw) 2 /s = s(hw) 2 ); 3) reshaping the output into ( nc s , s, h, w), then (n, c, h, w). Local Perceptron takes the same inputs as Channel Perceptron. Each conv (with a following BN [22] as a common practice) is depth-wise and has the same number of sharesets s on the s-channel inputs, so the kernel is (s, 1, k, k).
Merging the Local Perceptron into Channel Perceptron via Locality Injection requires fusing the BN into the preceding conv layers or FC3. Note the conv layers are depth-wise and the number of channels is s. Let F ∈ R s×1×k×k be the conv kernel, µ, σ, γ, β ∈ R s be the accumulated mean, standard deviation and learned scaling factor and bias of the following BN, we construct the kernel F and bias b as Then it is easy to verify the equivalence: where the left side is the original computation flow of a conv-BN, and the right is the constructed conv with bias. The FC3 and BN in Channel Perceptron are fused in a similar way intoŴ ∈ R shw×hw ,b ∈ R shw . Then we convert every conv via Eq. 12 and add the resultant matrix ontoŴ. The biases of conv are simply replicated by hw times (because all the points on the same channel share a bias value) and added ontob. Finally, we obtain a single FC kernel and a single bias vector, which will be used to parameterize the inference-time FC3.

Hierarchical Architectural Design
Some recent vision MLP models [36,37] show a similar design pattern: downsampling the inputs aggressively (e.g., by 16×) at the very beginning, and stacking multiple blocks to process the small-sized features. In contrast, we adopt a hierarchical design, which has proven effective by previous studies on CNNs [20,33,35,42] and Transformers [27].
Specifically, we arrange RepMLP Blocks in four stages, and the blocks in a stage share the same structural hyperparameters. The input images are downsampled by 4× with an embedding layer, which is implemented by a conv layer with a kernel size of 4×4 and stride of 4. From a stage to the next, we use an embedding layer to halve the width and height of feature maps and double the channels. Therefore, a RepMLPNet can be instantiated with the following hyper-parameters: the number of RepMLP Blocks in each stage [B 1 , B 2 , B 3 , B 4 ], the number of channels of the first stage C (the four stages will have C, 2C, 4C, 8C channels, respectively), the input resolution H×W (so that Considering the number of parameters in FC3 is s(hw) 2 , we use a smaller s at an earlier stage.
An advantage of our hierarchical architecture is that the feature maps produced by any stage can be readily used by a downstream framework. For example, UperNet [41] requires four levels of feature maps with different sizes, so it cannot use MLP-Mixer or ResMLP as backbone.

ImageNet Classification
We first instantiate a series of RepMLPNets with different architectural hyper-parameters, as shown in Table 1.
We evaluate RepMLPNets on ImageNet [8]. All the RepMLPNets are trained with identical settings: a global batch size of 256 distributed on 8 GPUs, AdamW [29] optimizer with initial learning rate of 0.002, weight decay of 0.1 and momentum of 0.9. We train for only 100 epochs in total with cosine learning rate annealing, including a 10epoch warm-up at the beginning. We use label smoothing of 0.1, mixup [45] with α = 0.4, CutMix [44] with α = 1.0, and RandAugment [7]. As a series of strong baselines, we present ResNet-101 [20], ResNeXt-101 [42] and RegNetX-6.4GF [33] trained with a strong scheme with RandAugment, mixup and label smoothing. We would like the comparison to be slightly biased towards the traditional CNNs, so we train them for 120 epochs. All the models are evaluated with single crop and the throughput (samples/second) is tested on 2080Ti GPU with a batch size of 128. The BN layers in CNNs are also fused for the fair comparison.
It should be noted that most of the results reported by [26,36,37,43] are produced with a long training schedule of 300 or 400 epochs, or an advanced distillation method (the DeiT-style training [38]). Therefore, except for the results cited from the corresponding papers, we train an MLP-Mixer and a ResMLP-S12 with simple training settings for a fair comparison (labeled as "our impl" in Table 2). Specifically, the MLP-Mixer is trained with the settings identical to RepMLPNets; the ResMLP-S12 is trained with the official code and the same hyper-parameters as its reported 120-epoch result [37] except that we use a smaller batch size due to limited resources (but our reproduced accuracy is 2.7% higher than its reported result [37]).
Compared to the other CNNs and MLPs, we make the following observations. 1) With fair settings, RepMLPNet shows superiority over the other MLPs, e.g., RepMLPNet-T256 outperforms MLP-Mixer (our impl, 256×256 inputs) by 0.5% in the accuracy while the FLOPs of the former is only 1/4 of the latter. 2) With simple training methods, ResMLP and MLP-Mixer significantly degrade, e.g., the accuracy of ResMLP-S12 drops by 8.9% (76.6% → 67.7%) without the 300-epoch DeiT-style training. 3) RepMLPNet with 100-epoch training delivers a favorable accuracy-efficiency trade-off: RepMLPNet-B256 matches the accuracy of ResMLP-B24 without DeiT-style distillation, consumes 1/4 training epochs, has only 40% FLOPs and fewer parameters. 4) With the comparable FLOPs, MLPs are faster than CNNs, e.g., RepMLPNet-D256 has higher FLOPs than ResNeXt-101 but runs 1.6× as fast as the latter. This discovery suggests that MLPs are promising as high-throughput inference models.
To further demonstrate that FLOPs may not reflect the throughput [15], we train EfficientNet-B1/B2 [35] with the aforementioned 120-epoch strong scheme and report the results in Table 3. Interestingly, though EfficientNets have very low FLOPs, the actual performance on GPU is inferior: RepMLPNet-T224 has 4× FLOPs as EfficientNet-B1 but runs 1.9× as fast as the latter; with comparable throughput, the accuracy of RepMLPNet-B256 is 3.6% higher than EfficientNet-B2. We reckon the high throughput of RepMLPNet on GPU can be attributed to not only the efficiency of matrix multiplication but also the simplicity of architecture hence high degree of parallelism [30].
We then study the effects of two key designs in RepMLP Block: the Global Perceptron and the set-sharing linear mapping of FC3. We increase the number of share-sets S or ablate the Global Perceptron and observe the performance as well as the model size. Fig. 4  improves the accuracy by around 1%. This is expected as the Local Perceptron and Channel Perceptron do not communicate information across channels, which is compensated by Global Perceptron. By increasing S, fewer channels will be sharing the same set of mapping parameters, resulting in a significant performance gain without any extra FLOPs. Therefore, for the application scenarios where the speed-accuracy trade-off is the primary concern while the model size is not (e.g., in high-power computing centers), we may increase S for higher accuracy.

Locality Injection Matters
We conduct ablation studies on CIFAR-100 [23] and ImageNet to evaluate Locality Injection. Specifically, we build a small RepMLPNet with two stages, B = [6, 6], S = [8,32], C = 128. As another benchmark model, we scale down ResMLP-12 by reducing the channel dimensions. Besides, we change the downsampling ratio at the very beginning of all the models to 2×, so that the embedding dimension becomes 16×16, which is close to the case of ResMLP designed for ImageNet (14×14).
For the ResMLP, we add 1×1 and 3×3 branches parallel to the spatial aggregation layer. Note that the spatial aggregation in ResMLP and MLP-Mixer is equivalent to our setsharing FC with only one share-set (i.e., all the channels use the same set of (hw) 2 parameters). In this case, all the conv layers should have s = 1 accordingly, which means a depthwise conv with one input channel and one output channel. Consequently, adding a 1×1 conv introduces only five parameters (one for the 1×1×1×1 kernel and four for the single-channel BN layer including µ, σ, γ, β), so the whole model has only 5 × 12 = 60 extra parameters. Similarly, adding a 3×3 layer brings only (3 × 3 + 4) × 12 = 156 parameters. Though the extra parameters and FLOPs are negligible, the speed is observably slowed down (e.g., with 1×1 and 3×3 conv, the training-time ResMLP-12 has only 0.4% higher FLOPs but runs 37% slower) due to the reduction of degree of parallelism [30], which highlights the significance of merging the conv layers into the FC. For the RepMLPNet, the extra parameters brought by adding a 3×3 conv is (3 × 3 + 4)s due to the set-sharing mechanism.
All the ResMLPs and RepMLPNets on CIFAR-100 are trained with the same learning rate schedule and weight decay as described before, a batch size of 128 on a single GPU, and the standard data augmentation: padding to 40×40, randomly cropping to 32×32 and left-right random flipping. Predictably, the performance is not satisfactory since CIFAR-100 is too small for the FC layer to learn the inductive bias from the data. This discovery is consistent with the concurrent works [36,37] which highlight that MLPs show inferior performance on small datasets. Adding the conv branches only during training significantly boost the accuracy even though they are eventually eliminated. Impressively, though the ResMLP has only 216 extra training-time parameters, the accuracy raises by 9.51%, and we observe a similar phenomenon on RepMLPNet. We then experiment with RepMLP-T224/D256 on ImageNet.
With the Local Perceptron removed, the accuracy decreases by 2.15% and 2.30%, respectively. The gap is narrower compared to the results on CIFAR, which is expected because ImageNet is significantly larger, allowing the model to learn some inductive bias from data [36]). In summary, as Locality Injection works on different models and datasets, we conclude that it is a universal tool for vision MLPs.

Semantic Segmentation
The hierarchical design of RepMLPNet qualifies it as a backbone for the off-the-shelf downstream frameworks that require feature maps of different levels, e.g., UperNet [41]. However, transferring an ImageNet-pretrained MLP to the downstream task is challenging. Taking Cityscapes [6] semantic segmentation as the example, we reckon there are two primary obstacles for using an MLP backbone. 1) The backbone is usually trained with low resolution (e.g., 256×256 on ImageNet) then transferred to the highresolution task (e.g., 1024×2048 of Cityscapes). However, the parameter count of MLP is coupled with the input resolution (by our specific definition of "MLP"), making the transfer difficult.
2) The resolution for training (512×1024 on Cityscapes) and testing (1024×2048) may not be the same, so the backbone has to adapt to a variable resolution.
In brief, our solution is to split the inputs into nonoverlapping patches, feed the patches into the backbone, restore the output patches to form the feature maps, which are then fed into the downstream frameworks. For example, the first RepMLP Block of RepMLPNet-D256 works with 64×64 inputs because the FC kernel is (64 2 , 64 2 ). On Cityscapes, we can split the feature map into several 64×64 patches and feed the patches into the RepMLP Block. How- ever, doing so breaks the correlations among patches hence hinders a global understanding of the semantic information. Accordingly, we propose to replace the embedding (2×2 conv) layers by regular conv (3×3 conv) layers to communicate information across the patch borders. Interestingly, one may worry such a strategy would yield poor results at the edges of patches, but we observe that the predictions at the edges are as good as the other parts (see the Appendix).
As the first attempt to use an MLP as the backbone for Cityscapes semantic segmentation, RepMLPNet delivers promising results (Table 6). By further replacing the 3×3 downsampling layers by 5×5, the mIoU improves with negligible extra FLOPs, which is expected as a larger convolution enables better communications among patches. Specifically, we use the implementation of UperNet [41] in MM-Segmentation [5] and the 80K-iteration training schedule. We present the details and analysis in the Appendix.

Limitations and Conclusions
This paper proposes a re-parameterization method to inject locality into FC layers, a novel MLP-style block, and a hierarchical MLP architecture. RepMLPNet is favorable compared to several concurrently proposed MLPs in terms of the accuracy-efficiency trade-off and the training costs.
However, as an MLP, RepMLPNet has several noticeable common weaknesses. 1) Similar to the Vision Transformers, MLPs are easy to overfit, requiring strong data augmentation and regularization techniques. 2) On the low-power devices like mobile phones, the model size of MLPs may be an obstacle. 3) Though the results of our first attempt to use MLP backbone for semantic segmentation are promising, we observe no superiority over the traditional CNNs.

Appendix A: Visualizing Locality Injection
We demonstrate the locality is injected into the FC kernel by showing the kernel weights.
Specifically, we visualize the weights of FC3 kernel sampled from the 10th RepMLP Block of the 3rd stage of RepMLPNet-D256 trained on ImageNet. We reshape the kernel intoW(s, h, w, 1, h, w), which is (16,16,16,1,16,16), then sample the weights related to the first input channel and the (7,7) point (marked by a purple square) on the first output channel, which isW 1,7,7,1,:,: (indices starting from 1). Then we take the absolute value, rescale by the minimum value of the whole matrix, and take the logarithm for the better readability.
As shown in Fig. 3, a point with darker color indicates the FC considers the corresponding position on the input channel more related to the output point at (7,7). Obviously, the original kernel has no locality as the marked point and the neighbors have no larger values than the others.
Then we merge the parallel conv layers into the kernel via Locality Injection. The resultant kernel has larger values around the marked point, suggesting that the model focuses more on the neighbors, which is expected. Besides, the kernel's capacity to model the long-range dependencies is not lost as some points (marked by red dashed rectangles) outside the largest conv kernel (3×3 in this case, marked by a blue square) still have larger values than some points inside.

Appendix B: Details of Semantic Segmentation
We solve the problem of using MLP as the backbone for semantic segmentation (e.g., UperNet) by 1) the hierarchical design, 2) splitting feature maps into non-overlapping patches and 3) communications between patches. Fig. 4 shows an example of RepMLPNet + UperNet. 1) UperNet requires feauture maps of 4 different levels, which fits our hierarchical architecture. 2) Since RepMLP Block works with a fixed input feature map size, we split the feature maps into non-overlapping patches each with the required size.
3) The original 2× embedding cannot realize inter-patch communication, so we replace it with 3×3 conv. To reduce the computational cost of 3×3 conv, we decompose it into a 1×1 conv for expanding the channels and  . An example of using RepMLPNet as the backbone of UperNet. After 4× downsampling on the 512×1024 inputs, the feature map size becomes 128×256. Then we split the feature maps into 2×4 non-overlapping patches, each of 64×64, because the first RepMLP Block maps inputs of 64×64 into 64×64 (i.e., the FC kernel is (64 2 ,64 2 )). Similarly, the outputs of the four stages are reshaped back and fed into the UperNet. a 3×3 stride-2 depth-wise conv for downsampling. Fig. 5 shows the difference between a 2× embedding and a 3×3 conv.
Interestingly, as the input is split into non-overlapping patches, one may expect that the predictions would be less accurate at the edges of patches, but we observe no such phenomenon. Fig. 6 shows that the predictions at the edges are as good as the internal pixels within patches. This discovery suggests that the dependencies across patches have been well established and that the representational capacity of MLP is strong enough for such a dense prediction task.
We hope our results spark further research on the application of MLP on downstream tasks.  Figure 5. The difference between 2× embedding and 3×3 conv is that the latter realizes communications across patch edges. In this figure, a square denotes a pixel on a feature map and the thick lines denote the edges of patches. We take the upper left corner of a patch as an example Figure 6. The predictions at the edges of patches are no observably worse. We show two images from the Cityscapes validation set as examples. As the test resolution is 1024×2048, the input to the first RepMLP Block is 256×512 (after the beginning 4× downsampling), so that the input is split into 32 non-overlapping patches and then fed into RepMLP Blocks. We use red dashed lines to denote the edges of patches and it is observed that the predictions at the edges are almost as good as the other parts.