## 3 Methodology
### Explainable AI for Malware Classification
#### 3.4.1 XAI Tools  
To enhance interpretability, we employ the following visualization techniques:  
* Grad-CAM (Gradient-weighted Class Activation Mapping): Highlights the most influential regions in the image by analyzing the gradient information of the final convolutional layer.
* Grad-CAM++: An extension of Grad-CAM that provides finer localization of important image features by considering pixel-wise importance.
* Eigen-CAM: Uses principal component analysis (PCA) on feature maps to highlight the most dominant patterns in the image.
* HiRes-CAM: A high-resolution version of Grad-CAM that captures fine-grained details in the malware image, improving feature attribution precision.  
\begin{table}
\begin{tabular}{l c c c c} \hline \hline \multirow{2}{*}{**Model**} & **Top-1** & **Parameters** & \multirow{2}{*}{**FLOPs (B)**} & **Inference** \\  & **Accuracy (\%)** & **(M)** & & **Time (ms)** \\ \hline YOLO11n-cls & 70.0 & 1.6 & 0.5 & 1.1 \\ YOLO11s-cls & 75.4 & 5.5 & 1.6 & 1.3 \\ YOLO11m-cls & 77.3 & 10.4 & 5.0 & 2.0 \\ YOLO11l-cls & 78.3 & 12.9 & 6.2 & 2.8 \\ YOLO11x-cls & 79.5 & 28.4 & 13.7 & 3.8 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Comparison of YOLO11 variants for classification. Metrics are reported at 224 \(\times\) 224 resolution. Inference time is measured using TensorRT on NVIDIA T4 GPU. Adapted from [35].  
To generate heatmap-based explanations for Android malware classification, we employed the open-source pytorch-grad-cam library (MIT license, available at [36]), which provides modular implementations of popular Class Activation Mapping (CAM) techniques. We used version >=1.4.0 without internal modifications. Four CAM-based XAI methods were integrated into our pipeline: Grad-CAM, Grad-CAM++, Eigen-CAM, and HiRes-CAM. These methods were applied to the final convolutional layer of the YOLO11 model (i.e., \(\texttt{layer}=-2\)) within the Ultralytics framework. All RGB malware images were resized to \(256\times 256\) using a letterbox function and normalized to the \([0,1]\) range. Heatmaps were computed using backpropagated gradients and overlaid on the original images to highlight regions that contributed most to the classification.  
The overall architecture of this CAM-based visualization pipeline is illustrated in Figure 2, which demonstrates the sequential steps from input image preprocessing to the generation of class-discriminative heatmaps using four different CAM techniques.  
The entire process is further detailed in Algorithm 2, which outlines the core steps of the explainability routine.  
```
0: Trained YOLO11 model and malware RGB input image
0: RGB heatmap highlighting relevant regions
1: Load YOLO11 model and set to evaluation mode
2: Resize input image to \(256\times 256\) using letterbox; normalize to \([0,1]\)
3: Select final convolutional layer (e.g., \(\texttt{layer}=-2\))
4: Choose CAM method: Grad-CAM, Grad-CAM++, Eigen-CAM, or HiRes-CAM
5: Forward image through model and compute activation maps using selected CAM method
6: Generate RGB heatmap highlighting class-relevant regions
7:return Visual explanation of model decision
```  
**Algorithm 2** CAM-Based Explainability for YOLO11 Classification  
While CAM-based visualizations enhance interpretability, they also have limitations in a security context. Heatmaps may be sensitive to adversarial perturbations, where slight modifications to an APK's structure can significantly alter the attribution output without changing the classification result. Moreover, obfuscated or packed malware samples may produce diffuse or misleading heatmaps, reducing the reliability of visual interpretations [37]. These limitations should be considered when deploying XAI tools in high-stakes malware analysis pipelines.  
Figure 2: XAI pipeline in YoloMal-XAI. The input image is preprocessed and passed through YOLO11, with four CAM methods applied to the final convolutional layer to generate class-relevant heatmaps.