# Methodology for Evaluating the Generalization of ResNet
## 3 Method  
### Class Activation Map  
Due to the black-box nature of deep neural network models, directly assessing their generalization ability is challenging. To address these challenges, gaining insights into the decision-making processes of these models can offer novel approaches for evaluating generalization. Various methods for explaining the decision-making of neural network models have been proposed. Among them, the Class Activation Map (CAM) based on the attribution explanation method is an efficient and accurate approach [23; 24]. CAM can quantify the importance of different positions in the input image to the CNN model's final output. In other words, the class activation maps can be used to represent the feature weights learned by the model at different pixels in the input image. One study [25] suggested that irrelevant features learned by the network model will decrease the generalization ability of the model. Drawing from the principle of algorithm stability, it can be inferred that a model's generalization capability can be enhanced when it learns greater feature weights at positions that are pertinent to the task. Class activation map (CAM) [23; 24] is a type ofattribution interpretation method that can calculate the correlation degree of each pixel in the image with the final prediction of the model. As depicted in Figure 1, Grad-CAM [24], an evolution of CAM, is utilized to generate a heat map that graphically represents these correlations. The heat map's values are normalized to a scale where 0 signifies the least significant correlation, and 1 denotes the most substantial correlation. CAM was proposed in the field of image classification, especially for CNN models, which have good interpretability. It serves as a quantitative measure of the feature weights across various pixel positions within the image, as well as a representation of the spatial distribution of these learned features. For a given category c, the general calculation method of CAM is as follows:  
\[\mathbf{M}^{c}=\text{ReLU}(\sum_{k}w_{k}^{c}\,\mathbf{F}_{k}) \tag{1}\]  
where \(\mathbf{M}^{c}\in\mathbb{R}^{h\times w}\) represents the class activation map of the model for category c. \(\mathbf{F}_{k}\in\mathbb{R}^{h\times w}\) is the feature map output by the middle layer of the model, and \(w_{k}^{c}\) represents the importance of the \(k\)-th dimension feature map relative to category c. The calculation method of CAM proposed by [PERSON] et al. [23] uses the weight parameter of the fully connected layer after the network convolution layer as \(w_{k}^{c}\). This method requires adding a global average pooling layer (GAP), and class activation maps can only be calculated after the last layer of convolution. The Grad-CAM [24] method uses the gradient mean of the loss function on the feature map as \(w_{k}^{c}\). This method can calculate class activation maps at any layer in the network without modifying the network structure. According to the literature [25] and the algorithm stability principle, the higher the ratio of task-relevant features learned by the model, the better its generalization. In this paper, for the image classification task, task-relevant features are defined as the features that are distributed over the category-specific object's location. Figure 2 illustrates the feature distribution learned by the model and the annotated bounding boxes delineating the category object's location. The figure is organized into rows, with the top row depicting the input image processed by the model. The subsequent rows (second to fourth) correspond to three distinct models, each exhibiting varying levels of generalization capability. This research employed the concept of the generalization gap to quantify the models' generalization performance [1]. The generalization gap values, which are indicative of the model's generalization proficiency, are listed in the first column and were 4.0, 25.0, and 47.1, respectively, with the models' generalization ability diminishing from top to bottom.