A cross-species target detection method, device, equipment and storage medium
By generating pseudo samples through the CycleGAN model and optimizing the YOLOv7 model, the problems of insufficient data and poor adaptability in cross-breed detection were solved, the detection accuracy and efficiency were improved, and it was adapted to the identification of pigs of different breeds.
Patent Information
- Application Number
- CN202411964284.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2044-12-30
AI Technical Summary
Existing target detection models in the livestock industry have poor cross-breed adaptability, strong data dependence, and limitations in data augmentation technology, resulting in decreased detection accuracy.
The CycleGAN model is used for style transfer to generate pseudo samples. The VGG19 perceptual loss function is combined to optimize the feature image, freeze the input layer, use the K-means|| algorithm to adjust the anchor box, and introduce the ECA channel attention mechanism to optimize the YOLOv7 model.
It improves the accuracy and efficiency of cross-variety detection, reduces data dependence, enhances the generalization ability of the model, reduces computing resource consumption, and improves detection stability in complex environments.
Smart Images

Figure CN119904730B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of variety detection, and particularly relates to a cross-variety target detection method, device, equipment and storage medium. BACKGROUND
[0002] In intensive breeding systems, the automatic monitoring and identification of each variety group, such as a pig variety group, is crucial to improving breeding efficiency. Traditional target detection techniques rely heavily on a large amount of labeled data, and this method has many limitations in detection. Existing target detection models, such as YOLO, FasterR-CNN, etc., although have achieved good results in general object detection tasks, but when dealing with specific application scenarios in the livestock industry, the following shortcomings are shown:
[0003] Strong data dependence: existing deep learning models rely on a large amount of high-quality labeled data for training. However, in actual breeding farms, collecting and labeling a large number of pig group images is very time-consuming and costly, especially for different varieties of pigs, the amount of data often cannot meet the requirements of the model. The lack of small sample data sets has become the main bottleneck affecting the performance of the model.
[0004] Poor adaptability across varieties: existing models are usually trained in a specific variety or specific scenario, and have weak generalization ability. Therefore, when applied to other varieties of pigs, different varieties of pigs differ significantly in size, color, hair characteristics, etc., which makes the generalization ability of existing models insufficient, and the detection accuracy will decrease significantly.
[0005] Limitations of data augmentation techniques: To alleviate the problem of data deficiency, existing methods often use data augmentation techniques (such as rotation, flipping, etc.) to expand the data set. However, these conventional data augmentation methods cannot generate high-quality samples with cross-variety characteristics, so their effectiveness is limited in practical applications.
[0006] To solve these problems, a cross-variety small sample detection method is provided to reduce data dependence and improve the detection accuracy of different variety groups, thereby overcoming the limitations of existing technology. SUMMARY
[0007] In view of the deficiencies of the prior art, the purpose of the present application is to provide a cross-variety target detection method, device, equipment and storage medium to solve the problems of data deficiency, limited model generalization ability and poor cross-variety adaptability in the prior art, and significantly improve the accuracy and efficiency of target detection.
[0008] According to one aspect of the present application, a cross-variety target detection method is disclosed, the method comprising
[0009] obtaining a control sample image of a control variety;
[0010] inputting the control sample image into a CycleGAN model, so that a generator of the CycleGAN model converts the control sample image into a pseudo sample image with target variety characteristics, wherein the CycleGAN model optimizes a feature image of the input control sample image based on a VGG19 perception loss function to obtain the pseudo sample image;
[0011] obtaining a target control YOLOv7 model, the target control YOLOv7 model being a model based on a YOLOv7 architecture;
[0012] obtaining an actual sample image of a target variety;
[0013] determining a target sample image based on the pseudo sample image and the actual sample image;
[0014] inputting the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model to obtain a target YOLOv7 model, the target YOLOv7 model being used for identifying and detecting the target variety.
[0015] In some embodiments, inputting the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model comprises:
[0016] During the updating process, a target proximal layer at an input end of the target control YOLOv7 model is controlled to be frozen, and a target proximal layer at an output end of the target control YOLOv7 model is controlled to adjust a feature of the input target sample image, so as to reduce overfitting of the target control YOLOv7 model to the actual sample image.
[0017] In some embodiments, the method further comprises:
[0018] performing image enhancement processing on the control sample image to obtain a control enhanced image;
[0019] performing control rectangular frame labeling on a control variety in the control enhanced image;
[0020] extracting an aspect ratio of the control rectangular frame in the control enhanced image based on labeled data of the control rectangular frame;
[0021] Clustering the aspect ratios of the control rectangular box based on a K-means|| algorithm to obtain a control optimized anchor box whose cluster center corresponds to an initial control anchor box of an initial control YOLOv7 model, wherein the initial control YOLOv7 model is trained based on a training data set of the control variety, and the training data set includes a plurality of control training images of the control variety;
[0022] The initial control anchor frame of the initial control YOLOv7 model is updated based on the control optimized anchor frame to obtain the target control YOLOv7 model.
[0023] In some embodiments, the method further comprises:
[0024] Perform data enhancement processing on the target sample image to obtain a target enhanced image;
[0025] Marking the target variety in the target enhanced image with a target rectangular frame;
[0026] Extracting the aspect ratio of the target rectangular box in the target enhanced image based on the annotation data of the target rectangular box;
[0027] Clustering the aspect ratio of the target rectangular box based on the K-means|| algorithm to obtain a target optimized anchor box corresponding to the cluster center and the target original anchor box of the target YOLOv7 model;
[0028] The target original anchor frame of the target YOLOv7 model is updated based on the target optimized anchor frame to obtain the target optimized YOLOv7 model.
[0029] In some embodiments, the method further comprises:
[0030] An ECA channel attention mechanism is added to each convolutional layer of the initial control YOLOv7 model or the target control YOLOv7 model to improve the model's selectivity for features.
[0031] In some embodiments, the method further comprises:
[0032] An ECA channel attention mechanism is added to each convolutional layer of the target YOLOv7 model or the target optimized YOLOv7 model.
[0033] In some embodiments, the control breed is a white pig breed, and the target breed is a Duroc pig breed.
[0034] According to another aspect of the present application, a cross-variety target detection device is also disclosed, the device comprising:
[0035] The control sample image acquisition module is configured to acquire a control sample image of a control variety;
[0036] The sample input module is configured to input the control sample image into a CycleGAN model, so that a generator of the CycleGAN model converts the control sample image into a pseudo sample image with target variety characteristics, wherein the CycleGAN model optimizes a feature image of the input control sample image based on a VGG19 perception loss function to obtain the pseudo sample image.
[0037] The target control YOLOv7 model is configured to acquire a target control YOLOv7 model, which is trained based on a training data set of the control variety, and the training data set includes multiple control training images of the control variety.
[0038] The actual sample image acquisition module is configured to acquire an actual sample image of a target variety.
[0039] The target sample image acquisition module is configured to determine a target sample image based on the pseudo sample image and the actual sample image.
[0040] The model update module is configured to input the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model, so as to obtain a target YOLOv7 model, which is configured to perform identification detection on the target variety.
[0041] According to another aspect of the present application, an electronic device is also disclosed, which includes a memory and at least one processor, the memory having instructions stored therein; the at least one processor invokes the instructions in the memory to enable the electronic device to perform the steps of the cross-variety target detection method according to any one of the above.
[0042] According to another aspect of the present application, a computer readable storage medium is also disclosed, which has instructions stored thereon, wherein the instructions are executed by a processor to implement the steps of the cross-variety target detection method according to any one of the above.
[0043] The present application includes but is not limited to the following benefits: (1) the present application performs style transfer on the control variety to the target variety through the CycleGAN model, generates pseudo samples, improves the detection efficiency and accuracy of the target variety under the condition of limited data volume, and expands the training data set of the model by obtaining pseudo samples, thereby improving the generalization ability of the model, so that it can better adapt to new and unseen data; (2) in the pseudo sample generation process, the quality of the generated pseudo sample image can be improved by using the VGG19 perception loss function for feature image optimization, thereby improving the recognition accuracy of the model; (3) in the present application, by freezing the input end target near-end layer, the stability and generalization ability of the model in processing basic image features can be maintained, further, allowing the output end target near-end layer of the model to adjust the features of the target sample, the model can better learn and adapt to the specific features of the target variety, thereby improving the detection accuracy of the target variety; further, freezing part of the model reduces the number of parameters that need to be trained, thereby reducing the training time and computational resource consumption, which makes the model updating more efficient, especially in the case of limited resources, by keeping the feature extraction layer of the frozen layer of the model unchanged, the stability of the model can be ensured when receiving new training data, preventing performance fluctuations or degradation during training; (4) in the present application, the K-means|| algorithm is used to adjust the anchor box in YOLOv7, adapt to the features of the target group in different sizes and postures, and increase the accurate identification of the detection model to the features of the target group; (5) in the present application, by introducing the ECA channel attention mechanism, the YOLOv7 model can automatically focus on important feature channels during detection, and can more efficiently identify and distinguish target group features in complex environments, the addition of the ECA module enables the model to maintain high detection performance under the condition of small amount of data and cross variety, showing significant technical effects. BRIEF DESCRIPTION OF DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows.
[0045] Figure 1 is a flowchart of the cross-variety target detection method of the present application;
[0046] Figure 2 is another flowchart of the cross-variety target detection method of the present application;
[0047] Figure 3 is another flowchart of the cross-variety target detection method of the present application;
[0048] Figure 4 is another flowchart of the cross-variety target detection method of the present application;
[0049] Figure 5 is a structural block diagram of a cross-species target detection device of an embodiment of the present application;
[0050] Figure 6 is a structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0051] An embodiment of the present application provides a cross-species target detection method according to one aspect of the present application, which comprises the following steps: obtaining a control sample image of a control species; inputting the control sample image into a CycleGAN model, so that a generator of the CycleGAN model converts the control sample image into a pseudo sample image with target species characteristics, wherein the CycleGAN model optimizes the input control sample image based on a VGG19 perception loss function to obtain the pseudo sample image; obtaining a target control YOLOv7 model; obtaining an actual sample image of a target species; determining a target sample image based on the pseudo sample image and the actual sample image; inputting the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model to obtain a target YOLOv7 model, which is used for identifying and detecting the target species. The present scheme improves the detection efficiency and detection accuracy of the target species under the condition of limited data quantity by performing style transfer of the control species to the target species to generate a pseudo sample.
[0052] The terms "first", "second", "third", "fourth" and the like in the description, claims, as well as throughout the figures of the present application, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the use of the terms so termed herein is to be interpreted to only cover the embodiments described or depicted herein and not a priori to cover all possible embodiments in which similar objects occur. In other words, similar objects are not necessarily to be interpreted as being constituted by the same elements or units, unless explicitly so defined herein. It is to be understood that the data so used can be interchanged, where appropriate, to refer to a similar embodiment, to the embodiments described or depicted herein. In addition, the terms "comprising", "having" and any of their derivatives, are intended to cover non-exclusive inclusions, for example, a process, method, system, product or apparatus that includes a list of steps or units is not necessarily limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to such a process, method, product or apparatus.
[0053] For the sake of understanding, the specific flow of the embodiments of the present application is described below, and specifically, Figure 1 is a flowchart of a cross-species target detection method of the present application, and specifically, refer to Figure 1 , comprising the following steps:
[0054] S100, obtaining a control sample image of a control species.
[0055] Specifically, the control breed in the present application can be taken as white pigs, and the target breed in the present application can be taken as Duroc pigs. It should be noted that white pigs and Duroc pigs are only an example, and in other implementable schemes, the control breed can also be a Qinchuan cattle, and the target breed can also be a Yonbong cattle, or the control breed can also be an Angora rabbit, and the target breed can also be a lop-eared rabbit.
[0056] For the convenience of understanding, the control breed in the present application is taken as white pigs, and the target breed in the present application is taken as Duroc pigs. Specifically, the images of white pigs can be taken by a camera as control sample images, and in the present example, the control sample images can be 1000.
[0057] S102, inputting the control sample images into the CycleGAN model, so that the generator Generator of the CycleGAN model converts the control sample images into pseudo sample images with target breed characteristics.
[0058] Specifically, the generator learns the conversion characteristics from white pigs to Duroc pigs, including the differences in coat color, texture and morphology, so that the generated pseudo sample looks more like a Duroc pig. Further, the CycleGAN model optimizes the feature images of the input control sample images based on the VGG19 perceptual loss function to obtain pseudo sample images; it can be understood that VGG19 is a deep convolutional neural network that can extract high-level semantic features in images. By referring to the feature output of VGG19 when generating pseudo samples, it is ensured that the generated images are closer to the target breed (Duroc pig) in terms of semantics and pixels. Traditional CycleGAN uses mean square error (MSE) as the loss function, and mean square error mainly focuses on pixel-level differences, which is difficult to capture the overall semantic information of the image. After introducing the perceptual loss, the generated pseudo sample is more accurate in structure and details, and closer to the real Duroc pig sample. In the present example, 50 pseudo sample images are obtained.
[0059] S104, obtaining a target control YOLOv7 model.
[0060] Specifically, the target control YOLOv7 model is a model based on the YOLOv7 framework.
[0061] S106, obtaining actual sample images of the target breed.
[0062] Specifically, the images of the target breed (Duroc pig) can be taken by a camera as actual sample images. In the present example, the actual sample images can be 37.
[0063] S108, determine the target sample image based on the pseudo sample image and the actual sample image.
[0064] It can be understood that the target sample image is a collection of the pseudo sample image and the actual sample image.
[0065] S110, input the target sample image into the target YOLOv7 model to update the target YOLOv7 model to obtain a target YOLOv7 model, and the target YOLOv7 model is used for identifying and detecting the target breed.
[0066] Specifically, the generated 50 pseudo samples are mixed with the actual Duroc pig dataset (37 actual sample images) in proportion to form an enhanced Duroc dataset for transfer learning training of the YOLOv7 model. The expanded Duroc dataset is applied to the pre-trained YOLOv7 model, and the model is gradually adapted to new Duroc pig features through transfer learning, thereby improving the cross-breed detection capability under the condition of few samples.
[0067] It should be noted that the target YOLOv7 model obtained after transfer learning training reaches an average precision (mAP) of 85.52% on the Duroc pig dataset, which is improved by 25.34% compared with the original model of the target YOLOv7 model. This improvement shows that the pseudo samples generated by CycleGAN effectively enhance the cross-breed detection capability of the model.
[0068] It can be understood that the above technical solution performs style transfer of the control breed to the target breed through the CycleGAN model to generate pseudo samples, which improves the detection efficiency and detection accuracy of the target breed under the condition of limited data volume, and by obtaining pseudo samples, the training dataset of the model is expanded, thereby improving the generalization capability of the model, so that it can better adapt to new and unseen data; further, in the pseudo sample generation process, the VGG19 perception loss function is used for feature image optimization, which can improve the quality of the generated pseudo sample image, and further improve the recognition accuracy of the model.
[0069] Further, Figure 2 Another flowchart of the cross-breed target detection method of the present application, specifically referring to Figure 2 , comprising the following steps:
[0070] S200, obtaining a control sample image of a control breed.
[0071] S202, inputting the control sample image into the CycleGAN model to convert the control sample image into a pseudo sample image with target breed characteristics by the generator Generator of the CycleGAN model.
[0072] S204, acquire the target contrast YOLOv7 model.
[0073] S206, acquire the actual sample image of the target variety.
[0074] S208, determine the target sample image based on the pseudo sample image and the actual sample image.
[0075] Specifically, the related introduction of steps S100-S208 can refer to the related introduction of steps S100-S108, which will not be repeated here.
[0076] S210, input the target sample image into the target contrast YOLOv7 model to update the target contrast YOLOv7 model. During the updating process, the input end target near end layer of the target contrast YOLOv7 model is controlled to be frozen, and the output end target near end layer of the target contrast YOLOv7 model is controlled to adjust the features of the input target sample image, so as to reduce the overfitting of the target contrast YOLOv7 model to the actual sample image.
[0077] Specifically, the input end target near end layer can be the first few layers of the target contrast YOLOv7 model, and the output end target near end layer can be the last few layers of the target contrast YOLOv7 model. Wherein, whether the first few layers are the first 3 layers or the first 4 layers, and whether the last few layers are the last 3 layers or the last 4 layers can be determined in advance.
[0078] It can be understood that by freezing the first few layers, the stability and generalization ability of the model in processing basic image features can be maintained. These layers are usually responsible for capturing general features in images (such as edges and textures), rather than details specific to a certain variety, which helps to prevent the model from overfitting to specific actual sample images. Allowing the last few layers of the model to be adjusted can make the model better learn and adapt to the specific features of the target variety. These layers are usually responsible for higher-level feature recognition, such as the recognition of specific shapes and objects, thereby improving the detection accuracy of the target variety.
[0079] That is, by freezing the target near-end layer of the input end, the stability and generalization ability of the model in processing basic image features can be maintained, further, allowing the output target near-end layer of the model to adjust the features of the target sample can make the model better learn and adapt to the specific features of the target variety, thereby improving the detection accuracy of the target variety; further, freezing part of the model reduces the number of parameters that need to be trained, thereby reducing the training time and computational resource consumption, which makes the model updating more efficient, especially in the case of limited resources. By keeping the feature extraction layer of the frozen layer of the model unchanged, the stability of the model when receiving new training data can be ensured, preventing performance fluctuations or degradation during training. And this updating strategy provides a flexible way to adjust the model to adapt to new data sets or tasks while maintaining the use of existing knowledge, which is particularly important for dealing with changing application environments and expanding data sets.
[0080] Further, Figure 3 For another flowchart of the cross-variety target detection method of the present application, specifically, refer to Figure 3 , comprising the following steps:
[0081] S300, data enhancement processing is performed on the control sample image to obtain a control enhanced image.
[0082] Specifically, the increase processing of the control sample image can include Gaussian noise, salt and pepper noise, brightness adjustment, flipping, and contrast adjustment image enhancement means.
[0083] S302, the control variety in the control enhanced image is labeled with a control rectangular frame.
[0084] Wherein, the data format of the labeling data of the control rectangular frame is [x min ,y min ,x max ,y max ], that is, the coordinates of the upper left corner and the lower right corner of the rectangular frame.
[0085] S304, the aspect ratio of the control rectangular frame in the control enhanced image is extracted based on the labeling data of the control rectangular frame.
[0086] Specifically, the width (width=x max -x min ) and height (height=y max -y min ) in the labeling data are extracted, and the aspect ratio (width / height) of all labeled frames is calculated.
[0087] S306, cluster the aspect ratios of the control rectangular boxes based on the K-means|| algorithm to obtain control optimized anchor boxes corresponding to the clustering centers and the initial control anchor boxes of the initial control YOLOv7 model, the initial control YOLOv7 model being trained based on a training data set of the control variety, the training data set including multiple control training images of the control variety.
[0088] In this example, 9 clustering centers are set to adapt to the configuration of 9 initial anchor boxes in the initial control YOLOv7 model. Further, the Euclidean distance between each control rectangular annotation box and each clustering center is calculated, and each control rectangular annotation box is assigned to the nearest clustering center. After the assignment is completed, the clustering centers are recalculated according to the aspect ratios of the clustered annotation boxes. The assignment and center calculation process are repeated until the change in the clustering centers is less than a set threshold (e.g., 0.01) or the maximum number of iterations is reached. After several iterations, the K-means|| algorithm converges, and a set of 9 optimized control optimized anchor (indicated as Anchor+ serial number in the set) boxes is obtained. For example, the following set is obtained:
[0089] Output anchor box data: the final anchor box set contains 9 groups of aspect ratio values, and the specific format is as follows:
[0090] Anchor 1: [width=23, height=69]
[0091] Anchor 2: [width=46, height=49]
[0092] Anchor 3: [width=30, height=100]
[0093] Anchor 4: [width=43, height=86]
[0094] Anchor 5: [width=85, height=56]
[0095] Anchor 6: [width=66, height=78]
[0096] Anchor 7: [width=46, height=132]
[0097] Anchor 8: [width=99, height=83]
[0098] Anchor 9: [width=73, height=126].
[0099] S308, updating the initial anchor box of the initial contrast YOLOv7 model based on the contrast optimization anchor box to obtain a target contrast YOLOv7 model.
[0100] Specifically, the data of the above 9 groups of contrast optimization anchor boxes are applied to the configuration file of the initial contrast YOLOv7 model to replace the initial contrast anchor boxes in the initial contrast YOLOv7 model.
[0101] It is tested that the model after anchor box optimization achieves 98.16% mAP on the white pig dataset, which is 1.37% higher than the unoptimized model. Further testing the model performance on the Duroc pig dataset, the mAP of the optimized YOLOv7 model on the dataset is 85.52%, which verifies the effectiveness of anchor box optimization in cross-species detection.
[0102] It can be understood that in the above technical solution, the K-means|| algorithm is used to adjust the anchor box in YOLOv7, adapt to the characteristics of the target group in different sizes and postures, and increase the accurate recognition of the target group characteristics by the detection model. The optimized anchor box is more suitable for pig body characteristics, so that the model can maintain high detection effect in the detection of pigs of different species and postures. This embodiment shows the significant effect of anchor box optimization in improving the accuracy of small sample and cross-species detection.
[0103] Further, Figure 4 Another flowchart of the cross-species target detection method of the present application, specifically referring to Figure 4 , comprising the following steps:
[0104] S400, performing data enhancement processing on the target sample image to obtain a target enhanced image.
[0105] S402, labeling the target rectangular frame in the target enhanced image.
[0106] S404, extracting the width-height ratio of the target rectangular frame in the target enhanced image based on the labeling data of the target rectangular frame.
[0107] S406, clustering the width-height ratio of the target rectangular frame based on the K-means|| algorithm to obtain a target optimization anchor box corresponding to the target original anchor box of the target YOLOv7 model.
[0108] S408, updating the target original anchor box of the target YOLOv7 model based on the target optimization anchor box to obtain a target optimization YOLOv7 model.
[0109] It can be understood that the principles of steps S400-S408 are the same as those of steps S300-S308, except that in this example, the target YOLOv7 model for identifying the target variety is updated and optimized based on the K-means|| algorithm, while the steps S300-S308 are to optimize the initial control YOLOv7 model for identifying the control variety. The specific principles can be understood by analogy with the above description of steps S300-S308, which will not be repeated here.
[0110] Further, in other implementable schemes, an ECA channel attention mechanism can also be added in each convolutional layer of the initial control YOLOv7 model or the target control YOLOv7 model. Or in other implementable schemes, an ECA channel attention mechanism can also be added in each convolutional layer of the target OLOv7 model or the target optimized YOLOv7 model.
[0111] It can be understood that in order to improve the feature attention ability of the YOLOv7 model in the pig target detection task, the ECA (Efficient Channel Attention) channel attention mechanism is introduced in this embodiment, so that the model can focus more effectively on the pig body features such as coat color, body shape and other appearance features. Specifically, the ECA module is integrated into the back of each convolutional layer, especially in the backbone network of the model, for weighted selection of important information in the extracted features. The introduction of this module helps the model to pay more attention to the key visual features of the pig body, such as coat color difference and body shape outline, thereby improving the detection accuracy.
[0112] The working principle of the ECA channel attention mechanism is based on 1D convolution operation, which improves the feature selection ability without increasing too many parameters. The ECA module dynamically adjusts the weights according to the importance of each channel, and the specific principle is as follows:
[0113] Channel weighting: the ECA module calculates the weights of each channel through 1D convolution operation, without using complex fully connected layers or global pooling operations. This method significantly reduces the computational complexity, so that the lightweight characteristics of the model can be maintained.
[0114] Enhanced feature sensitivity: by giving important features higher weights, the ECA module enables the model to have higher flexibility and sensitivity when processing information in different channels, which helps to accurately distinguish pig body features in complex scenes.
[0115] This lightweight convolution-based attention mechanism significantly improves the model's ability to capture specific features while maintaining computational efficiency, making the YOLOv7 model more robust in detecting pigs in a variety of farm environments.
[0116] The test results show that the performance test is performed on the YOLOv7 model containing the ECA module, and the results show that the average precision (mAP) of the model is improved by 0.93% compared with the base model without the ECA module. Especially in the scene where the pig group is dense and the occlusion is serious, the ECA module helps the model to capture the key features more accurately, and improves the detection stability of the model. On the Duroc pig dataset, it is found that the YOLOv7 model containing the ECA module improves the mAP by 10.58% compared with the base model, verifying the effectiveness of the ECA module in the cross-breed detection task.
[0117] In the embodiments of the present application, by introducing the ECA channel attention mechanism, the YOLOv7 model can automatically focus on important feature channels during the detection process, and more efficiently recognize and distinguish pig body features in complex environments. The addition of the ECA module enables the model to maintain high detection performance with a small amount of data and across breeds, showing significant technical effects. This lightweight attention mechanism is suitable for other target detection tasks and is also well adapted to scenes that require specific feature attention.
[0118] Further, according to an aspect of the present application, a cross-breed target detection device is also disclosed, as shown in Figure 5 The device comprises:
[0119] A control sample image acquisition module is configured to acquire a control sample image of a control breed;
[0120] A sample input module is configured to input the control sample image into a CycleGAN model, so that a generator of the CycleGAN model converts the control sample image into a pseudo sample image with target breed characteristics, wherein the CycleGAN model optimizes the input control sample image based on a VGG19 perception loss function to obtain the pseudo sample image;
[0121] A target control YOLOv7 model acquisition module is configured to acquire a target control YOLOv7 model, which is trained based on a training data set of the control breed, and the training data set includes multiple control training images of the control breed;
[0122] An actual sample image acquisition module is configured to acquire an actual sample image of a target breed;
[0123] A target sample image acquisition module is configured to determine a target sample image based on the pseudo sample image and the actual sample image;
[0124] The model updating module is configured to input the target sample image into the target contrast YOLOv7 model to update the target contrast YOLOv7 model, so as to obtain a target YOLOv7 model, and the target YOLOv7 model is configured to recognize and detect the target variety.
[0125] The application of the related modules of the device in this example can refer to the related description of the above method principle, which will not be repeated here.
[0126] According to another aspect of the present application, the present application also discloses an electronic device, which comprises a memory and at least one processor, the memory stores instructions; the at least one processor invokes the instructions in the memory to enable the electronic device to perform the steps of the cross-variety target detection method as above.
[0127] The above Figure 5 The grid warehouse billing device based on the operating state in the embodiment of the present application is described in detail from the perspective of modular functional entities, and the electronic device in the embodiment of the present application is described in detail from the perspective of hardware processing.
[0128] Figure 6 is a structural schematic diagram of an electronic device provided by the embodiment of the present application. The electronic device 600 can have great differences due to different configurations or performances, and can include one or more processors (central processing units, CPUs) 610 (for example, one or more processors) and a memory 620, and one or more storage media 630 (for example, one or more mass storage devices) storing application programs 633 or data 632. The memory 620 and the storage media 630 can be temporary storage or persistent storage. The programs stored in the storage media 630 can include one or more modules (not shown in the figure), and each module can include a series of instruction operations in the electronic device 600. Furthermore, the processor 610 can be configured to communicate with the storage media 630 and execute a series of instruction operations in the storage media 630 on the electronic device 600.
[0129] The electronic device 600 can also include one or more power supplies 640, one or more wired or wireless network interfaces 650, one or more input and output interfaces 650, and / or one or more operating systems 631, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art can understand that Figure 6 The electronic device structure shown does not constitute a limitation based on the electronic device, and can include more or fewer components than shown, or combine certain components, or different component arrangements.
[0130] The application further provides a computer readable storage medium, which can be a nonvolatile computer readable storage medium or a volatile computer readable storage medium, and the computer readable storage medium stores instructions, and when the instructions are executed on a computer, the computer executes the steps of the cross-species target detection method.
[0131] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system or device, unit can refer to the corresponding process in the foregoing method embodiments, and will not be described here.
[0132] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application or the whole or part of the technical solutions that make essential contributions to the prior art can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the embodiments of the method of the present application. The foregoing storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various program code storage media.
[0133] The above, the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A cross-variety target detection method, characterized in that: The method comprises Obtain images of control samples of control varieties; Inputting the control sample image into a CycleGAN model so that a generator of the CycleGAN model converts the control sample image into a pseudo sample image having characteristics of a target variety, wherein the CycleGAN model performs feature image optimization on the input control sample image based on a VGG19 perceptual loss function to obtain the pseudo sample image; Obtain a target control YOLOv7 model, where the target control YOLOv7 model is a model based on the YOLOv7 architecture; Obtain actual sample images of the target species; determining a target sample image based on the pseudo sample image and the actual sample image; Inputting the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model to obtain a target YOLOv7 model, wherein the target YOLOv7 model is used to identify and detect the target variety; performing data enhancement on the control sample image to obtain a control enhanced image; Marking the control varieties in the control enhanced image with control rectangular frames; extracting the aspect ratio of the reference rectangular frame in the reference enhanced image based on the annotation data of the reference rectangular frame; Clustering the aspect ratios of the control rectangular box based on a K-means|| algorithm to obtain a control optimized anchor box whose cluster center corresponds to an initial control anchor box of an initial control YOLOv7 model, wherein the initial control YOLOv7 model is trained based on a training data set of the control variety, and the training data set includes a plurality of control training images of the control variety; Updating the initial control anchor frame of the initial control YOLOv7 model based on the control optimized anchor frame to obtain the target control YOLOv7 model; Perform data enhancement processing on the target sample image to obtain a target enhanced image; Marking the target variety in the target enhanced image with a target rectangular frame; Extracting the aspect ratio of the target rectangular box in the target enhanced image based on the annotation data of the target rectangular box; Clustering the aspect ratio of the target rectangular box based on the K-means|| algorithm to obtain a target optimized anchor box corresponding to the cluster center and the target original anchor box of the target YOLOv7 model; The target original anchor frame of the target YOLOv7 model is updated based on the target optimized anchor frame to obtain the target optimized YOLOv7 model.
2. The cross-variety target detection method according to claim 1, characterized in that: Inputting the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model includes: During the updating process, the input-end target proximal layer of the target control YOLOv7 model is controlled to be frozen, and the output-end target proximal layer of the target control YOLOv7 model is controlled to perform feature adjustment on the input target sample image to reduce overfitting of the target control YOLOv7 model to the actual sample image.
3. The cross-variety target detection method according to claim 1, characterized in that: The method further comprises: An ECA channel attention mechanism is added to each convolutional layer of the initial control YOLOv7 model or the target control YOLOv7 model to improve the model's selectivity for features.
4. The cross-variety target detection method according to claim 1, characterized in that: The method further comprises: An ECA channel attention mechanism is added to each convolutional layer of the target OLOv7 model or the target optimized YOLOv7 model.
5. The cross-variety target detection method according to claim 1, characterized in that: The control breed is a white pig breed, and the target breed is a Duroc pig breed.
6. A cross-category target detection device, characterized in that: The device is used to perform the method according to any one of claims 1 to 5, and the device comprises: A control sample image acquisition module is used to acquire a control sample image of a control variety; A sample input module, configured to input the control sample image into a CycleGAN model, so that a generator of the CycleGAN model converts the control sample image into a pseudo sample image having characteristics of a target variety, wherein the CycleGAN model performs feature image optimization on the input control sample image based on a VGG19 perceptual loss function to obtain the pseudo sample image; A target control YOLOv7 model acquisition module is used to acquire a target control YOLOv7 model, wherein the target control YOLOv7 model is a model based on the YOLOv7 architecture, and the target control YOLOv7 model is trained based on a training data set of the control variety, wherein the training data set includes a plurality of control training images of the control variety; An actual sample image acquisition module is used to acquire actual sample images of target varieties; a target sample image acquisition module, configured to determine a target sample image based on the pseudo sample image and the actual sample image; A model updating module is used to input the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model to obtain a target YOLOv7 model, and the target YOLOv7 model is used to identify and detect the target variety.
7. An electronic device, characterized in that: The electronic device includes a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the electronic device executes each step of the cross-variety target detection method as described in any one of claims 1-5.
8. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by a processor, the steps of the cross-variety target detection method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Underwater ship bottom suspicious target detection method and device, electronic equipment and readable medium
CN115294322A
Semiconductor chip pattern wafer defect detection method and device and storage medium
CN118840342A