# Lightweight Anomaly Detection in Digit Recognition Using Federated Learning
## 8 Conclusions  
This work demonstrates that both training and inference for AD can be performed entirely on resource-constrained edge hardware using 32-bit floating-point autoencoders. We designed and evaluated several lightweight models on the ESP32-CAM MCU, showing that reliable on-device training is feasible without relying on quantization, pruning, or pretraining. Despite its limited memory, the ESP32-CAM supports models with full training memory footprints between 100 and 480 KB, with many fitting entirely within the internal RAM, while datasets can be accommodated using the device's external 4 MB PSRAM. The system achieves training times between 12 and 210 min and inference latency ranging from 9 to 42 ms depending on model complexity. To balance training efficiency and model performance, we employed the proposed dual-phase early stopping strategy. \begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline
**Work** & **Device Type** & \begin{tabular}{c} **Device** \\ **(RAM/Frequency)** \\ \end{tabular} & **Model Type** & **Model Size** & \
\begin{tabular}{c} **Inference** \\ **Latency** \\ \end{tabular} &
\begin{tabular}{c} **On-** \\ **Device** \\ **Train** \\ \end{tabular} & **FL** \\ \hline
[26] & - & - & SCVAE & 12 MB & 6 ms & - & - \\ \hline
[27] & - & - & Stacked AE & - & - & - & - \\ \hline
[28] & ESP32 & 520 KB/240 MHz & AE & - & - & - & - \\ \hline
[29] & STM32L476 & 128 KB/80 MHz &
\begin{tabular}{c} PCA, AE, \\ Conv-AE \\ \end{tabular} & 77.55 KB, -, - & 6.428 ms, -, - & - & - \\ \hline
[30] & - & - & AE & - & - & - & - \\ \hline
[33] &
\begin{tabular}{c} Arduino Nano 33 \\ BLE Sense \\ \end{tabular} & 256 KB/64 MHz & AE & - & - & \(\checkmark\), OL & - \\ \hline
[34] & \begin{tabular}{c} i5-7600K, ARM \\ Cortex A72 \\ \end{tabular} & \begin{tabular}{c} -/3.8 GHz, \\ 4 GB/1.5 GHz \\ \end{tabular} & Deep Conv-AE & 2.7–273 KB & \
\begin{tabular}{c} 0.366–0.746 μs, \\ 6.044–13.575 μs \\ \end{tabular} &
\begin{tabular}{c} ✓ \\ - \\ \end{tabular} & - \\ \hline
[40] & i7-11700K & 64 GB/3.6 GHz & Deep AE for FL & - & - & \(\checkmark\) & \(\checkmark\) \\ \hline
[41] & \
\begin{tabular}{c} i7-8700K, \\ NVIDIA GeForce \\ RTX 2080 Max-Q \\ \end{tabular} &
\begin{tabular}{c} 32 GB/3.7 GHz, \\ 8 GB GPU \\ \end{tabular} & LSTM AE & - & - & \(\checkmark\) & \(\checkmark\) \\ \hline
[42] & \begin{tabular}{c} Raspberry Pi 4, \\ Jetson Nano \\ \end{tabular} & \
\begin{tabular}{c} 4 GB/1.5 GHz, \\ 4 GB GPU \\ \end{tabular} & AE, LSTM &
\begin{tabular}{c} 29 MB, \\ 42 MB \\ \end{tabular} & 13.1 ms, 19.6 ms & \(\checkmark\) & \(\checkmark\) \\ \hline
[44] & - & - & WAFL-AE & - & - & \(\checkmark\) & \(\checkmark\) \\ \hline
[43] & - & - & AE, DNN & - & - & \(\checkmark\) & \(\checkmark\) \\ \hline This work & ESP32-CAM & 520 KB/240 MHz & AE & 25–120 KB & 9–42 ms & \(\checkmark\) & \(\checkmark\) \\ \hline \hline \end{tabular}
\end{table} 
Table 9: Comparison of anomaly detection systems on the edge. We further extended this setup into a practical FL testbed involving ten ESP32-CAM devices communicating over Wi-Fi. Through extensive experiments across diverse scenarios--including IID, non-IID, and corrupted data distributions--we demonstrated the system's robustness and scalability. The best-performing models achieved F1 scores of up to 0.87 with standard IID settings and 0.86 under the strict single-digit-per-device non-IID configuration. Importantly, even when up to two devices were completely trained on corrupted data, collaborative training remained stable without requiring explicit anomaly or malicious client detection. These results confirm that standard federated aggregation can effectively mitigate the influence of local data anomalies, featuring solid system resilience. While our results demonstrate the feasibility and robustness of on-device training and FL on edge hardware, several limitations remain. The models and datasets used are intentionally small due to the strict memory constraints of the ESP32-CAM, and larger-scale applications have not yet been explored.