SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Tianqin Li
tianqin1@cs.cmu.edu
Ziqi Wen
ziqwen@cs.cmu.edu
Yangfan Li
Nortwestern University
yangfanli2024@u.northwestern.edu
Tai Sing Lee
tai@cnbc.cmu.edu
Current deep-learning models for object recognition are known to be heavily biased toward texture. In contrast, human visual systems are known to be biased toward shape and structure. What could be the design principles in human visual systems that led to this difference? How could we introduce more shape bias into the deep learning models? In this paper, we report that sparse coding, a ubiquitous principle in the brain, can in itself introduce shape bias into the network. We found that enforcing the sparse coding constraint using a non-differential Top-K operation can lead to the emergence of structural encoding in neurons in convolutional neural networks, resulting in a smooth decomposition of objects into parts and subparts and endowing the networks with shape bias. We demonstrated this emergence of shape bias and its functional benefits for different network structures with various datasets. For object recognition convolutional neural networks, the shape bias leads to greater robustness against style and pattern change distraction. For the image synthesis generative adversary networks, the emerged shape bias leads to more coherent and decomposable structures in the synthesized images. Ablation studies suggest that sparse codes tend to encode structures, whereas the more distributed codes tend to favor texture. Our code is host at the github repository: https://topk-shape-bias.github.io/
Sparse and efficient coding is a well-known design principle in the sensory systems of the brain [3, 31]. Recent neurophysiological findings based on calcium imaging found that neurons in the superficial layer of the macaque primary visual cortex (V1) exhibit even a higher degree of lifetime sparsity and population sparsity in their responses than previously expected. Only 4-6 out of roughly 1000 neurons would respond strongly to any given natural image [37]. Conversely, a neuron typically responded strongly to only  $0.4\%$  of the randomly selected natural scene images. This high degree of response sparsity is commensurate with the observation that many V1 neurons are strongly tuned to more complex local patterns in a global context rather than just oriented bars and gratings [36]. On the other hand, over  $90\%$  of these neurons did exhibit statistically significant orientation tuning, though mostly with much weaker responses. This finding is reminiscent of an earlier study that found similarly sparse encoding of multi-modal concepts in the hippocampus [32]. This leads to the hypothesis that neurons can potentially serve both as a super-sparse specialist code with their strong responses, encoding specific prototypes and concepts, and as a more distributed code, serving as the classical sparse basis functions for encoding images with much weaker responses. The specialist
code is related to the idea of prototype code, the usefulness of which has been explored in deep learning for serving as memory priors [24] in image generation, for representing structural visual concepts [38, 39], or for constraining parsimonious networks [26] for object recognition.
In computer vision community, recent studies found that Convolutional Neural Networks (CNNs) trained for object recognition rely heavily on texture information [11]. This texture bias leads to misclassification when objects possess similar textures but different shapes [2]. In contrast, human visual systems exhibit a strong 'shape bias' in that we rely primarily on shape and structures over texture for object recognition and categorization [20]. For instance, a human observer would see a spherical object as a ball, regardless of its texture patterns or material make-up [34]. This poses an interesting question: What is the design feature in the human vision systems that lead to the shape bias in perception?
Figure 1: Shape bias of our sparse CNNs versus standard CNNs and SOTA transformer-based networks in comparison to the shape bias of human subjects, as evaluated on benchmark dataset [10] across 16 classes. The red dotted line shows the frontier of transformer-based networks with the best shape bias. The greed dotted line shows that sparse CNNs push the frontier of the shape bias boundary toward humans.
In this paper, we explore whether the constraint of the high degree of strong-response sparsity in biological neural networks can induce shape bias in neural networks. Sparsity, particularly in overcomplete representations, is known to encourage the formation of neurons encoding more specific patterns [30]. Here, we hypothesize that these learned specific patterns contain more shape and structure information, thus sparsifying the neuronal activation could induce shape bias in neuronal representation. To test this hypothesis, we impose a sparsity mechanism by keeping the Top K absolute response of neuronal activation at each channel in one or multiple layers of the network, and zeroing out the less significant activation with K is a sparsity parameter that we can adjust for systematic evaluation.
We found that this sparsity mechanism can indeed introduce more shape bias in the network. In fact, simply introducing the Top-K operation during inference in the pre-trained CNNs such as AlexNet [19] or VGG16 [33] can already push the frontier of the shape bias benchmark created by [10] (as shown in Figure 1). Additional training of these networks with the Top-K operation in place further enhances the shape bias in these object recognition networks. Furthermore, we found that the Top-K mechanism also improves the shape and structural bias in image synthesis networks. In the few-shot image synthesis task, we show that the Top-K operation can make objects in the synthesized images more distinct and coherent.
To understand why Top-K operation can induce these effects, we analyzed the information encoded in Top-K and non-Top-K responses using the texture synthesis paradigm and found that Top-K responses tend to encode structural parts, whereas non-Top-K responses contribute primarily to texture and color encoding, even in the higher layers of the networks. Our finding suggests that sparse coding is important not just for making neural representation more efficient and saving metabolic energy but
also for contributing to the explicit encoding of shape and structure information in neurons for image analysis and synthesis, which might allow the system to analyze and understand 3D scenes in a more structurally oriented part-based manner [4], making object recognition more robust.
Shape Bias v.s. Texture Bias There has been considerable debate over the intrinsic biases of Convolutional Neural Networks (CNNs). [11] conducted a pivotal study demonstrating that these models tend to rely heavily on texture information for object recognition, leading to misclassifications when objects have similar textures but distinct shapes. In addition, it has also been shown that using the texture information alone are sufficient to achieve object classification [6]. This texture bias contrasts markedly with human visual perception, which exhibits a strong preference for shape over texture – a phenomenon known as 'shape bias' [20]. Humans tend to categorize and recognize objects primarily based on their shape, a factor that remains consistent across various viewing conditions and despite changes in texture [34]. These studies collectively form the foundation upon which our work builds, as we aim to bridge the gap in shape bias between computer vision systems and human visual systems.
Improving Shape Bias of Vision Models Following the identification of texture bias in CNNs by [11], numerous studies sought to improve models' shape bias for better generalization. Training methods have been developed to make models more shape-biased, improving out-of-distribution generalization. Some approaches, like [11], involved training with stylized images to disconnect texture information from the class label. Such approach posed computational challenges and didn't scale well. Others, like [15], used human-like data augmentation to mitigate the problem, while [23] proposed shape-guided augmentation, generating different styles on different sides of an image's boundary. However, these techniques all rely on data augmentation. Our focus is on architectural improvements for shape bias, similar to [1] which created a texture-biased model by reducing the CNN model's receptive field size. We propose using sparsity operations to enhance shape bias of CNNs. Furthermore, [7] proposes to scale up the transformer model into 22 billion parameters and show a near human shape bias evaluation results. We, on the other hand, are not comparing with their network since we focus on CNNs which requires less computation and doesn't require huge data to learn. We demonstrate in the supplementary that the same sparsity constraint could also be beneficial to the ViT family as well, hinting the generalizability of our findings.
Robustness In Deep Learning Robustness in deep learning literature typically refers to robustness against the adversarial attack suggested by [35] which showed that minuscule perturbations to images, imperceptible to the human eye, can drastically alter a deep learning model's predictions. Subsequent research [14, 21] corroborated with these findings, showing that deep neural networks (DNNs) are vulnerable to both artificially-induced adversarial attacks and naturally occurring, non-adversarial corruptions. However, the robustness we are mentioning in this paper is about the robustness against confusing textures that are misaligned with the correct object class, as illustrated by the cue-conflict datasets provided by [11]. Although sparsity has been shown to be effective against the adversarial attack [25], explicit usage of Top-K in shape bias has not been explored.
3.1 Spatial Top-K Operation in CNN
Sparse Top-K Layer We implement the sparse coding principle by applying a Top-K operation which keeps the most significant K responses in each channel across all spatial locations in a particular layer. Specifically, for an internal representation tensor  $X \in R^{c \times h \times w}$ , Top-K layer produces  $\mathrm{X}_{\mathrm{Top\_K}} \coloneqq \mathrm{Top\_K}(\mathrm{X}, \mathrm{K})$ , where the  $\mathrm{X}_{\mathrm{Top\_K}}$  is defined as:
$$
\mathrm {X} _ {\text {T o p} \_ K} [ i, j, k ] := \left\{ \begin{array}{l l} \mathrm {X} [ i, j, k ], & \text {i f a b s} (\mathrm {X} [ i, j, k ]) \geq \operatorname {R a n k} (\operatorname {a b s} (\mathrm {X} [ i, :, : ])) [ K ] \\ 0, & \text {o t h e r w i s e} \end{array} \right. \tag {1}
$$
Equation 1 specifies how each entry of a feature tensor  $\mathbf{X} \in R^{c \times h \times w}$  would be transformed inside the Top-K layer. The zero-out operation in Equation 1 suggests that the gradient w.r.t. any non Top-K
value, as well as the gradients that chain with it in the previous layers will become zero. However, our analysis later suggests that the network can still learn and get optimized, leading to improved dynamic spatial Top-K selection.
Sparse Top-K With Mean Replacement To determine the relative importance of the Top-K values or the Top K positions in the Top-K operation, we create an alternative scheme in which all the Top-K responses in a channel are replaced by the mean of the Top-K responses in the channel Top_K_Mean_Rpl as defined below:
$$
\mathrm{X}_{\text{Top\_K\_Mean\_Rpl}}[\mathbf{i},  \mathbf{j},  \mathbf{k}]:= \left\{ \begin{array}{ll}\frac{1}{n}\sum_{j,k\in \{\text{Top - K}\}_{n}}\mathrm{X}[\mathbf{i},  \mathbf{j},  \mathbf{k}], & \text{if abs} (\mathrm{X}[\mathbf{i},  \mathbf{j},  \mathbf{k}])\geq \text{Rank} (\text{abs} (\mathrm{X}[\mathbf{i},  \therefore ,  \mathbf{:}]))[ \mathbf{K}]\\ 0, & \text{otherwise} \end{array} \right.
$$
This Top_K_Mean_Rpl operation reduces the communication rate between layers by 1000 times. We study the impact of this operation on object performance in an object recognition network (See section 4.3 for the results) and to determine which type of information (values versus positions) is essential for inducing the shape bias.
3.2 Visualizing the Top-K code using Texture Synthesis
We used a texture synthesis approach [9] with ablation of Top-K responses to explore the information contained in the Top-K responses in a particular layer using the following method.
Suppose a program  $F(\cdot)$  denotes a pre-trained VGG16 network with a number of parameters N [33] and  $TS: R^{h \times w \times 3} \times N \to R^{h \times w \times 3}$  denotes the texture synthesis program from [9] where an input image  $I$  is iteratively optimized by gradient descent to best match the target image  $T$ 's internal activation when passing through  $F(T)$ . We detail the operations inside  $TS$  below. Denote the internal representation at each layer  $i$  of the VGG16 network when passing an input image  $I$  through  $F(\cdot)$  as  $X_{i}(I)$ , and suppose there exist  $L$  layers in the VGG16 network. We update the image  $I$  as follows:
$$
I \leftarrow I - l r * \left(\frac {\partial}{\partial I} \sum_ {i} ^ {L} \left[ G r (X _ {i} (I)) - G r (X _ {i} (T)) \right]\right)
$$
where  $Gr(\cdot): R^{h \times w \times c} \to R^{c \times c}$  denotes the function that computes gram matrix of a feature tensor, i.e.  $Gr(X_i(I)) = X_i(I)^T X_i(I)$ . We adopt LBFGS [28] with initial learning rate 1.0 and 100 optimization steps in all our experiments with the texture synthesis program.
Utilizing the above texture synthesis program  $TS(\cdot, \mathrm{VGG16})$ , we can obtain the synthesis results in  $S_{\mathrm{w/oTop-K}}$  by manipulating the internal representation of VGG16 such that we only use the non-Top-K responses to compute the Gram matrix when forming the Gram matrix optimization objectives. This effectively computes a synthesis such that it only matches with the internal non-Top-K neural response. For a given target image  $T$ , this leads to  $S_{\mathrm{w/oTop-K}}$ :
$$
S _ {\mathrm {w} / \mathrm {o} \text {T o p - K}} = T S (T, \text {Z e r o O u t I n t e r n a l T o p K} (\text {V G G 1 6}))
$$
, which would show the information encoded by non-Top-K responses. Next, we include the Top-K firing neurons when computing the Gram matrix to get  $S_{\mathrm{w/Top-K}}$ :
$$
S _ {\mathrm {w} / \text {T o p - K}} = T S (T, \text {I d e n t i f y F u n c t i o n} (\text {V G G 1 6}))
$$
. Comparing these two results will allow us assess the information contained in the Top-K responses.
3.3 Visualizing the Top-K neurons via Reconstruction
Similar to section 3.2, we provide further visualization of the information Top-K neurons encode by iteratively optimizing an image to match the internal Top-K activation directly. Mathematically, we redefine our optimization objective in section 3.2:
$$
I \leftarrow I - l r * \left(\frac {\partial}{\partial I} \sum_ {i} ^ {L} \left[ X _ {i} (I) - \operatorname {M a s k} _ {i} * X _ {i} (T) \right]\right)
$$
, where  $\mathsf{Mask}_i$  a controllable mask for each layer  $i$ . There are three types of mask we used in the experiments: {Top-K_Mask, non_Top-K_Mask, Identity_Mask}. Top-K_Mask selects only the Top-K fired neurons while keeps the rest of the neurons zero, whereas non_Top-K_Mask only selects the opposite of the Top-K_Mask and Identity_Mask preserves all neurons. By comparing these three settings, one can easily tell the functional difference between Top-K and non Top-K fired neurons (See results in Figure 3).
3.4 Shape Bias Benchmark
To demonstrate our proposal that the Top-K responses are encoding the structural and shape information, we silence the non-Top-K responses during inference when using pre-trained CNNs. To test the networks' shape bias, we directly integrate our code into the benchmark provided by [10]. The benchmark contains a cue-conflict test which we use to evaluate the Top-K operation. The benchmark also includes multiple widely adopted models with pre-trained checkpoints and human psychological evaluations on the same cue-conflict testing images.
4.1 Top-K Neurons Encode Structural Information
To test the hypothesis that the shape information is mostly encoded among the Top-K significant responses, whereas the non-Top-K responses are encoding primarily textures, we used the method described in Section 3.2 and compared the texture images synthesized with and without the Top-K responses for the computation of the Gram matrix. Figure 2 compares the TS output obtained by matching the early layers and the higher layers of the VGG16 network in the two conditions. One can observe that ablation of the Top-K responses eliminated much of the structural information, resulting in more texture images. We conclude from this experiment that (1) Top-K responses are encoding structural parts information; (2) Non Top-K responses are primarily encoding texture information.
i. Original
ii. TS w. Top-K + Non Top-K
Figure 2: Texture Synthesis (TS) using [9]. i. shows the original image, ii. shows the TS results of  $S_{\mathrm{w/Top-K}}$  with both Top-K and Non Top-K activation intact, iii. shows the TS results  $S_{\mathrm{w/oTop-K}}$  with Top-K activation deleted before performing TS.
iii. TS w. Non Top-K
To provide further insights about the different information Top-K and non Top-K neurons are encoding, we show another qualitative demonstration in Figure 3 where we optimize images that would excite the Top-K neurons alone and the non Top-K neurons alone respectively (See full description in Section 3.3).
Original Image
Figure 3: Visualizing Top-K and non Top-K neurons through optimizing input images to match their activation.
Reconstruction w/ Top-K + Non Top-K
Reconstruction w/ Top-K only
Reconstruction w/ Non Top-K only
From Figure 3, it is clear that optimizing images to match the Top-K fired neurons yields high level scene structures with details abstracted away while optimization efforts to match the non Top-K fired neurons produce low level local textures of the target images. Together, we provide evidence to
support our hypothesis that it is the strong firing neurons in the convolutional neural networks that provide structural information while the textures are encoded among the weakly activated neurons. Next, we demonstrate that this phenomenon will result in improved shape bias in both analysis and synthesis tasks.
4.2 Top-K Responses already have Shape Bias without Training
We test the Top-K activated CNNs with different degrees of sparsity on the shape bias Benchmark proposed from [10]. This benchmark evaluates the shape bias by using a texture-shape cue conflict dataset where the texture of an image is replaced with the texture from other classes of images. It defines the shape and texture bias in the following ways:
$$
\text {s h a p e} = \frac {\text {o f c o r r e c t s h a p e r e c o n g i n t i o n s}}{\text {o f c o r r e c t r e c o n g i n t i o n s}}
$$
$$
\text {t e x t u r e} = \frac {\text {o f c o r r e c t t e x t u r e r e c o n g i n i t i o n s}}{\text {o f c o r r e c t r e c o n g i n i t i o n s}}
$$
It has been shown in previous work [10, 11] that CNNs perform poorly on shape-based decision tests whereas human subjects can make successful shape-based classification on nearly all the evaluated cases. This results in CNN models having relatively low shape bias scores while humans have close to 1 shape bias score. Interestingly, it has been observed that Vision Transformers (ViT) model family has attained significant improvement in shape bias [10].
Figure 4: Overall shape bias of sparse CNNs, CNNs, Transformer and humans
Adding the Top-K operation to a simple pretrained such as AlexNet or VGG16 alone already can already induced a significant increase in shape bias, as shown in Fig.4. With the sparsity knob K equal to  $10\%$  and  $20\%$ , the Top-K operation alone appears to achieve as much or more shape bias as the state-of-the-art Vision Transformer models in the cue-conflict dataset, leading further support to the hypothesis that Top-K sparsity can lead to shape bias.
We plot the best of the Top-K sparsified AlexNet and VGG16 for each evaluation of 16 object classes in Fig.5. We can observe that sparsity constraint improve shape-biased decision-making for most of the object classes, bringing the performance of the pre-trained model closer to human performance. With the proper settings of sparsity, certain classes (e.g. the bottle and the clock category) could attain human level performance in shape-biased scores.
However, we should note that the confidence interval is quite large, indicating that the network performs differently across the different classes. A closer look at shape bias for each class is shown in Figure 5.
4.3 Top-K training induces Shape Bias in Recognition Networks
To evaluate the shape bias can be enhanced by training with Top-K operation, we trained ResNet-18 [13] on different subsets of ImageNet dataset [8]. Each subset contains randomly selected 10 original categories from ImageNet, for all the training and evaluation. Every experiment is run three times to obtain an error bar. During the evaluation, we employ AdaIn style-transfer using programs adopted from [18] to transform the evaluation images into a texture-ablated form as shown in Figure 6. The original texture of the image is replaced by styles of non-related images using style transform.
Figure 5: The classification result on the Shape Bias Benchmark proposed from[10]. This plot shows the shape bias of sparse CNNs, CNNs and humans on different class in texture-shape cue conflict dataset. It also show the shape bias of different sparsity degree. e.g.  $5\%$  means that only top  $5\%$  activation value would be passed to the next layer. Vertical lines means the average value.
This allows us to evaluate how much a trained model is biased toward the original texture instead of the underlying shape.
(e)
Figure 6: Evaluating shape bias of the network with stylized ImageNet subsets. Three pairs of images are presented sampled from the our evaluation datasets. Specifically, we transfer (a)  $\rightarrow$  (b), (c)  $\rightarrow$  (d) and (e)  $\rightarrow$  (f) by AdaIN [18] and keep the original class labels. During the evaluation, the transferred images are presented instead of the original test image to measure the network's texture bias sensititivity.
In this experiment, we train classification networks with two non-overlapping subsets of the ImageNet, namely IN- $S_1$  and IN- $S_2$ . We select the categories that are visually distinctive in their shapes. The details about the datasets can be found in the Supplementary Information. We trained ResNet-18 models over the selected IN- $S_1$  and IN- $S_2$  dataset with the standard Stochastic Gradient Descent (SGD, batch size 32) and a cosine annealing learning rate decay scheduling protocol with lr starting from 0.1. The same optimization is applied to ResNet-18 models with a  $20\%$  spatial Top-K layer added after the second bottleneck block of the ResNet-18. All models are then evaluated on the stylezed version of IN- $S_1$  and IN- $S_2$  evaluation dataset after trained with 50 epochs.
Top-1 Acc. (%)	IN-S1(↑)	Stylized-IN-S1(↑)	IN-S2(↑)	Stylized-IN-S2(↑)
ResNet-18 [13]	87.8 ± 0.5	49.3 ± 1.5	81.3 ± 1.7	52.4 ± 2.2
ResNet-18 w. Top-K during training	89.4 ± 0.6	55.4 ± 0.8	83.4 ± 0.9	59.7 ± 0.6
ResNet-18 w. Top_K_Mean_Rpl during training	84.9 ± 0.3	56.8 ± 1.7	75.5 ± 2.5	53.1 ± 1.0
Table 1: Evaluation for models trained on IN-  $S_{1}$  and IN-  $S_{2}$  datasets, each of which consists 10 classes of all train/val data from ImageNet-1k dataset [8].
Table 1, shows that (i) the classification accuracy on the original evaluation dataset doesn't drop: mean top-1 accuracy of 87.8 (baseline) v.s. 89.4 (w. Top-K) on IN- $S_{1}$  and 81.3 (baseline) v.s. 83.4 (w.