RESEARCH PROJECT Published 18 March 2022 · Multimedia Tools and Applications

Confusion Matrix-Based Modularity Induction into Pretrained CNN

Salman Ahmad1, Shahab U. Ansari1, Usman Haider1, Kamran Javed2, Jalees Ur Rahman1 and Sajid Anwar1,†

1 Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, District Swabi, Topi, Pakistan
2 National Center of Artificial Intelligence (NCAI), Saudi Data and Artificial Intelligence Authority (SDAIA), Riyadh, Saudi Arabia
† Deceased

Abstract

Convolutional neural networks (CNNs) are inspired by the visual cortex of the human brain, which is made of connected regions. When a region receives an input, it extracts meaningful information and passes it on to its neighbor. A CNN copies this layered structure with several layers that extract features. In neuroscience, it is believed that the brain’s cognitive abilities come from its modular structure, meaning that it is built from separate modules.

This work proposes a framework that adds modularity to a CNN that has already been trained. The input domain of the CNN is split into functional modules, each made of different pathways, using a new method called Confusion Matrix driven Centroid Based Clustering (CMCBC). CMCBC is an unsupervised clustering technique based on the k-Medoid algorithm. It uses the confusion matrix to find how similar each pair of classes is, and it takes a medoid for every cluster instead of using a distance function.

The framework was tested on two standard datasets, MNIST and CIFAR10. On MNIST, the modular CNN reached 98.51% accuracy, compared with 99.39% for the baseline, while saving 53% of the multiplications in the network, which greatly reduces its complexity. On CIFAR10, the model reached 78.01% accuracy, 6% below the 84% baseline. After the network was retrained to align the weights further, it outperformed the baseline by 2.78% and reached 86.78% accuracy.

Introduction

The structure of a CNN is inspired by the visual cortex of the brain. In the brain, different connected regions each extract useful information from what they receive and pass it to the next region, and a CNN imitates this with several layers that extract features one after another. Neuroscientists also believe that the modular structure of the human brain, which is made of separate but cooperating parts, is the source of its cognitive abilities.

This work looks at how to bring this modular idea into an image classification network. It addresses three problems: how to split the input domain into parts, how to control the way information is routed through the network, and how to bring the modules together again.

Proposed Method

The method starts from a CNN that has already been trained to classify images. The confusion matrix of this network records, for each class, how often the network predicts every class. The large numbers on the diagonal are correct predictions, and the numbers off the diagonal show which classes are confused with each other. For the MNIST digits, Figure 1 shows the counts and Figure 2 shows the same matrix as fractions. A distance matrix is also shown in Figure 3.

Confusion matrix of the MNIST digits with some mistakes circled in red
Figure 1. Confusion matrix for the MNIST digits. Red circles mark some of the confusions.
Normalized confusion matrix for MNIST
Figure 2. Normalized confusion matrix for MNIST.
Distance matrix for MNIST
Figure 3. Distance matrix for MNIST.

The proposed CMCBC method uses this information to group similar classes into clusters. The clusters form the modules of the network. The clusters, a mask, the weights of the trained model and the training data then go into a step of retraining and runtime pruning, which gives the final pruned model (Figure 4). In this step, a pruning module sits between two layers of the network and sets some of the feature maps to zero, so that different pathways run through the network (Figure 5). The calculation for each layer is shown in Figure 6.

Block diagram: clusters, mask, trained model weights and training dataset go into retraining and runtime pruning, giving a pruned model
Figure 4. Overview of retraining and runtime pruning, which produces the pruned model.
A pruning module between two layers that uses a mask and clusters to set some feature maps to zero
Figure 5. The pruning module between two layers uses the mask and the clusters to set some feature maps to zero.
Input convolved with filters gives pre-activations, then an activation function gives post-activations
Figure 6. Calculation in one layer: the input is convolved with the filters, and an activation function is applied.

Figure 7 shows the structure of the network used for MNIST. It includes the runtime pruning layers (rt_pruning1 and rt_pruning2) between the convolutional layers.

Layer-by-layer structure of the modular network for MNIST, including the runtime pruning layers
Figure 7. Structure of the modular network for MNIST, including the runtime pruning layers.

Results and Discussion

The framework was tested on MNIST, a set of handwritten digits, and on CIFAR10, a set of small color pictures of ten kinds of objects. On MNIST, the modular network saved 53% of the multiplications of the original network and lost less than one percentage point of accuracy (98.51% compared with 99.39%). Figure 8 compares the accuracy of the modular network under different settings.

Bar chart of the accuracy of the modular CNN on MNIST under different settings
Figure 8. Accuracy of the modular CNN on MNIST under different settings.

CIFAR10 is a harder task. Without retraining, the modular network reached 78.01% accuracy, 6% below the baseline of 84%. After retraining to align the weights further, it reached 86.78%, which is 2.78% better than the baseline. The confusion matrix for CIFAR10 (Figure 9) shows which classes are mixed up most often: cats and dogs are the clearest example. Figure 10 shows the distance matrix and Figure 11 the accuracy under different settings.

Normalized confusion matrix for CIFAR10
Figure 9. Normalized confusion matrix for CIFAR10.
Distance matrix for CIFAR10
Figure 10. Distance matrix for CIFAR10.
Bar chart of the accuracy of the modular CNN on CIFAR10 under different settings
Figure 11. Accuracy of the modular CNN on CIFAR10 under different settings.

Author Contributions

Funding

No funds or grants were received.

Data Availability

The data used in this paper is publicly available: MNIST and CIFAR10.

Competing Interests

The authors declare no conflict of interest.