6 clinically significant respiratory patterns (Eupnea, Tachypnea, Bradypnea, Biots, Cheyne-Stokes and Central-Apnea). The performance of the obtained BI-AT-GRU is tested by real-world data measured by depth camera, and the results show that the proposed model can classify 6 different respiratory patterns with the accuracy, precision, recall and F1 of 94.5%, 94.4%, 95.1% and 94.8% respectively. In comparative experiments, the obtained BI-AT-GRU specific to respiratory pattern classification outperforms the existing state-of-the-art models. The proposed deep model and the modeling ideas have the great potential to be extended to large scale applications such as public places, sleep scenario, and office environment.
Index Terms-Breathing pattern, physiological signal measurement, recurrent neural network, remote monitoring
Respiration is a core physiological process for all living creatures on earth. A persons physiological state [1] as well as emotion [2] and stress [3] may be reflected by representation of some respiratory parameters. Therefore, we should pay attention to respiration. Integrated various respiratory signs, respiratory patterns are able to more comprehensively reflect the conditions of respiratory activity. Many clinical literatures suggested that abnormal respiratory patterns are able to predict a few specific diseases [4] , providing relatively detailed clues for clinical treatments [5, 6] . Unfortunately, these abnormal respiratory patterns occur in a way difficult for people to notice themselves. If we could develop a system capable of remotely and unobtrusively detecting these unnoticeable abnormal breathing patterns under various scenarios, people who have the diseases may be diagnosed at earliest possible time.
Contact measurement devices are heavy, expensive, and inconvenient for patients to use [7] . Therefore, non-contact measurement methods are more suitable for detecting abnormal respiratory patterns. Doppler radar, thermal imaging technology and camera based on motion detection are usually used for recording respiratory signals. The continual use of radar has the potential risk of the explosion to released radiation [8] . Thermal imaging cameras are susceptible to ambient heat [9, 10] . The method based on motion detection is able to solve the above problems, because its measurement is based on the variation in displacement instead of the changes in pixel intensity. Depth camera is a good method based on motion detection which has been widely utilized in the acquisition and analysis of respiratory signals [11, 12] . Nonetheless, most relevant work focused on improving the accuracy of extracting respiratory signals and restraining the noise in movement [13] . Some paid attention to the detection of abnormal respiratory patterns, but did not classify them specifically [14] . Thus, the available clinical clues were limited.
Deep learning has been extensively used in many fields. In terms of respiratory pattern detection, Cho et al. capitalized on the convolutional neural networks (CNN) to achieve the identification of deep breathing [15] . Kim et al. used 1D CNN to classify the respiratory signals estimated by radars into four categories [16] . Therefore, the classification of respiratory signals extracted by the non-contact measurement system with the aid of deep learning is a study worth trying and of much significance. In the above study, all the data sets required for model construction were obtained, though, by assessing the respiratory activities of the test subjects. This approach for capturing different types of respiratory patterns yields a limited set of data. Were there no large amount of training data to support, the neural network might not be able to give full play to its advantages. Furthermore, researchers often present studies that the classification models generally adopt the general network architecture in the field of deep learning without specific designs for respiratory pattern classification. At the same time, the network is not optimized according to the characteristics of the collected data.
In this paper, we pioneer an AT-BI-GRU deep neural network for classifying abnormal respiratory patterns. To fill the gap between the large amount of training data and scarce realworld data, we first propose Respiratory Simulation Model (RSM) to generate abundant reliable data. The obtained classifier validated by 605 real-world data measured by depth camera can be used to achieve the remote and unobtrusive measurement of respiratory patterns.
The proposed respiratory pattern classification model consists of four parts: 1) develop respiratory simulation model for generating simulated data; 2) acquire real-world data using depth camera; 3) establish and validate BI-AT-GRU model; and 4) conduct the comparative experiments.
Respiratory patterns can be divided into normal breathing (Eupnea) and abnormal breathing such as Bradypnea, Tachypnea, Biots, Cheyne-Stokes and Central-Apnea. Standard waveforms are available at the website (https://doi.org/ 10.6084/m9.figshare.9981236.v2).
Respiration is a cyclic process of inhalation and exhalation, which are reflected in the rise and fall of the waveform. Thus, respiratory signals measured by non-contact method can be approximated by sine wave. Actual measured respiratory signals, especially those measured by non-contact method, are prone to deviation due to environmental changes, leading to fluctuations in respiratory depth and frequency within a certain range. Affected by body movements in measurements, signals also tend to have longitudinal and oblique deviation. Considering the possible deviation mentioned above, the actual measured respiratory signals can be defined by the following equation:
where ω is a constant time window, indicating the cycle of examining a respiratory pattern; i is a variable time, which is used to represent changes of signals belonging to the same respiratory pattern; the point dividing each period of i can be called a breakpoint; a i is respiratory depth; b i is respiratory rate; c i and d i are longitudinal deviation degree and oblique deviation degree of respiratory signal, respectively. Gaussian white noise is added to the simulated respiratory signal to make it closer to the real-world measured respiratory signal.
By changing values of a i , b i , c i and d i in equation (1), different features in the process of respiration can be simulated, such as speed, depth and time of apnea. A specific partial waveform can be generated by randomizing the parameters of each waveform in a pre-set range. We combine every partial waveform through breakpoints then specific respiratory patterns can be obtained. The random range of parameters is set for the 6 respiratory patterns by reference to standard waveforms and real-world waveforms, and it can be acquired in our released RSM code (https://doi.org/10.6084/ m9.figshare.9978833.v1). To illustrate the process of generating data, we select an abnormal respiratory pattern to demonstrate (https://doi.org/10.6084/m9.figshare.9981311.v1).
The depth camera is used to conduct non-contact respiratory signal measurement to obtain real-world data. Our measurement process includes obtaining depth images via the depth camera, selecting region of interest (ROI) and processing depth data.
A Kinect v2 depth camera was used to record depth images of subjects when they breathed. A total of 20 participants were asked to sit in a chair and learn to imitate 6 respiratory patterns. Spirometer of a sleep monitor (GY-6620, HeNan HuaNan Medical Science and Technology Co., LTD.) was used to check their respiratory situations to make sure they had learned the pattern. If real-world respiratory data is inconsistent with these obtained by the gold standard method, we excluded them for subsequently modeling. Subjects were at 1-4m from the depth camera, and were asked to breathe in a specific respiratory pattern for one minute at a time. The recording frame number of Kinect v2 was set as 10 fps.
In depth images, we selected three ROIs, namely chest, abdomen and shoulder. These ROIs not only solve the problem that a single ROI may not work for some people, but also increase the amount of data obtained by one measurement. We calculated the average value of depth data in certain ROI of each frame to extract respiratory signals. Subsequently, all frames of raw data were smoothed by a moving average filter with a data span of 5 to eliminate sudden changes of waveform. Finally, min-max normalization was carried out on respiratory signals. Fig. 1 shows actual measured Central-Apnea waveforms of one subject specific to three ROIs. 
According to characteristics of our task, we first apply BI-AT-GRU to classify respiratory patterns. BI-AT-GRU was trained by simulation data generated by RSM and was tested by realworld data measured by depth camera.
Both simulated respiratory data and real-world respiratory data can be regarded as time series data, a kind of sequential data. Recurrent Neural Network (RNN) is a neural network model, and is very suitable for sequential data modeling [17] . Long-Short Term Memory (LSTM) is an important variant network of RNN, and can solve the problem of long training time of RNN and long-term memory loss in long sequences [18] . Gated Recurrent Unit (GRU) [19] is a simplified variant of LSTM.
We utilized an improved GRU viz. BI-AT-GRU for respiratory pattern classification by adding bidirectional and attentional mechanisms to GRU network. The network architecture is shown in Fig. 2 . The whole network is divided into input layer, BI-GRU layer, attention layer and output layer. The input layer is used to input simulated data (training stage) or depth data (testing stage) at each point of respiratory waveform.
By observing and studying different respiratory pattern waveforms measured by depth camera, we found two particular characteristics: 1) when judging respiratory patterns, compared with left to right observation of respiratory waveform, observation in reverse chronological order (right to left observation) can acquire more information; and 2) there are key turning points in some combined respiratory patterns such as Central-Apnea which consists of normal breathing and apnea. Those turning points can provide reliable evidence for judging respiratory patterns. Based on these two findings, we added bidirection and attention into GRU, respectively corresponding to BI-GRU layer and attention layer in BI-AT-GRU.
Bidirection: Bidirectional RNN (BI-RNN) was proposed by Bahdanau et al. [20] and used in text translation. Inspired by this work, we added a bidirectional mechanism to GRU to obtain forward sequence information − → h t from beginning to end of breathing process and backward sequence information ← − h t from end to beginning. This can be expressed by following equations:
where x t is input simulated data generated by RSM (in training stage) or input depth data (in testing stage) at time t; T represents the period of a respiratory pattern. Attention: Attention RNN has been widely applied in document classification [21] , speech recognition [22] and relation classification [23] . In above studies, the attention mechanism is used to express the importance of words in sentences or sentences in documents. In our taskclassification of respiratory patterns, each point in the respiratory waveform is of different importance when determining certain respiratory pattern. Therefore, we add attentional mechanism into GRU, which can be expressed by following equations: where h t is the state at time t, which contains bidirectional information extracted from the waveform; W a and b a are the parameters obtained by training phase. First, a tanh function is used to obtain the hidden representation u t . Then normalized importance weight α t is obtained through a sof tmax function. V a is also a parameter obtained by training processing and it can be understood as the importance of one specific point to the certain respiration pattern. Finally, the sum of product of α t and h t at each point is calculated to obtain the output of the attention layer, which is denoted as S. S here is high-level representation of certain waveform for classification. Output layer uses the output S of the attention layer to classify respiratory patterns. In training stage, we encoded the label in one-hot format and cross-entropy was adopted as loss function.
The size of training set was 120,000 including 6 respiratory patterns. Each pattern had 20,000 samples randomly generated by the proposed RSM. Hidden layers, attention hidden layers and batch size were 128, 16, 128, respectively. To get real-world data of 6 respiratory patterns, we measured the respiratory signal of 20 subjects (12 female and 8 male). Subjects were instructed to imitate every respiratory patterns for one minute.
The trained BI-AT-GRU model was tested by real-world data measured by the depth camera and the test set size was 605. Among them, there were 108 groups of Eupnea, Bradypnea and Tachypnea; 97 groups of Cheyne-stokes and Central-Apnea and 87 groups of Biots. Some wrong real-world respiration patterns were eliminated. We trained BI-AT-GRU, BI-AT-LSTM, GRU and LSTM with the same training set with sample size of 120,000. The performance of these models was verified by the same test set (605 samples). Results demonstrated in Table 1 . It can be seen from Table 1 : 1) four metrics of BI-AT-GRU are higher than other models, and models with bidirectional and attentional mechanisms perform better than their basic networks; 2) GRU based networks perform slightly better than LSTM based in our task; and 3) the classification accuracy of all networks maintain a high level, proving the feasibility of training the network with RSM data. In the confusion matrix of each model (Fig. 3) , we can see that the classification error mainly came from prediction of Cheyne-Stokes to be Central-Apnea. The possible reason is that these patterns are only different in breathing depth, which reflected in amplitude of the waveform. While in normalization processing, amplitude of respiratory signal is sensitive to the time window. In addition, the movement of subjects body can lead to mutations of amplitude, thus increasing the error rate. It can be seen that BI-AT-GRU has the lowest error rate, which is an important reason why it performs best. Moreover, performances of BI-AT-GRU and BI-AT-LSTM are better than their basic networks, indicating the contribution of these two mechanisms. 
In this paper, we first apply BI-AT-GRU for classifying respiratory patterns. Because of the scarcity of real-world data, we propose a novel Respiratory Simulation Model to generate abundant training data. In validation experiments, the obtained BI-AT-GRU specific to respiratory pattern classification yields the excellent performance, and outperforms the existing state-of-the-art models. The obtained classifier has the great potential to be extended to large scale applications.