Campus illegal behavior detection method and system based on computer vision
By improving the YOLOv7 network, using CSPPF and AWBPFN, combined with the Size-IoU loss function, the problem of low small target detection accuracy in campus violation detection in complex environments has been solved, and the detection accuracy and model's perception of small targets have been significantly improved.
Patent Information
- Application Number
- CN202410624349.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-20
- Publication Date
- 2024-09-03
AI Technical Summary
The existing technology has low accuracy in detecting campus violations in complex environments, especially small target detection (such as smoking and mobile phone use), which is difficult to meet management needs and is affected by factors such as noise, background interference, occlusion, and lighting changes. big.
A campus violation detection method based on computer vision is proposed. By improving the YOLOv7 network, channel space pyramid network (CSPPF) and adaptive weighted bidirectional feature pyramid network (AWBFPN) are used to enhance multi-scale feature fusion capabilities, and a new loss function Size- IoU improves the model's perception of small targets.
It significantly improves the accuracy of smoking and mobile phone use behavior detection, reduces missed detections and false detections, and improves detection accuracy. Experimental results show that Precision, Recall and mAP@0.5 and other indicators have been significantly improved.
Smart Images

Figure CN118587642A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer vision target detection, and in particular to a computer vision-based campus violation detection method and system. Background Art
[0002] Small target detection in complex environments is an important problem in the field of computer vision. It involves accurately detecting and locating small-sized target objects in the presence of complex backgrounds, low contrast, or occlusion. In traditional target detection methods, deep learning-based methods are usually used, that is, manually designing and extracting features to represent targets. However, small target detection in complex environments still has some challenges. First, due to the small size of small targets, the target object has less information and is easily affected by noise and interference, resulting in unstable detection results. Secondly, in complex backgrounds, target objects often have similar textures and colors to the surrounding environment, making them difficult to distinguish accurately. In addition, factors such as occlusion, lighting changes, and perspective changes can also make it difficult to detect small targets.
[0003] The inventors have found that in the prior art, the detection accuracy of campus smoking detection and campus mobile phone usage behavior detection is low, which is difficult to meet the work needs of managers. Summary of the invention
[0004] In order to solve the shortcomings of the existing technology, the present invention provides a method and system for detecting campus violations based on computer vision; the model trained by the present invention has stronger perception ability and can better handle targets of different scales and positions. Inspired by the idea of cross-scale feature fusion, the model significantly improves the ability to fuse multi-scale features.
[0005] On the one hand, a computer vision-based campus violation detection method is provided;
[0006] The campus violation detection method based on computer vision includes:
[0007] Obtain the campus surveillance image to be detected;
[0008] Input the campus surveillance image to be detected into the trained campus violation detection model CB-YOLO to obtain the campus violation detection result; the campus violation detection result includes: smoking behavior on campus or using mobile phone behavior on campus;
[0009] Among them, the trained campus violation detection model is used to extract image features of the campus surveillance images to be detected, classify and predict the features, and obtain classification prediction results;
[0010] Among them, the trained campus violation detection model is obtained by improving the original YOLOv7 network. The SPPCSPC module of the original YOLOv7 network is replaced by the channel space pyramid network CSPPF; the CAT module of the original YOLOv7 network is replaced by the adaptive weighted bidirectional feature pyramid network AWBFPN; the loss function of the original YOLOv7 network is set to the loss function Size-Iou.
[0011] On the other hand, a campus violation detection system based on computer vision is provided;
[0012] Campus violation detection system based on computer vision, including:
[0013] An acquisition module is configured to: acquire a campus surveillance image to be detected;
[0014] The detection module is configured to: input the campus surveillance image to be detected into the trained campus violation detection model CB-YOLO to obtain the campus violation detection result; the campus violation detection result includes: smoking behavior on campus or using mobile phone behavior on campus;
[0015] Among them, the trained campus violation detection model is used to extract image features of the campus surveillance images to be detected, classify and predict the features, and obtain classification prediction results;
[0016] Among them, the trained campus violation detection model is obtained by improving the original YOLOv7 network. The SPPCSPC module of the original YOLOv7 network is replaced by the channel space pyramid network CSPPF; the CAT module of the original YOLOv7 network is replaced by the adaptive weighted bidirectional feature pyramid network AWBFPN; the loss function of the original YOLOv7 network is set to the loss function Size-Iou.
[0017] On the other hand, there is also provided an electronic device, comprising:
[0018] a memory for non-transitory storage of computer-readable instructions; and
[0019] a processor for executing the computer readable instructions,
[0020] When the computer-readable instructions are executed by the processor, the method described in the first aspect is executed.
[0021] On the other hand, a storage medium is provided, which non-temporarily stores computer-readable instructions, wherein when the non-temporary computer-readable instructions are executed by a computer, the instructions of the method described in the first aspect are executed.
[0022] On the other hand, a computer program product is provided, comprising a computer program, wherein the computer program is used to implement the method described in the first aspect when running on one or more processors.
[0023] The above technical solution has the following advantages or beneficial effects:
[0024] 1. This paper proposes a detection model for detecting smoking and mobile phone use named CB-YOLO, which uses YOLOv7 as the baseline model to make up for the shortcomings of traditional small target detection algorithms in complex environments.
[0025] 2. This paper proposes a new channel space pyramid network (CSPPF) to enhance the effective processing capability of YOLOv7 for multi-scale features to adapt to the different angle changes of mobile phones and smoking in actual detection scenarios.
[0026] 3. In order to improve the fusion capability of multi-scale features, this paper proposes a simple and efficient adaptive weighted bidirectional feature pyramid network (AWBFPN) and embeds it into the head of YOLOv7. This improvement effectively improves the model's perception of small targets and reduces missed detection and false detection.
[0027] 4. The present invention proposes a new loss function Size-IoU, which effectively improves the detection accuracy by adding the scale factor and size difference of the predicted box and the real box area as two new penalty items. The present invention uses two datasets, Smoking and Phone_check, to evaluate the model of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0029] Figure 1 The YOLOv7 network structure of the first embodiment;
[0030] Figure 2 The CB-YOLO network structure proposed by the present invention in Example 1;
[0031] Figure 3 It is the channel space pyramid network CSPPF module of embodiment 1;
[0032] Figure 4 The adaptive weighted bidirectional feature pyramid network of embodiment 1;
[0033] Figure 5 is the loss function Size-Iou of the first embodiment;
[0034] Figure 6 This is a schematic diagram of the internal structure of the first CBS module of Example 1;
[0035] Figure 7 This is a schematic diagram of the internal structure of the first MP module in Example 1;
[0036] Figure 8 This is a schematic diagram of the internal structure of the first ELAN module in accordance with the first embodiment;
[0037] Fig. 9 This is a schematic diagram of the internal structure of the first RepConv module in Example 1;
[0038] Fig.10 FIG. 4 is a schematic diagram of the internal structure of the first ELAN-H module of Embodiment 1. DETAILED DESCRIPTION
[0039] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used in the present invention have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0040] Embodiment 1
[0041] This embodiment provides a method for detecting campus violations based on computer vision;
[0042] The campus violation detection method based on computer vision includes:
[0043] S101: Acquire a campus surveillance image to be detected;
[0044] S102: inputting the campus surveillance image to be detected into the trained campus violation detection model CB-YOLO to obtain the campus violation detection result; the campus violation detection result includes: smoking behavior on campus or using mobile phone behavior on campus;
[0045] Among them, the trained campus violation detection model is used to extract image features of the campus surveillance images to be detected, classify and predict the features, and obtain classification prediction results;
[0046] Among them, the trained campus violation detection model is obtained by improving the original YOLOv7 network. The SPPCSPC module of the original YOLOv7 network is replaced by the channel space pyramid network CSPPF; the CAT module of the original YOLOv7 network is replaced by the adaptive weighted bidirectional feature pyramid network AWBFPN; the loss function of the original YOLOv7 network is set to the loss function Size-Iou.
[0047] Furthermore, the training process of the trained campus violation detection model includes:
[0048] Constructing a training set and a test set, wherein the training set and the test set both include: campus surveillance images with known detection results of smoking behavior on campus or mobile phone use behavior on campus;
[0049] Input the training set into the campus violation detection model to train the model. When the loss function value of the model no longer decreases or the number of iterations reaches a set number, stop the training to obtain the campus violation detection model after preliminary training.
[0050] The test set is input into the campus violation detection model after preliminary training to test the model. When the test index values of the model reach the set threshold, it means that the current campus violation detection model after preliminary training has passed the test. The model that has passed the test is used as the final campus violation detection model after training.
[0051] Exemplarily, a data set is constructed, including a smoking data set and a mobile phone playing data set. The smoking data set includes 3791 images for training and 1069 images for testing. The mobile phone playing data set includes 4000 images for training and 1000 images for testing. By screening and supplementing the data set, the present invention aims to improve the generalization ability of the algorithm in various practical scenarios and ensure the accuracy and reliability of the evaluation results. Doing so helps to more comprehensively evaluate the performance of the algorithm and lays the foundation for further research and application.
[0052] Furthermore, the loss function of the model takes into account the overlapping area, center distance, and aspect ratio of the detection box, and adds the comparison of the area of the predicted box and the real box and the difference in size as two new penalty terms, such as Figure 5 shown.
[0053] The loss function formula is as follows:
[0054]
[0055]
[0056]
[0057] Among them, a is the weight function, v is used to measure the consistency of aspect ratio; σ(z,z gt ) is the center of the real box z and the center of the predicted box z gt The Euclidean distance, b 2 is the square of the diagonal distance between the real box and the predicted box, w and h are the height and width of the real box, w gt and hgt is the height and width of the prediction box; α and β are weight parameters used to balance the impact of area scale factor and size difference factor on Size-IoU value.
[0058] s is the size ratio of the real box and the predicted box, calculated by:
[0059]
[0060] Among them, s1 and s2 are the areas of the predicted box and the true box respectively.
[0061] The newly added penalty term βr represents the size difference factor, where r represents the size difference between the predicted box and the true box. The calculation formula is:
[0062]
[0063] Where c is the diagonal length of the true box, and c′ is the diagonal length of the predicted box. The penalty term βr is introduced to take into account the size difference between the predicted box and the true box. When the size difference between the predicted box and the true box is small, the value of r will be close to 1, and the Size-IoU value will be adjusted accordingly. When the size difference is large, the value of r will be close to 0, which has little effect on the Size-IoU value.
[0064] Furthermore, the test indicators of the model include: precision, recall, average precision, average precision of each category and mAP@0.5.
[0065] For example, the present invention selects the most commonly used evaluation indicators in small target detection, including Precision and Recall. These indicators can help the present invention evaluate the performance of the model in the small target detection task.
[0066] Precision (P) refers to the proportion of targets predicted by the model as positive samples that are actually positive samples. It measures the accuracy of the model among all samples predicted as positive.
[0067] Recall (R) refers to the proportion of targets that are actually positive samples that the model successfully predicts as positive samples. It measures the model's ability to detect all positive samples. In addition to Precision and Recall, the present invention also considers other indicators to evaluate the performance of the model.
[0068] mAP@0.5 represents the mAP value when the IoU threshold is 0.5, which measures the average accuracy of the model under looser IoU conditions.
[0069] mAP@0.5:0.95 represents the mAP value in the range of IoU threshold from 0.5 to 0.95, which more comprehensively measures the detection ability of the model at different IoU thresholds.
[0070] In addition, the present invention also considers Params as an indicator, which measures the computational complexity of the model.
[0071] Accuracy:
[0072]
[0073] Recall:
[0074]
[0075] Average accuracy:
[0076] AP=∑ n (R n -P n-1 )·P n ;
[0077] Average precision for each category;
[0078] mAP@0.5:
[0079]
[0080] Average AP of each category when the IoU threshold is 0.5;
[0081] Among them, TP: the number of samples correctly detected as positive; TN: the number of samples correctly detected as negative; FP: the number of negative samples incorrectly marked as positive; FN: the number of positive samples incorrectly marked as negative; n: different recall levels; R n and P n : Recall and Precision at the nth Recall level; N: number of categories; AP i : AP of the ith category.
[0082] It should be understood that the YOLOv7 network consists of three parts: Input, Backbone and Head. Unlike yolov5, the neck layer and the head layer are collectively referred to as the head layer. In fact, their functions are the same. Input preprocesses the input data, Backbone is used to extract features, and Head is used for prediction.
[0083] YOLOv7 is an object detection algorithm that is improved and optimized based on the YOLO (You Only Look Once) series of algorithms. The core idea of the YOLO series of algorithms is to transform the object detection task into a single regression problem, and the object can be located and classified simultaneously through a single forward propagation. YOLOv7 was developed by Alexey Bochkovskiy, and some changes have been made in the network structure and training strategy to improve detection accuracy and speed. The following are some features of YOLOv7:
[0084] 1. Model reparameterization. YOLOV7 introduces model reparameterization into the network architecture. The idea of reparameterization first appeared in REPVGG.
[0085] 2. Label allocation strategy. The label allocation strategy of YOLOV7 adopts the cross-grid search of YOLOV5 and the matching strategy of YOLOX.
[0086] 3. ELAN efficient network architecture: A new network architecture proposed in YOLOV7, focusing on efficiency.
[0087] 4. Training with auxiliary head. YOLOV7 proposed a training method for auxiliary head. The main purpose is to improve the accuracy by increasing the training cost without affecting the reasoning time, because the auxiliary head only appears during the training process.
[0088] Network process: First, preprocess the input image, align it into a 640*640 RGB image, and input it into the backbone network. According to the three-layer output in the backbone network, the head layer continues to output three layers of feature maps of different sizes through the backbone network. After RepVGG block and conv, the three types of image detection tasks (classification, foreground and background classification, and border) are predicted, and the final result is output.
[0089] People may adopt various postures when using mobile phones and smoking, resulting in uncertainty in the angle and position of the mobile phone. This diversity increases the adaptability requirements of the detection algorithm to various postures and angles. At the same time, cigarettes and mobile phones are small targets, usually involving very small pixel areas, which may cause the details of the smoking area to be lost or blurred, thereby increasing the difficulty of detection. In order to solve the above problems, the present invention improves YOLOv7 and proposes a new model CB-YOLO. The CB-YOLO model structure diagram is shown in the figure. Figure 2 shown.
[0090] The YOLOv7 network consists of three parts: input, backbone and head. Unlike yolov5, the neck layer and the head layer are collectively referred to as the head layer. In fact, their functions are the same. The functions of each part are the same as those of yolov5, such as backbone is used to extract features, head is used for prediction, Figure 1 shown.
[0091] In the field of target detection, effectively representing and processing multi-scale features is a major challenge. The backbone network used by YOLOv7 is usually based on deep convolutional neural networks, which perform well in extracting features of larger targets, but have relatively weak feature representation capabilities for small targets. The detail information of small targets is easily lost in the network, resulting in a decrease in detection performance. In order to handle targets of different scales, YOLOv7 introduces the SPPCSPC module. This structure has certain advantages in processing multi-scale targets. However, the SPPCSPC module increases the number of parameters and computational complexity of the model. For small targets, it increases the computational burden of the model, which may lead to certain delays in real-time target detection tasks. Therefore, in this scenario, the performance of YOLOv7 may not be ideal. The improved model structure diagram CB-YOLO is shown in the figure below. Figure 2 shown.
[0092] Furthermore, the trained campus violation detection model includes:
[0093] The first CBS module, the second CBS module, the third CBS module, the fourth CBS module, the first ELAN module, the first MP module, the second ELAN module, the second MP module, the third ELAN module, the third MP module, the fourth ELAN module, the channel space pyramid network CSPPF, the first adaptive weighted bidirectional feature pyramid network AWBFPN, the first ELAN-H module, the first RepConv module and the first detection head module are connected in sequence;
[0094] The output end of the channel space pyramid network CSPPF is also connected to the input end of the first upsampling layer, the output end of the first upsampling layer is connected to the input end of the second adaptive weighted bidirectional feature pyramid network AWBFPN, the output end of the second adaptive weighted bidirectional feature pyramid network AWBFPN is connected to the input end of the second ELAN-H module, the output end of the second ELAN-H module is connected to the input end of the second upsampling layer, the output end of the second upsampling layer is connected to the input end of the third ELAN-H module, the output end of the third ELAN-H module is connected to the input end of the fourth MP module, the output end of the fourth MP module is connected to the input end of the fourth adaptive weighted bidirectional feature pyramid network AWBFPN, the output end of the fourth adaptive weighted bidirectional feature pyramid network AWBFPN is connected to the input end of the fifth MP module, and the output end of the fifth MP module is connected to the input end of the first adaptive weighted bidirectional feature pyramid network AWBFPN;
[0095] Wherein, the output end of the fourth ELAN-H module is connected to the input end of the second RepConv module, and the output end of the second RepConv module is connected to the input end of the second detection head module;
[0096] The output end of the third ELAN-H module is connected to the input end of the third RepConv module, and the output end of the third RepConv module is connected to the input end of the third detection head module;
[0097] Wherein, the output end of the second ELAN-H module is connected to the input end of the fourth adaptive weighted bidirectional feature pyramid network AWBFPN;
[0098] The output end of the first ELAN module is connected to the input end of the fifth CBS module, and the output end of the fifth CBS module is connected to the input end of the third adaptive weighted bidirectional feature pyramid network AWBFPN;
[0099] Among them, the output end of the third ELAN module is connected to the input end of the sixth CBS module, and the output end of the sixth CBS module is connected to the input end of the second adaptive weighted bidirectional feature pyramid network AWBFPN.
[0100] Furthermore, if Figure 6 As shown, the internal structures of the first CBS module, the second CBS module, the third CBS module, the fourth CBS module, the fifth CBS module and the sixth CBS module are consistent. The first CBS module includes: a convolutional layer C0, a batch normalization layer and an activation function layer connected in sequence.
[0101] It should be understood that the first CBS module is used to extract features from input data and enhance the expressiveness of the features through batch normalization and activation functions.
[0102] Furthermore, if Figure 7 As shown, the internal structures of the first MP module, the second MP module, the third MP module, the fourth MP module and the fifth MP module are consistent, and the first MP module includes:
[0103] Two parallel branches: the first branch and the second branch;
[0104] The first branch includes: a first maximum pooling layer and a seventh CBS module connected in sequence;
[0105] The second branch includes: an eighth CBS module and a ninth CBS module connected in sequence;
[0106] The input end of the first maximum pooling layer and the input end of the eighth CBS module are both connected to the input end of the first MP module;
[0107] The output end of the seventh CBS module and the output end of the ninth CBS module are both connected to the input end of the first series splicing layer, and the output end of the first series splicing layer serves as the output end of the first MP module.
[0108] Furthermore, if Figure 8 As shown, the internal structures of the first ELAN module, the second ELAN module, the third ELAN module and the fourth ELAN module are consistent, and the first ELAN module includes:
[0109] an input terminal of a first ELAN module;
[0110] The input end of the first ELAN module is connected to the input end of the tenth CBS module and the input end of the twelfth CBS module respectively;
[0111] The output end of the tenth CBS module is connected to the input end of the second series splicing layer, and the output end of the second series splicing layer is connected to the input end of the eleventh CBS module; the output end of the eleventh CBS module serves as the output end of the first ELAN module;
[0112] The output end of the twelfth CBS module is connected to the input end of the thirteenth CBS module, the output end of the thirteenth CBS module is connected to the input end of the fourteenth CBS module, the output end of the fourteenth CBS module is respectively connected to the input end of the second series splicing layer and the input end of the fifteenth CBS module, the output end of the fifteenth CBS module is connected to the input end of the sixteenth CBS module, and the output end of the sixteenth CBS module is connected to the input end of the second series splicing layer.
[0113] Furthermore, if Fig. 9As shown, the internal structures of the first RepConv module, the second RepConv module and the third RepConv module are consistent. The first RepConv module includes:
[0114] Three parallel branches: the third branch, the fourth branch and the fifth branch;
[0115] The third branch includes: a convolutional layer C1 and a batch normalization layer P1 connected in sequence;
[0116] The fourth branch includes: a convolutional layer C2 and a batch normalization layer P2 connected in sequence;
[0117] The fifth branch includes: a batch normalization layer P3;
[0118] The input end of the convolution layer C1, the input end of the convolution layer C2, and the input end of the batch normalization layer P3 are all connected to the input end of the first RepConv module;
[0119] Among them, the output end of the batch normalization layer P1, the output end of the batch normalization layer P2 and the output end of the batch normalization layer P3 are all connected to the input end of the adder J1, and the output end of the adder J2 serves as the output end of the first REP module.
[0120] It should be understood that the first RepConv module is used to achieve enhanced receptive field and acquisition of semantic information, thereby improving target detection performance.
[0121] Furthermore, if Figure 3 As shown, the channel space pyramid network CSPPF includes:
[0122] The convolution layer C3, batch normalization layer, activation function layer, first maximum pooling layer, second maximum pooling layer, series connection unit and convolution layer C4 are connected in sequence; the output end of the first maximum pooling layer is connected to the input end of the series connection unit;
[0123] The output end of the convolutional layer C3 is connected to the input end of the serial splicing unit;
[0124] The output end of the convolution layer C3 is connected to the input end of the first softmax activation function layer, the input end of the first multiplier, and the input end of the second softmax activation function layer;
[0125] The output end of the first softmax activation function layer and the output end of the second softmax activation function layer are connected to the input end of the first multiplier;
[0126] The output ends of the first multiplier are respectively connected to the input ends of the third maximum pooling layer;
[0127] The output terminal of the first multiplier is also connected to the input terminal of the series splicing unit;
[0128] The input of the convolutional layer C3 is the input of the channel space pyramid network CSPPF;
[0129] The output of the convolutional layer C4 is the output of the channel space pyramid network CSPPF.
[0130] Furthermore, if Figure 3 As shown in the figure, the channel space pyramid network CSPPF is used in the Head part of CB-YOLO to replace the original SPPCSPC module. By extracting features in different receptive fields, the perception of small targets is enhanced. The CSPPF network can accurately detect targets at multiple scales and has better performance than traditional methods.
[0131] It should be understood that the Channel Spatial Pyramid Pooling-Fast (CSPPF) is dedicated to pooling features at different scales and introducing scale focusing to improve the network's perception ability, so as to better handle targets of different scales and positions. The module structure diagram is as follows Figure 3 As shown, the present invention uses the SoftMax() operation to find important information in the channel dimension in the input features, thereby improving the expressiveness of the features. This helps to enhance the network's perception of defect features of different scales. At the same time, this important perception ability is passed to the grids of different scales after the pooling operation, and finally the multi-scale features are spliced and fused with them. The specific operation is:
[0132]
[0133]
[0134]
[0135] Among them, U4 pp Represents the features after two layers of maximum pooling operations, represents the maximum pooling operation, σ represents the ReLu activation function, U4 input features, Represents the features processed by the SoftMax function, represents the SoftMax activation function, U4 C represents the features after 1×1 convolution operation, ⊙ represents the tensor product operation, U4 F represents the final CSPPF module, Γ represents the concatenated fusion features in the channel dimension, U4 p Represents the features after a layer of maximum pooling operation.
[0136] Furthermore, if Figure 4 As shown, the internal structures of the first adaptive weighted bidirectional feature pyramid network AWBFPN, the second adaptive weighted bidirectional feature pyramid network AWBFPN, the third adaptive weighted bidirectional feature pyramid network AWBFPN and the fourth adaptive weighted bidirectional feature pyramid network AWBFPN are consistent, and the first adaptive weighted bidirectional feature pyramid network AWBFPN includes:
[0137] First, input features p3, p4 and p5, and obtain p6 and p7 after two downsampling operations;
[0138] Then, 1×1 convolution is performed on the feature maps p3, p4, p5, p6, and p7 to adjust the number of channels and obtain p3_in, p4_in, p5_in, p6_in, and p7_in.
[0139] Next, p7_in is upsampled to obtain upsampled p7_U, and the upsampled p7_U is stacked with p6_in to obtain p6_td; then, p6_td is upsampled to obtain upsampled p6_U, and the upsampled p6_U is stacked with p5_in to obtain p5_td; p5_td is continued to be upsampled to obtain upsampled p5_U, and the upsampled p5_U is stacked with p4_in to obtain p4_td; finally, p4_td is upsampled to obtain upsampled p4_U, and the upsampled p4_U is stacked with p3_in to obtain p3_out.
[0140] After obtaining p3_out, p4_td, p4_in, p5_td, p5_in, p6_in, p6_td, and p7_in, p3_out is downsampled to obtain p3_D, and p3_D is stacked with p4_td and p4_in to obtain p4_out. Next, p4_out is downsampled to obtain p4_D, and p4_D is stacked with p5_td and p5_in to obtain p5_out. Then, p5_out is downsampled to obtain p5_D, and p5_D is stacked with p6_in and p6_td to obtain p6_out. Finally, p6_out is downsampled to obtain p6_D, and p6_D is stacked with p7_in to obtain p7_out.
[0141] Finally, p3_out, p4_out, p5_out, p6_out and p7_out are obtained, and p3_in, p4_in, p5_in, p6_in and p7_in are stacked as the input features of the next layer.
[0142] Furthermore, the first adaptive weighted bidirectional feature pyramid network AWBFPN is used for cross-scale feature fusion. This is because different input features have different resolutions, and the contribution of the original module to the fused output features is usually uneven. AWBFPN can solve this problem well.
[0143] It should be understood that the adaptive weighted bidirectional feature pyramid network (AWBFPN) introduces learnable weights to learn the importance of different input features, while repeatedly applying top-down and bottom-up multi-scale feature fusion. An additional learnable weight parameter β is introduced and added to the weight list, and the importance of different input feature maps can be adjusted through training.
[0144] ω is the original weight tensor, and its shape is tensor[2], indicating that there are two weight values that need to be fused.
[0145] β is an additional weight parameter, its shape is Tensor[1], representing an additional weight value.
[0146] Concatenate ω and β on dimension θ. Since ω is a tensor with shape tensor[2] and m is a tensor with shape tensor[1], they are expanded on dimension 0 during the concatenation, resulting in a new tensor β with shape tensor[3].
[0147] For example, assuming ω is equal to [0.5, 0.3] and β is equal to [0.2], then the result after concatenation is [0.5, 0.3, 0.2]. In this way, the γ tensor contains the original weight ω and the additional weight β, which can be used in subsequent calculations. The calculation formula is:
[0148]
[0149] γ=Cat((ω,β),dim=0);
[0150] Among them, through each γ n >=0 is ensured by the Relu function, ε=0.0001 ensures the stability of the value, ω and β are weight parameters, γ is the new tensor after calculation, the Cat band edge connects the two weight parameters, dim=0 indicates the first dimension, and μ represents the feature. Because the softmax operation is avoided, the training speed is greatly improved.
[0151] Furthermore, if Fig.10 As shown, the internal structures of the first ELAN-H module, the second ELAN-H module, the third ELAN-H module and the fourth ELAN-H module are consistent, and the first ELAN-H module includes:
[0152] The seventeenth CBS module, the eighteenth CBS module, the nineteenth CBS module, the twentieth CBS module, the twenty-first CBS module, the channel splicing unit and the twenty-second CBS module are connected in sequence;
[0153] The input end of the seventeenth CBS module is also connected to the input end of the twenty-third CBS module, and the output end of the twenty-third CBS module is connected to the input end of the channel splicing unit, and the channel splicing unit is used to realize splicing of input features in the channel dimension;
[0154] The input end of the seventeenth CBS module is the input end of the first ELAN-H module, and the output end of the twenty-second CBS module is the output end of the first ELAN-H module;
[0155] The output end of the seventeenth CBS module, the output end of the eighteenth CBS module, the output end of the nineteenth CBS module, and the output end of the twentieth CBS module are all connected to the input end of the channel splicing unit.
[0156] For example, ELAN-H is composed of multiple CBSs, whose input and output feature sizes remain unchanged, and the number of channels will change in the first two CBSs. The subsequent input channels are consistent with the output channels, and the output is the required channel after the last CBS. The ELAN-W module selects five for addition.
[0157] Exemplarily, the first ELAN-H module is used to achieve learning and convergence of network parameters by controlling the gradient path.
[0158] Furthermore, the first detection head module, the second detection head module and the third detection head module are implemented by a RepConv module.
[0159] Further, the head network comprises: four parallel branches: a first branch, a second branch, a third branch and a fourth branch;
[0160] The first branch includes: a first REP module and a first CBM module connected in sequence;
[0161] The second branch includes: a second REP module and a second CBM module connected in sequence;
[0162] The third branch includes: a third REP module and a third CBM module connected in sequence;
[0163] The fourth branch includes: a fourth REP module and a fourth CBM module connected in sequence;
[0164] An input terminal of the first REP module is connected to an output terminal of the third ELAN-W module;
[0165] The input end of the second REP module is connected to the output end of the fourth ELAN-W module;
[0166] The input end of the third REP module is connected to the output end of the fifth ELAN-W module;
[0167] An input terminal of the fourth REP module is connected to an output terminal of the sixth ELAN-W module.
[0168] Furthermore, the head network is used to achieve target classification.
[0169] Further, the internal structures of the first CBS module, the second CBS module, the third CBS module, the fourth CBS module, the fifth CBS module, the sixth CBS module, the seventh CBS module, the eighth CBS module, and the ninth CBS module are consistent, and the first CBS module includes:
[0170] The convolutional layer, batch normalization layer and activation function layer SiLU are connected in sequence.
[0171] It should be understood that the first CBS module is used to extract features from input data and enhance the expressiveness of the features through batch normalization and activation functions.
[0172] Further, the internal structures of the first CBM module, the second CBM module, the third CBM module and the fourth CBM module are consistent, and the first CBM module includes:
[0173] The convolutional layer, batch normalization layer and activation function layer Sigmoid are connected in sequence.
[0174] Exemplarily, the first detection head module parses the model output and converts it into actual detection results. In YOLOv7, each detection head corresponds to a set of prediction results, which are based on different anchor boxes and output feature maps.
[0175] The present invention uses NVIDIA A100-SXM4-40GB graphics card for training and testing. The training parameters are Epoch = 200, Batchsize = 40, learning rate = 0.01, and the input resolution is set to 640*640. Other main environment configurations are shown in Table 1.
[0176] Table 1
[0177] CPU Intel Xeon Processor (Icelake) Memory 16G Operating system Linux GPU NVIDIA A100-SXM4-40GB Tools PyCharmAnacondaCUDA ML framework TensorFlowPyTorch Code Language Python 3.9
[0178] After the above improvements, the optimized model CB-YOLO was obtained. Experiments show that compared with the baseline model, on the mobile phone playing dataset, the algorithm of the present invention improves Precision by 3.9%, Recall by 2.1%, mAP@0.5 by 6.4%, and mAP@0.5:0.95 by 2%. On the smoking dataset, Precision improves by 3.3%, Recall improves by 1.9%, mAP@0.5 improves by 1.7%, and mAP@0.5:0.95 improves by 0.3%. As shown in Table 2 and Table 3.
[0179] Table 2 Comparative experiments on mobile phone datasets using different methods
[0180] Method P R maP@0.5 mAP@0.5:0.95 Params Baseline (YOLOv7) 0.902 0.882 0.894 0.503 35.66M YOLOv5s 0.896 0.821 0.897 0.452 6.69M Faster-rcnn / 0.937 0.514 168.96M SSD300 / / 0.928 0.503 23.75M SSD512 / / 0.902 0.414 24.39M Retinnet / 0.929 0.460 19.77M Ours(CB-YOLO) 0.941 0.903 0.958 0.523 29.23M
[0181] Table 3 Comparative experiments on smoking dataset
[0182] Method P R map@0.5 mAP@0.5:0.95 Params Baseline (YOLOv7) 0.691 0.664 0.641 0.278 35.66M YOLOv7-tiny 0.660 0.646 0.615 0.244 5.73M YOLOv7x 0.686 0.656 0.622 0.265 67.90M Faster-rcnn / / 0.671 0.294 168.96M SSD300 / / 0.608 0.251 23.75M CB-YOLO(Ours) 0.724 0.683 0.658 0.281 29.23M
[0183] The effectiveness of the model components of the present invention is demonstrated through ablation experiments, and the experimental results are shown in Table 4.
[0184] Table 4 Ablation experiments on the smoking dataset
[0185] Baseline P R map@0.5 mAP@0.5:0.95 YOLOv7 0.691 0.664 0.641 0.278 +CSPPF 0.693 0.677 0.635 0.263 +AWBFPN 0.701 0.632 0.624 0.274 +AWBFPN+AWBFPN 0.713 0.664 0.648 0.269 CB-YOLO(ours) 0.724 0.683 0.658 0.281
[0186] Embodiment 2
[0187] This embodiment provides a campus violation detection system based on computer vision;
[0188] Campus violation detection system based on computer vision, including:
[0189] An acquisition module is configured to: acquire a campus surveillance image to be detected;
[0190] The detection module is configured to: input the campus surveillance image to be detected into the trained campus violation detection model CB-YOLO to obtain the campus violation detection result; the campus violation detection result includes: smoking behavior on campus or using mobile phone behavior on campus;
[0191] Among them, the trained campus violation detection model is used to extract image features of the campus surveillance images to be detected, classify and predict the features, and obtain classification prediction results;
[0192] Among them, the trained campus violation detection model is obtained by improving the original YOLOv7 network. The SPPCSPC module of the original YOLOv7 network is replaced by the channel space pyramid network CSPPF; the CAT module of the original YOLOv7 network is replaced by the adaptive weighted bidirectional feature pyramid network AWBFPN; the loss function of the original YOLOv7 network is set to the loss function Size-Iou.
[0193] It should be noted that the acquisition module and the detection module correspond to steps S101 to S102 in Embodiment 1, and the examples and application scenarios implemented by the modules and the corresponding steps are the same, but are not limited to the contents disclosed in Embodiment 1. It should be noted that the modules as part of the system can be executed in a computer system such as a set of computer executable instructions.
[0194] The description of each embodiment in the above embodiments has different emphases. For parts not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0195] The proposed system can be implemented in other ways. For example, the system embodiment described above is only illustrative, and the division of the modules is only a logical function division. In actual implementation, there may be other division methods, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.
[0196] Embodiment 3
[0197] This embodiment also provides an electronic device, including: one or more processors, one or more memories, and one or more computer programs; wherein the processor is connected to the memory, and the one or more computer programs are stored in the memory. When the electronic device is running, the processor executes the one or more computer programs stored in the memory so that the electronic device executes the method described in the above embodiment one.
[0198] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0199] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.
[0200] In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in a processor or an instruction in the form of software.
[0201] The method in the first embodiment can be directly embodied as a hardware processor, or a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.
[0202] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with this embodiment can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0203] Embodiment 4
[0204] This embodiment further provides a computer-readable storage medium for storing computer instructions. When the computer instructions are executed by a processor, the method described in the first embodiment is completed.
[0205] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A campus violation detection method based on computer vision, characterized by: include: Obtain the campus surveillance image to be detected; Input the campus surveillance image to be detected into the trained campus violation detection model CB-YOLO to obtain the campus violation detection result; The campus violation detection results include: smoking behavior or using mobile phones on campus; Among them, the trained campus violation detection model is used to extract image features of the campus surveillance images to be detected, classify and predict the features, and obtain classification prediction results; Among them, the trained campus violation detection model is obtained by improving the original YOLOv7 network. The SPPCSPC module of the original YOLOv7 network is replaced by the channel space pyramid network CSPPF; the CAT module of the original YOLOv7 network is replaced by the adaptive weighted bidirectional feature pyramid network AWBFPN; the loss function of the original YOLOv7 network is set to the loss function Size-Iou.
2. The computer vision-based campus violation detection method as claimed in claim 1, characterized in that: The training process of the trained campus violation detection model includes: Constructing a training set and a test set, wherein the training set and the test set both include: campus surveillance images with known detection results of smoking behavior on campus or mobile phone use behavior on campus; Input the training set into the campus violation detection model to train the model. When the loss function value of the model no longer decreases or the number of iterations reaches a set number, stop the training to obtain the campus violation detection model after preliminary training. The test set is input into the initially trained campus violation detection model to test the model. When the test index values of the model all reach the set threshold, it means that the current initially trained campus violation detection model has passed the test. The model that has passed the test is used as the final trained campus violation detection model. The loss function formula is as follows: Among them, a is the weight function, v is used to measure the consistency of aspect ratio; σ(z,z gt ) is the center of the real box z and the center of the predicted box z gt The Euclidean distance, b 2 is the square of the diagonal distance between the real box and the predicted box, w and h are the height and width of the real box, w gt and h gt is the height and width of the prediction box; α and β are weight parameters used to balance the impact of area scale factor and size difference factor on Size-IoU value.
3. The computer vision-based campus violation detection method as claimed in claim 1, characterized in that: The trained campus violation detection model includes: The first CBS module, the second CBS module, the third CBS module, the fourth CBS module, the first ELAN module, the first MP module, the second ELAN module, the second MP module, the third ELAN module, the third MP module, the fourth ELAN module, the channel space pyramid network CSPPF, the first adaptive weighted bidirectional feature pyramid network AWBFPN, the first ELAN-H module, the first RepConv module and the first detection head module are connected in sequence; The output end of the channel space pyramid network CSPPF is also connected to the input end of the first upsampling layer, the output end of the first upsampling layer is connected to the input end of the second adaptive weighted bidirectional feature pyramid network AWBFPN, the output end of the second adaptive weighted bidirectional feature pyramid network AWBFPN is connected to the input end of the second ELAN-H module, the output end of the second ELAN-H module is connected to the input end of the second upsampling layer, the output end of the second upsampling layer is connected to the input end of the third ELAN-H module, the output end of the third ELAN-H module is connected to the input end of the fourth MP module, the output end of the fourth MP module is connected to the input end of the fourth adaptive weighted bidirectional feature pyramid network AWBFPN, the output end of the fourth adaptive weighted bidirectional feature pyramid network AWBFPN is connected to the input end of the fifth MP module, and the output end of the fifth MP module is connected to the input end of the first adaptive weighted bidirectional feature pyramid network AWBFPN; Wherein, the output end of the fourth ELAN-H module is connected to the input end of the second RepConv module, and the output end of the second RepConv module is connected to the input end of the second detection head module; wherein, the output end of the third ELAN-H module is connected to the input end of the third RepConv module, and the output end of the third RepConv module is connected to the input end of the third detection head module; wherein, the output end of the second ELAN-H module is connected to the input end of the fourth adaptive weighted bidirectional feature pyramid network AWBFPN; wherein, the output end of the first ELAN module is connected to the input end of the fifth CBS module, and the output end of the fifth CBS module is connected to the input end of the third adaptive weighted bidirectional feature pyramid network AWBFPN; wherein, the output end of the third ELAN module is connected to the input end of the sixth CBS module, and the output end of the sixth CBS module is connected to the input end of the second adaptive weighted bidirectional feature pyramid network AWBFPN.
4. The computer vision-based campus violation detection method as claimed in claim 3, characterized in that: The channel space pyramid network CSPPF includes: The convolution layer C3, batch normalization layer, activation function layer, first maximum pooling layer, second maximum pooling layer, series connection unit and convolution layer C4 are connected in sequence; the output end of the first maximum pooling layer is connected to the input end of the series connection unit; The output end of the convolutional layer C3 is connected to the input end of the serial splicing unit; The output end of the convolution layer C3 is connected to the input end of the first softmax activation function layer, the input end of the first multiplier, and the input end of the second softmax activation function layer; The output end of the first softmax activation function layer and the output end of the second softmax activation function layer are connected to the input end of the first multiplier; The output ends of the first multiplier are respectively connected to the input ends of the third maximum pooling layer; The output terminal of the first multiplier is also connected to the input terminal of the series splicing unit; The input of the convolutional layer C3 is the input of the channel space pyramid network CSPPF; The output of the convolutional layer C4 is the output of the channel space pyramid network CSPPF; The channel space pyramid network CSPPF enhances the perception ability of the target by extracting features in different receptive fields.
5. The computer vision-based campus violation detection method as claimed in claim 3, characterized in that: The channel space pyramid network CSPPF specifically operates as follows: Among them, U4 pp Represents the features after two layers of maximum pooling operations, represents the maximum pooling operation, σ represents the ReLu activation function, U4 input features, Represents the features processed by the SoftMax function, represents the SoftMax activation function, U4 C represents the features after 1×1 convolution operation, ⊙ represents the tensor product operation, U4 F represents the final CSPPF module, Γ represents the concatenated fusion features in the channel dimension, U4 p Represents the features after a layer of maximum pooling operation.
6. The computer vision-based campus violation detection method as claimed in claim 3, characterized in that: The first adaptive weighted bidirectional feature pyramid network AWBFPN includes: First, input features p3, p4 and p5, and obtain p6 and p7 after two downsampling operations; Then, 1×1 convolution is performed on the feature maps p3, p4, p5, p6, and p7 to adjust the number of channels and obtain p3_in, p4_in, p5_in, p6_in, and p7_in; Next, p7_in is upsampled to obtain the upsampled p7_U, and the upsampled p7_U is stacked with p6_in to obtain p6_td; then, p6_td is upsampled to obtain the upsampled p6_U, and the upsampled p6_U is stacked with p5_in to obtain p5_td; p5_td is upsampled to obtain the upsampled p5_U, and the upsampled p5_U is stacked with p4_in to obtain p4_td; finally, p4_td is upsampled to obtain the upsampled p4_U, and the upsampled p4_U is stacked with p3_in to obtain p3_out; After obtaining p3_out, p4_td, p4_in, p5_td, p5_in, p6_in, p6_td and p7_in, p3_out is downsampled to obtain p3_D, and p3_D is stacked with p4_td and p4_in to obtain p4_out; then, p4_out is downsampled to obtain p4_D, and p4_D is stacked with p5_td and p5_in to obtain p5_out; then, p5_out is downsampled to obtain p5_D, and p5_D is stacked with p6_in and p6_td to obtain p6_out; finally, p6_out is downsampled to obtain p6_D, and p6_D is stacked with p7_in to obtain p7_out; Finally, p3_out, p4_out, p5_out, p6_out and p7_out are obtained, and p3_in, p4_in, p5_in, p6_in and p7_in are stacked as the input features of the next layer.
7. The campus violation detection system based on computer vision is characterized by: include: An acquisition module is configured to: acquire a campus surveillance image to be detected; The detection module is configured to: input the campus surveillance image to be detected into the trained campus violation detection model CB-YOLO to obtain the campus violation detection result; The campus violation detection results include: smoking behavior or using mobile phones on campus; Among them, the trained campus violation detection model is used to extract image features of the campus surveillance images to be detected, classify and predict the features, and obtain classification prediction results; Among them, the trained campus violation detection model is obtained by improving the original YOLOv7 network. The SPPCSPC module of the original YOLOv7 network is replaced by the channel space pyramid network CSPPF; the CAT module of the original YOLOv7 network is replaced by the adaptive weighted bidirectional feature pyramid network AWBFPN; the loss function of the original YOLOv7 network is set to the loss function Size-Iou.
8. An electronic device, comprising: a memory for non-transitory storage of computer readable instructions; as well as a processor for executing the computer readable instructions, Wherein, when the computer-readable instructions are executed by the processor, the method described in any one of claims 1 to 6 is executed.
9. A storage medium characterized by being non-temporary The computer-readable instructions are stored, wherein when the non-transitory computer-readable instructions are executed by a computer, the instructions of the method according to any one of claims 1 to 6 are executed.
10. A computer program product, characterized in that The invention comprises a computer program, which is used to implement the method according to any one of claims 1 to 6 when running on one or more processors.
