## 2 Materials and Methods
### Posture Recognition Algorithm  
The algorithm is based on a supervised deep neural network model (including LSTM layer) to train a model for classifying four weight training posture types. Each sample contains six features (three-axis accelerations and angular velocities measured by the wrist IMU), and the sampling rate is 100 Hz. The output layer is a dense layer with softmax as the activation function. The output data size is (1, 4), so the model can classify four labels. The epoch is set to 30 and the batch size is set to 64. The python code for this model based on Keras + Tensorflow is as follows:  
input_layer = tf.keras.layers.Input (shape = (128, 6))  
hidden1 = tf.keras.layers.LSTM (128) (input_layer)  
hidden2 = tf.keras.layers.Dropout (0.5) (hidden1)  
hidden3 = tf.keras.layers.Dense (6, activation ='relu') (hidden2)  
output = tf.keras.layers.Dense (NUM_GESTURES, activation ='softmax') (hidden3)  
model = tf.keras.Model (inputs = fitness_dataset, outputs = output)  
model.compile (optimizer = 'rmsprop', loss ='mse', metrics = ['mae'])history = model.fit (inputs_train, outputs_train, epochs = 30, batch_size = 64, verbose = 0, validation_data = (inputs_validate, outputs_validate))  
After training, the pre-trained model is converted to a TensorFlow Lite model file (.tflite) with a file size of 412 KB. TensorFlow Lite is a machine-learning solution for mobile or embedded devices, with APIs available for Android and iOS mobile development platforms. Developers can convert TF (TensorFlow) models into TF Lite files and import them into their mobile projects to realize edge computing locally. In this paper, we use Flutter to develop Android mobile application, and use the TensorFlow Lite patch tflite_flutter (version: 0.8.0) of Flutter Package to import the model file into the development project. The six-axis data from the wrist IMU is used as input data to the pre-trained model of the local App for classifying the user's motion posture (three pre-defined dumbbell movements and rest state). The flowchart of the algorithm running in the App is shown in Figure 4.  
When the LSTM model completes the identification, the oldest 32 samples are removed, and the latest 32 samples are added into the input data (total 128 samples) for LSTM. The output of the LSTM model is a probability vector \(r\) with dimension (1,p), where p is the number of postures to be identified. The element with the largest probability (>0.5) in this vector is the most possible posture label at the moment. If the same label is identified for \(n\) consecutive times, this label will be used as the output result of the posture recognition algorithm.  
In order to collect the motion data for training the neural network, the participants were divided into a training group (control group) and a test group. The datasets for training and testing were collected by an experiment instructor who instructed the participants to put on the wearable device developed in this paper, and the participants performed four postures (rest, bicep curl, lateral raise, and shoulder press) at their own pace. The instructor used the developed smartphone App to record the participants' exercise data (with a sampling rate of 100 Hz). The data were stored in the local database, converted to a csv file, and uploaded to the storage space of the cloud database at the end of sampling. Then the local computer downloaded the cloud data for training.  
The dimension of the input data is (1,128,6), and the IMU six-axis data are packaged in 32 time steps, as shown in Figure 5. Each set of data has 128 consecutive samples. Once a set of data has been processed, the first (oldest) 32 samples in this set are discarded and  
Figure 4: Flowchart of the posture recognition algorithm.  
32 new samples are added to the end of the set to create another data set until the sample in the data is exhausted.