Cross-variety target detection method and device, equipment and storage medium
The CycleGAN model generates pseudo-samples and updates the YOLOv7 model, which solves the problems of insufficient data and insufficient generalization capabilities in cross-variety target detection, and significantly improves the detection accuracy and efficiency.
Patent Information
- Application Number
- CN202411964284.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2044-12-30
AI Technical Summary
The prior art has problems such as strong data dependence, limited model generalization ability and poor cross-breeding adaptability in animal husbandry, resulting in low detection accuracy and efficiency.
The CycleGAN model is used to transfer the control varieties to the target varieties style, generate pseudo-samples, and update the target control YOLOv7 model based on the actual sample images to improve the model's training data set and generalization ability.
By generating high-quality pseudo-samples, the training data set of the model is expanded, the accuracy and efficiency of cross-variety detection are improved, the generalization ability of the model is enhanced, and the adaptability is significantly improved.
Smart Images

Figure CN119904730A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of variety detection, and specifically relates to a cross-variety target detection method, device, equipment and storage medium. Background Art
[0002] In intensive farming systems, automated monitoring and identification of various breed groups, such as pig breed groups, is crucial to improving farming efficiency. Traditional object detection technologies rely on a large amount of labeled data, which has many limitations in detection. Existing object detection models, such as YOLO and FasterR-CNN, have achieved good results in general object detection tasks, but have the following shortcomings when dealing with specific application scenarios in animal husbandry:
[0003] Strong data dependence: Existing deep learning models rely on a large amount of high-quality labeled data for training. However, in actual farms, collecting and labeling a large number of pig images is very time-consuming and costly, especially for pigs of different breeds, the amount of data is often difficult to meet the requirements of the model. The lack of small sample data sets has become the main bottleneck affecting model performance.
[0004] Poor cross-breed adaptability: Existing models are usually trained on specific breeds or scenarios, and have weak generalization capabilities. Therefore, when applied to other breeds of pigs, different breeds of pigs have significant differences in body shape, color, hair characteristics, etc., which makes the generalization ability of existing models insufficient and the detection accuracy will be significantly reduced.
[0005] Limitations of data augmentation techniques: To alleviate the problem of insufficient data, 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-species characteristics, and therefore have limited effects in practical applications.
[0006] To solve these problems, it is very necessary to provide a cross-variety small sample detection method to reduce data dependence to improve the detection accuracy of different variety groups, thereby overcoming the limitations of existing technologies. Summary of the invention
[0007] In view of the shortcomings of the prior art, the purpose of the present invention is to provide a cross-variety target detection method, device, equipment and storage medium to solve the problems in the prior art such as insufficient data, limited model generalization ability and poor cross-variety adaptability, 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] Obtain control sample images of control varieties;
[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 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;
[0011] Obtain a target control YOLOv7 model, where the target control YOLOv7 model is a model based on a YOLOv7 architecture;
[0012] Obtain actual sample images of the target species;
[0013] Determine a target sample image based on the pseudo sample image and the actual sample image;
[0014] The target sample image is input 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.
[0015] In some embodiments, inputting the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model includes:
[0016] During the updating process, the target proximal layer at the input end of the target control YOLOv7 model is controlled to be frozen, and the target proximal layer at the output end 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.
[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] Marking the control varieties in the control enhanced image with control rectangular frames;
[0020] Extracting the aspect ratio of the reference rectangular frame in the reference enhanced image based on the annotation data of the reference rectangular frame;
[0021] Clustering the aspect ratios of the control rectangular frame based on the K-means|| algorithm to obtain a control optimized anchor frame corresponding to the cluster center and the initial control anchor frame of the 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] Performing 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 selectivity of the model to features.
[0031] In some embodiments, the method further comprises:
[0032] An ECA channel attention mechanism is added in 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] A control sample image acquisition module is used to acquire a control sample image of a control variety;
[0036] A sample input module, used for inputting the control sample image into the CycleGAN model, so that the generator of the CycleGAN model converts the control sample image into a pseudo sample image having the characteristics of the target variety, wherein the CycleGAN model performs feature image optimization on the input control sample image based on the VGG19 perceptual loss function to obtain the pseudo sample image;
[0037] A target control YOLOv7 model is used to obtain a target control YOLOv7 model, wherein 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;
[0038] An actual sample image acquisition module is used to acquire an actual sample image of a target variety;
[0039] A target sample image acquisition module, used to determine a target sample image based on the pseudo sample image and the actual sample image;
[0040] 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.
[0041] According to another aspect of the present application, an electronic device is also disclosed, which 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 the above items.
[0042] According to another aspect of the present application, a computer-readable storage medium is also disclosed, on which instructions are stored, characterized in that when the instructions are executed by a processor, each step of the cross-variety target detection method as described in any of the above items is implemented.
[0043] The present invention includes but is not limited to the following beneficial effects: (1) The present invention transfers the style of the control variety to the target variety through the CycleGAN model to generate pseudo samples, thereby improving the detection efficiency and detection accuracy of the target variety under the condition of limited data volume, and by obtaining pseudo samples, the training data set of the model is expanded, thereby improving the generalization ability of the model, so that it can better adapt to new and unseen data; (2) In the process of pseudo sample generation, by using the VGG19 perceptual loss function to optimize the feature image, the quality of the generated pseudo sample image can be improved, thereby improving the recognition accuracy of the model; (3) In the present invention, by freezing the input end target proximal layer, the stability and generalization ability of the model in processing basic image features can be maintained. Furthermore, by allowing the output end target proximal 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; In a step, freezing a part of the model reduces the number of parameters that need to be trained, thereby reducing training time and computing resource consumption, which makes model updates more efficient, especially when resources are limited. By keeping the feature extraction layer of the frozen layer of the model unchanged, it can be ensured that the model maintains a certain stability when accepting new training data, preventing performance fluctuations or degradation during training; (4) The present invention uses the K-means|| algorithm to adjust the anchor frame in YOLOv7 to adapt the characteristics of the target group in different body shapes and postures, thereby increasing the detection model's accuracy in identifying the characteristics of the target group; (5) In the present invention, by introducing the ECA channel attention mechanism, the YOLOv7 model can automatically focus on important feature channels during the detection process, and more efficiently identify and distinguish the characteristics of the target group in complex environments. The addition of the ECA module enables the model to maintain a high detection performance in the case of a small amount of data and across varieties, showing significant technical effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.
[0045] Figure 1 is a flow chart of the cross-variety target detection method of the embodiment of the present application;
[0046] Figure 2 is another flow chart of the cross-variety target detection method of the embodiment of the present application;
[0047] Figure 3 is another flow chart of the cross-variety target detection method of the embodiment of the present application;
[0048] Figure 4 is another flow chart of the cross-variety target detection method of the embodiment of the present application;
[0049] Figure 5 is a structural block diagram of a cross-variety target detection device according to an embodiment of the present application;
[0050] Figure 6 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The embodiment of the present invention provides a method for cross-variety target detection according to one aspect of the present application, the method comprising obtaining a control sample image of a control variety; 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 the target variety, wherein the CycleGAN model optimizes the input control sample image based on the VGG19 perceptual loss function to obtain a pseudo sample image; obtaining a target control YOLOv7 model; obtaining an actual sample image of the target variety; determining the target sample image based on the pseudo sample image and the actual sample image; inputting the target sample image into a 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. This solution generates a pseudo sample by transferring the style of the control variety to the target variety, thereby improving the detection efficiency and detection accuracy of the target variety under the condition of limited data volume.
[0052] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0053] For ease of understanding, the specific process of the embodiment of the present invention is described below. Specifically, Figure 1 This is a flow chart of the cross-variety target detection method of this application. For details, refer to Figure 1 , including the following steps:
[0054] S100, obtaining a control sample image of a control variety.
[0055] Specifically, the control variety in the present application can be white pigs as an example, and the target variety in the present application can be Duroc pigs. It should be noted that white pigs and Duroc pigs are only exemplary descriptions. In other feasible schemes, the control variety can also be Qinchuan cattle, and the target variety can also be Yanbian cattle, or the control variety can also be Angora rabbits, and the target variety can also be lop-eared rabbits.
[0056] For ease of understanding, the control breed in this application is a white pig, and the target breed in this application is a Duroc pig. Specifically, an image of a white pig can be taken by a camera as a control sample image. In this example, the control sample images may be 1,000. These control sample images have different lighting conditions, postures, and environmental backgrounds to ensure that the generated pseudo samples are diverse.
[0057] S102: Input the control sample image into the CycleGAN model, so that the generator of the CycleGAN model converts the control sample image into a pseudo sample image having characteristics of the target variety.
[0058] Specifically, the generator learns the conversion features of white pigs to Duroc pigs, including differences in coat color, texture and morphology, so that the generated pseudo samples look more like Duroc pigs. Furthermore, the CycleGAN model optimizes the feature image of the input control sample image based on the VGG19 perceptual loss function to obtain the pseudo sample image; it can be understood that VGG19 is a deep convolutional neural network that can extract high-level semantic features in the image. By referring to the feature output of VGG19 when generating pseudo samples, it is ensured that the generated image is closer to the target breed (Duroc pig) at both the semantic and pixel levels. The traditional CycleGAN uses the mean square error (MSE) as the loss function, and the mean square error mainly focuses on pixel-level differences and is difficult to capture the overall semantic information of the image. After introducing the perceptual loss, the generated pseudo samples are more accurate in structure and details, and closer to the real Duroc pig samples. In this 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: Acquire actual sample images of the target variety.
[0062] Specifically, the images of the target breed (Duroc pig) taken by the camera can be used as the actual sample images. In this example, the actual sample images may be 37 images.
[0063] S108: Determine a 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 pseudo sample images and actual sample images.
[0065] S110, inputting 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.
[0066] Specifically, the generated 50 pseudo samples were 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 was applied to the pre-trained YOLOv7 model, and the model was gradually adapted to the new Duroc pig features through transfer learning, thereby improving the cross-breed detection capability under few sample conditions.
[0067] It should be noted that the target YOLOv7 model obtained after transfer learning training achieved an average precision (mAP) of 85.52% on the Duroc pig dataset, which is 25.34% higher than the target control YOLOv7 model of the original model. This improvement shows that the pseudo samples generated by CycleGAN effectively enhance the model's cross-breed detection ability.
[0068] It can be understood that the above technical solution transfers the style of the control variety to the target variety through the CycleGAN model to generate pseudo samples, thereby improving the detection efficiency and detection accuracy of the target variety under the condition of limited data volume, and by obtaining pseudo samples, the training data set of the model is expanded, thereby improving the generalization ability of the model, so that it can better adapt to new and unseen data; further, in the process of pseudo sample generation, by using the VGG19 perceptual loss function to optimize the feature image, the quality of the generated pseudo sample image can be improved, thereby improving the recognition accuracy of the model.
[0069] Furthermore, Figure 2 This is another flow chart of the cross-variety target detection method of the present application. For details, refer to Figure 2 , including the following steps:
[0070] S200, obtaining a control sample image of a control variety.
[0071] S202: Input the control sample image into the CycleGAN model, so that the generator of the CycleGAN model converts the control sample image into a pseudo sample image having characteristics of the target variety.
[0072] S204, obtaining a target control YOLOv7 model.
[0073] S206: Acquire actual sample images of the target variety.
[0074] S208: Determine a target sample image based on the pseudo sample image and the actual sample image.
[0075] Specifically, for the related introduction of steps S100-S208, please refer to the related introduction of steps S100-S108, which will not be repeated here.
[0076] S210, inputting the target sample image into the target control YOLOv7 model to update the target control YOLOv7 model. During the updating process, the target proximal layer at the input end of the target control YOLOv7 model is controlled to be frozen, and the target proximal layer at the output end 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.
[0077] Specifically, the target proximal layers at the input end may be the first few layers of the target control YOLOv7 model, and the target proximal layers at the output end may be the last few layers of the target control YOLOv7 model, wherein the front base layer may be the first 3 layers or the first 4 layers, and the last few layers may be the last 3 layers or the last 4 layers, which may be predetermined.
[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 generally responsible for capturing common features in images (such as edges and textures) rather than details specific to a certain variety, which helps prevent the model from overfitting to specific real sample images. Allowing the latter layers of the model to adjust can enable the model to better learn and adapt to the specific characteristics of the target variety. These layers are generally responsible for more advanced feature recognition, such as recognition of specific shapes and objects, thereby improving the detection accuracy of the target variety.
[0079] That is, by freezing the target proximal layer at the input end, the stability and generalization ability of the model in processing basic image features can be maintained. Furthermore, by allowing the target proximal layer at the output end 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 training time and computing resource consumption, which makes model updates more efficient, especially in the case of limited resources. By keeping the feature extraction layer of the frozen layer of the model unchanged, it can ensure that the model maintains a certain stability when accepting new training data, preventing performance fluctuations or degradation during training. And this update 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 coping with changing application environments and expanding data sets.
[0080] Furthermore, Figure 3 This is another flow chart of the cross-variety target detection method of the present application. For details, refer to Figure 3 , including the following steps:
[0081] S300, performing data enhancement processing on the control sample image to obtain a control enhanced image.
[0082] Specifically, the additional processing performed on the control sample image may include image enhancement means of performing Gaussian noise, salt and pepper noise, brightness adjustment, flipping, and contrast adjustment on the control sample image.
[0083] S302, marking the control varieties in the control enhanced image with control rectangular frames.
[0084] The data format of the label data of the reference rectangle is [x min ,y min ,x max ,y max ], which are the coordinates of the upper left and lower right corners of the rectangular border.
[0085] S304 : extracting the aspect ratio of the reference rectangular box in the reference enhanced image based on the annotation data of the reference rectangular box.
[0086] Specifically, for the width (width = x max -x min ) and height (height = y max -y min ) to extract and calculate the aspect ratio (width / height) of all annotation boxes.
[0087] S306. Cluster the aspect ratios of the control rectangular box based on the K-means|| algorithm to obtain a control optimized anchor box corresponding to the cluster center and the initial control anchor box of the initial control YOLOv7 model. The initial control YOLOv7 model is trained based on a training data set of control varieties, and the training data set includes multiple control training images of control varieties.
[0088] In this example, 9 cluster centers are set to adapt to the 9 initial anchor boxes configurations in the initial control YOLOv7 model. Furthermore, the Euclidean distance between each control rectangular annotation box and each cluster center is calculated, and each control rectangular annotation box is assigned to the cluster center with the nearest distance. After the assignment is completed, the cluster center is recalculated according to the aspect ratio of each cluster annotation box. Repeat the above assignment and center calculation process until the change in the cluster center is less than the set threshold (for example, 0.01) or the maximum number of iterations is reached. After several iterations, the K-means|| algorithm converges and obtains a set of aspect ratios of 9 optimized control optimized anchors (represented by Anchor+serial number in the set). For example, the following set is obtained:
[0089] Output anchor frame data: The final anchor frame set contains 9 sets of aspect ratios, 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. Update 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.
[0100] Specifically, the data of the above 9 groups of control optimized anchor frames are applied to the configuration file of the initial control YOLOv7 model to replace the initial control anchor frames in the initial control YOLOv7 model.
[0101] The results show that the model after anchor box optimization achieved 98.16% mAP on the white pig dataset, which is 1.37% higher than the unoptimized model. The model performance was further tested on the Duroc pig dataset, and the mAP of the optimized YOLOv7 model on this dataset was 85.52%, which verifies the effectiveness of anchor box optimization in cross-breed detection.
[0102] It can be understood that in the above technical solution, the K-means|| algorithm is used to adjust the anchor frame in YOLOv7 to adapt to the characteristics of the target group in different body shapes and postures, thereby increasing the detection model's ability to accurately identify the characteristics of the target group. The optimized anchor frame is more suitable for pig body characteristics, so that the model can maintain a high detection effect in pig body detection of different species and postures. This embodiment shows the significant effect of anchor frame optimization in improving the accuracy of small sample and cross-breed detection.
[0103] Furthermore, Figure 4 This is another flow chart of the cross-variety target detection method of the present application. For details, refer to Figure 4 , including the following steps:
[0104] S400: Perform data enhancement processing on the target sample image to obtain a target enhanced image.
[0105] S402: Mark the target variety in the target enhanced image with a target rectangular frame.
[0106] S404: extracting the aspect ratio of the target rectangular box in the target enhanced image based on the annotation data of the target rectangular box.
[0107] S406. Cluster the aspect ratios 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.
[0108] S408. Update the target original anchor frame of the target YOLOv7 model based on the target optimized anchor frame to obtain a target optimized 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 optimized and updated based on the K-means|| algorithm, while the steps of 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 introduction of the above steps S300-S308, and will not be repeated here.
[0110] Further, in other feasible solutions, an ECA channel attention mechanism may be added to each convolutional layer of the initial control YOLOv7 model or the target control YOLOv7 model. Or in other feasible solutions, an ECA channel attention mechanism may be added to each convolutional layer of the target YOLOv7 model or the target optimized YOLOv7 model.
[0111] It is understandable that in order to improve the feature attention ability of the YOLOv7 model in the pig target detection task, this embodiment introduces the ECA (Efficient Channel Attention) channel attention mechanism, so that the model can more effectively focus on pig body features, such as hair color, body shape and other appearance features. Specifically, the ECA module is integrated into the back of each convolutional layer, especially the backbone network of the model, to weight and select important information from the extracted features. The introduction of this module helps the model pay more attention to the key visual features of the pig body, such as hair color differences and body shape contours, thereby improving detection accuracy.
[0112] The working principle of the ECA channel attention mechanism is based on 1D convolution operation, which is used to improve feature selection without adding too many parameters. The ECA module dynamically adjusts the weights according to the feature importance of each channel. The specific principles are as follows:
[0113] Channel weighting: The ECA module calculates the weight of each channel through 1D convolution operations without using complex fully connected layers or global pooling operations. This method significantly reduces the amount of calculation and maintains the lightweight characteristics of the model.
[0114] Enhanced feature sensitivity: By giving higher weights to important features, the ECA module enables the model to have greater flexibility and sensitivity in processing information from different channels, helping to accurately distinguish pig body features in complex scenarios.
[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 detection in a changing farm environment.
[0116] The test results show that the performance test on the YOLOv7 model containing the ECA module shows that the average precision (mAP) of the model is improved by 0.93% compared with the basic model without the ECA module. Especially in scenes with dense pigs and severe occlusion, the ECA module helps the model capture key features more accurately and improves the detection stability of the model. Tests on the Duroc pig dataset found that the YOLOv7 model containing the ECA module improved the mAP by 10.58% compared with the basic model, verifying the effectiveness of the ECA module in cross-breed detection tasks.
[0117] In the embodiment 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 identify and distinguish pig body features in complex environments. The addition of the ECA module enables the model to maintain high detection performance in the case of small amounts of data and across breeds, showing significant technical effects. This lightweight attention mechanism is applicable to other target detection tasks and is also well adaptable to scenarios that require attention to specific features.
[0118] Further, according to one aspect of the present application, a cross-variety target detection device is also disclosed, such as Figure 5 As shown, the device comprises:
[0119] A control sample image acquisition module is used to acquire a control sample image of a control variety;
[0120] A sample input module, used for inputting a 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 a pseudo sample image;
[0121] A target control YOLOv7 model acquisition module is used to acquire a target control YOLOv7 model. The target control YOLOv7 model is trained based on a training data set of a control variety. The training data set includes a plurality of control training images of the control variety.
[0122] An actual sample image acquisition module is used to acquire an actual sample image of a target variety;
[0123] A target sample image acquisition module, used to determine the target sample image based on the pseudo sample image and the actual sample image;
[0124] The 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.
[0125] The application introduction of the relevant modules of the device in this example can refer to the relevant introduction of the principle of the above method, which will not be repeated here.
[0126] According to another aspect of the present application, the present application also discloses an electronic device, which includes a memory and at least one processor, wherein instructions are stored in the memory; at least one processor calls the instructions in the memory so that the electronic device executes each step of the above cross-variety target detection method.
[0127] above Figure 5 The grid warehouse billing device based on operating status in the embodiment of the present invention is described in detail from the perspective of modular functional entities, and the electronic device in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0128] Figure 6 6 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. The electronic device 600 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 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. Among them, the memory 620 and the storage medium 630 can be short-term storage or permanent storage. The program stored in the storage medium 630 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the electronic device 600. Furthermore, the processor 610 can be configured to communicate with the storage medium 630 to execute a series of instruction operations in the storage medium 630 on the electronic device 600.
[0129] The electronic device 600 may 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. It will be appreciated by those skilled in the art that Figure 6 The structure of the electronic device shown does not constitute a limitation on the electronic device, and may include more or less components than shown in the figure, or combine some components, or arrange the components differently.
[0130] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the cross-variety 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, device, or unit can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.
[0132] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.
[0133] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A cross-variety target detection method, characterized in that: The method comprises Obtain control sample images 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 a YOLOv7 architecture; Obtain actual sample images of the target species; Determine a target sample image based on the pseudo sample image and the actual sample image; The target sample image is input 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.
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 target proximal layer at the input end of the target control YOLOv7 model is controlled to be frozen, and the target proximal layer at the output end 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: 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 frame based on the K-means|| algorithm to obtain a control optimized anchor frame corresponding to the cluster center and the initial control anchor frame of the 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; 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.
4. The cross-variety target detection method according to claim 1, characterized in that: The method further comprises: Performing 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.
5. The cross-variety target detection method according to claim 3, 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 selectivity of the model to features.
6. The cross-variety target detection method according to claim 4, characterized in that: The method further comprises: An ECA channel attention mechanism is added in each convolutional layer of the target OLOv7 model or the target optimized YOLOv7 model.
7. 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.
8. A cross-variety target detection device, characterized in that: 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, used for inputting the control sample image into the CycleGAN model, so that the generator of the CycleGAN model converts the control sample image into a pseudo sample image having the characteristics of the target variety, wherein the CycleGAN model performs feature image optimization on the input control sample image based on the 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 a 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 an actual sample image of a target variety; A target sample image acquisition module, used 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.
9. 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-7.
10. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by the processor, the various steps of the cross-variety target detection method as described in any one of claims 1-7 are implemented.
Citation Information
Patent Citations
Underwater ship bottom suspicious target detection method and device, electronic equipment and readable medium
CN115294322A
Unbalanced data-oriented candy surface defect detection method
CN117541576A
Semiconductor chip pattern wafer defect detection method and device and storage medium
CN118840342A
Low-illumination obstacle detection method and system, and terminal and storage medium
WO2023065497A1
Cited By
Rongchang pig hair color identification and dynamic statistical method
CN120894579A
A method for identifying and dynamically counting the hair color of Rongchang pigs
CN120894579B