# Exploring Attributions in Convolutional Neural Networks for Cow Identification
## 2 Materials and Methods
The following evaluation of attribution methods was proposed:  
* Compute the Shapley value of the accuracy of the model for the foreground and the background;
* Compute the average contribution for a pixel in the foreground and in the background;
* Compare the previous two values. The hypothesis was that if the average attribution was close to the Shapley value, then it could be assumed that the attribution method correctly allocated the importance according to the model. In the definition of the Shapley value in Equation (2), \(i\) is either foreground or background; the set of players \(N\) has two elements: foreground and background; the value or the payoff \(v\) is the accuracy of the identification model. \[\phi_{i}=\sum_{S\subseteq N\setminus\{i\}}\frac{|S|!\left(n-|S|-1\right)!}{n!} [v(S\cup\{i\})-v(S)] \tag{2}\]  
More specifically, the definition of \(v(S)\) for the different values of \(S\) is as follows:  
Foreground: The foreground was left and the background was replaced with white noise for both the test and reference images; \(v(S)\) is the accuracy of the model over these images. Background: The process was executed as previously mentioned, but there the background was left and the foreground was replaced with white noise. Empty set: \(v(\mathcal{O})\) is set to the expected probability of being correct if the individual is guessed at random. Foreground and background: \(v(S)\) is the accuracy of the model on the original images. It should be noted that the model is kept fixed during the evaluation of the accuracy, and it is trained on the original images. The foreground and the background images are presented in Figure 1.  
The attribution methods that were chosen for identifying the regions of the cow face images that contribute the most to the final output were gradient-based approaches [40]. Several gradient methods are in use in computer vision and machine learning, but relatively few have been proposed for triplet loss networks. In the present study, we used adaptations of Vanilla gradient, Grad-CAM [41], and EmbeddingCAM [42] in order to highlight the parts of the cattle face images that appear to be most important for the decision made by the CNN in the identification process. The Shapley value for the foreground and background images was computed to measure the relative contributions, similar to research where the Shapley value assesses the importance of the dataset images [43]. In experimental research [40] Grad-CAM showed the highest accuracy among other Explainable AI methods (XAI). [44] suggested that particular modifications of the Grad-CAM method perform even better. However, the evaluation of the goodness of the explanations in most of the research still relies on a review by a human expert. In the current experiment, the use of Shapley values aims to give an objective measure of the attribution of a region in the image with regard to the trained model. **Vanilla gradient**[45] is a technique used to interpret neural network predictions by examining the gradients of the output with respect to the input features:  
\[\frac{\partial f_{w}(a;p,n)}{\partial a} \tag{3}\]  
where \(f_{w}(a;p,n)=\text{MSE}(a,p)-\text{MSE}(a,n)\) is the difference between the mean squared errors (MSE) in the positive and negative images; \(a\) is the anchor image, and \(w\) are the weights of the model. This approach is being used in order to help identify which input features are most influential in the network's decision-making process by highlighting areas where slight changes in input lead to significant changes in the output. By computing the gradients, the influence of each input pixel (in the case of images) on the final prediction could be traced, providing insights into which aspects of the data are deemed important by the model. This method has several limitations that have been addressed in new methods [46]. Gradients are often noisy, meaning they can highlight irrelevant or uninformative pixels alongside meaningful features.