Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Before discussing exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although a flowchart may describe the steps as a sequential process, many of the steps can be performed in parallel, concurrently or simultaneously. In addition, the order of the steps may be rearranged. A process may be terminated when its operations are completed, but may have additional steps not included in the figure. A process may correspond to a method, a function, a procedure, a subroutine, a subprogram, etc.
Furthermore, the terms "first," "second," and the like may be used herein to describe various orientations, actions, steps, elements, or the like, but the orientations, actions, steps, or elements are not limited by these terms. These terms are only used to distinguish one direction, action, step or element from another direction, action, step or element. For example, the first speed difference may be referred to as a second speed difference, and similarly, the second speed difference may be referred to as a first speed difference, without departing from the scope of the present application. The first speed difference and the second speed difference are both speed differences, but they are not the same speed difference. The terms "first", "second", etc. are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of the present invention, "a plurality" means at least two, e.g., two, three, etc., unless specifically limited otherwise.
Example one
Fig. 1 is a flowchart of a positive sample obtaining method for target detection according to an embodiment of the present invention, where the embodiment is applicable to a case where a sample is screened for a training model in image recognition, and specifically includes the following steps:
step 1000, obtaining an image to be detected, wherein the image to be detected comprises at least one figure image.
In this embodiment, the image to be detected is an image captured by an imaging device or the like and used for image recognition, and includes one person image or a plurality of person images. In alternative embodiments, the image to be detected may be an animal image, a vehicle image, or other image capturing material images besides a human image.
And 1100, acquiring an anchor frame of the image to be detected.
In this embodiment, the target detection algorithm usually samples a large number of regions in the input image, then determines whether the regions contain targets that are interested in, and adjusts the edges of the regions to predict the real-around bounding box (real-around bounding box) of the targets more accurately. The area sampling method used by different models may be different. A plurality of bounding boxes of different sizes and aspect ratios (aspect ratios) are generated centered around each pixel. These bounding boxes are called anchor boxes (anchor boxes), which are rectangular boxes.
Further, in an alternative embodiment, assume that the input image is h high and w wide. We generate anchor frames of different shapes, centered around each pixel of the image, respectively. Let the size s be e (0, 1)]And has an aspect ratio of r>0, then the width and height of the anchor frame will be respectively
And
given the center position, the anchor frame, which is known to be wide and high, is determined.
Step 1200, acquiring a real annotation frame of the person image.
The real labeling frame is obtained by manual labeling of a labeling person, so that the labeling frame just covers the person in the image during labeling, and the real labeling frame is a rectangular frame.
The real annotation frame is divided manually by the annotation personnel, but the person in the image must be just included, and the preferable mode is that the real annotation frame intersects with the boundary of the person image, so that the real annotation frame can cover the person in the image without greatly influencing the target detection.
Step S1100 and step S1200 have no logical sequence relationship, step S1200 may be executed first and then step S1100 may be executed, or step S1100 and step S1200 may be executed simultaneously.
Step 1300, matching the anchor frame and the real marking frame according to a preset matching rule to obtain a first matching pair set.
In this embodiment, the anchor frame and the real annotation frame are matched one-to-one according to a preset matching rule to form a matching pair, and under the preset matching rule, the same real annotation frame may be matched with different anchor frames. And forming a first matching pair set by matching all successfully matched anchor frames and the real marking frames. Illustratively, 1000 anchor frames are generated in an image to be detected, a labeling person marks out 10 real labeling frames, the anchor frames and the real labeling frames are matched under a preset rule to form 100 matching pairs of the anchor frames and the real labeling frames, and then the 100 matching pairs form a matching pair set.
And 1400, screening the first matching pair set according to a preset screening rule to obtain a second matching pair set.
In this embodiment, the screening rule is obtained by a large amount of experimental data by those skilled in the art, and through the screening rule, the matching pairs of the anchor frame and the real annotation frame in the first matching pair set can be determined one by one, and if a certain matching pair meets the screening rule, the matching pair is retained, and if not, the matching pair is deleted, so as to ensure that the training model does not generate false detection between similar characters. And when the matching pairs of all the anchor frames and the real marking frames are screened once, the reserved matching pairs form a second matching pair set.
And 1500, taking the second matching pair set as a positive sample set for target detection.
In this embodiment, the second matching pair filtered by the filtering rule in step 1400 is used as a sample for image recognition, and is input into the training model, and the parameters of the training model are continuously corrected according to the output result, so as to obtain a trained model, and the image recognition function can be realized by the trained model.
The positive sample obtaining method for target detection provided by this embodiment includes analyzing an image to be detected to generate a corresponding anchor frame and a real labeling frame, matching the obtained anchor frame and the real labeling frame according to a matching rule to obtain a matching pair set, screening the matching pair set according to a screening rule to delete redundant matching pairs, and using the screened matching pair set as a training sample.
Example two
Referring to fig. 2, fig. 2 is a flowchart of a positive sample obtaining method for target detection according to a second embodiment of the present invention. The embodiment is based on an embodiment scheme, optimized and improved, and particularly provides a specific scheme of a matching rule of an anchor frame and a real marking frame. As shown in fig. 2, the method includes:
step 2000, obtaining an image to be detected, wherein the image to be detected comprises at least one person image.
And step 2100, acquiring an anchor frame of the image to be detected.
And 2200, acquiring a real annotation frame of the person image.
Similarly, step S2100 and step S2200 may not have a logical sequence relationship, and step S2200 may be performed first and then step S2100 may be performed, or step S2100 and step S2200 may be performed simultaneously.
Step 2300, matching all the real labeling frames and the anchor frame having the maximum intersection ratio with all the real labeling frames to form a first matching subset.
In this embodiment, the Jaccard coefficient (Jaccard index) can measure the similarity between the two sets. Given sets AA and BB, their Jaccard coefficients, i.e. the size of the intersection of the two, divided by the size of the union of the two:
J(A,B)=|A∩B|/|A∪B|
in practice, we can consider the pixel area within the bounding box to be a collection of pixels. In this way, we can measure the similarity of two bounding boxes by the Jaccard coefficient of the pixel sets of the two bounding boxes. When measuring the similarity of two bounding boxes, we generally refer to the Jaccard coefficient as the intersection over area (IoU), i.e., the ratio of the intersection area to the phase area of the two bounding boxes. The intersection ratio ranges between 0 and 1, where 0 indicates no overlapping pixels in the two bounding boxes and 1 indicates that the two bounding boxes are equal.
And calculating and comparing each real labeling frame with all the anchor frames respectively, selecting the anchor frame with the maximum intersection and comparison (intersection of the two frames/union of the two frames) with the real labeling frame to form a matching pair, and using the matching pair as a first part matching pair set to ensure that each real labeling frame has the anchor frame and the corresponding anchor frame.
And 2400, matching all the anchor frames with the real mark frames which are intersected with all the anchor frames and exceed the preset threshold value to form a second matching subset.
In this embodiment, an intersection ratio is calculated between each real labeling frame and each anchor frame, and the real labeling frames and the anchor frames whose intersection ratio exceeds a preset threshold are selected to form a matching pair and serve as a second part matching pair set. In the training sample in the prior art, the anchor frame and the real marking frame are generally matched by selecting the intersection ratio of 0.5, and the similarity of the matching pair of the anchor frame and the real marking frame can be ensured by selecting the intersection ratio of 0.5, so that the accuracy of the sample is ensured. In some embodiments, the preset threshold is 0.5, and as an alternative embodiment, the preset threshold may be selected in the range of 0.4-0.6.
And 2500, taking the first matching subset and the second matching subset as a first matching pair set.
In this embodiment, the first matching subset and the second matching subset obtained in step 2400 are merged to serve as a first matching pair set, where the first matching pair set includes a matching pair of the real labeling frame and the anchor frame with the largest cross-over ratio and a matching pair of the real labeling frame and the anchor frame with the cross-over ratio exceeding a preset threshold.
And 2600, screening the first matching pair set according to a preset screening rule to obtain a second matching pair set.
And step 2700, taking the second matching pair set as a positive sample set for target detection.
According to the positive sample obtaining method for target detection provided by the embodiment, a more detailed scheme is provided for obtaining a first matching pair set by matching an anchor frame and a real marking frame according to a preset matching rule, firstly, all the real marking frames and the anchor frame having the maximum intersection and coincidence ratio with all the real marking frames are matched to form a first matching subset, and each real marking frame is ensured to have the anchor frame corresponding to the anchor frame; secondly, matching all the anchor frames and the real labeling frames which are intersected with all the anchor frames and exceed a preset threshold value to form a second matching subset, and finally taking the first matching subset and the second matching subset as a first matching pair set. The positive sample obtaining method for target detection provided by the embodiment solves the problems of insufficient training samples and low quality in image recognition in the prior art, and ensures the quantity and diversity of the training samples in the image recognition.
EXAMPLE III
Referring to fig. 3, fig. 3 is a flowchart of a positive sample obtaining method for target detection according to a third embodiment of the present invention. The embodiment is based on an embodiment scheme, and performs optimization and improvement, and particularly provides a specific scheme for obtaining a second matching pair set by screening a first matching pair set according to a preset screening rule. As shown in fig. 3, the method includes:
3000, acquiring an image to be detected, wherein the image to be detected comprises at least one figure image.
3100, obtaining an anchor frame of the image to be detected.
And 3200, acquiring a real annotation frame of the figure image.
Similarly, step S3100 and step S3200 do not have a logical sequence relationship, and step S3200 may be executed first and then step S3100 may be executed, or step S3100 and step S3200 may be executed simultaneously.
And 3300, matching the anchor frame and the real labeling frame according to a preset matching rule to obtain a first matching pair set.
And 3400, constructing a to-be-detected real marking frame set.
In this embodiment, the real labeling boxes that need to be checked are determined first, and these real labeling boxes are used as the real labeling box set to pair the first matching pair set.
Further, in an alternative embodiment, as shown in fig. 4, the constructing the to-be-detected real labeling box set in the step 3400 may include the following steps:
step 3410, when the same anchor frame in the first matching pair set comprises a plurality of matched real labeling frames, the plurality of matched real labeling frames are the real labeling frames to be detected.
In this embodiment, if an anchor frame is larger than a certain specified threshold a in a cross-over ratio with another real mark frame, in addition to the real mark frame matched with the anchor frame, the real mark frame is a real mark frame that needs to be additionally checked. As can be seen from a lot of experimental data by those skilled in the art, the threshold value a is preferably 0.25, that is, if there is an anchor box, in addition to the matching real label box, whose intersection ratio with another real label box is also greater than 0.25, the real label box is the real label box that needs to be checked additionally, in this embodiment, the same anchor box may correspond to multiple real label boxes, and their intersection ratios are all greater than 0.25, then all of these corresponding real label boxes need to be checked.
And 3420, constructing a to-be-detected real labeling box set consisting of all the to-be-detected real labeling boxes.
In this embodiment, all the real annotation frames to be checked obtained in step 3410 are combined into a set of real annotation frames to be checked, where the set includes all the real annotation frames to be checked, and is used to select the anchor frame to be checked and the set of real annotation frames in the first matching pair set.
And 3500, screening the first matching pair set based on the to-be-detected real labeling box set according to a preset screening rule to obtain a second matching pair set.
Further, in an optional embodiment, as shown in fig. 5, the step 3500 of screening the first matching pair set based on the to-be-detected real labeling box set according to the preset screening rule to obtain the second matching pair set may include the following steps:
step 3510, if any matching pair in the first matching pair set contains any one real labeling box in the to-be-detected real labeling box set, judging the matching pair.
In this embodiment, in the first matching pair set, if any matching pair includes any one of the real labeling boxes in the set of real labeling boxes to be detected, the matching pair belongs to a matching pair that needs to be determined, and the matching pair is defined as a matching pair to be determined.
Step 3520, if the undetermined matching pair meets the preset screening rule, the undetermined matching pair is reserved, otherwise, the undetermined matching pair is deleted, and a second matching pair set is obtained.
In this embodiment, if the undetermined matching pair obtained in step 3510 meets the preset screening rule, the undetermined matching pair is retained in the first matching pair set, and if the undetermined matching pair does not meet the preset screening rule, the undetermined matching pair is deleted in the first matching pair set. And after all the undetermined matching pairs are screened by the preset screening rule, the remaining matching pairs in the first matching pair set form a second matching pair set.
In an alternative embodiment, the preset screening rule is preferably:
true mark box _ x 1-anchor box _ x1< margin _ w
Anchor frame _ x 2-true mark frame _ x2< margin _ w
True mark box _ y 1-anchor box _ y1< margin _ h
Anchor frame _ y 2-true mark frame _ y2< margin _ h
The method comprises the steps of obtaining a mark _ w (b) (a real mark frame _ x 2-a real mark frame _ x1), obtaining a mark _ h (a real mark frame _ y 2-a real mark frame _ y1), obtaining an anchor frame _ x1, an anchor frame _ x2, an anchor frame _ y1, an anchor frame _ y2, a real mark frame _ x1, a real mark frame _ x2, a real mark frame _ y1 and a real mark frame _ y2, wherein the mark _ w (b) is a preset value and can be adjusted according to actual conditions.
The preset value b can be adjusted according to practical situations according to a lot of experimental data of those skilled in the art, and the preset value b in this implementation can range from 0.2 to 0.3, preferably 0.25.
In the embodiment, the matched pair of the anchor frame and the real marking frame is selected according to the intersection ratio of the anchor frame and the real marking frame and the boundary condition of the anchor frame relative to the real marking frame, the problem of false detection between similar objects is solved by introducing a screening mechanism of the matched pair of the anchor frame and the real marking frame, the diversity of samples is ensured, and thus a target detection model and an image recognition model with higher performance can be obtained.
And 3600, taking the second matching pair set as a positive sample set for target detection.
In the method for obtaining a positive sample for target detection provided in this embodiment, a more detailed scheme is provided for obtaining a second matching pair set by screening a first matching pair set according to a preset screening rule, where the scheme includes: firstly, a real labeling frame set to be detected is constructed, and then the first matching pair set is screened based on the real labeling frame set to be detected according to a preset screening rule to obtain a second matching pair set, so that redundant matching pairs in the initial matching pair set are optimized, and the sample diversification and accuracy are guaranteed. And constructing the real labeling box set to be detected further comprises: when the same anchor frame in the first matching pair set comprises a plurality of matched real marking frames, the plurality of matched real marking frames are the real marking frames to be detected; and taking all the real marking frames to be detected as a set of the real marking frames to be detected. The step of screening the first matching pair set based on the to-be-detected real labeling box set according to a preset screening rule to obtain a second matching pair set further comprises the following steps of: if any matching pair in the first matching pair set contains any one real labeling frame in the real labeling frame set to be detected, judging the matching pair and defining the matching pair as a matching pair to be determined; and if the undetermined matching pair meets the preset screening rule, reserving the undetermined matching pair, and otherwise, deleting the undetermined matching pair to obtain a second matching pair set. The positive sample obtaining method for target detection provided by the embodiment solves the problems of insufficient training samples and low quality in image recognition in the prior art, and realizes sufficient quantity and diversity of the training samples.
Example four
The positive sample acquisition device for target detection provided by the fourth embodiment of the present invention can execute the positive sample acquisition method for target detection provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. Fig. 6 is a schematic structural diagram of a positive sample acquiring device 4000 for target detection according to a fourth embodiment of the present invention. Referring to fig. 6, a positive sample acquiring device 4000 for target detection according to an embodiment of the present invention may specifically include:
an image obtaining module 4100, configured to obtain an image to be detected, where the image to be detected includes at least one person image;
an anchor frame acquiring module 4200, configured to acquire an anchor frame of the image to be detected;
the annotation acquisition module 4300 is configured to acquire a real annotation frame of the person image;
the matching module 4400 is configured to match the anchor frame with the real labeling frame according to a preset matching rule to obtain a first matching pair set;
a screening module 4500, configured to screen the first matching pair set according to a preset screening rule to obtain a second matching pair set;
a sample obtaining module 4600, configured to use the second set of matching pairs as a positive sample set for target detection.
Further, the matching module 4400 further includes:
the first matching submodule is used for matching all the real labeling frames with the anchor frame which has the maximum intersection ratio with all the real labeling frames to form a first matching subset;
the second matching submodule is used for matching all the anchor frames with the real marking frames which are intersected with all the anchor frames and exceed the preset threshold value to form a second matching subset;
and the third matching sub-module is used for taking the first matching subset and the second matching subset as the first matching pair set.
Further, the screening module 4500 further includes:
the to-be-detected set submodule is used for constructing a to-be-detected real labeling frame set;
and the matching pair screening submodule is used for screening the first matching pair set based on the to-be-detected real labeling frame set according to a preset screening rule to obtain a second matching pair set.
Further, the sub-module for the to-be-detected set further comprises:
the real marking frame unit to be detected is used for determining a plurality of matched real marking frames as the real marking frames to be detected when the same anchor frame in the first matching pair set comprises the plurality of matched real marking frames;
and the to-be-detected real labeling frame set unit is used for taking all the to-be-detected real labeling frames as the to-be-detected real labeling frame set.
Further, the matching pair screening submodule further includes:
a screening judgment unit, configured to judge a matching pair if any matching pair in the first matching pair set includes any one of the real labeling frames in the set of real labeling frames to be detected, and define the matching pair as a to-be-determined matching pair;
and the second matching pair set forming unit is used for reserving the undetermined matching pair if the undetermined matching pair meets the preset screening rule, and deleting the undetermined matching pair to obtain a second matching pair set if the undetermined matching pair does not meet the preset screening rule.
Further, the second matching pair set composing unit further includes:
a screening rule unit for determining the screening rule as:
true mark box _ x 1-anchor box _ x1< margin _ w
Anchor frame _ x 2-true mark frame _ x2< margin _ w
True mark box _ y 1-anchor box _ y1< margin _ h
Anchor frame _ y 2-true mark frame _ y2< margin _ h
The real labeling frame _ x2-b is the real labeling frame _ x1, the mark _ h is the real labeling frame _ y2-b is the real labeling frame _ y1, the anchor frame _ x1, the anchor frame _ x2, the anchor frame _ y1, the anchor frame _ y2, the real labeling frame _ x1, the real labeling frame _ x2, the real labeling frame _ y1 and the real labeling frame _ y2 are the coordinates of the anchor frame and the real labeling frame respectively, and b is a preset value and can be adjusted according to actual conditions.
In the embodiment, the matched pair of the anchor frame and the real marking frame is selected according to the intersection ratio of the anchor frame and the real marking frame and the boundary condition of the anchor frame relative to the real marking frame, the problem of false detection between similar objects is solved by introducing a screening mechanism of the matched pair of the anchor frame and the real marking frame, the diversity of samples is ensured, and thus a target detection model and an image recognition model with higher performance can be obtained.
In the positive sample obtaining apparatus for target detection in this embodiment, a corresponding anchor frame and a real labeling frame are generated by analyzing an image to be detected, a matching pair set is obtained by matching the obtained anchor frame and the real labeling frame according to a matching rule, the matching pair set is screened according to a screening rule to delete redundant matching pairs, and the screened matching pair set is used as a training sample, so that a sample model with higher performance can be obtained, the problems of insufficient training samples and low quality in image recognition in the prior art are solved, and the sufficient quantity and diversity of the training samples are realized.
EXAMPLE five
Fig. 7 is a schematic structural diagram of a computer device according to a fifth embodiment of the present invention, as shown in fig. 7, the computer device includes a memory 5100 and a processor 5200, the number of the processors 5200 in the computer device may be one or more, and fig. 7 illustrates one processor 5200 as an example; the memory 5100 and processor 5200 of the device may be connected by a bus or other means, such as by a bus in fig. 7.
The memory 5100 serves as a computer-readable storage medium and may be configured to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the power adapter testing method in the embodiments of the present invention (e.g., the image obtaining module 4100, the anchor frame obtaining module 4200, the annotation obtaining module 4300, the matching module 4400, the screening module 4500, and the sample obtaining module 4600 in the positive sample obtaining device for target detection). The processor 5200 executes various functional applications of the device/terminal/device and data processing, i.e., implements the positive sample acquisition method for object detection described above, by running software programs, instructions, and modules stored in the memory 5100.
The processor 5200 is configured to run a computer program stored in the memory 5100, and implement the following steps:
acquiring an image to be detected, wherein the image to be detected comprises at least one figure image;
acquiring an anchor frame according to an image to be detected and acquiring a real marking frame according to a figure image;
matching the anchor frame with the real marking frame according to a preset matching rule to obtain a first matching pair set;
screening the first matching pair set according to a preset screening rule to obtain a second matching pair set;
and taking the second matching pair set as a positive sample of target detection.
In one embodiment, the computer program of the computer device provided in the embodiments of the present invention is not limited to the above method operations, and may also perform related operations in the positive sample acquiring method for target detection provided in any embodiment of the present invention.
The memory 5100 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal, and the like. In addition, the memory 5100 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, the memory 5100 may further include memory located remotely from the processor 5200, which may be connected to devices/terminals/devices through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
EXAMPLE six
An embodiment of the present invention further provides a storage medium containing computer-executable instructions, where a computer program is stored on the storage medium, the computer program includes program instructions, and when the program instructions are executed by a processor, the positive sample acquisition method for target detection is implemented, and the positive sample acquisition method for target detection includes:
acquiring an image to be detected, wherein the image to be detected comprises at least one figure image;
acquiring an anchor frame of the image to be detected and acquiring a real marking frame of the figure image;
matching the anchor frame and the real marking frame according to a preset matching rule to obtain a first matching pair set;
screening the first matching pair set according to a preset screening rule to obtain a second matching pair set;
and taking the second matching pair set as a positive sample set for target detection.
Of course, the storage medium containing the computer-executable instructions provided by the embodiments of the present invention is not limited to the above method operations, and may also perform related operations in the positive sample acquiring method for target detection provided by any embodiments of the present invention.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the embodiments of the present invention.
It should be noted that, in the above embodiment of the positive sample acquiring device for target detection, the included units and modules are merely divided according to the functional logic, but are not limited to the above division as long as the corresponding functions can be realized; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.