## 3 LSTM and FSST-Based Fault Diagnosis Algorithm
### Model Setup and Training  
Figure 4 provides a detailed view of our proposed **LSTM neural network model** architecture for automated labeling. This model facilitates the segmentation and classification of time-series data collected from agricultural sensors to automate the labeling process. The architecture begins with an input layer that processes one-dimensional time-series data, capturing agricultural parameter sensor readings. Following the input layer, multiple LSTM layers are utilized to capture temporal dependencies within the data, allowing the model to recognize sequential patterns that reflect various operational states. An intermediate layer then extracts the most important classification features, and a final softmax layer then assigns a label to each waveform segment, effectively identifying and categorizing different operational states, such as irrigation, operational status, or device abnormalities. This architecture supports a scalable, automated labeling system to enhance data processing efficiency and improve accuracy in smart agriculture.  
The LSTM neural network, configured with these architecture settings, receives time-series data as input, processes each sample in sequential mode, and outputs classifications for each waveform class. To maximize performance, an appropriate number of hidden nodes are used, enhancing the model's capacity to capture complex temporal patterns in the data, such as fluctuations in soil moisture or temperature changes.  
Several elements are implemented to train the neural network efficiently. The data processing pipeline is parallelized to effectively handle large training datasets. An on-demand data-reading method is used to avoid loading all data into memory at once in order to manage memory when processing large volumes of sensor data. The _gather_ function in the data repository further optimizes memory usage by allowing efficient access to the required data in the form of cell-shaped arrays containing training and test signals as well as labeled masks.  
During training, various metrics are monitored to assess model performance and to adjust parameters as needed. The key metrics include the following:  
* **Loss function changes**: This loss function measures the discrepancy between the predicted values and actual labels; by monitoring the loss function value over time, we can evaluate whether the model is effectively learning. Ideally, the loss function decreases consistently, indicating that the model's predictions are becoming more accurate.
* **Training accuracy**: This metric indicates how well the neural network is learning from the training data. Tracking training accuracy helps determine the model's ability to capture patterns in the time-series data, which helps accurately classify sensor statuses in agricultural applications.
* **Validation accuracy**: This measures the model's generalization ability on unseen data. High validation accuracy and balanced training accuracy indicate that the model is not overfitting. In smart agriculture, this is particularly important for ensuring the model's robustness in varying environmental conditions.
* **Training speed**: Efficient training is essential for managing large datasets. If training is slow, hyperparameters can be tuned or data preprocessing methods adjusted. Optimizing training speed is particularly relevant in agricultural applications, where models need to process high-frequency data in real time.
* **Overfitting**: Overfitting occurs when the model performs well on training data but poorly on validation data. If training accuracy continues to increase while validation accuracy decreases, adjustments such as regularization techniques or data augmentation can be applied to prevent overfitting.  
Figure 4: Neural network architecture.