# Long Short-Term Memory (LSTM)-Based Dog Activity Detection Using Accelerometer and Gyroscope
## 4 Framework for LSTM Model  
The overall architecture of our proposed model has been shown in Figure 1. First, we collected data from the dogs using sensors. Second, we synchronize the sensor data with the video recordings. Third, we used data preprocessing techniques to clean the data. Fourth, we developed our LSTM model and evaluated its performance. An algorithm for detecting dog activity was developed that acquires biosignals via wearable devices, such as an accelerometer and gyroscope. Different preprocessing strategies, such as data filtration and normalization, were used to preprocess the biosignals. An LSTM-based algorithm was used to anticipate the dog's behavior. This dog activity detection algorithm works in the following way:  
Wearable devices with gyroscopes and accelerometers were employed firstly to collect experimental data from the dogs. These sensors were attached to the 10 different breeds' necks and tails, age groups, and genders of dogs. The use of these sensor devices has allowed for the examination and recording of 10 distinct types of activities. For preprocessing and filtering the raw data, a butter low-pass filter was utilized that was retrieved from the sensor devices. We obtained more accurate data as a product of the filters' removal of noise and undesired signals from the data. The dataset underwent data normalization in order to uniformly scale and normalize the range of all the data. Figure 1: The architecture of proposed model. The wearable sensor's sampling frequency is 33.3 Hz. Consequently, we have a matrix with a dimension of 99 to store the data. Each matrix is structured as a set of 124 \(\times\) 99 = 12,276 feature vectors, where 124 stands for the matrix's 124 dimensions and 99 for the number of rows in each window or data size. The very first row of the vectors for each element was then labeled with the type for that element. In conducting this research, we employed a deep learning method. Deep learning, in contrast to conventional artificial neural networks, can both extract features and classify them. Without the aid of a human or using a manual process, it automatically extracts the highly significant features and uses them for classification and detection. Long short-term memory (LSTM) networks are a deep learning technique that may recognize order dependency in situations involving sequence prediction. This behavior is essential in fields with complicated problems, such as voice recognition, machine translation, and behavior analysis. As the data we gathered from the sensors consisted of x, y, and z values, we decided to convert these data into vector magnitude data, and an LSTM was built using this vector to classify different dog behaviors. For different application that requires feature extraction and classification, LSTMs are one of the most famous recurrent neural network (RNN) methods. The LSTM model, which included LSTM, dropout, fully connected dense, and a Softmax layers, was used in this work to explore the activities of dogs. **Input layer:** In the form of vector magnitude, the accelerometer and gyroscope provided the input layer of the model with six-axis data, i.e., three axis from each sensor. **LSTM layer:** We have used 6 LSTM layers. At first, we used LSTM layers with 256 neurons 2 times, while applying dropout at 30%. After that, we applied LSTM with 128 neurons, with a dropout at 20% for the second time. In the last stage of LSTM layers, we used LSTM with 64 neurons with dropout at 20% again. **Dropout Layer:** Dropout layers help the model to overcome the overfitting problem. It also prevents the synchronized weight optimization of all neurons in a layer. Dropout layers with dropout values of 0.3, 0.2, and 0.2 were utilized in our model to reduce the complexity of the model. **Dense/Fully Connected Layer:** Dense layer aids in adjusting the output's dimensionality so that the model may more easily establish the relationship between the values of the data it is working with.