Article holding detection method and device, equipment and storage medium

By combining human detection and machine-holding detection models in machine-holding detection, the confidence of machine-holding detection and outputting alarm information is solved, and the problems of false detection and missed detection in the existing technology are improved, and the accuracy and accuracy of machine-holding detection are improved.

CN119888791APending Publication Date: 2025-04-25SHENZHEN VIRTUAL CLUSTERS INFORMATION TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411976835.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

The existing mechanical detection methods are prone to background interference in real scenes, making it difficult to distinguish items similar to those of knives and sticks, resulting in high error detection rates and more missed detection phenomena.

Method used

By obtaining scene detection data, input the trained human body detection model to obtain the human image sequence, and then input the human body positioning image to the instrument detection model to count the instrument detection confidence that is greater than the preset discrimination threshold. If the preset warning threshold is reached, the target actor will be locked and the alarm information will be output.

Benefits of technology

Improve the accuracy of mechanical inspection, reduce false detection and missed inspection, and enhance the ability to distinguish items similar to the appearance of knives and sticks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119888791A_ABST
    Figure CN119888791A_ABST
Patent Text Reader

Abstract

The invention provides an instrument holding detection method and device, equipment and a storage medium. The method comprises the following steps: acquiring scene detection data; inputting the scene detection data into a trained human body detection model to obtain a human body image sequence which comprises a plurality of human body positioning images; the human body positioning image is input into a trained instrument holding detection model to obtain an instrument holding detection result sequence, and the instrument holding detection result sequence comprises at least one actor and a plurality of corresponding instrument holding detection confidence degrees; counting a warning quantity value, which is greater than a preset judgment threshold value, of the holder detection confidence coefficient, and if the warning quantity value is greater than a preset warning threshold value, setting the corresponding actor as a target actor; and the target actor is locked, and alarm information is output.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image analysis technology, and in particular to a method, device, equipment and storage medium for detecting a weapon. Background Art

[0002] Existing weapon detection methods based on deep learning models can be divided into two directions: target detection and image recognition. Image recognition-based weapon detection models usually process the entire image and extract global features for the image. It is difficult to accurately identify local targets in the image and is more susceptible to background interference, resulting in low recognition accuracy. The weapon detection model based on target detection can more effectively utilize local features and focus more on foreground objects. It is a more widely used technical solution. However, in life scenes, there are many objects that are similar in appearance to knives and sticks, such as pencils, mobile phones, umbrellas, etc. Existing technical methods often lack attention to distinguishing such objects, resulting in a high false detection rate in real scenes. In addition, the shapes of knives and sticks themselves are diverse, coupled with differences in camera viewing angles and holding methods, existing target models often rely too much on underlying features when identifying knives, resulting in missed detections. Summary of the invention

[0003] The present application provides a weapon detection method, device, equipment and storage medium for improving the accuracy of weapon detection and reducing missed detections.

[0004] In a first aspect, an embodiment of the present application provides a method for detecting a weapon, the method comprising: Get scene detection data; Inputting the scene detection data into a trained human body detection model to obtain a human body image sequence, wherein the human body image sequence includes: a plurality of human body positioning images; Inputting the human body positioning image into a trained weapon detection model to obtain a weapon detection result sequence, wherein the weapon detection result sequence includes: at least one actor and a corresponding plurality of weapon detection confidences; Counting the number of warning values ​​of the weapon detection confidence level greater than a preset discrimination threshold, and if the number of warning values ​​is greater than the preset warning threshold, setting the corresponding actor as a target actor; The target actor is locked and an alarm message is output.

[0005] In a second aspect, an embodiment of the present application provides a device for detecting a weapon, the device comprising: A data acquisition module, used to acquire scene detection data; A human body positioning module is used to input the scene detection data into a trained human body detection model to obtain a human body image sequence, wherein the human body image sequence includes: a plurality of human body positioning images; A weapon detection module, used for inputting the human body positioning image into a trained weapon detection model to obtain a weapon detection result sequence, wherein the weapon detection result sequence includes: at least one actor and a corresponding plurality of weapon detection confidences; a weapon carrying analysis module, used for counting the warning quantity value of the weapon carrying detection confidence level greater than a preset discrimination threshold, and if the warning quantity value is greater than the preset warning threshold, setting the corresponding actor as a target actor; The warning output module is used to lock the target actor and output warning information.

[0006] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising a memory and a processor; The memory is used to store computer programs; The processor is used to execute the computer program and implement the weapon detection method as described in any one of the embodiments of the present application when executing the computer program.

[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor enables the processor to implement a method for detecting a weapon as described in any one of the embodiments of the present application.

[0008] The embodiment of the present application provides a method for detecting a person with a weapon, including: obtaining scene detection data; inputting the scene detection data into a trained human body detection model to obtain a human body image sequence, the human body image sequence including: multiple human body positioning images; inputting the human body positioning images into a trained weapon detection model to obtain a weapon detection result sequence, the weapon detection result sequence including: at least one actor and multiple corresponding weapon detection confidences; counting the number of warning values ​​of weapon detection confidences greater than a preset discrimination threshold, if the number of warning values ​​is greater than the preset warning threshold, setting the corresponding actor as a target actor; locking the target actor, and outputting an alarm message. Through the above method, a human body positioning image is obtained on the basis of performing human body positioning once, reducing the amount of data processing of the weapon detection model, and multiple target actors are detected through the weapon detection model. When the number of weapon detection confidences reaching the preset warning threshold is greater than the warning threshold, an alarm is output to prevent false alarms, improve the accuracy of weapon detection, and reduce missed detections. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0010] Figure 1 A schematic flow chart of a method for detecting a weapon in an embodiment of the present application; Figure 2 A schematic block diagram of a weapon detection model provided in an embodiment of the present application; Figure 3 A schematic block diagram of a weapon detection device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0011] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0012] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0013] It should also be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0014] It should be further understood that the term “and / or” used in the specification and appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0015] See also Figure 1 , Figure 1 FIG. 1 is a schematic flow chart of a method for detecting a weapon in an embodiment of the present application. Figure 1 As shown, the specific steps of the weapon detection method include: S101-S105.

[0016] S101: Acquire scene detection data.

[0017] Exemplarily, scene detection data is generally images captured by a camera in a specific scene, such as a shopping mall, a street, and a campus.

[0018] S102: Input the scene detection data into a trained human body detection model to obtain a human body image sequence, which includes: a plurality of human body positioning images.

[0019] In the embodiment of the present application, the trained human body detection model is implemented by the YOLOv5s model, and the human body is marked and selected by the trained human body detection model to obtain the human body marked coordinates. At the same time, considering that the knife held in the weapon scene often exceeds the edge of the human body, especially the left and right edges, when generating the human body positioning image, the human body marked coordinates at the edge are expanded by 10% in the up and down direction, and the human body marked coordinates at the edge are expanded by 15% in the left and right direction to obtain the human body positioning image.

[0020] It should be noted that human body positioning and tracking using the YOLOv5s model is a very mature technology, and the specific process will not be repeated in this application.

[0021] S103: Input the human body positioning image into a trained weapon detection model to obtain a weapon detection result sequence, where the weapon detection result sequence includes: at least one actor and a corresponding plurality of weapon detection confidence levels.

[0022] Exemplarily, after the trained human body detection model delivers a human body image sequence, it is necessary to perform weapon detection on the human body image sequence, wherein the weapon detection is performed by the trained weapon detection model. The trained weapon detection model is implemented by the YOLOv5s model. The trained weapon detection model performs weapon detection on each actor in each human body positioning image, generates a weapon detection confidence, and continuously detects multiple human body positioning images in the human body image sequence to obtain multiple weapon detection confidences corresponding to each actor.

[0023] S104. Count the number of warning values ​​of weapon detection confidence that is greater than a preset discrimination threshold. If the number of warning values ​​is greater than the preset warning threshold, set the corresponding actor as a target actor.

[0024] Exemplarily, the preset discrimination threshold value ranges from 80% to 95%. The preset warning threshold is determined according to the number of human body positioning images detected. For example, if 10 human body positioning images are detected, the preset warning threshold is 7. The number of warnings is used to determine whether the level at which action needs to be taken has been reached. If the number of warnings exceeds this threshold, it is considered that there is sufficient evidence that the actor may have violated the rules. The above method helps filter out accidental high-confidence events and ensures that only targets that actually have abnormal behavior are marked.

[0025] S105: Lock the target actor and output alarm information.

[0026] Exemplary methods of locking the target actor include: color box selection, label marking, arrow indication and highlight processing. In a specific embodiment, highlight processing is a commonly used locking method, which makes the target actor more prominent in the image by increasing the brightness or contrast. For monitoring personnel, the location and characteristics of the target actor can be pointed out by voice broadcast, vibration reminder and map marking.

[0027] In this embodiment, if the confidence level of weapon detection is greater than 0.7 in 8 out of 10 consecutive judgments on each pedestrian, the pedestrian is considered to be carrying a knife.

[0028] The embodiment of the present application provides a method for detecting a person with a weapon, including: obtaining scene detection data; inputting the scene detection data into a trained human body detection model to obtain a human body image sequence, the human body image sequence including: multiple human body positioning images; inputting the human body positioning images into a trained weapon detection model to obtain a weapon detection result sequence, the weapon detection result sequence including: at least one actor and multiple corresponding weapon detection confidences; counting the number of warning values ​​of weapon detection confidences greater than a preset discrimination threshold, if the number of warning values ​​is greater than the preset warning threshold, setting the corresponding actor as a target actor; locking the target actor, and outputting an alarm message. Through the above method, a human body positioning image is obtained on the basis of performing human body positioning once, reducing the amount of data processing of the weapon detection model, and multiple target actors are detected through the weapon detection model. When the number of weapon detection confidences reaching the preset warning threshold is greater than the warning threshold, an alarm is output to prevent false alarms, improve the accuracy of weapon detection, and reduce missed detections.

[0029] In order to more clearly introduce the technical solution of the present application, the technical solution of the present application will be introduced through specific embodiments below. It should be noted that the specific embodiments are used to expand the technical solution of the present application, but are not intended to limit the present application.

[0030] In some embodiments, see Figure 2 , Figure 2 This is a schematic block diagram of a weapon detection model provided in an embodiment of the present application. Figure 2 As shown, before inputting the human body positioning image into the trained weapon detection model, the weapon detection model to be trained is trained, and the specific steps include: S201-S210.

[0031] S201. Obtain a training image set, where the training image set includes: positive sample images and negative sample images.

[0032] Exemplarily, the embodiment of the present application sets 2 positive sample images and 2 negative sample images for the training image set, so as to enhance the learning ability of the weapon detection model to be trained for fine-grained weapon features and guide the model to distinguish between weapon scenes and other error-prone scenes.

[0033] In some embodiments, obtaining a training image set includes: A training image set is obtained, and the training image set includes: a first category image, a second category image, a third category image, and a fourth category image; human body annotation is performed on the first category image, the second category image, and the third category image, respectively, to obtain a first human body annotation image, a second human body annotation image, and a third human body annotation image; tool type annotation is performed on the first human body annotation image, the second human body annotation image, and the third human body annotation image, to obtain a first tool holding annotation image, a second tool holding annotation image, and a third tool holding annotation image; tool type annotation is performed on the fourth category image, to obtain a tool holding annotation image; human body virtual annotation is performed according to the tool annotation image, to obtain a fourth tool holding annotation image; the first human body annotation image and the second human body annotation image are set as positive sample images, and the third tool holding annotation image and the fourth tool holding annotation image are set as negative sample images, to obtain a training image set.

[0034] For example, considering that knives and sticks have different appearance features, knives and sticks are considered as two categories. Considering that similarities often appear in real scenes, long daily objects often involved in real scenes are considered as one category. Considering that the act of holding a weapon includes the hand-held action, the simply placed knife is considered as one category. Therefore, the collected images contain 4 types of data: hand-held knife images and hand-held stick images as positive sample images, and knife images and hand-held similar object images as negative samples.

[0035] For positive sample images, annotate the human body holding the weapon in the image. For negative sample images of handheld analogues, annotate the human body holding the analogues. For negative sample images of knives, use the average length and width of the human body frame in the same scene to virtually annotate the human body and the range of the human body in the corresponding scene. In the above annotation process, the human body rectangle frame of the virtual human body annotation should include the knife and the analogue.

[0036] All human images are labeled with the parts of holding knives, holding sticks, and holding similar objects. The label of the first human labeled image is "hold knives", the label of the second human labeled image is "hold sticks", and the label of the third human labeled image is "hold others". At the same time, the knife part is labeled for the third human labeled image, and the label is recorded as "weapon". After that, the average length and width of the human body frame are calculated according to the scene, and the human body frame containing the knife part is randomly generated for the knife image as a negative sample using a normal distribution, and the position coordinates of the knife part annotation based on the human body are recalculated.

[0037] S202: inputting the positive sample images and the negative sample images into a weapon detection model to be trained, wherein the weapon detection model to be trained includes: a feature extraction layer, a detection head, a feature fusion layer, and an attention layer.

[0038] S203: Based on the feature extraction layer, multi-dimensional features are extracted from the positive sample image and the negative sample image to obtain multi-dimensional features.

[0039] For example, feature maps from different depths (shallow to deep) are combined, because shallow features often contain more specific low-level information (such as color, boundary), while deep features represent higher-level concepts (such as part or whole of an object). Use receptive fields of different sizes or images of different resolutions for feature extraction to capture details at different scales. The multi-dimensional features of positive sample images and negative sample images are obtained by the above method, denoted as F0.

[0040] S204: Based on the detection head, classify and predict the multi-dimensional features to obtain a category probability matrix.

[0041] For example, Figure 2 As shown in FIG, after the multi-dimensional features are processed by the detection head, the category probability is output, and the category probability matrix is ​​synthesized according to the output category probability, which is denoted as P.

[0042] S205: Based on the feature extraction layer, extract the multi-dimensional features to obtain the underlying features.

[0043] For example, as the depth of the network increases, each layer will continue to extract more complex and abstract features based on the previous layer. This hierarchical process enables the model to understand the high-level semantic information in the image. Through deeper feature extraction layers, the underlying features of the multi-dimensional features are obtained, denoted as F1.

[0044] S206. Based on the feature fusion layer, the category probability matrix and the underlying features are nonlinearly fused through a tensor product operation to obtain fused features.

[0045] Considering that the low-level features output by the feature extraction network mostly represent non-instance information, such as color, contour, and lighting, in order to suppress this redundant information, the low-level category probability matrix P of the model and the underlying feature F1 are nonlinearly fused through the tensor product operation to obtain the fused feature, denoted as F2. To prevent dimensionality explosion, similar to randomized multilinear mapping, the model implements tensor product through Hadamard product In some embodiments, the specific calculation formula of the tensor product operation is: , where F2 is the fusion feature, ⊙ represents the Hadamard product, R1 and R2 represent random matrices with univariate uniform distribution, P is the category probability matrix, and F1 is the underlying feature. After the above tensor product operation, the channel dimension of the fusion feature F2 increases.

[0046] S207. Based on the attention layer, the fusion features are calculated through a preset activation function to obtain a spatial attention map, and then the spatial attention map is converted into a feature vector through a flattening operation.

[0047] Exemplarily, the fusion feature F2 is calculated on the channel through an activation function to obtain a spatial attention map, and the specific formula of the activation function is: ; Among them, c is the channel dimension of the fused feature F2, and m is the subscript in the feature decomposition process, where m=1, 2,....H*W.

[0048] To reduce computational cost, the spatial attention map is flattened into feature vector F3.

[0049] S208. Calculate the consistency loss of the feature vector corresponding to the positive sample image according to a preset loss function.

[0050] Exemplarily, the Euclidean distance between positive sample images is calculated, and the specific calculation formula is: ; Among them, x and x' are different positive sample images.

[0051] Then, the consistency loss is calculated according to the preset loss function. The specific calculation formula is: ; Among them, L con is the consistency loss, H is the height dimension of the underlying feature F1, and F i and F j They are the feature vectors between different positive sample images, W is the width size of the underlying feature F1. For example, the output feature of the P3 module of yolov5 is usually taken, and the size is 256*40*40 (C*H*W).

[0052] By minimizing this loss, the distance between samples of the same category under different data distributions is shortened.

[0053] S209, performing weighted calculation on the consistency loss and the detection loss of a preset detection model to obtain a weighted loss, where the preset detection model is a model trained with multi-dimensional features.

[0054] Exemplarily, the preset detection model can be a trained human body detection model. Since the YOLOv5s model has the functions of human body detection and object detection, knives can also be detected during human body detection, but there will be accuracy issues. In this application, the loss of the preset detection model is used as a reference amount for weighted calculation to improve the training accuracy of the weapon detection model.

[0055] At the end of the model, the consistency loss is weighted and added to the loss of the original detection model, that is: , where L total is the weighted loss, L det To preset the detection loss of the detection model, the hyperparameter λ is an empirical parameter and can be set according to actual conditions.

[0056] It should be noted that steps S203-S209 can be regarded as a category consistency module of the weapon detection model. Through the above-mentioned category consistency module, while ensuring real-time detection, the model effectively reduces the missed detection of knives with different appearances in different scenes, thereby achieving higher detection accuracy.

[0057] It should also be noted that the category consistency module proposed in the embodiment of the present application is only used in the training of the weapon detection model and is masked during the model reasoning process, so it does not affect the real-time calculation rate of the weapon detection model.

[0058] S210: until the weighted loss reaches a preset convergence condition, a trained weapon detection model is obtained.

[0059] In this embodiment, the trained human body detection model and the trained weapon detection model can be implemented by the YOLOv5s model. Considering that the knife in the weapon scene often exceeds the edge of the human body, especially the left and right edges, the image of the human body is expanded by 10% upward and 15% in the left and right directions when generating the human body image. Therefore, the weapon detection model uses 320×320 as the input image size setting of the YOLOv5s model. In this embodiment, after the category consistency module is added to the P3 layer of the YOLOv5s model, the dimension of the fusion feature F2 is set to 1024, and the hyperparameter λ of the consistency loss is set to 0.5.

[0060] It can be understood that the embodiment of the present application sets two kinds of targeted negative sample images to prompt the model to learn to distinguish between targets and other similar targets, thereby reducing the false detection rate of the model in real scenes; by adding a category consistency module based on low-level feature similarity, the model's attention to target features in different scenes is strengthened, and the model's attention to redundant background is suppressed. Through the trained human detection model and the trained weapon detection model, the surveillance video is end-to-end intelligently analyzed, and the accuracy of pedestrian weapon detection in real scenes is improved without changing the computational cost.

[0061] In some embodiments, scene detection data is input into a trained human body detection model to obtain a human body image sequence, including: based on the trained human body detection model, performing human body detection on the scene detection data, and taking the moment when the human body is detected as the initial moment; determining a video frame sequence according to the initial moment and a preset number of video frames; and inputting the video frame sequence into a trained human body detection model to obtain a human body image sequence.

[0062] Specifically, for constructing a video frame sequence, the length of the video frame sequence can be set to L, and pedestrians can be detected in the video frame. The number of frames is counted from the time the pedestrian is detected. The first video frame sequence V0 is constructed from the Lth frame, and the sequence from the i-th frame to the L+i-th frame is recorded as V i , when an interruption occurs and the number of interruptions reaches n, it is recalculated. Through the trained human body detection model for the video frame sequence V i The human body is annotated in the process, and then the human body annotation frame is expanded first, the human body image is obtained according to the human body annotation frame, and the human body image sequence is constructed.

[0063] In some embodiments, a video frame sequence is input into a trained human body detection model to obtain a human body image sequence, including: inputting a video frame sequence into a trained human body detection model to obtain human body annotation points; determining a human body annotation box based on the human body annotation points and preset framework parameters; and capturing a human body image sequence from the video frame sequence based on the human body annotation box.

[0064] For example, considering that knives held in weapon scenes often extend beyond the edge of the human body, especially the left and right edges. When generating a human body positioning image, multiple human body annotation points are added, and the preset framework parameters are to increase the distance by 10% in the up and down directions and 15% in the left and right directions. The increased distance is determined based on the distance between the two farthest human body annotation points in the direction. The human body annotation coordinates at the edge are expanded by 10%, and in the left and right directions, the human body annotation coordinates at the edge are expanded by 15%, and a human body positioning image is obtained.

[0065] In some embodiments, the preset framework parameters include: a first expansion parameter and a second expansion parameter, the first expansion parameter is used to determine a first annotation box boundary with the two most lateral annotation points of the human body annotation point in a first preset direction, and the second expansion parameter is used to determine a second annotation box boundary with the two most lateral annotation points of the human body annotation point in a second preset direction, and the first annotation box boundary and the second annotation box boundary are combined to form a human body annotation box.

[0066] See also Figure 3 , Figure 3 3 is a schematic block diagram of a weapon detection device provided in an embodiment of the present application, wherein the weapon detection device 300 is used to execute the aforementioned weapon detection method. The weapon detection device 300 may be configured in a server.

[0067] Among them, the server can be an independent server or a server cluster, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN) and big data and artificial intelligence platforms.

[0068] like Figure 3 As shown, the weapon detection device 300 includes: a data acquisition module 301, a human body positioning module 302, a weapon detection module 303, a weapon analysis module 304 and a warning output module 305.

[0069] The data acquisition module 301 is used to acquire scene detection data.

[0070] The human body positioning module 302 is used to input the scene detection data into a trained human body detection model to obtain a human body image sequence, wherein the human body image sequence includes: a plurality of human body positioning images.

[0071] The weapon detection module 303 is used to input the human body positioning image into a trained weapon detection model to obtain a weapon detection result sequence, wherein the weapon detection result sequence includes: at least one actor and a corresponding plurality of weapon detection confidence levels.

[0072] The weapon analysis module 304 is used to count the warning quantity values ​​of the weapon detection confidence level that are greater than a preset discrimination threshold, and if the warning quantity value is greater than the preset warning threshold, set the corresponding actor as a target actor.

[0073] The warning output module 305 is used to lock the target actor and output warning information.

[0074] An embodiment of the present application provides an electronic device, which includes a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program and implement any one of the weapon detection methods in the embodiments of the present application when executing the computer program.

[0075] An embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the processor implements any one of the weapon detection methods in the embodiments of the present application.

[0076] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A method for detecting a weapon, characterized in that: Get scene detection data; Inputting the scene detection data into a trained human body detection model to obtain a human body image sequence, wherein the human body image sequence includes: a plurality of human body positioning images; Inputting the human body positioning image into a trained weapon detection model to obtain a weapon detection result sequence, wherein the weapon detection result sequence includes: at least one actor and a corresponding plurality of weapon detection confidences; Counting the number of warning values ​​of the weapon detection confidence level greater than a preset discrimination threshold, and if the number of warning values ​​is greater than the preset warning threshold, setting the corresponding actor as a target actor; The target actor is locked and an alarm message is output.

2. The method for detecting a weapon as claimed in claim 1, characterized in that: Before inputting the human body positioning image into the trained weapon detection model, the method further includes: Acquire a training image set, wherein the training image set includes: positive sample images and negative sample images; Inputting the positive sample image and the negative sample image into a weapon detection model to be trained, wherein the weapon detection model to be trained includes: a feature extraction layer, a detection head, a feature fusion layer and an attention layer; Based on the feature extraction layer, multi-dimensional feature extraction is performed on the positive sample image and the negative sample image to obtain multi-dimensional features; Based on the detection head, classify and predict the multi-dimensional features to obtain a category probability matrix; Based on the feature extraction layer, feature extraction is performed on the multi-dimensional features to obtain underlying features; Based on the feature fusion layer, the category probability matrix and the underlying features are nonlinearly fused through a tensor product operation to obtain a fused feature; Based on the attention layer, the fusion feature is calculated by a preset activation function to obtain a spatial attention map, and then the spatial attention map is converted into a feature vector by a flattening operation; Calculating the consistency loss of the feature vector corresponding to the positive sample image according to a preset loss function; Performing weighted calculation on the consistency loss and the detection loss of a preset detection model to obtain a weighted loss, wherein the preset detection model is a model trained by the multi-dimensional features; Until the weighted loss reaches a preset convergence condition, the trained weapon detection model is obtained.

3. The method for detecting a weapon as claimed in claim 2, characterized in that: The step of acquiring a training image set comprises: Acquire a training image set, wherein the training image set includes: first category images, second category images, third category images, and fourth category images; Performing human body annotation on the first category image, the second category image, and the third category image respectively to obtain a first human body annotation image, a second human body annotation image, and a third human body annotation image; Annotating the first human body annotated image, the second human body annotated image, and the third human body annotated image by device type to obtain a first device holding annotated image, a second device holding annotated image, and a third device holding annotated image; Annotating the fourth category image by tool type to obtain a tool annotated image; Performing virtual annotation of the human body according to the tool annotation image to obtain a fourth tool annotation image; The first human body annotated image and the second human body annotated image are set as the positive sample images, and the third weapon annotated image and the fourth weapon annotated image are set as the negative sample images, so as to obtain the training image set.

4. The method for detecting a weapon as claimed in claim 2, wherein: The specific calculation formula of the tensor product operation is: , where F2 is the fusion feature, ⊙ represents the Hadamard product, R1 and R2 represent random matrices with univariate uniform distribution, P is the category probability matrix, and F1 is the underlying feature.

5. The method for detecting a weapon as claimed in claim 1, wherein: The step of inputting the scene detection data into a trained human body detection model to obtain a human body image sequence comprises: Based on the trained human body detection model, perform human body detection on the scene detection data, and use the moment when the human body is detected as the initial moment; Determining a video frame sequence according to the initial moment and a preset number of video frames; The video frame sequence is input into a trained human body detection model to obtain the human body image sequence.

6. The method for detecting a weapon as claimed in claim 5, characterized in that: The step of inputting the video frame sequence into a trained human body detection model to obtain the human body image sequence comprises: Input the video frame sequence into a trained human body detection model to obtain human body annotation points; Determining a human body annotation frame according to the human body annotation points and preset frame parameters; According to the human body annotation frame, the human body image sequence is captured from the video frame sequence.

7. The method for detecting a weapon as claimed in claim 6, wherein: The preset framework parameters include: a first outward expansion parameter and a second outward expansion parameter, wherein the first outward expansion parameter is used to determine a first annotation box boundary with two annotation points at the most lateral sides of the human body annotation point in a first preset direction, and the second outward expansion parameter is used to determine a second annotation box boundary with two annotation points at the most lateral sides of the human body annotation point in a second preset direction, and the first annotation box boundary and the second annotation box boundary are combined to form the human body annotation box.

8. A device for detecting a weapon, characterized in that: The weapon detection device comprises: A data acquisition module, used to acquire scene detection data; A human body positioning module is used to input the scene detection data into a trained human body detection model to obtain a human body image sequence, wherein the human body image sequence includes: a plurality of human body positioning images; A weapon detection module, used for inputting the human body positioning image into a trained weapon detection model to obtain a weapon detection result sequence, wherein the weapon detection result sequence includes: at least one actor and a corresponding plurality of weapon detection confidences; a weapon carrying analysis module, used for counting the warning quantity value of the weapon carrying detection confidence level greater than a preset discrimination threshold, and if the warning quantity value is greater than the preset warning threshold, setting the corresponding actor as a target actor; The warning output module is used to lock the target actor and output warning information.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor; The memory is used to store computer programs; The processor is configured to execute the computer program and implement the method for detecting a weapon as claimed in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the weapon detection method according to any one of claims 1 to 7.