Method and system for detecting and authenticating a specific pet in an image and electronic device
Patent Information
- Application Number
- CN202610733847.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-26
- Publication Date
- 2026-08-21
AI Technical Summary
[0007]提供一种图像中特定宠物的检测认证方法及系统及电子设备,解决现有技术中宠物个体识别数据成本高、扩展性差、鲁棒性不足、难以区分外观相似个体的技术问题
[0048] Achieving precise identification at the individual pet level: This invention constructs an image cue feature matrix containing positive and negative samples, combined with a contrastive learning mechanism, which can effectively learn the common features of the same individual pet and the differences between different individual pets. This enables precise detection and identification of specific individual pets in reference images such as surveillance footage, rather than just identifying the pet species. It can meet the identity authentication needs of practical application scenarios such as finding lost pets, handling infringement disputes, insurance claims, and monitoring pet behavior.
Smart Images

Figure CN122618655A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of pet recognition technology, specifically to a method, system, and electronic device for detecting and authenticating a specific pet in an image. Background Technology
[0002] With the improvement of residents' living standards, the number of pet owners has exploded, leading to a growing demand for intelligent pet-related services, such as lost pet assistance, infringement disputes, identity verification, and pet behavior monitoring. The core requirement of these applications is accurate identification at the individual pet level—that is, locating and recognizing the target pet in an image. Current technologies suffer from the following key shortcomings:
[0003] Most solutions can only classify pet breeds, but cannot distinguish between different individuals of the same breed;
[0004] It lacks robustness to changes in pet posture, lighting, and shooting angle, and has a high false recognition rate in complex scenes.
[0005] It is difficult to distinguish between pets that look very similar, and the recognition accuracy cannot meet the needs of practical applications;
[0006] Therefore, there is an urgent need in this field for a fast, high-precision method and system for specific pet detection and authentication that supports few-sample learning, in order to solve the problems existing in the above-mentioned prior art. Summary of the Invention
[0007] This invention provides a method, system, and electronic device for detecting and authenticating specific pets in images, which solves the technical problems of high data cost, poor scalability, insufficient robustness, and difficulty in distinguishing individuals with similar appearances in existing pet identification technologies.
[0008] The present invention is achieved through the following technical solution.
[0009] The present invention provides a method for detecting and authenticating a specific pet in an image, comprising the following steps:
[0010] S1: Dataset Construction and Augmentation
[0011] Original images of pets were collected under different lighting conditions, backgrounds, poses, and shooting angles. For each image, pet body bounding boxes, body keypoints, pet face bounding boxes, facial keypoints, pose, and pet IDs were annotated to create a pet detection dataset. Since a single image in the pet detection dataset may contain multiple pets, each pet's image was extracted based on its bounding boxes. Each extracted image contained only one pet, and an index table mapping images to individual pet identifiers was established, forming a pet cue dataset. Pet images were extracted based on their body bounding boxes, and the coordinates of the pet face bounding boxes and facial keypoints were transformed to obtain a pet face detection and localization dataset. Finally, pet face images were extracted based on their face bounding boxes and facial keypoints, and alignment and normalization operations were performed on the face images to form a pet recognition dataset.
[0012] Multi-pose image generation is performed on the pet cue dataset based on the diffusion model and posture control network to construct an enhanced cue dataset;
[0013] S2: Model Training: Based on the pet detection dataset and the enhanced prompt dataset, a coarse-grained overall detection model is trained by combining positive and negative sample image prompts with a contrastive learning mechanism; a pet face detection network is trained based on the pet face detection and localization dataset; and a pet face recognition network is trained based on the pet face recognition dataset.
[0014] S3: Inference Detection and Authentication: Obtain a reference image of the pet to be queried, input it into the visual encoder, and construct image cue features; input it into the coarse-grained overall detection model to obtain coarse-grained similar targets; input the coarse-grained similar targets and the reference image of the pet to be queried into the pet face detection network and pet face recognition network to perform fine-grained identity authentication to obtain fine-grained similar targets, and output the final detection and authentication results.
[0015] Furthermore, step S1 specifically includes:
[0016] S11: Collect original images of pets under different lighting conditions, backgrounds, poses, and shooting angles. For each image, annotate the pet's body bounding box, body key points, face bounding box, face key points, pose, and pet ID to form a pet detection dataset. When multiple pets are present in an image within the pet detection dataset, extract each pet's image based on its bounding box. Each extracted image contains only one pet. Establish an index table corresponding to the images and individual pet identifiers to form a pet cue dataset. Extract the extracted pet images based on the pet's body bounding box annotations, and convert the coordinates of the pet's face bounding box and face key points to obtain a pet face detection dataset. Extract the pet's face image based on the face bounding box annotations and face key points, and perform alignment and normalization operations on the pet face image to form a pet recognition dataset.
[0017] S12: Pose Template Library Construction: Based on the aforementioned body key points, construct a pose template library containing several standard pet poses. Each template defines the standard position coordinates of each body key point.
[0018] S13: Multi-pose image generation: Using the pet cue dataset and its body key point information, generate an image of the pet in a pose that does not appear in the pose template library;
[0019] S14: Enhanced Dataset Construction: The pet cue dataset is merged with the generated multi-pose images to obtain the enhanced cue dataset.
[0020] Furthermore, in step S11, the number of original images for each pet is no less than 3; the key body points include at least several of the following: head center, neck, forelimb elbow, forelimb wrist, hindlimb knee, hindlimb ankle, tail base, and abdomen center.
[0021] Further, in step S2, the training of the coarse-grained overall detection model specifically includes:
[0022] S21: Selection of positive sample cue images: For each individual pet in each training image, randomly select no less than 3 positive sample cue images of the corresponding individual from the augmented cue dataset of the corresponding pet, and cover at least 3 different poses;
[0023] S22: Negative sample cue image selection: Negative sample cue images are randomly selected from the augmented cue dataset of other pet individuals, with the number of negative samples being 5-50 times the number of positive samples;
[0024] S23: Image preprocessing prompt: Crop the individual pet area according to the bounding box annotation, perform random scaling, and then uniformly adjust it to the set size;
[0025] S24: Feature Extraction and Adaptation: A pre-trained visual encoder is used to extract visual features from positive and negative sample cue images, and a learnable feature adapter is used to transform and normalize the visual features.
[0026] S25: Image cue feature matrix construction: Combine positive sample features and negative sample features in sequence to construct the image cue feature matrix, and record the index range of positive samples;
[0027] S26: Training Image Feature Extraction: Input the training image into the image backbone network to extract multi-scale image features;
[0028] S27: Multimodal feature fusion: Input multi-scale image features and image cue feature matrix into multimodal fusion network, and introduce cue-guided attention mechanism for feature enhancement;
[0029] S28: Similarity Calculation and Label Assignment: Calculate the similarity score between each spatial location of the fused feature map and each prompt feature, and assign labels based on the bounding box annotation information;
[0030] S29: Loss Calculation and Parameter Update: Calculate the weighted sum of classification loss, bounding box loss, and keypoint localization loss as the total loss, and update the network parameters through backpropagation.
[0031] Furthermore, in step S24, the feature adapter adopts a two-layer fully connected network structure. The first layer maps 512-dimensional features to 1024-dimensional features; the second layer maps 1024-dimensional features back to 512-dimensional features using residual connections, and finally performs L2 normalization.
[0032] Furthermore, in step S29, the classification loss adopts binary cross-entropy loss; the bounding box loss adopts full intersection-union loss; the key point localization loss adopts L1 loss; during training, only the parameters of the feature adapter participate in the update, while the parameters of the visual encoder remain frozen.
[0033] Furthermore, the training of the pet face detection network and the pet face recognition network in step S2 specifically includes:
[0034] S211: Train a pet face detection network with keypoint localization using a pet face detection localization dataset;
[0035] S212: Train a pet face recognition network using a pet face recognition dataset.
[0036] Furthermore, step S3 specifically includes:
[0037] S31: Obtain a reference image of the pet to be queried;
[0038] S32: Input the reference image of the pet into the visual encoder to obtain the image cue feature matrix;
[0039] S33: Input the target image into the coarse-grained global detection model, and after threshold filtering and non-maximum suppression, obtain coarse-grained similar targets;
[0040] S34: Perform pet face detection, alignment and feature extraction on each coarse-grained similar target, calculate the similarity with the reference face features of the pet to be queried, and if the similarity is greater than the preset threshold, the fine-grained similar target is obtained.
[0041] S35: Output the final detection and certification results.
[0042] A system for detecting and authenticating a specific pet in an image, comprising:
[0043] The data processing module generates multi-pose images and constructs an augmented dataset.
[0044] The model training module is used to train a coarse-grained overall detection model, a pet face detection network, and a pet face recognition network based on the enhanced prompt dataset.
[0045] The inference authentication module is used to obtain a reference image of the pet to be queried. First, a coarse-grained overall detection model is used to obtain coarse-grained similar targets. Then, a pet face detection and recognition network is used to perform fine-grained identity authentication and output a fine authentication result. If the coarse-grained target does not have a pet face or the reference image of the pet to be queried does not have a pet face, then only coarse-grained similar targets are available.
[0046] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described method for detecting and authenticating a specific pet in an image.
[0047] The beneficial effects of this invention are:
[0048] Achieving precise identification at the individual pet level: This invention constructs an image cue feature matrix containing positive and negative samples, combined with a contrastive learning mechanism, which can effectively learn the common features of the same individual pet and the differences between different individual pets. This enables precise detection and identification of specific individual pets in reference images such as surveillance footage, rather than just identifying the pet species. It can meet the identity authentication needs of practical application scenarios such as finding lost pets, handling infringement disputes, insurance claims, and monitoring pet behavior.
[0049] Supports few-sample learning and has strong scalability: This invention only requires one or more reference images of an individual pet for detection, without the need to collect a large amount of labeled data for each individual pet and train a model separately, which greatly reduces the cost of data collection and labeling. It has good scalability and can support large-scale pet identity authentication applications.
[0050] Strong robustness and adaptability to complex scenarios: By introducing a multi-pose generation technology based on a diffusion model, this invention significantly improves the diversity of training data and inference prompts, enabling the model to adapt to various interference factors such as changes in lighting, pose, and shooting angle, and maintain a high detection accuracy in complex real-world scenarios.
[0051] Strong fine-grained discrimination capability: This invention adopts a two-level cascaded architecture that combines coarse-grained overall detection with fine-grained facial recognition, making full use of the complementarity between overall appearance features and facial features. At the same time, through comparative training with a large number of negative samples, it can effectively distinguish pet individuals with highly similar appearances, significantly reducing the false recognition rate.
[0052] High training efficiency: This invention freezes the parameters of the pre-trained visual encoder during the training process and only updates a small number of parameters of the feature adapter, which greatly reduces the computational resources and time required for training and improves the training efficiency of the model. Attached Figure Description
[0053] To more clearly illustrate the technical solutions in the embodiments of the invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0054] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0055] Figure 1 This is an overall flowchart of the detection and authentication method for a specific pet in an image according to the present invention. Detailed Implementation
[0056] The following is combined Figure 1 The present invention will be described in detail below.
[0057] Example 1:
[0058] The present invention provides a method for detecting and authenticating a specific pet in an image, the overall process of which is as follows: Figure 1 As shown, this method comprises two stages: Stage 1 detects targets of interest in videos or images to obtain preliminary search results; Stage 2 uses pet face recognition to obtain precise search and authentication results. Stage 1 considers the overall appearance of the pet, filtering out a batch of coarse-grained targets of interest (coarse-grained similar targets). Stage 1 employs pet face recognition, a fine-grained pet identity authentication method. Through these two stages, fast and high-precision detection and authentication of specific pets are achieved.
[0059] This invention designs a complete scheme that coordinates three stages: data augmentation, model training, and inference detection. It introduces a pose generation technology based on a diffusion model and uses StableDiffusion and ControlNet to achieve multi-pose extension of a single pet image, which greatly improves the diversity of training data and the robustness of the model to pets in different poses.
[0060] The specific steps are as follows:
[0061] Phase 1: Coarse-grained overall detection, providing coarse-grained similar targets.
[0062] I. Dataset Construction and Enhancement Phase
[0063] This phase involves constructing a dataset of individual pet images and augmenting the data using pose generation techniques. The specific steps include:
[0064] Step 1: Building the Basic Dataset
[0065] First, determine the number of individual pets in the dataset and assign a unique identifier to each pet. The pets can be common pet types such as dogs, cats, and rabbits. Second, for each pet, collect multiple original images under different conditions. These different conditions include: different shooting times (e.g., morning, noon, evening), different shooting locations (e.g., indoor, outdoor), different lighting conditions (e.g., natural light, artificial light), different postures (e.g., standing, lying down, walking), and different shooting angles (e.g., front, side, back). The number of original images for each pet should be no less than a preset threshold, preferably no less than three to five, to ensure that each pet has basic image data.
[0066] Then, for each original image, the individual pet region is annotated with body bounding boxes, body keypoints, and pose annotations, as well as pet face bounding boxes and pet face keypoints, forming a pet detection dataset. The annotation information includes: the coordinates of the top-left and bottom-right corners of the bounding box, the corresponding pet individual identifier, and the coordinates of the pet's body keypoints. These keypoints include, but are not limited to: the center of the head, neck, forelimb elbows, forelimb wrists, hind limb knees, hind limb ankles, the base of the tail, and the center of the abdomen. The keypoints should cover the major joints of the pet's torso and limbs to facilitate subsequent pose control generation. Pet face keypoints include the left and right eyes, nose, and left and right corners of the mouth.
[0067] Finally, an index table is established to correspond to images and individual pet identifiers, recording the individual pet number, bounding box coordinates, key point coordinates, and pose of each pet target in each image.
[0068] Step 2: Building the Pose Template Library
[0069] A pet posture template library is constructed based on key points. This library contains a variety of preset standard pet posture templates, each defining the standard position coordinates of each key point. The posture template library includes, but is not limited to, the following posture types: standing, walking, running, sitting, lying down, running, and jumping. The library contains at least ten templates to cover common pet behaviors and postures.
[0070] Step 3: Pose Generation Based on Diffusion Model
[0071] Using the StableDiffusion diffusion model and ControlNet control network, pose extension is performed on the original image of each pet to generate images of the pet in different poses. During the generation process, the pet's appearance features are kept unchanged, and only its pose is changed.
[0072] Step 4: Augmented Dataset Construction
[0073] The original images were merged with the generated pose-expanded images to construct the enhanced pet individual dataset. The enhanced dataset significantly increased the number of images per pet, including both the original image and generated images in various poses. The enhanced dataset contains images of the same pet in different poses, lighting conditions, and backgrounds, effectively improving the diversity and balance of the training data.
[0074] II. Model Training Phase
[0075] This stage trains a coarse-grained overall detection model by combining positive and negative sample image cues with a contrastive learning mechanism. This enables the model to learn the overall appearance features of individual pets and achieve rapid detection of specific pets.
[0076] Specifically, the following steps are included:
[0077] Step 1: Selecting positive sample prompt images
[0078] For each training image in the dataset, the pet individual identifier corresponding to that image is first determined. Then, several images are randomly selected from the augmented image set of that pet individual (including the original image and the generated pose-extended images) as positive sample cue images. The number of positive sample cue images is n, where n is not less than three. The positive sample cue images belong to the same pet individual as the current training image, but have different poses and shooting conditions, thus providing diverse visual features of the same pet individual.
[0079] In particular, to increase the diversity of positive cue images, the selected positive cue images should cover multiple posture types of the individual pet. The specific selection strategy is as follows: select one image from the standing posture, one image from the walking or running posture, and one image from the sitting or lying posture, ensuring that the positive cue images cover multiple perspectives of the pet, such as front, side, and back.
[0080] Step 2: Negative Sample Hint Image Selection
[0081] Several images are randomly selected from other pet images in the dataset as negative cue images. The number of negative cue images is 5-50 times the number of positive cue images. These negative cue images, drawn from different pet individuals, provide comparative information in the feature space, helping the model learn to distinguish the feature differences between different pet individuals.
[0082] To enhance the difficulty and diversity of negative samples, the selection of negative sample prompt images should cover pets of different breeds and appearance characteristics, and avoid selecting individuals that are too similar in appearance to the positive sample pets.
[0083] Step 3: Image region processing prompts
[0084] Region processing is performed on the selected positive and negative cue images. First, the region containing the individual pet is cropped based on the bounding box annotation information. Then, the cropped region is randomly scaled, with the scaling factor randomly selected within the range of 0.8 to 1.5 to enhance data diversity. Finally, the processed region is adjusted to a uniform size, preferably 224*224 pixels.
[0085] Step 4: Extracting positive and negative sample features
[0086] A pre-trained visual encoder extracts visual feature vectors from both positive and negative cue images. The visual encoder employs a contrastive language-image pre-trained model, such as the visual transformer architecture of the CLIP model. The input to the visual encoder is a 224*224 pixel image, and the output is a 512-dimensional visual feature vector. During training, the parameters of the visual encoder remain frozen and do not participate in gradient updates; its powerful visual semantic extraction capabilities are utilized exclusively.
[0087] Step 5: Feature Adaptation Transformation
[0088] A learnable feature adapter performs feature transformation on each visual feature vector. The feature adapter employs a two-layer fully connected network structure: the first fully connected layer maps the input feature dimension from 512 to 1024, expanding the expressive power of the features; a Gaussian error linear unit (GELU) is used as the activation function between the first and second layers, introducing a non-linear transformation; the second fully connected layer maps the feature dimension back from 1024 to 512, restoring the original feature dimension. A residual connection is used to add the adapter's output to the input visual feature vector, preserving the original feature information. Finally, L2 normalization is applied to the output features, ensuring the feature vector lies on a unit hypersphere, facilitating subsequent similarity calculations.
[0089] Step Six: Image Cue Feature Matrix Construction
[0090] A feature matrix for image prompts is constructed by combining positive and negative prompt features. Specifically, positive prompt features are placed at the beginning of the feature matrix, and negative prompt features are placed at the end. The index positions of the positive prompt features within the feature matrix are recorded for subsequent label assignment. The feature matrix has a dimension equal to the total number of prompts multiplied by 512, where the total number of prompts equals the sum of the number of positive and negative samples.
[0091] For example, when using 3 positive sample features and 30 negative sample features, the 3 positive sample features are arranged first and the 30 negative sample features are arranged last to construct a 33×512 dimensional image cue feature matrix, and the positive sample index range is recorded as [0,2].
[0092] Step 7: Training Image Feature Extraction
[0093] The current training image is input into the image backbone network to extract multi-scale image features. The image backbone network adopts a deep convolutional neural network architecture, such as the CSPDarknet network. The image backbone network outputs feature maps at three scales, with resolutions of 1 / 8, 1 / 16, and 1 / 32 of the input image, corresponding to different receptive field sizes, for detecting individual pet targets at different scales.
[0094] For example, when the training image is 640*640 pixels, it is input into the CSPDarknet-53 backbone network to extract feature maps at three scales with resolutions of 80*80, 40*40, and 20*20, respectively.
[0095] Step 8: Multimodal Feature Fusion
[0096] Multi-scale image features and image cue feature matrices are input into a multimodal feature fusion network to obtain a fused feature map. The multimodal feature fusion network employs a feature pyramid structure, containing both top-down and bottom-up paths. During the fusion process, a cue-guided attention mechanism is introduced, calculating the attention weights between image features and each cue feature, and enhancing the image features based on these weights. This attention mechanism enables image features to focus on regions related to the cue features, improving the expressive power of the features.
[0097] Step 9: Similarity Score Calculation
[0098] The similarity score between each spatial location in the fused feature map and each cue feature in the image cue feature matrix is calculated by comparing the learning head. Specifically, the fused feature map is batch-normalized to ensure uniform mean and variance across all channels. Then, each cue feature in the image cue feature matrix is L2-normalized. Next, the dot product similarity between the feature vectors at each spatial location in the fused feature map and each cue feature is calculated; this dot product similarity is equivalent to cosine similarity. Finally, the dot product similarity is adjusted using a learnable scaling factor and bias adjustment to obtain the final similarity score.
[0099] The similarity score represents the probability that the spatial location belongs to the individual pet corresponding to each prompt.
[0100] Step 10: Tag Assignment
[0101] Label assignment is performed based on the bounding box annotations and similarity scores of the training images. The specific method is as follows: First, prior boxes corresponding to each spatial location in the feature map are generated; then, the intersection-over-union (IoU) ratio between the prior boxes and the ground truth bounding boxes is calculated; next, the similarity score corresponding to the prior box location is calculated; finally, an alignment metric is calculated based on the IoU and similarity scores, and the prior boxes with the highest alignment metrics are selected as positive sample locations, with the remainder being negative sample locations. For positive sample locations, the target label is the alignment metric score, which is assigned to the corresponding positive sample cue index; for negative sample locations, the target label is zero.
[0102] Step 11: Loss Function Calculation
[0103] The loss function is calculated based on the prediction results and the target label. The loss function consists of two parts:
[0104] The first part is the classification loss, which uses the binary cross-entropy loss function to calculate the difference between the predicted similarity score and the target label. For positive sample positions, the binary cross-entropy loss is calculated for the corresponding positive sample cue index position; for negative sample positions, the binary cross-entropy loss is calculated for all cue index positions. The weight coefficient for the classification loss is 0.5.
[0105] The second part is the bounding box loss, which uses the Full Intersection over Union (MIU) loss function and is calculated only for positive sample locations. The MTU loss considers not only the overlap area between the predicted box and the ground truth box, but also the consistency of the center point distance and aspect ratio, thus more accurately measuring the localization accuracy of the bounding box.
[0106] The third part is the L1 Loss of key points on the pet's body.
[0107] The total loss is a weighted sum of the three losses. The gradient is calculated using the backpropagation algorithm to update the network parameters. During training, only the parameters of the feature adapter are updated; the remaining network parameters remain frozen.
[0108] III. Reasoning and Testing Phase
[0109] This stage utilizes a pre-trained coarse-grained global detection model to quickly filter out candidate targets that may contain the pet in the reference image, obtaining coarse-grained similar targets. Pose generation technology is used to enhance the robustness of the detection. Specifically, the following steps are included:
[0110] Step 1: Obtain a reference image of the individual pet to be queried.
[0111] Obtain a reference image of the individual pet to be queried and authenticated. The reference image can be one or more images, preferably showing the pet's clear frontal view with its face clearly visible.
[0112] Step 2: Construct an enhanced hint set
[0113] The original reference image is input into the visual encoder to obtain cue map features.
[0114] Step 3: Target Image Detection
[0115] The target image is input into the trained model, multi-scale image features are extracted, and fused with the image cue feature matrix to calculate the similarity score between each position and the cue features.
[0116] Step Six: Output Results
[0117] The similarity scores are subjected to threshold filtering and non-maximum suppression, and the detected pet bounding boxes, similarity scores, and corresponding cue indices are output. If the cue index corresponding to the detected bounding box belongs to the index range of the enhanced cue set, it means that a target pet has been detected in the image, and pets in such reference images are considered coarse-grained similar targets; if the corresponding cue index is the index of a negative sample cue, it means that other pets have been detected and should be excluded.
[0118] Phase 2: Fine-grained facial recognition, providing fine-grained similar targets.
[0119] This stage utilizes a pet face detection network and a pet face recognition network to perform fine-grained identity authentication on the coarse-grained similar targets obtained in the first stage, further eliminating false detection targets and obtaining the final detection and authentication results.
[0120] I. Dataset Construction Phase
[0121] We collected pet image data from various channels, including different breeds, ages, postures, and lighting conditions, to ensure data diversity and richness. For each pet, multiple images were required. Each image was labeled with a bounding box for the facial region, including five key points: eyes, nose, and the corners of the mouth, creating a pet face detection and localization dataset. After labeling, the facial region was extracted to create a separate pet face recognition dataset.
[0122] II. Model Training Phase
[0123] Step 1: Using a pet face detection and localization dataset, train a deep learning-based pet face detection network with keypoint localization. This network can detect facial regions in an image and provide the localization keypoints of the facial features;
[0124] Step 1: Train a pet face recognition network using the aforementioned pet face recognition dataset. This network can extract the identifying features of a pet's face for identity comparison between different individual pets.
[0125] III. Reasoning Stage
[0126] All coarse-grained similar targets obtained in the first stage are used as input for fine-grained identity authentication.
[0127] Step 1: Input the image region corresponding to each coarse-grained similar target into the detection and localization network to obtain the pet's face region and key point localization information;
[0128] Step 2: Based on the detected facial key points, align the pet's face area and then scale it to a uniform size, such as 224*224 pixels.
[0129] Step 3: Input the aligned and normalized pet face image into the pet face recognition network to extract the pet's facial identity features;
[0130] Step 4: Calculate the similarity between the features obtained in Step 3 and the features of the pet's face to be matched. If the similarity is greater than a preset threshold, the coarse-grained similarity target is determined to be the target pet individual and is used as a fine-grained similarity target; if the similarity is less than or equal to the preset threshold, it is determined to be a false detection target and is excluded.
[0131] Step 5: Output the final result
[0132] Output the bounding boxes, similarity scores, and identity information of all fine-grained similar targets as the final detection and authentication results.
[0133] Example 2:
[0134] This embodiment provides a detection and authentication system for a specific pet in an image, used to implement the detection and authentication method described in Embodiment 1. The system includes:
[0135] Data processing module: used to build basic datasets for individual pets, perform image annotation, construct a pose template library, generate multi-pose images based on a diffusion model, and finally build an enhanced dataset;
[0136] Model training module: Connected to the data processing module, it is used to train a coarse-grained global detection model, a pet face detection network, and a pet face recognition network based on the augmented dataset;
[0137] Inference and Authentication Module: Connected to the model training module, it is used to obtain reference images of the pet to be queried, generate a set of multi-pose enhanced prompts and construct an image prompt feature matrix. First, it uses a coarse-grained overall detection model to filter candidate targets to obtain coarse-grained similar targets. Then, it uses a pet face detection and recognition network to perform fine-grained identity authentication on the coarse-grained similar targets and outputs the final detection and authentication results.
[0138] Example 3:
[0139] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the method for detecting and authenticating a specific pet in an image as described in Embodiment 1.
[0140] This electronic device can be a variety of computing devices such as desktop computers, laptops, tablets, smartphones, and servers. The memory can include high-speed random access memory, as well as non-volatile memory, such as hard drives, RAM, plug-in hard drives, smart memory cards, secure digital cards, and flash memory cards. The processor can be a central processing unit (CPU), graphics processing unit (GPU), digital signal processor (DSP), application-specific integrated circuit (ASIC), etc.
[0141] The above embodiments are only for illustrating the technical concept and features of the present invention, and are intended to enable those skilled in the art to understand and implement the present invention. They should not be construed as limiting the scope of protection of the present invention. All equivalent changes or modifications made in accordance with the spirit and essence of the present invention should be covered within the scope of protection of the present invention.
Claims
1. A method for detecting and authenticating a specific pet in an image, characterized in that: Includes the following steps: S1: Dataset Construction and Enhancement: Construct a pet detection dataset, a pet face detection and localization dataset, a pet face recognition dataset, and a pet prompt dataset containing several individual pets. Based on the diffusion model and pose control network, multi-pose image generation is performed on the pet prompt dataset to construct an enhanced prompt dataset. S2: Model Training: Based on the pet detection dataset and the enhanced prompt dataset, a coarse-grained overall detection model is trained by combining positive and negative sample image prompts with a contrastive learning mechanism; a pet face detection network is trained based on the pet face detection and localization dataset. A pet face recognition network was trained based on a pet face recognition dataset. S3: Inference Detection and Authentication: Obtain a reference image of the pet to be queried, input it into the visual encoder, and construct image cue features; The coarse-grained overall detection model is input to obtain coarse-grained similar targets; the coarse-grained similar targets and the reference image of the pet to be queried are input into the pet face detection network and the pet face recognition network to perform fine-grained identity authentication to obtain fine-grained similar targets, and the final detection and authentication results are output.
2. The method for detecting and authenticating a specific pet in an image according to claim 1, characterized in that: Step S1 specifically includes: S11: Collect original images of pets under different lighting conditions, backgrounds, poses, and shooting angles. For each image, annotate the pet's body bounding box, body key points, face bounding box, face key points, pose, and pet ID to form a pet detection dataset. When multiple pets are present in an image within the pet detection dataset, extract each pet's image based on its bounding box. Each extracted image contains only one pet. Establish an index table corresponding to the images and individual pet identifiers to form a pet cue dataset. Extract the extracted pet images based on the pet's body bounding box annotations, and convert the coordinates of the pet's face bounding box and face key points to obtain a pet face detection dataset. Extract the pet's face image based on the face bounding box annotations and face key points, and perform alignment and normalization operations on the pet face image to form a pet recognition dataset. S12: Pose Template Library Construction: Based on the aforementioned body key points, construct a pose template library containing several standard pet poses. Each template defines the standard position coordinates of each body key point. S13: Multi-pose image generation: Using the pet cue dataset and its body key point information, generate an image of the pet in a pose that does not appear in the pose template library; S14: Enhanced Dataset Construction: The pet cue dataset is merged with the generated multi-pose images to obtain the enhanced cue dataset.
3. The method for detecting and authenticating a specific pet in an image according to claim 2, characterized in that: In step S11, the number of original images for each pet shall not be less than 3; the key body points shall include at least some of the following: head center, neck, forelimb elbow, forelimb wrist, hindlimb knee, hindlimb ankle, tail base, and abdomen center.
4. The method for detecting and authenticating a specific pet in an image according to claim 1, characterized in that: In step S2, the training of the coarse-grained overall detection model specifically includes: S21: Selection of positive sample cue images: For each individual pet in each training image, randomly select no less than 3 positive sample cue images of the corresponding individual from the augmented cue dataset of the corresponding pet, and cover at least 3 different poses; S22: Negative sample cue image selection: Negative sample cue images are randomly selected from the augmented cue dataset of other pet individuals, with the number of negative samples being 5-50 times the number of positive samples; S23: Image preprocessing prompt: Crop the individual pet area according to the bounding box annotation, perform random scaling, and then uniformly adjust it to the set size; S24: Feature Extraction and Adaptation: A pre-trained visual encoder is used to extract visual features from positive and negative sample cue images, and a learnable feature adapter is used to transform and normalize the visual features. S25: Image cue feature matrix construction: Combine positive sample features and negative sample features in sequence to construct the image cue feature matrix, and record the index range of positive samples; S26: Training Image Feature Extraction: Input the training image into the image backbone network to extract multi-scale image features; S27: Multimodal feature fusion: Input multi-scale image features and image cue feature matrix into multimodal fusion network, and introduce cue-guided attention mechanism for feature enhancement; S28: Similarity Calculation and Label Assignment: Calculate the similarity score between each spatial location of the fused feature map and each prompt feature, and assign labels based on the bounding box annotation information; S29: Loss Calculation and Parameter Update: Calculate the weighted sum of classification loss, bounding box loss, and keypoint localization loss as the total loss, and update the network parameters through backpropagation.
5. The method for detecting and authenticating a specific pet in an image according to claim 4, characterized in that: In step S24, the feature adapter adopts a two-layer fully connected network structure. The first layer maps 512-dimensional features to 1024-dimensional features; the second layer maps 1024-dimensional features back to 512-dimensional features, using residual connections, and finally performs L2 normalization.
6. The method for detecting and authenticating a specific pet in an image according to claim 4, characterized in that: In step S29, the classification loss uses binary cross-entropy loss; the bounding box loss uses full intersection-union loss; the key point localization loss uses L1 loss; during training, only the parameters of the feature adapter participate in the update, while the parameters of the visual encoder remain frozen.
7. The method for detecting and authenticating a specific pet in an image according to claim 1 or 4, characterized in that: The training of the pet face detection network and pet face recognition network in step S2 specifically includes: S211: Train a pet face detection network with keypoint localization using a pet face detection localization dataset; S212: Train a pet face recognition network using a pet face recognition dataset.
8. The method for detecting and authenticating a specific pet in an image according to claim 1, characterized in that: Step S3 specifically includes: S31: Obtain a reference image of the pet to be queried; S32: Input the reference image of the pet into the visual encoder to obtain the image cue feature matrix; S33: Input the target image into the coarse-grained global detection model, and after threshold filtering and non-maximum suppression, obtain coarse-grained similar targets; S34: Perform pet face detection, alignment and feature extraction on each coarse-grained similar target, calculate the similarity with the reference face features of the pet to be queried, and if the similarity is greater than the preset threshold, the fine-grained similar target is obtained. S35: Output the final detection and certification results.
9. A system for detecting and authenticating a specific pet in an image, characterized in that: include: The data processing module generates multi-pose images and constructs an augmented dataset. The model training module is used to train a coarse-grained overall detection model, a pet face detection network, and a pet face recognition network based on the enhanced prompt dataset. The inference authentication module is used to obtain a reference image of the pet to be queried. First, a coarse-grained overall detection model is used to obtain coarse-grained similar targets. Then, a pet face detection and recognition network is used to perform fine-grained identity authentication and output a fine authentication result. If the coarse-grained target does not have a pet face or the reference image of the pet to be queried does not have a pet face, then only coarse-grained similar targets are available.
10. An electronic device, characterized in that: It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the detection and authentication method for a specific pet in an image as described in claims 1-8.