# Field-Applicable Pig Anomaly Detection System Using Vocalization for Embedded Board Implementations
## 2 Embedded Board-Based Real-Time Pig Abnormality Detection System
### Anomaly Detector
#### 2.2.2 Filter Clustering and Pruning  
Although MnasNet is an optimized model for the target hardware, it is sometimes necessary to expand the model to obtain higher accuracy or reduce it to decrease computing power consumption. The easiest model scaling method is to reduce the overall latency by resizing the input image fed to MnasNet from \(224\times 224\) to \(128\times 128\)[22; 32]. Another method operates by removing the convolution layer filters at a fixed rate [33; 36; 37; 38; 39]. MnasNet employs a depth multiplier (DM) as a model scaling hyper-parameter that removes the filters and decreases or increases the number of channels in each layer of the model to control its size [22]. If the DM is set to 0.5, the number of filters in each layer is reduced to half, thereby reducing the latency. Recently, there has been a study that, instead of using the algorithm with the DM described earlier, which removes filters at a fixed rate before training the CNN-based deep learning model, applied a clustering method to remove filters of low importance among the ones present at the level of each layer of the trained neural network model [29]. This clustering method was first applied to the detector You Only Look Once (YOLO) [40], and the results proved that the network size was effectively reduced while the identification performance was maintained. In this study, an 8-bit filter clustering algorithm  
Figure 3: MnasNet architecture for pig abnormality classification: (**a**) MnasNet: 8-bit filters clustering algorithm applied to all layers; (**b**) SepConv; and (**c**) MBConv(E), \(k\times k\). is proposed to further improve the model compression ratio of the filter clustering algorithm proposed in [29], which relied on a 9-bit filter, while maintaining the detection performance. The algorithm proceeds in the following order:  
1. Except for the center of the filter, the weights in \(3\times 3\) filters belonging to a specific layer of the deep learning model are converted to binary values--0 if the value of the weight is less than the value at the center of the filter and 1 if greater than or equal to the value at the center of the filter (see Figure 4). Then, as shown in Figure 4c, 8-bit binary pattern values of the corresponding filters are obtained by converting them to 8-bit binary numbers. These 8-bit binary pattern values possess a maximum of 256 patterns. 2. After defining the 256 patterns that can be generated through the 8-bit binary filtering as individual clusters, all filters belonging to a specific layer of the deep learning model are classified into their corresponding clusters. For example, if a specific filter that has undergone the process described in Figure 4 has the binary pattern \(11010110_{(2)}\), it is classified in the 214 th cluster. 3. After clustering all the filters in a specific layer and using the original filter values shown in Figure 4a before the binary patterning is applied, we calculate the value \(l2-Norm\) (\(\sqrt{ \begin{array}{c}0.1^{2}+1.3^{2}+\ -1.4^{2}\\ +1.2^{2}+\ -0.7^{2}+\ -2.1^{2}\\ +1.7^{2}+1.1^{2}+\ -2.3^{2}\end{array} }\cong 4.40\)) of the filters belonging to each cluster and sort them based on the calculated value in their corresponding clusters. 4. At this stage, in each cluster, the filter with the highest \(l2-Norm\) value is considered the most relevant and important filter for the identification performance [37; 41] and hence retained, whereas all the remaining ones are removed because they are regarded as less important filters that will not affect the model's performance. 5. Steps 1 to 4 are performed in all the convolutional layers of the deep learning model. After the algorithm is applied to the entire network, only the highly important and relevant filters among the \(3\times 3\) filters in each layer will remain. This will improve the speed performance of the deep learning network by reducing its size while maintaining its classification performance.