Image object localization and counting model and implementation method thereof

By using an image target localization and counting model, multi-scale feature extraction and sliding window matching are employed to solve the problems of accuracy and location provision in classless target counting, achieving high-quality target localization and counting, applicable to the detection and counting of objects of any category.

CN117710356BActive Publication Date: 2026-11-27SHANGHAI HEHE INFORMATION TECH DEV +3
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311818545.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-26
Publication Date
2026-11-27
Estimated Expiration
2043-12-26

AI Technical Summary

Technical Problem

Existing classless target counting methods have low counting accuracy in scenes with dense targets, cannot provide target location information, and existing target detection models require specific category filtering and cannot detect objects in unseen domains.

Method used

By employing an image target localization and counting model, a similarity map is generated through the creation of a training dataset, extraction of multi-scale features, sliding window matching, and feature fusion. This model predicts the location and quantity of target objects, achieving classless target localization and counting.

Benefits of technology

It enables simultaneous target object localization and counting in an image, improving counting accuracy and flexibility. It can detect and count objects of any category and output target bounding boxes for easy user inspection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117710356B_ABST
    Figure CN117710356B_ABST
Patent Text Reader

Abstract

The application discloses an implementation method of an image target positioning and counting model. A training data set is made. Multi-scale features of a target image and multi-scale features of a single query sample are extracted from a pair of input data. The similarity of each scale feature of the query sample and each scale feature of the target image is calculated by block sliding through a sliding window matching mode to obtain a similarity map M of the query sample and the target image. The position of a target object possibly existing in the target image is mined based on the similarity map M of the query sample and the target image to generate a proposal box set. Fusion features are generated. The position and boundary box of the target object in the target image are predicted based on the fusion features, and only the position and boundary box of the target object screened through the confidence are included in the counting to obtain the final prediction of the position and quantity of the target object in the target image. The application simultaneously realizes the positioning and counting of the target object in the image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to an artificial intelligence model (e.g., a neural network) for image object detection and visual counting. Background Technology

[0002] Image object detection refers to finding targets (objects) of interest in an image and determining their category and location.

[0003] Visual counting is a method that uses computer vision technology to automatically count target objects in images and videos. Existing visual counting methods fall into two categories: category-specific counting and category-free counting. Category-specific counting refers to counting within predefined categories, such as crowds, cells, or cars. However, it exhibits poor generalization ability when transferred to other categories, meaning it struggles to adapt to the counting requirements of new categories. Category-free counting, on the other hand, is a method that automatically counts corresponding targets using a limited number of target samples provided by the user. It has broader applicability and promising practical applications.

[0004] Most existing classless object counting methods are based on density map regression. These methods typically input three query samples and obtain the object count by summing the predicted density maps. The counting results are often not integers, and can even be negative, resulting in generally low accuracy. For example, in scenarios with dense object density, the predicted density peaks tend to cluster together, causing the subsequent peak extraction process to miss real objects in the local neighborhood of a particular peak, leading to inaccurate counting results. Furthermore, due to the continuous nature of the density distribution, these methods cannot provide location information of the objects being counted, resulting in significant ambiguity. In practical applications, users cannot know whether objects have been correctly counted, thus hindering subsequent corrections.

[0005] Visual counting only provides the number of user-specified target objects and cannot locate them, which limits its application. Most existing methods that simply integrate target localization into the visual counting framework can only perform point-level localization, meaning they can only obtain the center point position of the target and cannot predict the target's bounding box (four-point coordinates). Furthermore, existing object detection models for visual counting require post-processing involving specific category filtering. This means that existing object detection models detect all categories of objects; if a specific category needs to be counted, it must first be filtered out from all categories before counting. Moreover, existing object detection models lack the ability to detect and count unseen domains (i.e., object categories not in the training dataset). Summary of the Invention

[0006] The technical problem to be solved by this invention is: how to implement an image target localization and counting model, so that the model can achieve classless target localization and counting based on a one-shot query patch.

[0007] To address the aforementioned technical problems, this invention proposes a method for implementing an image target localization and counting model, comprising the following steps: Step S1: Creating a training dataset; the training dataset includes multiple pairs of query samples and target images; all query samples are divided into multiple categories, each query sample is labeled with its category; the location and quantity of target objects in each target image corresponding to the category of the query sample are labeled. Step S2: Extracting multi-scale features of the target image and multi-scale features of a single query sample from a pair of input data. Step S3: Calculating the similarity between each scale feature of the query sample and each scale feature of the target image using a sliding window matching method, obtaining a similarity map M between the query sample and the target image. Step S4: Based on the similarity map M between the query sample and the target image, mining the locations of potential target objects in the target image, i.e., initially predicting the potential locations of the query sample in the target image, generating a set of proposal boxes. Step S5: Mapping the multi-scale features of the query samples to features of a uniform scale in the query samples through feature alignment, and generating fused features together with the multi-scale features of the target image, the similarity map M between the query sample and the target image, and the set of proposal boxes. Step S6: Based on the fusion features, predict the location bounding box and confidence score of the target object in the target image. Only the location bounding box of the target object that is filtered by the confidence score is included in the count, so as to obtain the location and number of the target object in the final predicted target image. Make the location and number of the target object in the final predicted target image as consistent as possible with the labeled location and number of the single query sample in the corresponding target image.

[0008] Further, in step S1, all query samples are clustered according to existing category labels; specifically: extracting category labels of query samples, establishing a set for each category, adding query samples of the same category to the corresponding category set, and establishing a matching association with target images containing target objects of that category; the prerequisite for establishing a matching association between target images and query samples is that the target image contains a target object of the category to which the query sample belongs.

[0009] Further, in step S2, a query sample is randomly selected from the query samples of the same category, called a single query sample; the single query sample and the corresponding target image are used as a pair of input data.

[0010] Furthermore, in step S2, multi-scale features of the target image and multi-scale features of the single query sample are first extracted from a pair of input data. Then, based on the multi-scale features extracted in the first step, further feature fusion is performed to output the multi-scale features of the target image and the multi-scale features of the single query sample after feature fusion. The first feature extraction is performed using a parameter sharing method.

[0011] Preferably, in step S2, the first feature extraction is implemented using a neural network for extracting image features; the second multi-scale feature extraction is implemented using a neural network for extracting multi-scale image features.

[0012] Furthermore, in step S2, multi-scale features refer to features with multiple different sizes; the number of different-size features contained in the multi-scale features of the target image is the same as the number of different-size features contained in the multi-scale features of the query sample.

[0013] Further, step S3 specifically includes the following sub-steps. Step S31: The k-th scale feature of the target image and the k-th scale feature of the query sample are used as input, where k is a positive integer and is the k-th feature sorted from largest to smallest according to the size of each feature in the multi-scale feature; the k-th scale feature of the target image is divided into multiple blocks, and the size of each block is equal to the size of the k-th scale feature of the query sample;

[0014] Step S32: Normalize the features of each block of the segmented target image along the channel dimension with the k-th scale feature of the query sample. Step S33: Match the features of each block of the target image with the k-th scale feature of the query sample to obtain the similarity map s calculated between the features of each block of the target image and the k-th scale feature of a single query sample. i The matching mentioned refers to using a point-by-point similarity calculation method. Where s i This represents the similarity map calculated between the features of each block after segmentation at the k-th scale of the target image and the features at the k-th scale of the single-example query sample. RELU() is the activation function, * indicates pointwise multiplication, |||2 indicates calculating the L2 norm, and a dot indicates multiplication. After step S33 is completed, multiple similarity maps s are obtained. i The number is equal to the number of blocks into which the k-th scale feature of the target image is segmented. Step S34: Divide the multiple similarity maps s iBy concatenating the blocks according to their positions on the k-th scale features of the target image, a similarity map is obtained between the k-th scale features of the complete target image and the k-th scale features of the single query sample. This complete similarity map is then bilinearly interpolated to obtain a matching map. Steps S31 to S34 are repeated to calculate the matching maps between the features of each scale of the target image and the corresponding scale features of the query sample. After step S34 is completed, multiple matching maps are obtained, the number of which equals the number of different size features contained in the multi-scale features of the target image. Step S35: All matching maps and the features of each scale of the target image are concatenated along the channel dimension to obtain the similarity map M between the query sample and the target image.

[0015] Preferably, in step S4, a neural network for preliminary localization of objects in an image is used.

[0016] Furthermore, in step S6, regression prediction of the target object's location bounding box and confidence score is performed through two fully connected layers, and L1 loss is used to supervise the target object's location bounding box, while proportional retention loss function is used to supervise the target object's confidence score prediction.

[0017] This invention also proposes an image target localization and counting model, including a training data production unit, a feature extraction unit, a similarity map calculation unit, a preliminary prediction unit, a feature alignment and fusion unit, and a final prediction and counting unit. The training data production unit is used to create a training dataset; the training dataset includes multiple pairs of query samples and target images; all query samples are divided into multiple categories, and each query sample is labeled with its category; the location and quantity of target objects in each target image corresponding to the category of the query sample are labeled. The feature extraction unit is used to extract multi-scale features of the target image and multi-scale features of a single query sample from a pair of input data. The similarity map calculation unit is used to calculate the similarity between each scale feature of the query sample and each scale feature of the target image using a sliding window matching method, obtaining a similarity map M between the query sample and the target image. The preliminary prediction unit is used to mine the locations of potential target objects in the target image based on the similarity map M between the query sample and the target image, that is, to preliminarily predict the potential locations of the query samples in the target image, generating a set of proposal boxes. The feature alignment and fusion unit is used to map the multi-scale features of the query sample to a uniform-scale feature of the query sample through feature alignment. This fusion feature is generated together with the multi-scale features of the target image, the similarity map M between the query sample and the target image, and the proposal box set. The final prediction and counting unit is used to predict the location bounding boxes and confidence scores of target objects in the target image based on the fusion features. Only the location bounding boxes of target objects that pass the confidence score screening are included in the counting, thus obtaining the final predicted location and number of target objects in the target image. This ensures that the location and number of target objects in the final predicted target image are as consistent as possible with the labeled location and number of the single query sample in the corresponding target image.

[0018] The technical effects achieved by this invention are: simultaneously locating and counting target objects in an image; and using a sliding window feature matching method to calculate the similarity map, which improves the quality of the similarity map and facilitates obtaining high-quality proposal boxes that are closer to the single-example query sample. Attached Figure Description

[0019] Figure 1 This is a flowchart illustrating the implementation method of the image target localization and counting model proposed in this invention.

[0020] Figure 2 This is a schematic diagram of the specific process of the sliding window matching method in step S3.

[0021] Figure 3 This is a schematic diagram of the sliding window matching method in step S3.

[0022] Figure 4 This is a schematic diagram of the image target localization and counting model proposed in this invention.

[0023] The attached figures are labeled as follows: 1. Training data production unit; 2. Feature extraction unit; 3. Similarity map calculation unit; 4. Preliminary prediction unit; 5. Feature alignment and fusion unit; 6. Final prediction and counting unit. Detailed Implementation

[0024] Please see Figure 1 The implementation method of the image target localization and counting model proposed in this invention includes the following steps.

[0025] Step S1: Create a training dataset. The training dataset includes multiple pairs of query samples (i.e., target objects) and target images. All query samples are divided into multiple categories using clustering methods or manually, and each query sample is labeled with its category. Each target image is labeled with the location and number of target objects belonging to the corresponding query sample category.

[0026] For example, to fully reflect the shape, size, and orientation of a class of targets, query samples are clustered based on existing category labels. Specifically, the category labels of the query samples are extracted, a set is created for each category, query samples of the same category are added to the corresponding category set, and a matching association is established with target images containing target objects of that category. The prerequisite for establishing a matching association between a target image and a query sample is that the target image contains a target object of the category to which the query sample belongs.

[0027] Step S2: Extract the multi-scale features F of the target image from a pair of input data (i.e., a query sample and the corresponding target image). I Multi-scale features F of single-instance query samples Q .

[0028] Preferably, in this step, a query sample is randomly selected from the query samples of the same category, referred to as a single-case query sample; this single-case query sample and its corresponding target image are used as a pair of input data. Randomly selecting a single-case query sample is used to ensure the diversity and comprehensiveness of the single-case query sample's representation of the target features of this category.

[0029] Preferably, in this step, multi-scale features of the target image and multi-scale features of the single query sample are first extracted from a pair of input data. Then, based on the first extracted multi-scale features, further feature fusion is performed to improve the model's adaptability to multi-scale targets, and the multi-scale features F of the fused target image are output. I Multi-scale features F of single-instance query samples QThe first feature extraction can be implemented using any neural network for image feature extraction, such as ResNet50; and parameter sharing (i.e., weight sharing) should be used during the first feature extraction. The second multi-scale feature extraction can be implemented using any neural network for multi-scale image feature extraction, such as a feature pyramid network (FPN).

[0030] Multi-scale features refer to features with multiple different sizes (i.e., different dimensions). The multi-scale feature F of a target image... I The number of features of different sizes included and the multi-scale features F of the query sample Q The number of features of different sizes contained is the same. For example, the multi-scale features F of the target image I There are 5 different sizes of features, F I = {[BS,C,H1,W1],[BS,C,H2,W2],[BS,C,H3,W3],[BS,C,H4,W4],[BS,C,H5,W5]}, where BS is the batch size, which refers to the amount of data used in a batch during training. C is the number of channels, for example, 256. H1,H2,H3,H4,H5 and W1,W2,W3,W4,W5 are respectively... The height and width of the original target image. The multi-scale features F of the query sample. Q There are also 5 different sizes of features, F Q ={[BS,C,h1,w1],[BS,C,h2,w2],[BS,C,h3,w3],[BS,C,h4,w4],[BS,C,h5,w5]}, where h1,h2,h3,h4,h5 and w1,w2,w3,w4,w5 are respectively The height and width of the original query sample.

[0031] Step S3: Using a sliding window matching method, the similarity between each scale feature of the query sample and each scale feature of the target image is calculated block by block, resulting in a similarity map M between the query sample and the target image.

[0032] The following example, calculating the similarity between features at a certain scale of the target image and features at the corresponding scale of the query sample, illustrates the sliding window matching method. Please refer to [link / reference]. Figure 2 Step S3 specifically includes the following sub-steps.

[0033] Step S31: Use the k-th scale feature of the target image and the k-th scale feature of the query sample as input, where k is a positive integer, for example, the k-th feature sorted in descending order of size among the multi-scale features. Then, use the k-th scale feature F of the target image... I The target image is divided into multiple blocks, each with a size equal to the size of the k-th scale feature of the query sample. The k-th scale features of the target image and the query sample are input into the model and processed to a uniform size, regardless of their original input dimensions. For example, if the processed target image's feature at a certain scale is 256 pixels × 256 pixels, the corresponding feature of the processed query sample at that scale is 64 pixels × 64 pixels. The largest scale feature of the target image is divided into 16 4×4 blocks, each with a feature size of 64 pixels × 64 pixels, equal to the size of the corresponding scale feature of the query sample.

[0034] Step S32: Feature analysis of each block in the segmented target image With the k-th scale feature F of the query sample Q Normalization is performed along the channel dimension, which means that each value in the channel dimension is processed to the range [0,1], and square brackets indicate that the value is included.

[0035] In machine learning, every layer has a dimensional feature, which represents the dimension of the output data. For example, if the input image is 28 pixels × 28 pixels and passes through a convolutional layer with 3 filters, the output data will have an additional dimension—the number of channels. The value of 3 for the number of channels indicates the number of filters in that convolutional layer.

[0036] This normalization step eliminates the influence of scale, ensuring that differences in the size or distribution of different datasets do not interfere with the similarity results, thereby improving the model's robustness and generalization ability. For example, if the numerical distribution of dataset A is all above 100, while the numerical distribution of dataset B is all between 0 and 1, then when a module trained on dataset B is generalized to dataset A, the difference in numerical distribution will prevent the module from achieving its optimal performance. Therefore, it is necessary to unify the distribution range of all data to [0,1].

[0037] Step S33: Extract features from each block of the target image Each is compared with the k-th scale feature F of the query sample. Q Perform matching to obtain the features of each block of the target image. Features F at the k-th scale of the singleton query sample Q The calculated similarity graph s i For example, matching is performed according to the blocks on the target image in a left-to-right, top-to-bottom order, such as... Figure 3As shown. The matching refers to the use of a point-by-point similarity calculation method, as shown below: Where s i The features of each block after segmentation at the k-th scale of the target image. Features F at the k-th scale of the singleton query sample Q The calculated similarity map uses ReLU() as the activation function, * to represent pointwise multiplication, |||2 to calculate the L2 norm, and dots to represent multiplication. Unlike traditional cosine similarity calculation methods, the pointwise similarity calculation method used in this application can more intuitively obtain the similarity between the features of a single query sample and the features of the target image at different locations. This matching process allows the model to retain rich semantic information, improves the model's relational modeling ability, and enables subsequent steps to generate high-quality proposal boxes that are closer to the query sample. After step S33 is completed, multiple similarity maps s are obtained. i The number is equal to the number of features F at the k-th scale of the target image. I The number of blocks into which it is divided.

[0038] Step S34: Combine multiple similarity images s i Based on the feature F of each block at the k-th scale of the target image I The positions on the graph are stitched together to obtain the feature F at the k-th scale of the complete target image. I Compared with the k-th scale feature F of the singleton query sample Q The similarity map is then used. Bilinear interpolation is applied to this complete similarity map to obtain the matching map.

[0039] Repeat steps S31 to S34 to calculate the matching map between the largest scale feature of the target image and the largest scale feature of the query sample; calculate the matching map between the second largest scale feature of the target image and the second largest scale feature of the query sample, and so on, until the smallest scale feature of the target image is calculated and matched with the smallest scale feature of the query sample. After step S34 is completed, multiple matching maps are obtained, the number of which is equal to the number of multi-scale features F of the target image. I The number of different size features included.

[0040] Step S35: Concatenate the features of all matching images and the target image at each scale along the channel dimension to obtain the similarity map M between the query sample and the target image. For example, if the channel dimension of a matching image is 256, and the channel dimension of the k-th scale feature of the corresponding target image is also 256, concatenating the two along the channel dimension will result in 256 + 256 = 512 dimensions.

[0041] Existing methods for calculating the similarity map between a query sample and the target image rely on multi-scale features F of a single query sample. QPerform global average pooling, then combine with the multi-scale features F of the target image. I The similarity map is obtained by performing a simple subtraction and then calculating the absolute value. The calculation process is as follows: s=|(F I -GAP(F Q ))|。 Where s represents the similarity map between the query sample and the target image, and GAP represents global average pooling. Global average pooling combines the multi-scale features F of a single query sample. Q The height and width are compressed into a single value, making the multi-scale features F of the single-instance query sample more efficient. Q The loss of detailed information in the height and width directions destroys the multi-scale features F of the single-instance query sample. Q The spatial structure and local features of the query sample are considered. This means that when calculating the similarity graph s, the multi-scale features F of the single query sample are not taken into account. Q and the multi-scale features F of the target image I The relative positions and spatial correlations between them. Furthermore, due to the multi-scale features F of the single-case query samples... Q and the multi-scale features F of the target image I Features with different dimensions, i.e., different numerical ranges (e.g., one with values ​​all above 100, and another with values ​​all between 0 and 1), may cause scaling bias when performing a simple subtraction operation. The numerical ranges of features from different dimensions may mismatch during subtraction, thus affecting the calculation result of the similarity map s. The sliding window feature matching method proposed in this application can calculate a high-quality similarity map M, which is completely different from the existing methods for calculating similarity maps s. This allows for the subsequent generation of high-quality proposal boxes that are closer to the single-example query sample based on this high-quality similarity map M.

[0042] Step S4: Based on the similarity map M between the query sample and the target image, mine the locations where the target object (i.e., the query sample) may exist in the target image. This is essentially a preliminary prediction of the potential locations of the query sample (i.e., the target object) in the target image, generating a set of proposal boxes P. The set of proposal boxes refers to the set of locations where the target object may exist in the target image. In this step, the prediction operation can be implemented using any neural network used for preliminary object localization in an image, such as a region proposal network (RPN).

[0043] Step S5: Align the multi-scale features F of the query samples through feature alignment. Q Features F mapped to a uniform scale of query samples Roi , and the multi-scale features F of the target image I The similarity graph M between the query sample and the target image and the set of proposal boxes P are used together to generate the fused feature F. FuseThe uniform scale is, for example, 7 pixels × 7 pixels. The feature alignment operation is, for example, to perform bilinear interpolation on the multi-scale features F of the query sample. Q The data is unified to [BS,C,h1,w1], and concatenated along the channel number dimension, with the mean value taken to obtain fused features. Then, the ROI Align neural network is used to map the fused features into a unified scale feature F of the query samples with dimensions [BS,C,7,7]. Roi The generated fusion feature F Fuse For example, the contrast-level relationship, saliency-level relationship, and attention-level relationship between the target image features and the query sample features are extracted respectively, and finally the fused feature F is obtained through the feature fusion module. Fuse .

[0044] Step S6: Based on the fusion feature F Fuse Predict the bounding boxes and confidence scores of target objects in the target image. Only the bounding boxes of target objects that pass the confidence score screening are included in the count, while the bounding boxes of target objects that do not pass the confidence score screening are not included in the count. This yields the final predicted location and number of target objects in the target image. The goal is to make the final predicted location and number of target objects in the target image as consistent as possible with the labeled location and number of the single query sample in the corresponding target image.

[0045] In this step, for example, two fully connected layers are used to perform regression prediction on the bounding boxes and confidence scores of the target objects, respectively. L1 loss is used to supervise the bounding box prediction, and proportional retention loss is used to supervise the confidence score prediction. Then, when filtering by confidence score, for example, only the bounding boxes of target objects with a confidence score greater than 0.5 are counted, and the final predicted location and number of target objects in the target image are output.

[0046] Steps S2-S6 are the training process of the image target localization and counting model proposed in this invention. Different single query samples of different categories and their corresponding target images are randomly selected and this training process is repeated until a usable image target localization and counting model is obtained after training is completed.

[0047] Please see Figure 4 The image target localization and counting model proposed in this invention includes a training data production unit 1, a feature extraction unit 2, a similarity map calculation unit 3, a preliminary prediction unit 4, a feature alignment and fusion unit 5, and a final prediction and counting unit 6. Figure 4 The device shown corresponds to Figure 1 The method shown.

[0048] The training data creation unit 1 is used to create a training dataset. The training dataset includes multiple pairs of query samples (i.e., target objects) and target images. All query samples are divided into multiple categories using clustering methods or manually, and each query sample is labeled with its category. Each target image is labeled with the location and quantity of the target object belonging to the corresponding query sample category.

[0049] The feature extraction unit 2 is used to extract multi-scale features F of the target image from a pair of input data (i.e., a query sample and the corresponding target image). I Multi-scale features F of singleton query samples Q .

[0050] The similarity map calculation unit 3 is used to calculate the similarity between each scale feature of the query sample and each scale feature of the target image by sliding the window matching block by block, so as to obtain the similarity map M between the query sample and the target image.

[0051] The preliminary prediction unit 4 is used to mine the possible locations of target objects (i.e., query samples) in the target image based on the similarity map M between the query sample and the target image, that is, to preliminarily predict the potential locations of query samples (i.e. target objects) in the target image and generate a set of proposal boxes P.

[0052] The feature alignment and fusion unit 5 is used to align the multi-scale features F of the query sample. Q Features F mapped to a uniform scale of query samples Roi , and the multi-scale features F of the target image I The similarity graph M between the query sample and the target image and the set of proposal boxes P are used together to generate the fused feature F. Fuse .

[0053] The final prediction and counting unit 6 is used to predict based on the fusion feature F Fuse Predict the bounding boxes and confidence scores of target objects in the target image. Only the bounding boxes of target objects that pass the confidence score screening are included in the count, while the bounding boxes of target objects that do not pass the confidence score screening are not included in the count. This yields the final predicted location and number of target objects in the target image. The goal is to make the final predicted location and number of target objects in the target image as consistent as possible with the labeled location and number of the single query sample in the corresponding target image.

[0054] Compared with existing technologies, the image target localization and counting model implemented in this invention has the following advantages: (1) Compared with existing target detection models, this invention does not require post-processing for specific category filtering, and still has the ability to detect and count targets in unseen domains. (2) Compared with existing density map-based visual counting methods, this invention can count unclassed objects based on single-instance query samples, i.e., the input is only a single-instance query sample; it can also count objects of any category and output the bounding boxes of the counted objects, making it convenient for users to check whether each object has been correctly detected and counted. It is more user-friendly in practical applications and improves the flexibility of practical applications. (3) In the step of calculating the similarity map, this invention adopts a sliding window feature matching method, which improves the model's relational modeling ability and thus improves the quality of subsequent network-generated proposal boxes.

[0055] The above are merely preferred embodiments of the present invention and are 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 implementing an image target localization and counting model, characterized in that, Includes the following steps; Step S1: Create a training dataset; the training dataset includes multiple pairs of query samples and target images; divide all query samples into multiple categories, and label each query sample with its category; label each target image with the location and number of target objects in the corresponding category of the query sample; Step S2: Extract multi-scale features of the target image and multi-scale features of the single query sample from a pair of input data; Step S3: Using a sliding window matching method, calculate the similarity between each scale feature of the query sample and each scale feature of the target image block by block, obtaining the similarity map M between the query sample and the target image; wherein, the similarity map between the k-th scale feature of the target image and each block of the k-th scale feature is obtained by calculating the similarity between each block and the k-th scale feature of the query sample using a point-by-point similarity method. ; Step S4: Based on the similarity map M between the query sample and the target image, mine the locations where the target object may exist in the target image, that is, preliminarily predict the potential location of the query sample in the target image, and generate a set of proposal boxes; Step S5: Map the multi-scale features of the query sample to the uniform-scale features of the query sample through feature alignment, and generate fused features together with the multi-scale features of the target image, the similarity map M between the query sample and the target image, and the proposal box set. Step S6: Based on the fusion features, predict the location bounding box and confidence score of the target object in the target image. Only the location bounding box of the target object that is filtered by the confidence score is included in the count, so as to obtain the location and number of the target object in the final predicted target image. Make the location and number of the target object in the final predicted target image as consistent as possible with the labeled location and number of the single query sample in the corresponding target image.

2. The method for implementing the image target localization and counting model according to claim 1, characterized in that, In step S1, all query samples are clustered according to existing category labels; specifically, the category labels of the query samples are extracted, a set is established for each category, query samples of the same category are added to the corresponding category set, and a matching association is established with the target image containing the target object of that category; the prerequisite for establishing a matching association between the target image and the query sample is that the target image contains the target object of the category to which the query sample belongs.

3. The method for implementing the image target localization and counting model according to claim 1, characterized in that, In step S2, a query sample is randomly selected from the query samples of the same category, called a single query sample; the single query sample and the corresponding target image are used as a pair of input data.

4. The method for implementing the image target localization and counting model according to claim 1, characterized in that, In step S2, multi-scale features of the target image and multi-scale features of the single query sample are first extracted from a pair of input data. Then, based on the first extracted multi-scale features, further feature fusion is performed to output the multi-scale features of the target image and the multi-scale features of the single query sample after feature fusion. The first feature extraction is performed using a parameter sharing method.

5. The method for implementing the image target localization and counting model according to claim 4, characterized in that, In step S2, the first feature extraction is implemented using a neural network for extracting image features; the second multi-scale feature extraction is implemented using a neural network for extracting multi-scale image features.

6. The method for implementing the image target localization and counting model according to claim 1, characterized in that, In step S2, multi-scale features refer to features with multiple different sizes; the number of different size features contained in the multi-scale features of the target image is the same as the number of different size features contained in the multi-scale features of the query sample.

7. The method for implementing the image target localization and counting model according to claim 1, characterized in that, Step S3 specifically includes the following sub-steps; Step S31: The k-th scale feature of the target image and the k-th scale feature of the query sample are used as input, where k is a positive integer and is the k-th feature sorted from largest to smallest according to the size of each feature in the multi-scale feature; the k-th scale feature of the target image is divided into multiple blocks, and the size of each block is equal to the size of the k-th scale feature of the query sample; Step S32: Feature analysis of each block in the segmented target image Compared with the k-th scale feature of the query sample Normalization is performed along the channel dimension; Step S33: Extract features from each block of the target image Each with the k-th scale feature of the query sample Perform matching to obtain the features of each block of the target image. Features of the k-th scale of a singleton query sample Calculated similarity graph The matching mentioned refers to using a point-by-point similarity calculation method. ;in ReLU represents the similarity map calculated between the features of each block after segmentation at the k-th scale of the target image and the features at the k-th scale of the single-example query sample. ReLU() is the activation function. This indicates point-by-point multiplication. This indicates the calculation of the L2 norm, and the dot represents multiplication; After step S33 is completed, multiple similarity maps are obtained. The number is equal to the number of blocks into which the k-th scale feature of the target image is segmented; Step S34: Combine multiple similarity images By stitching together the blocks according to their positions on the k-th scale features of the target image, a similarity map is obtained between the k-th scale features of the complete target image and the k-th scale features of the single-example query sample; bilinear interpolation is then used on this complete similarity map to obtain a matching map. Repeat steps S31 to S34 to calculate the matching maps between the features of the target image at each scale and the corresponding scale features of the query sample; after step S34 is completed, multiple matching maps are obtained, the number of which is equal to the number of different size features contained in the multi-scale features of the target image. Step S35: Concatenate the features of all matching images and the target image at each scale along the channel dimension to obtain the similarity map M between the query sample and the target image.

8. The method for implementing the image target localization and counting model according to claim 1, characterized in that, In step S4, a neural network is used to perform preliminary localization of objects in an image.

9. The method for implementing the image target localization and counting model according to claim 1, characterized in that, In step S6, regression prediction of the target object's bounding box and confidence score is performed using two fully connected layers, and L1 loss is used to supervise the target object's bounding box, while proportional retention loss function is used to supervise the target object's confidence score prediction.

10. An image target localization and counting model, characterized in that, It includes a training data production unit, a feature extraction unit, a similarity map calculation unit, a preliminary prediction unit, a feature alignment and fusion unit, and a final prediction and counting unit; The training data production unit is used to produce a training dataset; the training dataset includes multiple pairs of query samples and target images; all query samples are divided into multiple categories, and each query sample is labeled with its category; each target image is labeled with the location and quantity of the target object of the corresponding query sample category; The feature extraction unit is used to extract multi-scale features of the target image and multi-scale features of a single query sample from a pair of input data. The similarity map calculation unit is used to calculate the similarity between each scale feature of the query sample and each scale feature of the target image using a sliding window matching method, thereby obtaining a similarity map M between the query sample and the target image. Specifically, the similarity map between each block of the target image (after dividing the target image into blocks) and the k-th scale feature of the query sample is obtained by using a point-by-point similarity calculation method. ; The preliminary prediction unit is used to mine the possible locations of target objects in the target image based on the similarity map M between the query sample and the target image, that is, to preliminarily predict the potential location of the query sample in the target image and generate a set of proposal boxes. The feature alignment and fusion unit is used to map the multi-scale features of the query sample into features of the query sample at a uniform scale through feature alignment, and generate fused features together with the multi-scale features of the target image, the similarity map M between the query sample and the target image, and the proposal box set. The final prediction and counting unit is used to predict the location bounding box and confidence score of the target object in the target image based on the fusion features. Only the location bounding box of the target object that is filtered by the confidence score is included in the counting to obtain the location and number of the target object in the final predicted target image. This makes the location and number of the target object in the final predicted target image as consistent as possible with the labeled location and number of the single query sample in the corresponding target image.