# 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.1 MnasNet  
The CNN algorithm is considered an important breakthrough in the image classification field, and the application of models based on it showed a remarkable increase in image recognition performance. This resulted in the CNN algorithm being employed in various fields of study [27; 28; 29; 30]. Recently, different attempts to run such high-performance CNN models in a low-computing environment such as mobile ones have been reported [31; 32]. The representative hand-crafted CNN models  
Figure 2: Voice activity detection (VAD) block diagram.  
in low-computing environments include MobileNet and MobileNetV2, which demonstrated stable identification performances in a mobile environment [31; 32]. In addition, studies on neural architecture search (NAS), which automatically generates suitable models for specific target problems based on reinforcement learning (RL) rather than by hand-crafting a CNN model, has been conducted [33; 34]. Based on this concept, studies have attempted to automatically generate a model to apply such an NAS to a mobile environment rather than a PC environment, and the representative result of this study is known as mobile neural architecture search (MNAS) [22]. Unlike NAS, which emphasizes only the high accuracy of the generated model, the process of retrieving the CNN model using MNAS considers the hardware in which the generated model will be deployed. The search process for MNAS is optimized using Equation (1) [22].  
\[maximize_{m}\ ACC(m)\ \times\ \left[\frac{LAT(m)}{T}\right]^{w} \tag{1}\]  
To generate and optimize model \(m\), MNAS attempts to maximize the value obtained by calculating the accuracy of \(m\), \(ACC(m)\), multiplied by the latency measured by the target hardware, \(LAT(m)\), and divided by the target latency \(T\). \(W\) denotes a variable that determines the tradeoff between \(ACC\) and \(LAT\).  
[PERSON] et al. [22] set up MNAS to generate an optimized model capable of performing image recognition in a Google Pixel 1 mobile phone, resulting in the creation of MnasNet, a lightweight model that showed higher efficiency and accuracy than models specifically hand-crafted for mobile environments (MobileNet and MobileNetV2) [22; 35]. In this study, we employed the MnasNet model proposed by [PERSON] et al. [22] as a sound-based pig anomaly detector.  
The structure of MnasNet employed in the experiment is illustrated in Figure 3. Furthermore, the mobile bottleneck convolution (MBConv) and separable convolution (SepConv) layers used in MobileNetV2 are used here [22; 28]. Each block receives an input vector of shape \(H\times w\times F\) (\(H\) refers to height, \(w\) to width, and \(F\) to the number of channels). The MBConv block is calculated by expanding the number of channels \(F\) by three times (MBConv3; \(H\times w\times 3F\)) or six times (MBConv6; \(H\times w\times 6F\)) before going through depthwise convolution (DWConv), and then the number of channels is restored back to \(F\). The hierarchical structure of MnasNet is composed of repeating blocks with different channel expansion ratios (MBConv3; MBConv6), filter sizes (\(3\times 3\); \(5\times 5\)), and number of filters. In Figure 3, symbols \(\times 2/\times 3/\times 4\) on the right side of each layer numbered 1-5 represent the number of times that specific block is repeated. In this study, a spectrogram image of size \(128\times 128\times 3\) was used as an input. It was dimensionally reduced to \(4\times 4\times 320\) (the output of the last MBconv block) and fed as an input to a fully connected layer (FC). Thereafter, the FC was used to calculate the probability of belonging to each class to obtain the result of the classification.