# Enhanced YOLOv8 with BiFPN-SimAM for Precise Defect Detection in Miniature Capacitors
## 3 Materials and Methods
### SimAM Attention Mechanism  
Drawing inspiration from human neuronal activities, this mechanism mimics the distinctive firing patterns of information-rich neurons, which have the capacity to suppress the activity of their less informative neighbors. In the context of neuroscience, these pivotal neurons are identified through the formulation of a specific energy function for each neuron, facilitating the pinpointing of neurons that carry crucial information. Translating this concept into the domain of machine learning, the SimAM attention mechanism adeptly applies this principle. It possesses the ability to dynamically learn and harness similarity information among targets, thereby accurately determining the similarity metric across various features. Subsequently, it assigns appropriate weights to these features on the basis of their informational value. This method effectively bolsters the model's proficiency in detecting target defects within miniature capacitors. The underlying principle of SimAM is grounded in the recognition that not every feature contributes equally to the detection task. Certain features are more informative and play a pivotal role in the accuracy of defect detection. Similar to how information-rich neurons in human neuroscience display distinct firing patterns and modulate the activity of nearby neurons lacking in informative content, SimAM's focus on these salient features guarantees that the model's attention is focused on the most relevant aspects of the data [25].  
\[e_{t}(w_{t},b_{t},y,x_{i})=\left(y_{t}-\hat{t}\right)^{2}+\frac{1}{M-1}\sum_{i= 1}^{M-1}\left(y_{0}-\hat{x}_{i}\right)^{2}, \tag{1}\]  
Figure 2: Improved YOLOv8n network structure.  
The number of neurons is indicated by \(M\) in the preceding equation, and \(\hat{t}=w_{t}t+bt\) and \(\hat{x}_{i}=w_{t}x_{i}+b_{t}\) represent the linear transformations of the target neuron and other neurons in the same channel in the input eigenmap [26]. To make things simpler, the scalars \(y_{t}\) and \(y_{0}\) have binary labels, and to recombine the energy equations and obtain Equation (2), the regular term \(\lambda\) is added.  
\[\begin{array}{l}e_{t}(w_{t},b_{t},y,x_{i})=\frac{1}{M-1}\sum\limits_{i=1}^{M- 1}\left(-1-\left(w_{t}x_{i}+b_{t}\right)\right)^{2}\\ +(-1-\left(w_{t}t+b_{t}\right))^{2}+\lambda w_{t}^{2}\end{array} \tag{2}\]  
Solving the above equation yields the weights \(w_{t}\) and deviations \(b_{t}\):  
\[w_{t}=-\frac{2\left(t-\mu_{t}\right)}{\left(t-\mu_{t}\right)^{2}+2\sigma t^{2 }+2\lambda} \tag{3}\]  
\[b_{t}=-\frac{1}{2}(t+\mu_{t})w_{t} \tag{4}\]  
\(\mu_{t}\) and \(\sigma\) represent the mean variance of every neuron in that channel except \(t\), which eventually results in the formula for the least energy:  
\[e_{t}^{*}=\frac{4\left(\sigma^{2}+\lambda\right)}{\left(t-\hat{\mu}\right)^{2 }+2\sigma^{2}+2\lambda} \tag{5}\]  
According to the above equation, a neuron's significance increases with decreasing energy \(e_{t}^{*}\) since it allows for greater neuronal differentiation from nearby neurons. Equation (6) [27], when applied to deep neural networks, displays the final formula:  
\[\widetilde{X}=Sigmoid(\frac{1}{E})X \tag{6}\]  
The use of the sigmoid function is primarily to suppress the value of the energy in \(E\) that is too great, where \(X\) represents the input features. \(E\) is the sum of the minimum energy in all spatial and channel dimensions. Figure 3 displays the construction of the SimAM attention module. In this paper, the YOLOv8 bottleneck is integrated with the SimAM attention mechanism, which makes the model more focused on detecting targets. Furthermore, SimAM is very design-oriented, does not include too many extra parameters, and can ensure a high detection speed while improving the model's detection accuracy [28; 29; 30].  
Figure 3: SimAM attention module structure.