# Real-Time Foreign Object and Production Status Detection of Tobacco Cabinets Based on Deep Learning
## 2 Materials and Methods
### Backbone Network CSPDarknet  
**Residual network. ** We use the Residual network in CSPDarknet, and the residual convolution can be divided into two parts. The backbone part is a \(1\times 1\) convolution and a \(3\times 3\) convolution. Residual networks are characterized by being easy to optimize and capable of increasing accuracy by adding considerable depth. The internal residual block uses skip connections to alleviate the gradient disappearance problem caused by increasing depth in deep neural networks. In order to reduce the degree of overfitting, L2 regularization is performed every time of convolution. The calculation of L2 regularization is:  
\[min:C_{0}+\lambda||\omega||_{2}^{2} \tag{1}\]  
\(C_{0}\) is the loss function, \(\lambda\) is the regular coefficient, \(\omega\) is the weight vector and \(||\omega||_{2}^{2}\) is the square root of the sum of squares of all weight values. After convolution is completed, Batch Normalization is performed. The standardized calculation of Batch Normalization is as follows:  
Figure 5: YOLOX network. It consists of three parts: CSPDarkNet, FPN, and YOLO head. CSPDarknet is the backbone feature extraction network of YoloX; FPN is the enhanced feature extraction network of YoloX; Yolo Head is the classifier and regressor of YoloX. \[y_{i}^{b}=BN(x_{i})^{(b)}=\gamma(\frac{x_{i}^{b}-\mu(x_{i})}{\sqrt{\sigma(x_{i})^{2 }+\epsilon}})+\beta \tag{2}\]  
Among them, \(x_{i}^{b}\) represents the value of the i-th input node of the layer when the b-th foreign object sample of the current batch is input, \(x_{i}\) is the row vector formed by \([x_{i}^{(1)},x_{i}^{(2)},\dots,x_{i}^{(m)}]\), m is the batch size and \(\mu\) and \(\sigma\) are the mean and standard deviation of the row. \(\epsilon\) is used to prevent the extremely small amount introduced by dividing by zero; \(\gamma\) and \(\beta\) are the scales and shift parameters of the row. **Cross Stage Partial Network. ** The authors use the Cross Stage Partial Network (CSPNet) structure. The original residual block is split into two parts: the main part is the same as the original operation; the other part is connected to the next layer of the network after a small amount of processing (Figure 6a). **Focus network [5]. ** We utilize the Focus network (Figure 6b) structure to sample a value every two pixels in an image. At this time, four independent feature layers are obtained, and then the four independent feature layers are stacked. The wide information is converted into channel information, and the input channel is expanded by a factor of four. The spliced feature layer becomes twelve channels compared to the original three channels. **SiLU activation function [27]. ** For better smoothing, the SiLU activation function is adopted in our network. SiLU is smooth and non-monotonic. It can be seen as a smooth ReLU activation function and outperforms ReLU on deep models. SiLU function formula is:  
\[f(x)=x\cdot Sigmoid(x) \tag{3}\]  
**Spatial Pyramid Pooling (SPP) structure. ** The SPP structure is applied to the backbone network, and feature extraction is performed through maximum pooling of different pooling kernel sizes to improve the receptive field of the network. B. Building FPN Feature Pyramid for Enhanced Feature Extraction  
In the CSPdarknet network, YOLOX extracts three feature layers for object detection. The three feature layers are located in the middle layer, the middle-lower layer and the bottom layer in the backbone part. After obtaining the three feature layers, the authors use them to construct the FPN layer. FPN can fuse feature layers of different shapes, which is beneficial for extracting better features. C. Get Forecast Results with YOLO head  
Using the FPN feature pyramid, the authors can obtain three enhanced features, and then the authors pass these three enhanced features into the YOLO head to obtain foreign  
Figure 6: CSPNet and Focus network. (**a**) CSPNet: CSPNet is able to achieve richer gradient combinations while reducing the amount of computation.