A method and system for prioritizing monitoring of high-risk events in smart buildings
By introducing the multi-head attention module and contrastive learning loss function into the sound event detection technology, combined with data enhancement methods, the problems of poor robustness and missed judgments in the detection of dangerous sound events in the existing technology are solved, and the detection of high-risk events is realized. Prioritize detection and accurate identification.
Patent Information
- Application Number
- CN202410946871.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-07-16
AI Technical Summary
Existing sound event detection technology lacks risk level evaluation for dangerous sound events. The detection algorithm has poor robustness to environmental noise, and high-risk sound events are easily missed, especially when they overlap with other sound events.
A high-risk event supervision method for smart buildings designed using a multi-head attention module and contrastive learning loss function. The robustness of the model is improved through data enhancement methods, including time domain masking, environmental noise coverage and superposition of different-label samples. Feature extraction and loss functions are optimized to Prioritize detection of high-risk events.
It improves the robustness of the sound event detection model to environmental noise, reduces the risk of missing high-risk events, and enhances the detection capability of high-risk sound events.
Smart Images

Figure CN118503830B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of safety supervision in urban buildings, and in particular to a method and system for priority supervision of high-risk events in smart buildings. Background Art
[0002] This scheme is based on sound event detection technology. The existing sound event detection technology first lacks risk level evaluation for dangerous sound events, and secondly lacks data sets specifically for dangerous sound event detection. The detection algorithm itself lacks robustness due to the influence of the sound recording environment. Secondly, when the high-risk sound time overlaps with other sound events, there is a phenomenon of missing high-risk events.
[0003] Therefore, the present invention proposes a method and system for priority monitoring of high-risk events in smart buildings to solve the above problems. Summary of the invention
[0004] In view of the shortcomings of the prior art, the present invention develops a method and system for prioritizing supervision of high-risk events in smart buildings based on sound event detection. The present invention can improve the robustness of the sound event detection algorithm to environmental noise through a variety of data enhancement means, and can achieve priority detection of high-risk sound events through weighted loss function design.
[0005] On the one hand, the technical solution of the present invention to solve the technical problem is a method for prioritizing supervision of high-risk events in smart buildings, comprising the following steps:
[0006] S1. Build a smart building audio database: Use a unified device to collect audio from different locations in different buildings, process the collected audio data to obtain a dataset, and then divide the dataset into a training set and a training set according to the proportion. Train And the test set Dataset Test ;
[0007] S2. Constructing a sound event detection model: The sound event detection model consists of four parts: data enhancement layer, feature processing module, multi-head attention module and contrastive learning loss module.
[0008] S3. Train and evaluate the sound event detection model: Train The data is input into the sound event detection model to train the model, and then the test set Dataset Test The data is input into the trained sound event test model, and then the mean average precision of the output prediction results is calculated, and the optimal prediction result is determined based on the mean average precision.
[0009] In a specific implementation manner, step S1 is specifically as follows:
[0010] Design sound event soft labels for the collected audio, cut the collected audio according to the sound event soft labels, and then standardize the audio samples, fix the time of each audio sample to 7 seconds and the sampling rate to 22050Hz, and get the dataset Dataset. ,in , , Indicates the collected audio. Indicates the soft tag corresponding to the audio. Indicates the i-th type of audio collected, Represents all audios of the i-th category Corresponding tags for each type of audio Contains 200 audio samples, using represents the cth sample audio of the i-th type of audio, , N represents the number of audio types collected;
[0011] Then, each audio sample is labeled with a sound event hard label. Specifically, the start and end time of the sound event are labeled for each audio sample using the open source technology PANNs.
[0012] Then for each sample audio collected The danger level is divided into different levels according to the personal and property safety involved in the sound event. Classified as non-hazardous event , low-risk events , Medium-risk events , high-risk events ,in, represents the danger level of the i-th type of audio, = 1, , , ;
[0013] Finally, the processed data set is divided into the training set Dataset in a ratio of 8:2 Train And the test set Dataset Test .
[0014] In a specific implementation, the data enhancement layer in the sound event monitoring model is as follows:
[0015] The data in the dataset Dataset is input into the sound event monitoring model. First, it goes through the data enhancement layer, which includes time domain masking, environmental noise coverage, and different label sample superposition operations. After three operations, the positive sample enhanced audio is obtained. The specific steps are as follows:
[0016] S2.1.1. The sample audio in the dataset Dataset Input to the data enhancement layer, and perform data enhancement respectively. First, according to the sample audio x annotated by PANNs ic The starting position of the non-sound event time period is used to mask the other non-sound event time periods in the time domain, and the audio signal amplitude of the non-sound event time period is set to 0, thereby obtaining a preliminary enhanced audio ic ;
[0017] S2.1.2. Preliminary enhanced audio after time domain masking ic Perform environmental noise coverage operations, generate noise audio in different environments through the large model Make-An-Audio, and combine the noise audio with the preliminary enhanced audio ic Superposition to obtain secondary enhanced audio ;
[0018] S2.1.3. (1) Secondary enhancement of some audio in the dataset Perform the overlay operation of samples with different labels. The probability of overlaying samples with different labels is 1 / 5. Randomly select and enhance the audio twice. A sample audio data x of different security levels and types ja With secondary enhanced audio Superposition to obtain the corresponding final enhanced audio , and the sample audio data x jc Corresponding security level and tags Give the final enhanced audio As its second set of tags, the final enhanced audio Includes two sets of labels, one for audio x ic The corresponding label Its security level is , the other is audio x ja Labels given Its security level is , Represents sample audio data x ic The final enhanced data, Represents audio data x ic Secondary enhanced audio, x ja represents a randomly selected audio sample belonging to the jth category. , , , , ;
[0019] (2) For some of the second-enhanced audio in the dataset, no different-label sample superposition operation occurs. Then a sample different from the second-enhanced audio is randomly selected. Type of label Give secondary enhanced audio As the second set of labels, the corresponding safety level is set to non-hazardous level events , and get the corresponding final enhanced audio .
[0020] In a specific implementation, the feature extraction module in the sound event monitoring model is as follows:
[0021] The feature extraction module includes an STFT layer, an initial convolution layer, a first residual block, a second residual block, a third residual block, a fourth residual block, an attention fully connected layer and a ReLU activation function, an average pooling layer and a maximum pooling layer, a first fully connected layer and a ReLU activation function, and a second fully connected layer in sequence. The specific steps are as follows;
[0022] S2.2.1. The enhanced data obtained in step S2.1.3 Input to the feature extraction module, first through the STFT layer to convert it into a spectrum graph G with dimensions of B×Time×Band, Time represents the number of time frames, Band represents the number of frequency bands, B represents the size of the batch size, and the STFT layer is composed of short-time Fourier transform functions;
[0023] S2.2.2. The spectrum graph G is subjected to the initial convolution layer, the first residual block, the second residual block, the third residual block and the fourth residual block for feature extraction to obtain feature representation , , and , the calculation formula is as follows:
[0024] ,
[0025] ,
[0026] ,
[0027] ,
[0028] ,
[0029] ,
[0030] in, represents the convolutional layer, ReLU represents the maximum pooling layer, BN represents the batch normalization function, and Conv2D represents the 2D convolution operation. Indicates that the size of the output image is the same as the size of the input image, MaxPooling2D indicates the pooling operation, ResBlock indicates the residual calculation, DilatedRB indicates the combination of the residual network and the dilated convolution, that is, the convolution layer in ResBlock is changed to the dilated convolution, and dilation indicates the dilation factor of the dilated convolution;
[0031] The specific structure of each network layer is as follows:
[0032] The initial convolutional layer consists of a convolutional layer with a kernel size of 7×7, an output channel of 64, and a stride of 2×2. , batch normalization layer BN, ReLU activation function and maximum pooling layer with pooling window of 3×3 and stride of 2×2 composition;
[0033] The first residual block contains three residual blocks, each of which consists of a first convolutional layer with a convolution kernel of 3×3, an output channel of 128, and a stride of 1, a BN layer and an activation function ReLU layer, a second convolutional layer with a convolution kernel of 3×3, an output channel of 128, and a stride of 1, a skip connection, a BN layer, and an activation function ReLU layer, wherein the input before entering the residual block is added to the output of the second convolutional layer in the residual block through the skip connection and transmitted to the BN layer and the activation function ReLU layer;
[0034] The second residual block contains four residual blocks, of which the first and fourth residual blocks are consistent with the residual blocks contained in the first residual block, and the number of output channels becomes 256. The second and third residual blocks are dilated residual blocks, which are composed of a first dilated convolution layer with a convolution kernel of 3×3, an output channel of 256, a step size of 1, and a dilation factor of dilation, a BN layer and an activation function ReLU layer, a second dilated convolution layer with a convolution kernel of 3×3, an output channel of 256, a step size of 1, and a dilation factor of dilation, a jump connection, a BN layer, and an activation function ReLU layer. Specifically, the dilation of the second dilated residual block is 2, and the dilation of the third dilated residual block is 3;
[0035] The third residual block contains six residual blocks, of which the first, fifth and sixth residual blocks are consistent with the residual blocks contained in the first residual block, and the number of output channels becomes 512. The second, third and fourth residual blocks are dilated residual blocks, and the dilated residual block structure is consistent with the dilated residual block in the second residual block, and the number of channels becomes 512. At the same time, the dilation of the second, third and fourth dilated residual blocks is 2, 3, and 4 respectively;
[0036] The fourth residual block includes three residual blocks, which are consistent with the residual blocks included in the first residual block, and the number of output channels becomes 1024;
[0037] S2.2.3. The feature matrix , and Input to the attention fully connected layer and ReLU activation function, average pooling layer and maximum pooling layer to obtain the fusion feature matrix , the calculation formula is as follows:
[0038] , dim=-1,
[0039] ,
[0040] ,
[0041] ,
[0042] ,
[0043] , dim=-1,
[0044] in, and They represent the weight matrix and bias of the attention weight fully connected layer, ReLU represents the activation function, Softmax represents the Softmax normalization function, Represents element-by-element multiplication, GlobalAveragePooling2D represents the global average pooling operation, and GlobalMaxPooling2D represents the global maximum pooling operation. Indicated by , The multi-scale feature matrix formed by splicing, Indicates splicing and fusion operation, dim=-1 indicates splicing and fusion operation The parameter dim takes -1 to make the concatenation along the last dimension of the input. represents the attention matrix, represents the attention feature matrix, represents the average pooled attention feature matrix, The dimension is B×(256+512+1024)=B×1792, represents the maximum pooling attention feature matrix, The dimension is B×(256+512+1024)=B×1792, represents the fusion feature matrix, The dimension is B×(1792+1792)=B×3584;
[0045] S2.2.4. After the first fully connected layer, ReLU activation function and the second fully connected layer, dimensionality reduction is performed to obtain a feature vector E with a dimension of B×512. The calculation formula is as follows:
[0046] ,
[0047] Among them, ReLU represents the activation function, and Represent the weight matrix and bias of the first fully connected layer, respectively. and Represent the weight matrix and bias of the second fully connected layer respectively;
[0048] The dimensions of the first fully connected layer and the second fully connected layer are expressed as input feature dimension × output feature dimension, where the input feature dimension of the first fully connected layer is 3584 and the output feature dimension is 1024, and the input feature dimension of the second fully connected layer is 1024 and the output feature dimension is 512.
[0049] In a specific implementation, the multi-head attention module in the sound event monitoring model is as follows:
[0050] Input the feature vector E into the multi-head attention module, slice the feature vector E by dimension, set the number of attention heads H to 8, and obtain multiple feature vector segments E h ,in , feature vector fragment E h The size is B×64, and the feature vector segment E h Input to the multi-head attention module, and calculate the attention weight of each feature vector through the attention module Attention, which is calculated as follows:
[0051] ,
[0052] ,
[0053] ,
[0054] ,
[0055] in, represents the query matrix for the hth feature vector segment, represents the key matrix of h eigenvector segments, A matrix of values representing the h eigenvector segments, represents the attention weight of the h-th feature vector segment, represents the activation function, represents the weight matrix of the linear transformation corresponding to the query matrix of the h-th feature vector segment, represents the weight matrix of the linear transformation corresponding to the key matrix of the h-th eigenvector segment, represents the weight matrix of the linear transformation corresponding to the value matrix of the h-th eigenvector fragment, Represents the characteristic dimension of the matrix after linear transformation, set d=64, T represents transpose;
[0056] Each feature vector segment E h The attention weight of the h-th feature vector segment output after being processed by the attention module Assign to the corresponding self-attention module , specifically expressed as:
[0057] ;
[0058] Then all the self-attention modules are concatenated and fused to obtain a feature vector of size B×512 , the specific calculation is as follows:
[0059] ,
[0060] in, represents the h-th self-attention module, , Represents the weight of linear transformation, Concat represents the concatenation and fusion operation;
[0061] Finally, the feature vector After being transformed by a fully connected layer with a dimension of 512×N, a matrix C1 with a dimension of B×N is obtained. Array C1 is converted by a Softmax layer to obtain a classification probability matrix C2 with a dimension of B×N. B represents the size of the batch BatchSize, and N represents the number of audio types collected. Finally, the classification probability array C2 is combined with the Weit-Softmax loss for model tuning. The value of the b-th row and n-th column in the C2 matrix is It represents the probability value of classifying the bth data in the batch into the nth category. , .
[0062] In a specific implementation, the contrastive learning loss module in the sound event monitoring model is as follows:
[0063] Assume that Corresponding to the bth row and nth column in matrix C2, The corresponding parameters are input into the contrastive learning loss module for contrastive learning loss Weit-Softmax calculation. The formula is as follows:
[0064] ,
[0065] in, express The first set of labels The corresponding one-hot label, express The second set of labels The corresponding one-hot label, Indicates the security level corresponding to the first set of labels, Indicates that the value of the bth row and nth column in the C2 matrix is about to The probability of being classified into the nth class, Indicates the security level corresponding to the second set of labels, is the discriminant function, when If it holds, the discriminant function takes 1, otherwise it takes 0. As the discriminant function, The discriminant function is 1 when , otherwise it is 0;
[0066] Finally, according to the contrastive learning loss The result is used to determine whether a different-label sample superposition operation has occurred in the data enhancement stage. When an abnormal label sample superposition operation occurs, it is considered that multiple sound events appear in the same audio segment, and the multiple sound events are detected first.
[0067] In a specific implementation manner, step S3 is specifically as follows:
[0068] The training set Dataset Train The data in the sound event detection model is input into the sound event detection model to train the sound event detection model, and the hyperparameters in the training process are set. The learning rate is set to 0.001, the batch size is set to 128, and the number of Epochs is set to 200. The Adam optimizer is used for gradient optimization. After the training reaches the set number of Epochs, the training of the sound event detection model is stopped. At the same time, an automatic stop training mechanism is set to retain the minimum contrastive learning loss of the sound event detection model. When the contrastive learning loss of the model after training is less than the minimum contrastive learning loss after 10 consecutive Epochs, the training is terminated in advance.
[0069] Then the test set Dataset Test The data is input into the trained sound event test model, the mean average precision of the output prediction results is calculated, and finally the optimal prediction result is determined based on the mean average precision.
[0070] On the other hand, the present invention also provides a system for priority supervision of high-risk events in smart buildings, including a module for executing processing instructions for each step in the method for priority supervision of high-risk events in smart buildings based on sound event detection.
[0071] The effects provided in the content of the invention are only the effects of the embodiments, rather than all the effects of the invention. The above technical solution has the following advantages or beneficial effects:
[0072] The present invention uses sound collection equipment to establish a sound event detection system, establishes a sound event risk level system, adds background noise that may exist in various scenarios to audio data through data enhancement means based on large models, thereby enhancing the robustness of the model to environmental noise; enhances the feature extraction performance of the model through time domain masking enhancement; further extracts environmentally robust sound event features through a multi-head attention mechanism; combines data enhancement strategies, designs Weit-Softmax loss, strengthens the detection model's priority detection of dangerous events when sound events overlap, and reduces the risk of missing important sound events. The problem that the existing sound event detection technology lacks risk level evaluation for dangerous sound events, the detection algorithm itself lacks robustness due to the impact of the sound recording environment, and there is a phenomenon of missed judgment when multiple sound events overlap is solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0074] Figure 1 It is a schematic diagram of the method flow of the present invention.
[0075] Figure 2 Schematic diagram of the sound event detection model framework in the present invention.
[0076] Figure 3 It is a structural schematic diagram of the feature extraction module in the present invention.
[0077] Figure 4 Schematic diagram of the structure of the residual block in the present invention. DETAILED DESCRIPTION
[0078] In order to clearly illustrate the technical features of the present invention, the present invention is described in detail below through specific implementation methods and in conjunction with the accompanying drawings. The following disclosure provides many different embodiments or examples for implementing different structures of the present invention. In order to simplify the disclosure of the present invention, the components and settings of specific examples are described below.
[0079] Example 1
[0080] A method for prioritizing monitoring of high-risk events in smart buildings, comprising the following steps:
[0081] S1. Build a smart building audio database: Use a unified device to collect audio from different locations in different buildings, process the collected audio data to obtain a dataset, and then divide the dataset into a training set and a training set according to the proportion. Train And the test set Dataset Test ;
[0082] S2. Constructing a sound event detection model: The sound event detection model consists of four parts: data enhancement layer, feature processing module, multi-head attention module and contrastive learning loss module.
[0083] S3. Train and evaluate the sound event detection model: Train The data is input into the sound event detection model to train the model, and then the test set Dataset Test The data is input into the trained sound event test model, and then the mean average precision of the output prediction results is calculated, and the optimal prediction result is determined based on the mean average precision.
[0084] In a specific implementation manner, step S1 is specifically as follows:
[0085] Design sound event soft labels for the collected audio, cut the collected audio according to the sound event soft labels, and then standardize the audio samples, fix the time of each audio sample to 7 seconds and the sampling rate to 22050Hz, and get the dataset Dataset. ,in , , Indicates the collected audio. Indicates the soft tag corresponding to the audio. Indicates the i-th type of audio collected, Represents all audios of the i-th category Corresponding tags for each type of audio Contains 200 audio samples, using represents the cth sample audio of the i-th type of audio, , N represents the number of audio types collected;
[0086] Then, each audio sample is labeled with a sound event hard label. Specifically, the start and end time of the sound event are labeled for each audio sample using the open source technology PANNs.
[0087] Then for each sample audio collected The danger level is divided into different levels according to the personal and property safety involved in the sound event. Classified as non-hazardous event , low-risk events , Medium-risk events , high-risk events ,in, represents the danger level of the i-th type of audio, = 1, , , ;
[0088] Finally, the processed data set is divided into the training set Dataset according to the ratio of 8:2 Train And the test set Dataset Test .
[0089] The same equipment is needed to collect audio in different buildings, including shopping malls, residential buildings, office buildings, teaching buildings, playgrounds, hospitals, etc. The collected audio categories include bells, cash register alarms, emergency evacuation alarms, broadcasts, elevator door opening and closing, key insertion, electronic door lock password input, walking, running, laughing, crying, noise, talking, calling for help, scolding, dog barking, people colliding, objects falling, objects knocking, rollers, etc.
[0090] Set the danger level classification according to the scene requirements. For example, in a shopping mall, the sound of cash register alarm, emergency evacuation alarm, beating and scolding, cry for help, etc., which are often related to personal and property safety, are set as high-risk level events. The sound of door opening and closing, electronic door lock password input, object falling, object knocking, etc., which are often potentially dangerous, are set as medium-risk level events. The sound of broadcasting, elevator door opening and closing, walking, laughing, talking, etc., which are almost not dangerous, are set as low-risk level events. No sound is set as a no-risk level event.
[0091] In a specific implementation, the data enhancement layer in the sound event monitoring model is as follows:
[0092] The data in the dataset Dataset is input into the sound event monitoring model. First, it goes through the data enhancement layer, which includes time domain masking, environmental noise coverage, and different label sample superposition operations. After three operations, the positive sample enhanced audio is obtained. The specific steps are as follows:
[0093] S2.1.1. The sample audio in the dataset Dataset Input to the data enhancement layer, and perform data enhancement respectively. First, according to the sample audio x annotated by PANNs icThe starting position of the non-sound event time period is used to mask the other non-sound event time periods in the time domain, and the audio signal amplitude of the non-sound event time period is set to 0, thereby obtaining a preliminary enhanced audio ic ;
[0094] S2.1.2. Preliminary enhanced audio after time domain masking ic Perform environmental noise coverage operations, generate noise audio in different environments through the large model Make-An-Audio, and combine the noise audio with the preliminary enhanced audio ic Superposition to obtain secondary enhanced audio ;
[0095] S2.1.3. (1) Secondary enhancement of some audio in the dataset Perform the overlay operation of samples with different labels. The probability of overlaying samples with different labels is 1 / 5. Randomly select and enhance the audio twice. A sample audio data x of different security levels and types ja With secondary enhanced audio Superposition to obtain the corresponding final enhanced audio , and the sample audio data x jc Corresponding security level and tags Give the final enhanced audio As its second set of tags, the final enhanced audio Includes two sets of labels, one for audio x ic The corresponding label Its security level is , the other is audio x ja Labels given Its security level is , Represents sample audio data x ic The final enhanced data, Represents audio data x ic Secondary enhanced audio, x ja represents a randomly selected audio sample belonging to the jth category. , , , , , a and c both belong to the sample range, a and c are any values in the sample range, and the two may have the same value or different values;
[0096] (2) For some of the second-enhanced audio in the dataset, no different-label sample superposition operation occurs. Then a sample different from the second-enhanced audio is randomly selected. Type of label Give secondary enhanced audio As the second set of labels, the corresponding safety level is set to non-hazardous level events , and get the corresponding final enhanced audio .
[0097] In a specific implementation, the feature extraction module in the sound event monitoring model is as follows:
[0098] The feature extraction module includes an STFT layer, an initial convolution layer, a first residual block, a second residual block, a third residual block, a fourth residual block, an attention fully connected layer and a ReLU activation function, an average pooling layer and a maximum pooling layer, a first fully connected layer and a ReLU activation function, and a second fully connected layer in sequence. The specific steps are as follows;
[0099] S2.2.1. The enhanced data obtained in step S2.1.3 Input to the feature extraction module, first through the STFT layer to convert it into a spectrum graph G with dimensions of B×Time×Band, Time represents the number of time frames, Band represents the number of frequency bands, B represents the size of the batch size, and the STFT layer is composed of short-time Fourier transform functions;
[0100] S2.2.2. The spectrum graph G is subjected to the initial convolution layer, the first residual block, the second residual block, the third residual block and the fourth residual block for feature extraction to obtain feature representation , , and , the calculation formula is as follows:
[0101] ,
[0102] ,
[0103] ,
[0104] ,
[0105] ,
[0106] ,
[0107] in, represents the convolutional layer, ReLU represents the maximum pooling layer, BN represents the batch normalization function, and Conv2D represents the 2D convolution operation. Indicates that the size of the output image is the same as the size of the input image, MaxPooling2D indicates the pooling operation, ResBlock indicates the residual calculation, DilatedRB indicates the combination of the residual network and the dilated convolution, that is, the convolution layer in ResBlock is changed to the dilated convolution, and dilation indicates the dilation factor of the dilated convolution;
[0108] The specific structure of each network layer is as follows:
[0109] The initial convolutional layer consists of a convolutional layer with a kernel size of 7×7, an output channel of 64, and a stride of 2×2. , batch normalization layer BN, ReLU activation function and maximum pooling layer with pooling window of 3×3 and stride of 2×2 composition;
[0110] The first residual block contains three residual blocks, each of which consists of a first convolutional layer with a convolution kernel of 3×3, an output channel of 128, and a stride of 1, a BN layer and an activation function ReLU layer, a second convolutional layer with a convolution kernel of 3×3, an output channel of 128, and a stride of 1, a skip connection, a BN layer, and an activation function ReLU layer, wherein the input before entering the residual block is added to the output of the second convolutional layer in the residual block through the skip connection and transmitted to the BN layer and the activation function ReLU layer;
[0111] The second residual block contains four residual blocks, of which the first and fourth residual blocks are consistent with the residual blocks contained in the first residual block, and the number of output channels becomes 256. The second and third residual blocks are dilated residual blocks, which are composed of a first dilated convolution layer with a convolution kernel of 3×3, an output channel of 256, a step size of 1, and a dilation factor of dilation, a BN layer and an activation function ReLU layer, a second dilated convolution layer with a convolution kernel of 3×3, an output channel of 256, a step size of 1, and a dilation factor of dilation, a jump connection, a BN layer, and an activation function ReLU layer. Specifically, the dilation of the second dilated residual block is 2, and the dilation of the third dilated residual block is 3;
[0112] The third residual block contains six residual blocks, of which the first, fifth and sixth residual blocks are consistent with the residual blocks contained in the first residual block, and the number of output channels becomes 512. The second, third and fourth residual blocks are dilated residual blocks, and the dilated residual block structure is consistent with the dilated residual block in the second residual block, and the number of channels becomes 512. At the same time, the dilation of the second, third and fourth dilated residual blocks is 2, 3, and 4 respectively;
[0113] The fourth residual block includes three residual blocks, which are consistent with the residual blocks included in the first residual block, and the number of output channels becomes 1024;
[0114] S2.2.3. The feature matrix , and Input to the attention fully connected layer and ReLU activation function, average pooling layer and maximum pooling layer to obtain the fusion feature matrix , the calculation formula is as follows:
[0115] , dim=-1,
[0116] ,
[0117] ,
[0118] ,
[0119] ,
[0120] , dim=-1,
[0121] in, and They represent the weight matrix and bias of the attention weight fully connected layer, ReLU represents the activation function, Softmax represents the Softmax normalization function, Represents element-by-element multiplication, GlobalAveragePooling2D represents the global average pooling operation, and GlobalMaxPooling2D represents the global maximum pooling operation. Indicated by , The multi-scale feature matrix formed by splicing, Indicates splicing and fusion operation, dim=-1 indicates splicing and fusion operation The parameter dim takes -1 to make the concatenation along the last dimension of the input. represents the attention matrix, represents the attention feature matrix, represents the average pooled attention feature matrix, The dimension is B×(256+512+1024)=B×1792, represents the maximum pooling attention feature matrix, The dimension is B×(256+512+1024)=B×1792, represents the fusion feature matrix, The dimension is B×(1792+1792)=B×3584;
[0122] S2.2.4. After the first fully connected layer, ReLU activation function and the second fully connected layer, dimensionality reduction is performed to obtain a feature vector E with a dimension of B×512. The calculation formula is as follows:
[0123] ,
[0124] Among them, ReLU represents the activation function, and Represent the weight matrix and bias of the first fully connected layer, respectively. and Represent the weight matrix and bias of the second fully connected layer respectively;
[0125] The dimensions of the first fully connected layer and the second fully connected layer are expressed as input feature dimension × output feature dimension, where the input feature dimension of the first fully connected layer is 3584 and the output feature dimension is 1024, and the input feature dimension of the second fully connected layer is 1024 and the output feature dimension is 512.
[0126] In a specific implementation, the multi-head attention module in the sound event monitoring model is as follows:
[0127] Input the feature vector E into the multi-head attention module, slice the feature vector E by dimension, set the number of attention heads H to 8, and obtain multiple feature vector segments E h ,in , feature vector fragment E h The size is B×64, and the feature vector segment E h Input to the multi-head attention module, and calculate the attention weight of each feature vector through the attention module Attention, which is calculated as follows:
[0128] ,
[0129] ,
[0130] ,
[0131] ,
[0132] in, represents the query matrix for the hth feature vector segment, represents the key matrix of h eigenvector segments, A matrix of values representing the h eigenvector segments, represents the attention weight of the h-th feature vector segment, represents the activation function, represents the weight matrix of the linear transformation corresponding to the query matrix of the h-th feature vector segment, represents the weight matrix of the linear transformation corresponding to the key matrix of the h-th eigenvector segment, represents the weight matrix of the linear transformation corresponding to the value matrix of the h-th eigenvector fragment, Represents the characteristic dimension of the matrix after linear transformation, set d=64, T represents transpose;
[0133] Each feature vector segment E h The attention weight of the h-th feature vector segment output after being processed by the attention module Assign to the corresponding self-attention module , specifically expressed as:
[0134] ;
[0135] Then all the self-attention modules are concatenated and fused to obtain a feature vector of size B×512 , the specific calculation is as follows:
[0136] ,
[0137] in, represents the h-th self-attention module, , Represents the weight of linear transformation, Concat represents the concatenation and fusion operation;
[0138] Finally, the feature vector After being transformed by a fully connected layer with a dimension of 512×N, a matrix C1 with a dimension of B×N is obtained. Array C1 is converted by a Softmax layer to obtain a classification probability matrix C2 with a dimension of B×N. B represents the size of the batch BatchSize, and N represents the number of audio types collected. Finally, the classification probability array C2 is combined with the Weit-Softmax loss for model tuning. The value of the b-th row and n-th column in the C2 matrix is It represents the probability value of classifying the bth data in the batch into the nth category. , .
[0139] In a specific implementation, the contrastive learning loss module in the sound event monitoring model is as follows:
[0140] Assume that Corresponding to the b-th row and n-th column in matrix C2, The corresponding parameters are input into the contrastive learning loss module for contrastive learning loss Weit-Softmax calculation. The formula is as follows:
[0141] ,
[0142] in, express The first set of labels The corresponding one-hot label, express The second set of labels The corresponding one-hot label, Indicates the security level corresponding to the first set of labels, Indicates that the value of the bth row and nth column in the C2 matrix is about to The probability of being classified into the nth class, Indicates the security level corresponding to the second set of labels, is the discriminant function, when If it holds, the discriminant function takes 1, otherwise it takes 0. As the discriminant function, The discriminant function is 1 when , otherwise it is 0;
[0143] Finally, according to the contrastive learning loss The result of the above analysis is used to determine whether a different-label sample superposition operation has occurred in the data enhancement stage. When a different-label sample superposition operation has occurred, it is considered that multiple sound events have appeared in the same audio segment, and the multiple sound events are detected first.
[0144] In a specific implementation manner, step S3 is specifically as follows:
[0145] The training set Dataset Train The data in the sound event detection model is input into the sound event detection model to train the sound event detection model, and the hyperparameters in the training process are set. The learning rate is set to 0.001, the batch size is set to 128, and the number of Epochs is set to 200. The Adam optimizer is used for gradient optimization. After the training reaches the set number of Epochs, the training of the sound event detection model is stopped. At the same time, an automatic stop training mechanism is set to retain the minimum contrastive learning loss of the sound event detection model. When the contrastive learning loss of the model after training is less than the minimum contrastive learning loss after 10 consecutive Epochs, the training is terminated in advance.
[0146] Then the test set Dataset Test The data is input into the trained sound event test model, the mean average precision of the output prediction results is calculated, and finally the optimal prediction result is determined based on the mean average precision.
[0147] Example 2
[0148] A system for prioritizing the supervision of high-risk events in smart buildings, including a module for executing processing instructions for each step in a method for prioritizing the supervision of high-risk events in smart buildings based on sound event detection.
[0149] Example 3
[0150] In order to better demonstrate the technical effect of the present invention, the method of the present invention is compared with the existing method in different scenarios based on the data in the dataset Dataset. It can be seen from Table 1, Table 2, and Table 3 that the average mAP value of the present invention is higher, whether in the case of no noise and no sound event overlap, or with background noise, or when sound events overlap.
[0151] Table 1 Performance test results of sound events without noise and sound event overlap
[0152]
[0153] Table 2 Performance test results of sound events with background noise samples
[0154]
[0155] Table 3 Performance test results of high-risk sound events when sound events overlap
[0156]
[0157] Although the above describes the specific implementation mode of the invention in conjunction with the drawings, it is not intended to limit the scope of protection of the invention. Based on the technical solution of the present invention, various modifications or variations that can be made by those skilled in the art without creative work are still within the scope of protection of the present invention.
Claims
1. A method for prioritizing monitoring of high-risk events in smart buildings, characterized in that: The following steps are involved: S1. Build a smart building audio database: Use a unified device to collect audio from different locations in different buildings, process the collected audio data to obtain a dataset, and then divide the dataset into a training set and a training set according to the proportion. Train And the test set Dataset Test ; The specific steps are as follows: Design sound event soft labels for the collected audio, cut the collected audio according to the sound event soft labels, and then standardize the audio samples, fix the time of each audio sample to 7 seconds and the sampling rate to 22050Hz, and get the dataset Dataset. ,in , , Indicates the collected audio. Indicates the soft tag corresponding to the audio. Indicates the i-th type of audio collected, Represents all audios of the i-th category Corresponding tags for each type of audio Contains 200 audio samples, using represents the cth sample audio of the i-th type of audio, , N represents the number of audio types collected; Then, each audio sample is labeled with a sound event hard label. Specifically, the start and end time of the sound event are labeled for each audio sample using the open source technology PANNs. Then for each sample audio collected The danger level is divided into different levels according to the personal and property safety involved in the sound event. Classified as non-hazardous event , low-risk events , Medium-risk events , high-risk events ,in, represents the danger level of the i-th type of audio, = 1, , , ; Finally, the processed data set is divided into the training set Dataset in a ratio of 8:2 Train And the test set Dataset Test ; S2. Constructing a sound event detection model: The sound event detection model consists of four parts: data enhancement layer, feature processing module, multi-head attention module and contrastive learning loss module. The data enhancement layers in the sound event monitoring model are as follows: The data in the dataset Dataset is input into the sound event monitoring model. First, it goes through the data enhancement layer, which includes time domain masking, environmental noise coverage, and different label sample superposition operations. After three operations, the positive sample enhanced audio is obtained. The specific steps are as follows: S2.1.
1. The sample audio in the dataset Dataset Input to the data enhancement layer, and perform data enhancement respectively. First, according to the sample audio x annotated by PANNs ic The starting position of the non-sound event time period is used to mask the other non-sound event time periods in the time domain, and the audio signal amplitude of the non-sound event time period is set to 0, thereby obtaining a preliminary enhanced audio ic ; S2.1.
2. Preliminary enhanced audio after time domain masking ic Perform environmental noise coverage operations, generate noise audio in different environments through the large model Make-An-Audio, and combine the noise audio with the preliminary enhanced audio ic Superposition to obtain secondary enhanced audio ; S2.1.
3. (1) Secondary enhancement of some audio in the dataset Perform the overlay operation of samples with different labels. The probability of overlaying samples with different labels is 1 / 5. Randomly select and enhance the audio twice. A sample audio data x of different security levels and types ja With secondary enhanced audio Superposition to obtain the corresponding final enhanced audio , and the sample audio data x jc Corresponding security level and tags Give the final enhanced audio As its second set of tags, the final enhanced audio Includes two sets of labels, one for audio x ic The corresponding label Its security level is , the other is audio x ja Labels given Its security level is , Represents sample audio data x ic The final enhanced data, Represents audio data x ic Secondary enhanced audio, x ja represents a randomly selected audio sample belonging to the jth category. , , , , ; (2) For some of the second-enhanced audio in the dataset, no different-label sample superposition operation occurs. Then a sample different from the second-enhanced audio is randomly selected. Type of label Give secondary enhanced audio As the second set of labels, the corresponding safety level is set to non-hazardous level events , and get the corresponding final enhanced audio ; The feature extraction module in the sound event monitoring model is as follows: The feature extraction module includes an STFT layer, an initial convolution layer, a first residual block, a second residual block, a third residual block, a fourth residual block, an attention fully connected layer and a ReLU activation function, an average pooling layer and a maximum pooling layer, a first fully connected layer and a ReLU activation function, and a second fully connected layer in sequence; The multi-head attention module in the sound event monitoring model is as follows: Input the feature vector E into the multi-head attention module, slice the feature vector E by dimension, set the number of attention heads H to 8, and obtain multiple feature vector segments E h ,in , feature vector fragment E h The size is B×64, and the feature vector segment E h Input to the multi-head attention module, and calculate the attention weight of each feature vector through the attention module Attention. The calculation formula is as follows: , , , , in, represents the query matrix for the hth feature vector segment, represents the key matrix of h eigenvector segments, A matrix of values representing the h eigenvector segments, represents the attention weight of the h-th feature vector segment, represents the activation function, represents the weight matrix of the linear transformation corresponding to the query matrix of the h-th feature vector segment, represents the weight matrix of the linear transformation corresponding to the key matrix of the h-th eigenvector segment, represents the weight matrix of the linear transformation corresponding to the value matrix of the h-th eigenvector fragment, Represents the characteristic dimension of the matrix after linear transformation, set d=64, T represents transpose; Each feature vector segment E h The attention weight of the h-th feature vector segment output after being processed by the attention module Assign to the corresponding self-attention module , specifically expressed as: ; Then all the self-attention modules are concatenated and fused to obtain a feature vector of size B×512 , the specific calculation is as follows: , in, represents the h-th self-attention module, , Represents the weight of linear transformation, Concat represents the concatenation and fusion operation; Finally, the feature vector After being transformed by a fully connected layer with a dimension of 512×N, a matrix C1 with a dimension of B×N is obtained. Array C1 is converted by a Softmax layer to obtain a classification probability matrix C2 with a dimension of B×N. B represents the size of the batch BatchSize, and N represents the number of audio types collected. Finally, the classification probability array C2 is combined with the Weit-Softmax loss for model tuning. The value of the b-th row and n-th column in the C2 matrix is It represents the probability value of classifying the bth data in the batch into the nth category. , ; The contrastive learning loss module in the sound event monitoring model is as follows: Assume that Corresponding to the bth row and nth column in matrix C2, The corresponding parameters are input into the contrastive learning loss module for contrastive learning loss Weit-Softmax calculation. The formula is as follows: , in, express The first set of labels The corresponding one-hot label, express The second set of labels The corresponding one-hot label, Indicates the security level corresponding to the first set of labels, Indicates that the value of the bth row and nth column in the C2 matrix is about to The probability of being classified into the nth class, Indicates the security level corresponding to the second set of labels, is the discriminant function, when If it holds, the discriminant function takes 1, otherwise it takes 0. As the discriminant function, The discriminant function is 1 when , otherwise it is 0; Finally, according to the contrastive learning loss The result of is used to judge whether the superposition operation of different-label samples occurs in the data enhancement stage. When the superposition operation of different-label samples occurs, it is considered that multiple sound events appear in the same audio segment, and the multiple sound events are detected first; S3. Train and evaluate the sound event detection model: Train The data is input into the sound event detection model to train the model, and then the test set Dataset Test The data is input into the trained sound event test model, and then the mean average precision of the output prediction results is calculated, and the optimal prediction result is determined based on the mean average precision.
2. A method for prioritizing monitoring high-risk events in smart buildings according to claim 1, characterized in that: The feature extraction module in the sound event monitoring model is as follows: S2.2.
1. The enhanced data obtained in step S2.1.3 The data is input into the feature extraction module in batches and first converted into a spectrum graph G with dimensions of B×Time×Band through the STFT layer, where Time represents the number of time frames, Band represents the number of frequency bands, and B represents the size of the batch. The STFT layer consists of a short-time Fourier transform function. S2.2.
2. The spectrum graph G is subjected to the initial convolution layer, the first residual block, the second residual block, the third residual block and the fourth residual block for feature extraction to obtain feature representation , , and , the calculation formula is as follows: , , , , , , in, represents the convolutional layer, ReLU represents the maximum pooling layer, BN represents the batch normalization function, and Conv2D represents the 2D convolution operation. Indicates that the size of the output image is the same as the size of the input image, MaxPooling2D indicates the pooling operation, ResBlock indicates the residual calculation, DilatedRB indicates the combination of the residual network and the dilated convolution, that is, the convolution layer in ResBlock is changed to the dilated convolution, and dilation indicates the dilation factor of the dilated convolution; The specific structure of each network layer is as follows: The initial convolutional layer consists of a convolutional layer with a kernel size of 7×7, an output channel of 64, and a stride of 2×2. , batch normalization layer BN, ReLU activation function and maximum pooling layer with pooling window of 3×3 and stride of 2×2 composition; The first residual block contains three residual blocks, each of which consists of a first convolutional layer with a convolution kernel of 3×3, an output channel of 128, and a stride of 1, a BN layer and an activation function ReLU layer, a second convolutional layer with a convolution kernel of 3×3, an output channel of 128, and a stride of 1, a skip connection, a BN layer, and an activation function ReLU layer, wherein the input before entering the residual block is added to the output of the second convolutional layer in the residual block through the skip connection and transmitted to the BN layer and the activation function ReLU layer; The second residual block contains four residual blocks, of which the first and fourth residual blocks are consistent with the residual blocks contained in the first residual block, and the number of output channels becomes 256. The second and third residual blocks are dilated residual blocks, which are composed of a first dilated convolution layer with a convolution kernel of 3×3, an output channel of 256, a step size of 1, and a dilation factor of dilation, a BN layer and an activation function ReLU layer, a second dilated convolution layer with a convolution kernel of 3×3, an output channel of 256, a step size of 1, and a dilation factor of dilation, a jump connection, a BN layer, and an activation function ReLU layer. Specifically, the dilation of the second dilated residual block is 2, and the dilation of the third dilated residual block is 3; The third residual block contains six residual blocks, of which the first, fifth and sixth residual blocks are consistent with the residual blocks contained in the first residual block, and the number of output channels becomes 512. The second, third and fourth residual blocks are dilated residual blocks, and the dilated residual block structure is consistent with the dilated residual block in the second residual block, and the number of channels becomes 512. At the same time, the dilation of the second, third and fourth dilated residual blocks is 2, 3, and 4 respectively; The fourth residual block includes three residual blocks, which are consistent with the residual blocks included in the first residual block, and the number of output channels becomes 1024; S2.2.
3. The feature matrix , and Input to the attention fully connected layer and ReLU activation function, average pooling layer and maximum pooling layer to obtain the fusion feature matrix , the calculation formula is as follows: ,dim=-1, , , , , ,dim=-1, in, and They represent the weight matrix and bias of the attention weight fully connected layer, ReLU represents the activation function, Softmax represents the Softmax normalization function, Represents element-by-element multiplication, GlobalAveragePooling2D represents the global average pooling operation, and GlobalMaxPooling2D represents the global maximum pooling operation. Indicated by , The multi-scale feature matrix formed by splicing, Indicates splicing and fusion operation, dim=-1 indicates splicing and fusion operation The parameter dim takes -1 to make the concatenation along the last dimension of the input. represents the attention matrix, represents the attention feature matrix, represents the average pooled attention feature matrix, The dimension is B×(256+512+1024)=B×1792, represents the maximum pooling attention feature matrix, The dimension is B×(256+512+1024)=B×1792, represents the fusion feature matrix, The dimension is B×(1792+1792)=B×3584; S2.2.
4. After the first fully connected layer, ReLU activation function and the second fully connected layer, dimensionality reduction is performed to obtain a feature vector E with a dimension of B×512. The calculation formula is as follows: , Among them, ReLU represents the activation function, and Represent the weight matrix and bias of the first fully connected layer, respectively. and Represent the weight matrix and bias of the second fully connected layer respectively; The dimensions of the first fully connected layer and the second fully connected layer are expressed as input feature dimension × output feature dimension, where the input feature dimension of the first fully connected layer is 3584 and the output feature dimension is 1024, and the input feature dimension of the second fully connected layer is 1024 and the output feature dimension is 512.
3. A method for priority monitoring of high-risk events in smart buildings according to claim 2, characterized in that: Step S3 is as follows: The training set Dataset Train The data in the sound event detection model is input into the sound event detection model to train the sound event detection model, and the hyperparameters in the training process are set. The learning rate is set to 0.001, the batch size is set to 128, and the number of Epochs is set to 200. The Adam optimizer is used for gradient optimization. After the training reaches the set number of Epochs, the training of the sound event detection model is stopped. At the same time, an automatic stop training mechanism is set to retain the minimum contrastive learning loss of the sound event detection model. When the contrastive learning loss of the model after training is less than the minimum contrastive learning loss after 10 consecutive Epochs, the training is terminated in advance. Then the test set Dataset Test The data is input into the trained sound event test model, the mean average precision of the output prediction results is calculated, and finally the optimal prediction result is determined based on the mean average precision.
4. A system for high-risk event priority monitoring in smart buildings, characterized by: It includes a module for executing instructions for processing each step in a method for priority supervision of high-risk events in smart buildings as described in any one of claims 1-3.
