Campus dangerous behavior detection method, system, device and storage medium

By improving the head module of the YOLOv7 model to an attention mechanism unit (CM) and using the DRIoU loss function, the real-time accuracy and efficiency issues of campus dangerous behavior detection are solved, and the detection accuracy for occluded and dense targets is improved, making it suitable for campus safety management.

CN117152835BActive Publication Date: 2026-04-28SHANDONG COMP SCI CENTNAT SUPERCOMP CENT IN JINAN +2
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHANDONG COMP SCI CENTNAT SUPERCOMP CENT IN JINAN
Filing Date
2023-08-22
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing technologies are insufficient for efficiently and in real-time detecting and identifying dangerous behaviors such as fighting, running, and smoking on campus, and manual monitoring is inefficient and prone to oversights.

Method used

An improved YOLOv7 model is adopted, replacing the original head module with an attention mechanism unit (CM), and the DRIoU loss function is used to optimize the object detection model and improve the detection accuracy of occluded and dense objects.

Benefits of technology

It enables accurate detection of targets of different scales in campus settings, improves detection efficiency and accuracy, reduces missed detections and false detections, and is suitable for real-time campus security management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117152835B_ABST
    Figure CN117152835B_ABST
Patent Text Reader

Abstract

The application discloses a campus dangerous behavior detection method, system, device and storage medium, wherein the method comprises the following steps: acquiring an image to be detected; inputting the image to be detected into a trained campus dangerous behavior detection model to output a campus dangerous behavior detection result; wherein the trained campus dangerous behavior detection model is realized by using an improved yolov7, and the improved yolov7 is that a cat unit of a head module of an original yolov7 is replaced by an attention mechanism unit CM; the loss function used in the training process of the trained campus dangerous behavior detection model is DRIoU. In the campus scene, the campus dangerous behavior and action can be accurately captured and recognized, the detection precision can be ensured when different scales of targets are faced, and the detection precision of the occluded target and the dense target is optimized under the premise of real-time detection. Compared with the artificial monitoring method, the detection efficiency is higher, and the discovery is more timely.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of campus dangerous behavior detection technology, and in particular to campus dangerous behavior detection methods, systems, equipment and storage media. Background Technology

[0002] The statements in this section merely refer to the background art related to this invention and do not necessarily constitute prior art.

[0003] With the development of deep learning and its widespread application in education, combining computer vision technology to analyze and process video footage has become an inevitable trend. Object detection and behavior recognition are increasingly being applied in industry, security, healthcare, and education. Dangerous behaviors on campus refer to actions and behaviors such as fighting and running in stairwells. Campus safety issues are complex, and human intervention is difficult, time-consuming, labor-intensive, and prone to oversight. Currently, campus safety prevention mainly relies on educational programs organized by the school. Surveillance equipment currently often plays a post-incident analysis role in security protection. Summary of the Invention

[0004] To address the shortcomings of existing technologies, this invention provides a method, system, device, and storage medium for detecting dangerous behaviors on campus; the behaviors detected by this invention include three dangerous behaviors: fighting, running, and smoking.

[0005] On the one hand, it provides methods for detecting dangerous behaviors on campus;

[0006] Methods for detecting dangerous behaviors on campus include:

[0007] Acquire the image to be detected;

[0008] The image to be detected is input into the trained campus dangerous behavior detection model, and the campus dangerous behavior detection results are output.

[0009] The trained campus dangerous behavior detection model is implemented using an improved YOLOv7, which replaces the cat unit of the head module of the original YOLOv7 with the attention mechanism unit CM. The loss function used in the training process of the trained campus dangerous behavior detection model is DRIoU.

[0010] On the other hand, it provides a campus dangerous behavior detection system;

[0011] The campus dangerous behavior detection system includes:

[0012] The acquisition module is configured to acquire the image to be detected.

[0013] The behavior detection module is configured to: input the image to be detected into the trained campus dangerous behavior detection model, and output the campus dangerous behavior detection results;

[0014] The trained campus dangerous behavior detection model is implemented using an improved YOLOv7, which replaces the cat unit of the head module of the original YOLOv7 with the attention mechanism unit CM. The loss function used in the training process of the trained campus dangerous behavior detection model is DRIoU.

[0015] Furthermore, an electronic device is also provided, including:

[0016] Memory, used for non-transitory storage of computer-readable instructions; and

[0017] Processor, for executing the computer-readable instructions,

[0018] When the computer-readable instructions are executed by the processor, they perform the method described in the first aspect above.

[0019] In another aspect, a storage medium is also provided for non-transitory storage of computer-readable instructions, wherein when the non-transitory computer-readable instructions are executed by a computer, the instructions of the method described in the first aspect are executed.

[0020] In another aspect, a computer program product is also provided, including a computer program that, when run on one or more processors, is used to implement the method described in the first aspect above.

[0021] One of the above technical solutions has the following advantages or beneficial effects:

[0022] This system accurately captures and identifies dangerous behaviors and actions on campus, ensuring detection accuracy when facing targets of different scales. It optimizes detection accuracy for occluded and densely packed targets while maintaining real-time detection capabilities. Compared to manual monitoring methods, it offers higher detection efficiency and more timely discovery. Attached Figure Description

[0023] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.

[0024] Figure 1 This is the basic framework of the YOLO campus dangerous behavior system in Embodiment 1 of the present invention;

[0025] Figure 2 This is a system program flowchart of Embodiment 1 of the present invention;

[0026] Figures 3(a) to 3(g) This is a diagram of the improved YOLOv7 network structure according to Embodiment 1 of the present invention;

[0027] Figure 4 This is a structural diagram of the CM module according to Embodiment 1 of the present invention;

[0028] Figure 5 This is the map result of the optimal ratio in Embodiment 1 of the present invention;

[0029] Figure 6 This represents the precision result of the optimal ratio in Embodiment 1 of the present invention;

[0030] Figure 7 This represents the optimal recall ratio for Embodiment 1 of the present invention.

[0031] Figure 8 This is a network structure diagram of the existing YOLOv7 technology. Detailed Implementation

[0032] It should be noted that the following detailed descriptions are exemplary and intended to provide further illustration of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.

[0033] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the exemplary embodiments of the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. Furthermore, it should be understood that the terms “comprising” and “having”, and any variations thereof, are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0034] Example 1

[0035] This embodiment provides a method for detecting dangerous behaviors on campus;

[0036] like Figure 1 As shown, methods for detecting dangerous behaviors on campus include:

[0037] S101: Acquire the image to be detected;

[0038] S102: Input the image to be detected into the trained campus dangerous behavior detection model and output the campus dangerous behavior detection results;

[0039] The trained campus dangerous behavior detection model is implemented using an improved YOLOv7, which replaces the cat unit of the head module of the original YOLOv7 with the attention mechanism unit CM. The loss function used in the training process of the trained campus dangerous behavior detection model is DRIoU.

[0040] Furthermore, the training process of the trained campus dangerous behavior detection model includes:

[0041] A dataset is constructed and augmented. The dataset is then divided into training, validation, and test sets according to a set ratio. The dataset consists of campus surveillance images with known labels for dangerous campus behaviors. The labels include: smoking, fighting, and running in classrooms.

[0042] The training set is input into the campus dangerous behavior detection model to train the model. When the model's loss function DRIoU no longer decreases, the training is stopped, and the preliminarily trained model is obtained.

[0043] The model after initial training was validated using a validation set;

[0044] The model after initial training was tested using a test set;

[0045] When all test indicators reach the set threshold, training is stopped, and the trained campus dangerous behavior detection model is obtained.

[0046] The present invention employs, such as Figures 3(a) to 3(g) The flowchart shown illustrates the training of the YOLOv7 model. The processed dataset is divided into training and test sets, and then directly uses methods such as adding... Figure 4 The CM attention module shown is trained, and the training results of each iteration are saved.

[0047] Furthermore, the augmentation process on the dataset includes:

[0048] The image is flipped, contrast is adjusted, Gaussian noise is added, exposure is adjusted, and the color space is enhanced to simulate different lighting levels.

[0049] The dataset of this invention consists of videos and images collected by web crawlers. After manual labeling, a total of 11,400 sample images of dangerous behaviors on campus were obtained, along with the type and location of the dangerous behavior in each image. Figure 2 As shown.

[0050] Furthermore, the test metrics include: detection efficiency, accuracy, recall, and precision.

[0051] Detection efficiency:

[0052]

[0053] IOU represents the intersection-union ratio of the object detection boxes;

[0054] Accuracy:

[0055]

[0056] Recall rate:

[0057]

[0058] Accuracy:

[0059]

[0060] Recall rate F-1 calculation:

[0061]

[0062] Where b represents the prediction box, b gt The center point of the target, ρ 2 This represents the Euclidean distance between the center points of the ground truth bounding box and the center points of the predicted bounding box. c represents the distance along the diagonal of the union region containing both the ground truth and predicted bounding boxes. w1, w2, h1, and h2 represent the width and height of the predicted and ground truth bounding boxes, respectively. GroundTruth represents the target region given by the label. DetectionResult represents the target region identified by the model. TP represents a true positive, where both the model's judgment and the actual result are correct. TN represents a true negative, a negative sample predicted as negative by the model. FP represents a false positive, a negative sample predicted as positive by the model. FN represents a false negative, a positive sample predicted as negative by the model.

[0063] Validation was performed using test sets with different proportions. The combined value of image precision and recall was represented by AP, which stands for Precision-Recall Curve, i.e., the curve precision is integral over the independent variable recall.

[0064] It should be understood that precision and recall are considered to evaluate the false negative metric of the model, precision is used to evaluate the false positive metric, and F-1 is used to comprehensively control for recall and precision.

[0065] Furthermore, the loss function DRIoU is specifically expressed as follows:

[0066]

[0067]

[0068]

[0069]

[0070] Where b represents the prediction box, b gt ρ represents the center point of the target. 2 The function represents the Euclidean distance between the center points of the ground truth bounding box and the center points of the predicted bounding box. c represents the distance along the diagonal of the union region containing the ground truth bounding box and the predicted bounding box. w1 represents the width of the predicted bounding box, w2 represents the width of the ground truth bounding box, h1 represents the height of the predicted bounding box, h2 represents the height of the ground truth bounding box, and l1 and l2 represent the lengths of the two vectors. The function value of arctan(x) does not increase rapidly as the value of x increases.

[0071] It should be understood that the YOLOv7 network architecture may lead to incorrect deletions and selections when selecting fewer prediction boxes due to issues such as overlapping limbs between people, occlusion between objects and classes, and significant size differences between different types of detection targets in campus scenes. Traditional NMS algorithms typically use IoU indexing to suppress redundant detection boxes, where IoU suppression is based on the overlapping area of ​​the boxes. This can lead to missed detections and false detections. To optimize detection performance in dataset environments, this invention designs a DRIoU function that considers not only the intersection-union ratio (IoU) between two boxes but also their size and shape, filtering detection boxes through two comparisons.

[0072] It should be understood that the YOLOv7 network architecture consists of a backbone and a head; the backbone is used to extract features, and the head is used for prediction. In campus scenarios, student movements are diverse, but limbs constitute a small portion of the body, making recognition difficult. Cigarette targets are also too small to be easily identified. Therefore, this invention designs an attention mechanism (CM) to guide feature fusion. This mechanism obtains features of targets at different scales before feature fusion, and then performs feature fusion. This method can significantly improve the model's ability to represent targets at different scales without increasing computational cost.

[0073] Furthermore, the attention mechanism unit CM that guides feature fusion is used to better acquire features from convolutional layers with richer features for cascading operations.

[0074] Further, as shown in Figure 3(a), the improved YOLOv7 includes:

[0075] The following modules are connected in sequence: first CBS module, second CBS module, third CBS module, fourth CBS module, first ELAN module, first MP-1 module, second ELAN module, second MP-1 module, third EALN module, third MP-1 module, fourth ELAN module, SPPCSPC module, fifth CBS module, first upsampling module, first attention mechanism module CM, first ELAN-W module, sixth CBS module, second upsampling module, second attention mechanism module CM, and second ELAN-W module;

[0076] The second ELAN module is connected to the first attention mechanism module CM through the seventh CBS module;

[0077] The third EALN module is connected to the second attention mechanism module CM through the eighth CBS module;

[0078] The improved YOLOv7 further includes: a first MP-2 module, a first CAT module, a third ELAN-W module, a second MP-2 module, a second CAT module, and a fourth ELAN-W module connected in sequence;

[0079] The input terminal of the first CAT module is also connected to the input terminal of the first ELAN-W module;

[0080] The input of the second CAT module is also connected to the output of the SPC module.

[0081] Furthermore, the internal structure of the first attention mechanism module CM and the second attention mechanism module CM is the same. The first attention mechanism module CM includes:

[0082] The first, second, and third branches are parallel;

[0083] The first branch includes: a first adder, the output of which is connected to the input of a first average pooling layer; the output of the first average pooling layer is connected to the input of a first batch of normalization layers; the output of the first batch of normalization layers is connected to the input of a first nonlinear layer; the output of the first nonlinear layer is connected to the inputs of a first two-dimensional convolutional layer and a second two-dimensional convolutional layer; the output of the first two-dimensional convolutional layer is connected to the input of a first activation function layer; the output of the second two-dimensional convolutional layer is connected to the input of a second activation function layer; the outputs of both the first and second activation function layers are connected to the input of a first re-weighting module; and the output of the first re-weighting module is connected to the input of a concat module.

[0084] The second branch includes: a second average pooling layer, the output of which is connected to the input of a second batch normalization layer; the output of the second batch normalization layer is connected to the input of a second nonlinear layer; the output of the second nonlinear layer is connected to the inputs of a third two-dimensional convolutional layer and a fourth two-dimensional convolutional layer, respectively; the output of the third two-dimensional convolutional layer is connected to the input of a third activation function layer; the output of the fourth two-dimensional convolutional layer is connected to the input of a fourth activation function layer; the outputs of the third and fourth activation function layers are both connected to the input of a second re-weighting module; and the output of the second re-weighting module is connected to the input of a concat module.

[0085] The third branch includes: a second adder, the output of which is connected to the input of a third average pooling layer; the output of the third average pooling layer is connected to the input of a third batch normalization layer; the output of the third batch normalization layer is connected to the input of a third nonlinear layer; the output of the third nonlinear layer is connected to the inputs of a fifth two-dimensional convolutional layer and a sixth two-dimensional convolutional layer, respectively; the output of the fifth two-dimensional convolutional layer is connected to the input of a fifth activation function layer; the output of the sixth two-dimensional convolutional layer is connected to the input of a sixth activation function layer; the outputs of the fifth and sixth activation function layers are both connected to the input of a third re-weighting module; and the output of the third re-weighting module is connected to the input of a concat module.

[0086] The output of the second re-weight module is connected to the input of the first adder and the input of the second adder, respectively.

[0087] The internal structures of the first, second and third Re-weight modules are the same. The first Re-weight module includes a global average pooling layer and a fully connected layer connected in sequence.

[0088] The working principle of the first Re-weight module is as follows: Global Average Pooling performs pooling operations on the feature map to obtain global information for each feature channel; the fully connected layer maps the pooled channel information into a weight vector; the weight vector is applied to the original feature map to complete the re-weighting of the channels.

[0089] The first re-weight module aims to reduce the complexity and computational cost of the model.

[0090] The concat module is used to concatenate input values.

[0091] As shown in Figure 3(b), the ELAN module includes: a ninth CBS module, a tenth CBS module, an eleventh CBS module, a twelfth CBS module, a thirteenth CBS module, a third CAT module, and a fourteenth CBS module connected in sequence;

[0092] The output terminal of the ninth CBS module is connected to the input terminal of the fifteenth CBS module; the output terminal of the fifteenth CBS module is connected to the input terminal of the third CAT module, and the input terminal of the fifteenth CBS module is connected to the input terminal of the ninth CBS module.

[0093] The output terminals of the ninth and eleventh CBS modules are both connected to the input terminal of the third CAT module.

[0094] As shown in Figure 3(c), the internal structures of the first MP-1 module, the second MP-1 module, and the third MP-1 module are the same. The first MP-1 module includes two parallel branches:

[0095] First branch and second branch;

[0096] The first branch includes a maximum pooling layer and a sixteenth CBS module connected in sequence;

[0097] The second branch includes the seventeenth CBS module and the eighteenth CBS module connected in sequence;

[0098] The input terminals of the maximum pooling layer and the seventeenth CBS module are both connected to the input terminal of the first MP-1 module;

[0099] The output of the sixteenth CBS module is connected to the input of the fourth CAT module;

[0100] The output of the eighteenth CBS module is connected to the input of the fourth CAT module;

[0101] The output of the fourth CAT module is the same as the output of the first MP-1 module.

[0102] As shown in Figure 3(d), the internal structure of the first, second, third...eighth CBS modules is the same. The first CBS module includes: a convolutional layer, a batch normalization layer and an activation function layer connected in sequence.

[0103] As shown in Figure 3(e), the internal structures of the first ELAN-W module, the second ELAN-W module, the third ELAN-W module, and the fourth ELAN-W module are the same.

[0104] The first ELAN-W module includes: the nineteenth CBS module, the twentieth CBS module, the twenty-first CBS module, the twenty-second CBS module, the twenty-third CBS module, the fifth CAT module, and the twenty-fourth CBS module connected in sequence;

[0105] The output of the nineteenth CBS module is also connected to the input of the twenty-fifth CBS module;

[0106] The output of the 25th CBS module is connected to the input of the 5th CAT module;

[0107] The input terminal of the 25th CBS module is connected to the input terminal of the 19th CBS module;

[0108] The outputs of the nineteenth, twentieth, twenty-first, twenty-second, and twenty-third CBS modules are all connected to the input of the fifth CAT module.

[0109] As shown in Figure 3(f), the internal structure of the MP-2 module is the same as that of the MP-1.

[0110] As shown in Figure 3(g), the SPPCSPC module includes:

[0111] The output of the 26th CBS module is connected to the input of the 27th CBS module; the output of the 27th CBS module is connected to the input of the 28th CBS module.

[0112] The output of the 28th CBS module is connected to the input of the three max pooling layers, the output of the three max pooling layers is connected to the input of the 6th CAT module, the output of the 6th CAT module is connected to the input of the 29th CBS module, the output of the 29th CBS module is connected to the input of the 30th CBS module, the output of the 30th CBS module is connected to the input of the 7th CAT module, and the output of the 7th CAT module is connected to the input of the 31st CBS module.

[0113] The input of the twenty-sixth CBS module is also connected to the seventh CAT module through the thirty-second CBS module.

[0114] The internal structures of the first, second, third, fourth, fifth, sixth, and seventh CAT modules are the same, and they are all used for feature concatenation.

[0115] The original YOLOv7 network architecture diagram, as follows: Figure 8 As shown.

[0116] The present invention employs, such as Figures 3(a)-3(g) The flowchart shown divides the processed dataset into training and testing sets according to a certain ratio, and directly uses... Figure 4 The YOLOv7 model with the CM attention module added is trained, and the training results of each iteration are saved. Dividing the training and test sets into different ratios yields different training results. The ratio of A is 8:2, with an accuracy of 88.68% in 100 training epochs and a batch size of 16. The ratio of B is 9:1, with an accuracy of 90.20% in 100 training epochs and a batch size of 16, as shown in Table 2.

[0117] Table 2: Training results of training and test sets with different ratios

[0118] Dataset parameters Proportion Rounds Batchsize Accuracy A 8:2 100 16 88.6% B 9:1 100 16 90.20%

[0119] Analysis of the experimental results shows that the detection accuracy is highest when the training set ratio is 9:1, and decreases significantly when the ratio changes to 8:2. For the map (e.g., under optimal parameters)... Figure 5 As shown), iou (as shown) Figure 6 (as shown), loss rate (e.g.) Figure 7 Analyzing the test results shown (as indicated) yields the same conclusion.

[0120] Analysis of the experimental results reveals that YOLOv7 performs poorly in detecting occluded targets. The default non-maximum suppression algorithm removes two adjacent detection boxes, which can lead to missed detections in the case of dense targets. Using DRIoU to replace the original loss function can reduce the overlap of detected targets at different scales, thus improving the model's detection accuracy in both dense and occluded target scenarios.

[0121] After the above improvements, an optimized YOLOv7 model and weight file were obtained. With a training set to test set ratio of 9:1, a batch size of 16, and 100 training epochs, the average accuracy was 90.20%, which is a significant improvement over the original YOLOv7.

[0122] The improved model was then used to detect 100 untrained images divided into ten groups, yielding accuracies of 89.96%, 89.93%, 90.22%, 89.88%, 89.94%, 90.18%, 90.17%, 89.96%, 90.29%, and 90.08%, respectively. The average accuracy was 90.06%, which is very close to the training result of 90.20%.

[0123] In terms of performance, the YOLOv7 model, as a one-stage detection model, performs classification tasks while identifying the target location. It is much faster than the two-stage algorithm and is suitable for real-time detection. The optimized YOLOv7 model reduces the focus on redundant information and optimizes the detection of small and dense targets, improving accuracy while saving time.

[0124] In terms of practicality, the YOLOv7 model can perform real-time detection and visualized output, which greatly improves the speed of detecting dangerous behaviors on campus and brings greater convenience to campus safety management.

[0125] Example 2

[0126] This embodiment provides a campus dangerous behavior detection system;

[0127] The campus dangerous behavior detection system includes:

[0128] The acquisition module is configured to acquire the image to be detected.

[0129] The behavior detection module is configured to: input the image to be detected into the trained campus dangerous behavior detection model, and output the campus dangerous behavior detection results;

[0130] The trained campus dangerous behavior detection model is implemented using an improved YOLOv7, which replaces the cat unit of the head module of the original YOLOv7 with the attention mechanism unit CM. The loss function used in the training process of the trained campus dangerous behavior detection model is DRIoU.

[0131] It should be noted that the acquisition module and behavior detection module described above correspond to steps S101 to S102 in Embodiment 1. The examples and application scenarios implemented by the modules and corresponding steps are the same, but are not limited to the content disclosed in Embodiment 1. It should also be noted that the modules described above, as part of the system, can be executed in a computer system such as a set of computer-executable instructions.

[0132] The descriptions of each embodiment in the above embodiments have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0133] The proposed system can be implemented in other ways. For example, the system embodiments described above are merely illustrative, and the division of modules described above is only a logical functional division. In actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed.

[0134] Example 3

[0135] 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 to cause the electronic device to perform the method described in Embodiment 1.

[0136] It should be understood that in this embodiment, the processor can be a central processing unit (CPU), or it can be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.

[0137] Memory may include read-only memory and random access memory, and provides instructions and data to the processor. A portion of memory may also include non-volatile random access memory. For example, memory may also store information about the device type.

[0138] In the implementation process, each step of the above method can be completed by the integrated logic circuits in the processor hardware or by software instructions.

[0139] The method in Embodiment 1 can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor. The software modules can reside in readily available storage media in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method. To avoid repetition, a detailed description is not provided here.

[0140] Those skilled in the art will recognize that the units and algorithm steps described in connection with the various examples of this embodiment can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.

[0141] Example 4

[0142] This embodiment also provides a computer-readable storage medium for storing computer instructions, which, when executed by a processor, complete the method described in Embodiment 1.

[0143] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for detecting dangerous behaviors on campus, characterized by: include: Acquire the image to be detected; The image to be detected is input into the trained campus dangerous behavior detection model, and the campus dangerous behavior detection results are output. The trained campus dangerous behavior detection model is implemented using an improved YOLOv7, which replaces the cat unit of the head module of the original YOLOv7 with the attention mechanism unit CM; the loss function used in the training process of the trained campus dangerous behavior detection model is DRIoU. The improved YOLOv7 attention mechanism unit CM includes a first attention mechanism module CM and a second attention mechanism module CM; The first attention mechanism module CM and the second attention mechanism module CM have the same internal structure. The first attention mechanism module CM includes: The first, second, and third branches are parallel; The first branch includes: a first adder, the output of which is connected to the input of a first average pooling layer; the output of the first average pooling layer is connected to the input of a first batch of normalization layers; the output of the first batch of normalization layers is connected to the input of a first nonlinear layer; the output of the first nonlinear layer is connected to the inputs of a first two-dimensional convolutional layer and a second two-dimensional convolutional layer; the output of the first two-dimensional convolutional layer is connected to the input of a first activation function layer; the output of the second two-dimensional convolutional layer is connected to the input of a second activation function layer; the outputs of both the first and second activation function layers are connected to the input of a first re-weighting module; and the output of the first re-weighting module is connected to the input of a concat module. The second branch includes: a second average pooling layer, the output of which is connected to the input of a second batch normalization layer; the output of the second batch normalization layer is connected to the input of a second nonlinear layer; the output of the second nonlinear layer is connected to the inputs of a third two-dimensional convolutional layer and a fourth two-dimensional convolutional layer, respectively; the output of the third two-dimensional convolutional layer is connected to the input of a third activation function layer; the output of the fourth two-dimensional convolutional layer is connected to the input of a fourth activation function layer; the outputs of the third and fourth activation function layers are both connected to the input of a second re-weighting module; and the output of the second re-weighting module is connected to the input of a concat module. The third branch includes: a second adder, the output of which is connected to the input of a third average pooling layer; the output of the third average pooling layer is connected to the input of a third batch normalization layer; the output of the third batch normalization layer is connected to the input of a third nonlinear layer; the output of the third nonlinear layer is connected to the inputs of a fifth two-dimensional convolutional layer and a sixth two-dimensional convolutional layer, respectively; the output of the fifth two-dimensional convolutional layer is connected to the input of a fifth activation function layer; the output of the sixth two-dimensional convolutional layer is connected to the input of a sixth activation function layer; the outputs of the fifth and sixth activation function layers are both connected to the input of a third re-weighting module; and the output of the third re-weighting module is connected to the input of a concat module. The output of the second re-weight module is connected to the input of the first adder and the input of the second adder, respectively.

2. The campus dangerous behavior detection method as described in claim 1, characterized in that, The training process for the trained campus dangerous behavior detection model includes: A dataset is constructed and augmented. The dataset is then divided into training, validation, and test sets according to a set ratio. The dataset consists of campus surveillance images with known labels for dangerous campus behaviors. The labels include: smoking, fighting, and running in classrooms. The training set is input into the campus dangerous behavior detection model to train the model. When the model's loss function DRIoU no longer decreases, the training is stopped, and the preliminarily trained model is obtained. The model after initial training was validated using a validation set; The model after initial training was tested using a test set; When all test indicators reach the set threshold, training is stopped, and the trained campus dangerous behavior detection model is obtained.

3. The campus dangerous behavior detection method as described in claim 2, characterized in that, The augmentation process on the dataset includes: The image is flipped, contrast is adjusted, Gaussian noise is added, exposure is adjusted, and the color space is enhanced to simulate different lighting levels.

4. The campus dangerous behavior detection method as described in claim 2, characterized in that, The test metrics include: detection efficiency, accuracy, recall, and precision. Detection efficiency: ; IOU represents the intersection-union ratio of the object detection boxes; Accuracy: accuracy = ; Recall rate: recall = ; Accuracy: precision = ; Recall rate F-1 calculation: F-1 = ; in, Indicates the prediction box. The center point of the target This represents the calculation of the Euclidean distance between the center point of the ground truth bounding box and the center point of the predicted bounding box. This represents the diagonal distance of the union region containing the ground truth bounding box and the predicted bounding box. w1, w2, h1, and h2 represent the width and height of the predicted and ground truth bounding boxes, respectively. TP represents a true positive, where both the model and the actual data are correct; TN represents a true negative, a negative sample predicted as negative by the model; FP represents a false positive, a negative sample predicted as positive by the model; and FN represents a false negative, a positive sample predicted as negative by the model.

5. The campus dangerous behavior detection method as described in claim 2, characterized in that, The loss function DRIoU is specifically expressed as follows: Where b represents the prediction box. Indicates the center point of the target. This represents the Euclidean distance between the center points of the ground truth bounding boxes and the center points of the predicted bounding boxes, where c represents the distance along the diagonal of the union region containing the ground truth bounding boxes and the predicted bounding boxes. Represents the width of the prediction box. Represents the width of the actual bounding box. Represents the height of the prediction box. Represents the height of the actual bounding box. and Represents the lengths of two vectors. The function value does not increase rapidly as the value of x increases.

6. The campus dangerous behavior detection method as described in claim 1, characterized in that, The improved YOLOv7 includes: The following modules are connected in sequence: first CBS module, second CBS module, third CBS module, fourth CBS module, first ELAN module, first MP-1 module, second ELAN module, second MP-1 module, third EALN module, third MP-1 module, fourth ELAN module, SPPCSPC module, fifth CBS module, first upsampling module, first attention mechanism module CM, first ELAN-W module, sixth CBS module, second upsampling module, second attention mechanism module CM, and second ELAN-W module; The second ELAN module is connected to the first attention mechanism module CM through the seventh CBS module; The third EALN module is connected to the second attention mechanism module CM through the eighth CBS module; The improved YOLOv7 further includes: a first MP-2 module, a first CAT module, a third ELAN-W module, a second MP-2 module, a second CAT module, and a fourth ELAN-W module connected in sequence; The input terminal of the first CAT module is also connected to the input terminal of the first ELAN-W module; The input terminal of the second CAT module is also connected to the output terminal of the SPC module.

7. A campus dangerous behavior detection system, employing the campus dangerous behavior detection method as described in any one of claims 1-6, characterized in that, include: The acquisition module is configured to acquire the image to be detected. The behavior detection module is configured to: input the image to be detected into the trained campus dangerous behavior detection model, and output the campus dangerous behavior detection results; The trained campus dangerous behavior detection model is implemented using an improved YOLOv7, which replaces the cat unit of the head module of the original YOLOv7 with the attention mechanism unit CM. The loss function used in the training process of the trained campus dangerous behavior detection model is DRIoU.

8. An electronic device, characterized in that it comprises: Memory is used to store computer-readable instructions in a non-transitory manner. as well as Processor, for executing the computer-readable instructions, When the computer-readable instructions are executed by the processor, they perform the method described in any one of claims 1-6.

9. A storage medium, characterized in that, The computer-readable instructions are stored non-transitory, 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-6 are executed.