A campus sunshine run flow prediction method based on a transformer
Patent Information
- Application Number
- CN202311570028.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-23
- Publication Date
- 2026-10-13
- Estimated Expiration
- 2043-11-23
AI Technical Summary
传统的方法研究对象为普通群众,拥有规律的作息和交通时间;而本场景面向高校学生群体,相较于普通群众,运动习惯和人际关系更为复杂;传统的建模方法考虑情况单一,仅分析历史人流数据而没有考虑数据背后的因素
[0016]基于深度学习提出改进Transformer的运动偏好预测模型对学生在未来时刻的运动倾向进行预测,对学生的历史运动数据、运动影响因素和学生个人信息进行建模,能够针对学生群体的历史运动数据及影响运动的因素更好地预测未来时刻的运动状态,提高人流量预测的准确性,便于教师对操场等运动场地提前做出管理和规划。
Smart Images

Figure CN117764166B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of pedestrian flow prediction technology, and in particular to a method for predicting pedestrian flow in a campus sunshine run based on Transformer. Background Technology
[0002] Improving students' physical fitness and enhancing their physical exercise has become an important task for schools. In this context, universities across China have set mandatory targets such as "Sunshine Run" and "Campus Run," using methods based on computer vision and GPS technology to monitor performance. However, according to big data analysis, students tend to exercise during the evening after classes and after evening self-study sessions, leading to significant overcrowding on the playground. This not only affects the performance of the performance monitoring system, potentially causing errors in student running scores, but also poses significant safety hazards. Therefore, it is necessary to predict student activity patterns based on their exercise habits to facilitate effective student management by teachers.
[0003] Pedestrian flow prediction is a hot research topic in fields such as transportation and safety science. Current mainstream research targets the general public and focuses on urban areas. Based on historical population movement trajectories and visited locations, urban areas are divided and statistically analyzed in different ways. Models are then built to fit urban pedestrian flow prediction values, thereby achieving urban pedestrian flow prediction.
[0004] Traditional research methods primarily focus on urban settings, analyzing user activity patterns across different areas. This study, however, focuses on a school playground, analyzing the activity patterns of different users within the same area. Traditional methods also target the general public, who have regular schedules and commuting patterns; this study, however, targets university students, whose exercise habits and interpersonal relationships are more complex than those of the general public. Furthermore, traditional modeling methods are limited to analyzing historical pedestrian flow data without considering the underlying factors. Summary of the Invention
[0005] The technical problem to be solved by this invention is to provide a method for predicting the flow of people in a campus sunshine run based on Transformer. Based on deep learning, an improved Transformer motion preference prediction model is proposed to better predict the future motion status of students by taking into account their historical motion data and factors that affect their motion, thereby improving the accuracy of the prediction of the flow of people in the sunshine run.
[0006] This invention provides a Transformer-based method for predicting pedestrian flow during campus running events, comprising:
[0007] The process of constructing the pedestrian traffic dataset involves quantifying students' daily activity status, class status, temperature, and weather to form a time series of a specified length.
[0008] The motion preference prediction model was constructed and trained using a Transformer module based on a multi-head self-attention mechanism. A student ID encoding module was added to learn student features. The model input was a time series of a specified length, and the model output was a time series of a specified length following the last input time series. The motion preference prediction model was trained after data collection, processing, and data augmentation.
[0009] Prediction process: Input historical data, including at least a specified time period, into the trained motion preference prediction model to obtain the predicted student motion state results for a specified time series.
[0010] Furthermore, in the process of constructing the traffic data set, 16 hours are taken from 6:00 AM to 10:00 PM each day, divided into 30-minute intervals; the course status of each time period of the day, excluding physical education class, is obtained according to each student's daily schedule; the temperature and weather conditions of each time period of the day are obtained according to meteorological bureau data; the students' exercise data are obtained according to the campus sunshine run monitoring platform; one-hot encoding is used to quantize time, resulting in a total of 32 moments, with each moment's exercise status occupying 2 bits, course status occupying 2 bits, temperature occupying 1 bit, and weather occupying 3 bits. The exercise status, course status, temperature, and weather are used as input data, and the time series shape of each student's exercise data is [sequence_length=32, batch_size=1, feature_length=2+2+1+3=8].
[0011] Furthermore, the motion preference prediction model includes an input embedding module, a student ID encoding module, a multi-head self-attention module, a summation and normalization module, a multilayer perceptron module, an output embedding module, a linear layer module, and an activation function.
[0012] Furthermore, the input embedding module is used to quantify and continuousize the input time series, extract features, and map the data from a high dimension to a lower dimension representation.
[0013] Furthermore, in the student ID encoding module, the student's feature value uses the student ID as the individual feature, the adjacency matrix represents the student's interpersonal relationships, and the adjacency matrix is weighted using learnable weights.
[0014] Furthermore, in the prediction process, the data input to the motion preference prediction model also includes obtaining weather data, temperature data, and timetable data for a specified future time period. Then, the weather data, temperature data, and timetable data in the predicted time data are masked using real data to obtain a more accurate prediction result of the student's motion status.
[0015] The technical solutions provided in the embodiments of the present invention have at least the following technical effects:
[0016] Based on deep learning, an improved Transformer motion preference prediction model is proposed to predict students' future motion tendencies. It models students' historical motion data, motion influencing factors, and students' personal information, enabling better prediction of future motion status based on students' historical motion data and factors influencing motion. This improves the accuracy of traffic flow prediction and facilitates teachers' advance management and planning of sports venues such as playgrounds.
[0017] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0018] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0019] Figure 1 This is a flowchart illustrating the method of an embodiment of the present invention;
[0020] Figure 2 This is a schematic diagram of a motion preference prediction model based on an improved Transformer according to an embodiment of the present invention;
[0021] Figure 3 This is a detailed structural diagram of the motion preference prediction model according to an embodiment of the present invention. Detailed Implementation
[0022] This invention provides a Transformer-based method for predicting pedestrian traffic at a campus sunshine run. Based on deep learning, it proposes an improved Transformer motion preference prediction model, which better predicts future motion status by taking into account historical motion data of students and factors influencing motion, thereby improving the accuracy of pedestrian traffic prediction for the sunshine run.
[0023] The overall concept of the technical solutions in the embodiments of the present invention is as follows:
[0024] Based on deep learning, an improved Transformer motion preference prediction model is proposed to predict students' future motion tendencies. It models students' historical motion data, motion influencing factors, and students' personal information, enabling better prediction of future motion status based on students' historical motion data and factors influencing motion. This improves the accuracy of traffic flow prediction and facilitates teachers' advance management and planning of sports venues such as playgrounds.
[0025] Example 1
[0026] This embodiment provides a Transformer-based method for predicting pedestrian flow during campus running events, such as... Figure 1 As shown, it includes:
[0027] The process of constructing the pedestrian traffic dataset involves quantifying students' daily activity status, class status, temperature, and weather to form a time series of a specified length.
[0028] The motion preference prediction model was constructed and trained using a Transformer module based on a multi-head self-attention mechanism. A student ID encoding module was added to learn student features. The model input was a time series of a specified length, and the model output was a time series of a specified length following the last input time series. The motion preference prediction model was trained after data collection, processing, and data augmentation.
[0029] Prediction process: Input historical data, including at least a specified time period, into the trained motion preference prediction model to obtain the predicted student motion state results for a specified time series.
[0030] In one possible implementation, the specific steps are as follows:
[0031] 1. Collection and quantification of pedestrian flow data
[0032] The data is taken from 6:00 AM to 10:00 PM daily, a total of 16 hours, divided into 30-minute intervals. Therefore, the quantified one-hot encoding should be a time series of length 32. Based on each student's daily schedule, the class status for each time period of the day (excluding physical education classes) is obtained. Temperature and weather conditions for each time period of the day are obtained from meteorological data. Student exercise data is obtained from the campus sunshine running monitoring platform. The information for an individual on a specific day is shown in Table 1.
[0033] Table 1. Individual Daily Exercise Information
[0034]
[0035] The data in Table 1 is quantified as follows: 0 represents an activity status of not running in the sunshine on the playground, and 1 represents running in the sunshine; 0 represents a class status of no class, and 1 represents a class; the temperature at that time is denoted as t, and quantified as... The weather at that time was 0 for sunny, 1 for cloudy, and 2 for rainy. Using one-hot encoding to quantize the time dimension, a total of 32 time points can be obtained. At each time point, the motion state occupies 2 bits, the course state occupies 2 bits, the temperature occupies 1 bit, and the weather occupies 3 bits. The motion state, course state, temperature, and weather are used as input data. Therefore, the time series shape of the input motion data of each student is [sequence_length=32, batch_size=1, feature_length=2+2+1+3=8], as shown in Table 2.
[0036] Table 2 Quantification of Individual Daily Exercise Information
[0037]
[0038] According to the above rules, for campus sports data collection, assuming the number of students on campus is *nop*, we can obtain the time series data to be trained. This data has the shape [sequence_length = 32, batch_size = *nop*, feature_length = 8], denoted as S = [T1, T2, ..., T32]. For any *Ti* (i = 1, 2, ..., 32), we have...
[0039] 2. Modeling of motion preference prediction model
[0040] Traditional time series prediction relies on multi-layer perceptron learning of hidden features within the time series. However, due to the correlation between consecutive frames in a time series—for example, if a student exercises in the morning, the probability of them exercising again in the afternoon will be significantly reduced—this paper aims to learn the attention between long time series. It borrows the multi-head self-attention mechanism from natural language processing to learn the correlation between long texts. Furthermore, considering the group connections among students (e.g., roommates are more likely to run together), the model is improved by adding a student ID encoding module to learn student features. The structure diagram of the improved multi-head self-attention mechanism is shown below. Figure 2 and Figure 3 As shown. Figure 2 In the diagram, [T1, T2, T3, T4] represent the model input, [T5, T6] represent the output embedding, and [T6, T7] represent the final predicted output. The input and output shown in the diagram are merely examples; in this embodiment, the input consists of the first 32 time steps, and the final predicted output is the last 32 time steps. Specifically, the Encoder part extracts contextual information through the Attention mechanism, and the Decoder part decodes the information to predict the time series.
[0041] right Figure 2 The motion preference prediction model is broken down into modules, with each module as follows: Figure 3As shown. Figure 3 In this module, InputEmbedding is the input embedding module, Student_idEncoding is the student ID encoding module, Multi-HeadAttention is the multi-head attention module, Add&Norm is the summation and normalization module, FeedForward is the multilayer perceptron module, OutputEmbedding is the output embedding module, Linear is the linear layer module, and softmax is the activation function.
[0042] The input embedding module serves three purposes: (1) Numericalizing and Continuizing the Input Time Series: Mapping discrete time steps (30-minute intervals) to a continuous vector space. This helps the model process the data better, as neural networks are better suited for processing continuous data; (2) Feature Extraction: The model can learn feature representations of the input data, helping it capture important patterns and information in the data; (3) Dimensionality Reduction: Mapping data from a high-dimensional representation to a lower-dimensional representation, reducing computational costs. Its structure is shown in Table 3, which is stacked in the order of the PyTorch function modules in Table 3.
[0043] Table 3 Input Embedded Module Parameters
[0044] permute permute(1,0,2) 32×nop×8 nop×32×8 Input Embed Linear(input size=8, embedding size=64) nop×32×8 nop×32×64
[0045] The student ID encoding module is used to embed student features, denoted by Stu, and the input to the embedding module is denoted by IE. out That is, for any IE out have The structure of the student ID encoding module is shown in Table 4.
[0046] Table 4 Parameters of Student ID Encoding Module
[0047]
[0048] The feature values Stu of the nop students are obtained through the student ID. As an individual feature (assuming the student ID length is id_len), the adjacency matrix is used. Indicating students' interpersonal relationships (e.g., roommates are more likely to run together), using learnable weights. Weighting the adjacency matrix, we get: Stu = Ide·Adj·W Adj .
[0049] The multi-head self-attention module is the core component for extracting long-range correlations in time series data. It utilizes three learnable weights W. q W k and W vThe learned Q, K, and V matrices are shown in Equation (1). Q represents the query matrix, K and V represent the key-value pair matrices, and C represents the feature sequence input to the self-attention mechanism module.
[0050]
[0051] Using the Q, K, and V matrices, the attention value d is calculated using equation (2). k The dimension representing C.
[0052]
[0053] The multi-head self-attention mechanism is based on the attention mechanism and uses different heads for computation, as shown in equation (3). Where W... O For learnable matrices, Attention h This is the input for the multiple split Heads.
[0054] Multi-Head Attention=concat(Attention1,Attention2,...,Attention h W O (3)
[0055] The purpose of the summation and normalization module is to perform residual connections and data normalization. Residual connections can improve the robustness of the model and avoid gradient vanishing and gradient explosion. Normalization is for better convergence during training. Its structure is shown in Table 5.
[0056] Table 5. Parameters of the Summation and Normalization Module
[0057] Add add(IEout, C) nop×32×65 nop×32×65 Norm BatchNorm1d(65) nop×32×65 nop×32×65
[0058] The multilayer perceptron can further extract features from the features extracted by the multi-head attention mechanism module, and its structure is shown in Table 6.
[0059] Table 6 Parameters of the Multilayer Sensor Module
[0060] Linear0 Linear(65,65) nop×32×65 nop×32×65 ReLU ReLU() nop×32×65 nop×32×65 Linear1 Linear(65,65) nop×32×65 nop×32×65
[0061] The output embedding module has the same structure as the input embedding module. The Linear and Softmat structures at the Transformer output are shown in Table 7.
[0062] Table 7 Output Parameters
[0063] Linear Linear(65,8) nop×32×65 nop×32×8 Softmax Softmax() nop×32×8 nop×32×8 permute permute(1,0,2) nop×32×8 32×nop×8
[0064] 3. Training strategy for motion preference prediction model
[0065] Collect 14 days of exercise data from 1000 students. Record the time series of student p's exercise status, class status, temperature, and weather data on day d as follows: p = 1, 2, ..., 1000, d = 1, 2, ... 7. Stacking the time series data across days along the time dimension as the output label for training yields the training data for the p-th student, as shown in Table 8.
[0066] Table 8 Training Data
[0067]
[0068] Data augmentation was performed on 1,000 students using the method shown in Table 8, resulting in 160,000 sets of data, which were then used to train the motion preference prediction model.
[0069] 4. Pedestrian Flow Forecast
[0070] The improved Transformer-based motion preference prediction system, trained using the above method, can predict the next 32 moments (i.e., the next 15 minutes to 8 hours) based on a user's weather, schedule, exercise status, and temperature changes over the past week. It can also dynamically update the prediction results based on changes in time, ensuring accuracy. By using the past 32 moments' data of all students in the school as input to the model, it can predict the motion probability of each student at each moment within the next 32 moments, thus obtaining the predicted pedestrian flow results for the next 32 moments.
[0071] Direct prediction: Let the current time be Ti. Then, based on a student's historical data (weather, class schedule, exercise status, and temperature over the past 8 hours, denoted as Ti-32 to Ti), the next time can be predicted. The data (weather, schedule, exercise status, temperature for the next 15 minutes) is then used to... Time to Time Prediction The data at any given moment can be used to predict the weather, schedule, exercise status, and temperature 32 moments in the future, i.e., 8 hours from now, based on the current moment.
[0072] Masking prediction: In reality, apart from the unknown future activity data of students, weather data, class schedule data, and temperature data for the next 8 hours are all available. Therefore, the predicted data can be used to predict... The weather, timetable, and temperature data included in the time-based data are masked using real data, thus enabling prediction. Time-based data will be more accurate, and similarly... The time data is also masked, and so on, to achieve more accurate prediction of students' movement status.
[0073] Traditional data analysis strategies only analyze students' historical movement patterns, failing to model interpersonal relationships, class schedules during movement, and weather conditions, thus failing to extract sufficient movement prediction features. Furthermore, traditional prediction models utilize methods such as multilayer perceptrons, recurrent neural networks, long short-term memory neural networks, and self-attention mechanisms. Multilayer perceptrons cannot memorize historical data; recurrent neural networks cannot weight historical data; long short-term memory neural networks, while capable of weighting historical data, are too simplistic; and self-attention mechanisms, while effectively extracting historical data, struggle to integrate multimodal data samples. In contrast, the movement preference prediction model based on an improved Transformer proposed in this patent can extract relationships from long-term data and better model multimodal data, thereby achieving more accurate pedestrian flow prediction. Using the method proposed in this patent, direct prediction is possible even without access to weather forecast data (future weather and temperature) and student class schedule data; by acquiring future weather forecast data and student class schedule data, masked prediction can be implemented, achieving the highest accuracy in predicting student movement preferences.
[0074] This invention proposes an improved Transformer motion preference prediction model based on deep learning to predict students' motion tendencies in the future. It models students' historical motion data, motion influencing factors, and students' personal information, enabling better prediction of future motion status based on students' historical motion data and factors influencing motion. This improves the accuracy of traffic flow prediction and facilitates teachers' advance management and planning of sports venues such as playgrounds.
[0075] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for predicting pedestrian flow in a campus sunshine running track based on Transformer, characterized in that, include: The process of constructing the pedestrian traffic dataset involves quantifying students' daily activity status, class status, temperature, and weather to form a time series of a specified length. The motion preference prediction model is constructed and trained using a Transformer module based on a multi-head self-attention mechanism. A student ID encoding module is added to learn student features. The model input is a time series of a specified length, and the model output is a time series of a specified length following the last input time series. After data collection, processing, and data augmentation, the motion preference prediction model is trained. The motion preference prediction model includes an input embedding module, a student ID encoding module, a multi-head self-attention module, a summation and normalization module, a multilayer perceptron module, an output embedding module, a linear layer module, and an activation function. In the student ID encoding module, student feature values are represented by student ID numbers, and interpersonal relationships are represented using an adjacency matrix. Learnable weights are used to weight the adjacency matrix. Prediction process: Input historical data, including at least a specified time period, into the trained motion preference prediction model to obtain the predicted student motion state results for a specified time series.
2. The method according to claim 1, characterized in that: In constructing the aforementioned population flow dataset, a total of 16 hours, from 6:00 AM to 10:00 PM each day, is taken and divided into 30-minute intervals. The course status for each time period of the day, excluding physical education classes, is obtained based on each student's daily schedule. The temperature and weather conditions for each time period of the day are obtained based on meteorological bureau data. The students' exercise data are obtained based on the campus sunshine run monitoring platform. One-hot encoding is used to quantize the time, resulting in a total of 32 time points. For each time point, the exercise status occupies 2 bits, the course status occupies 2 bits, the temperature occupies 1 bit, and the weather occupies 3 bits. The exercise status, course status, temperature, and weather are used as input data, and the time series shape of each student's exercise data is [sequence_length=32, batch_size=1, feature_length=2+2+1+3=8].
3. The method according to claim 1, characterized in that: The input embedding module is used to quantify and continuousize the input time series, extract features, and map data from a high dimension to a lower dimension representation.
4. The method according to claim 1, characterized in that: In the prediction process, the data input to the motion preference prediction model also includes obtaining weather data, temperature data, and timetable data for a specified future time period. Then, the weather data, temperature data, and timetable data in the predicted time data are masked with real data to obtain a more accurate prediction result of the student's motion status.
Citation Information
Patent Citations
Multi-sensor time series analysis model based on attention mechanism
CN111291804A
Traffic prediction method based on time sequence data and functional evolution data
CN112883133A