# Federated Learning for Clients' Data Privacy Assurance in Food Service Industry
## 3 Methodology
### Contamination Classification  
To classify CSI-D recorded video frames into _clean_ and _contamination_ categories, we first selected video excerpts and converted them to frames that were labeled _clean_ and _contamination_. We then fed the labeled frames to a CNN model, MobileNetV3 [38], developed by Google, which is the next generation of the MobileNet family [39; 40; 41]. MobileNetV3 uses a novel architecture and a mix of complementary search methods to provide high accuracy and a computationally efficient model for mobile computer vision tasks. There are two models of MobileNetV3, MobileNetV3-Small and MobileNetV3-Large, designed for low or high resource usage needs, respectively. The architecture of these two models differs in terms of the number of blocks, expansion sizes, activation functions, etc. Classification Model Architecture  
MobileNetV3 depends on AutoML to identify the best architecture feasible in a search space for the given tasks. MnasNet [41] and NetAdapt [42] are used sequentially to exploit the search space more efficiently and discover and optimize the network architecture. MnasNet first uses reinforcement learning to identify the optimum global network structure by optimizing each network block, and then the NetAdapt algorithm tries to fine-tune the architecture by adjusting the number of filters per layer. Combining these two techniques can determine the best model for a specific hardware platform. MobileNetV3 also incorporates a squeeze-and-excitation block [43] into its core architecture to improve the network representational ability (emphasizing informative features and suppressing less helpful features) via adaptive channel-wise feature recalibration by explicitly modeling between the channels' interdependencies. MobileNetV3 uses an activation function called hard-swish, a modified version of the swish [44] activation function. Swish nonlinearity uses a sigmoid function, which is not computationally efficient. Hard-swish replaces the sigmoid with its piece-wise linear hard analog, as shown in (3):  
\[hard\text{-}swish[x]=x\frac{ReLU6(x+3)}{6} \tag{3}\]  
This replacement not only eliminates any numerical precision loss caused by various implementations of the approximate sigmoid but can also significantly minimize latency cost by reducing the number of memory accesses. In addition to the modifications mentioned above, some computationally expensive layers at the beginning and end of MobileNetV3 were redesigned to reduce the cost of feature generation while maintaining accuracy. To train the MobileNetV3 for classification between _clean_ and _contamination_ frames, we needed to choose a suitable loss function and optimizer. Since we are dealing with a binary classification task, binary cross-entropy (BCE) [45] was chosen as the model loss function. Comparing predicted probability to actual class labels using BCE yields a result that is either 0 or 1. It then creates a score that penalizes the probability, depending on the difference between the predicted and actual values. If the predicted value is far from the actual value, the BCE loss will be increased. Equation (4) shows the definition of BCE. \[Loss=-\frac{1}{N}{\sum_{i=1}^{N}}y_{i}\times\log(p(y_{i}))+(1-y_{i})\times\log (1-p(y_{i})) \tag{4}\]  
where \(N\) shows the training sample size, \(y_{i}\) is the assigned label, \(p(y_{i})\) shows the predicted probability of class 1 (_Contamination_), and \(1-p(y_{i})\) represents the predicted probability of class 0 (_Clean_). After the loss function is defined, the model requires an optimization algorithm to minimize the loss by changing the model weights and learning rate. We used the Adam (Adaptive Moment Estimation) optimizer [46] as a straightforward and computationally efficient approach for first-order gradient-based stochastic optimization. Adam estimates the first- and second-order moments to calculate individual adaptive learning rates for different parameters.