Image recognition method, device and medium for each animal in a livestock farm in edge scenes
By integrating the lightweight and complete target detection model of the YOLOv5 model in edge scenarios and using the cumulative confidence algorithm, the problem of insufficient computing resources and multi-scale issues in the target detection algorithm in the livestock farm is solved, achieving high accuracy and Efficient animal identification.
Patent Information
- Application Number
- CN202410949717.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-16
AI Technical Summary
In livestock farms in edge scenarios, target detection algorithms are difficult to meet the accuracy and real-time requirements due to insufficient computing resources and low recognition rates. Moreover, existing methods cannot effectively solve multi-scale problems and the problem of missed and wrong detection of small targets. .
Using the fusion processing of lightweight and complete target detection models based on the YOLOv5 model, the appropriate model is selected for detection through decision control, and the cumulative confidence algorithm is used to fuse the results to improve recognition accuracy and efficiency.
It significantly improves the accuracy and efficiency of animal recognition, can flexibly select models according to the environment, meets real-time requirements, and improves robustness and accuracy through cumulative confidence decision-making.
Smart Images

Figure CN118485823B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image recognition technology, and in particular to a method, device and medium for image recognition of animals in a livestock farm in an edge scene. Background Art
[0002] With the rapid development of artificial intelligence, target detection technology, as a branch of computer vision, has achieved many breakthrough results. Thanks to the breakthrough in technology, target detection technology has gradually moved towards practical application and has been widely used in many fields such as autonomous driving, video surveillance, national defense and military. In animal husbandry, the recognition and classification of animals has made great progress, but there are still some problems. First, some farms are in remote areas, and target detection algorithms need to be deployed more on edge and mobile devices, which is a challenge for the computing power and memory of the equipment. In edge scenarios, due to the complex environmental background and insufficient computing resources of the equipment, the recognition rate of the target is greatly reduced. In some complex scenarios, the learning ability is insufficient, resulting in the inability to effectively distinguish the target information. The conventional model structure is large in size and the detection speed is slow, which cannot take into account the accuracy and real-time requirements. Secondly, the existing methods cannot solve the multi-scale problem well, especially for small targets. There are cases of missed detection and false detection.
[0003] Faced with the challenge of limited local computing resources, edge computing came into being and provided a practical solution. In the process of computing offloading of edge computing, multiple factors must be carefully weighed, including the size and content of the data to be offloaded, the energy consumption of the equipment, the urgency of the task completion time, and the quality of the user experience, so as to accurately calculate the offloading ratio of the task. The computing network, with its flexibility and efficiency, can realize the on-demand allocation and flexible scheduling of computing resources, storage resources and network resources among the cloud, network and edge according to business needs. This dynamic allocation and scheduling capability not only makes computing resources more efficiently utilized, but also avoids waste and idleness of resources. In traditional edge scenarios, under the limitation of computing power, it is difficult to meet the task requirements of customers for carrying traditional target detection models. Therefore, how to combine target detection and computing offloading with each other and make the target detection algorithm more meet the needs of customers through edge computing has become a problem to be solved.
[0004] In view of this, a method, device and medium for image recognition of animals in a livestock farm in an edge scenario are proposed. Summary of the invention
[0005] In view of this, the purpose of the present invention is to propose an image recognition method for animals in a livestock farm under edge scenes. The method integrates a lightweight target detection model built based on the YOLOv5 model and a complete target detection model under edge scenes, selects the corresponding model for detection processing through decision control, and accumulates the results through a cumulative confidence algorithm. It can more accurately identify the target objects in the image, greatly reduce the time of target detection, enhance the flexibility of system selection, and significantly improve the recognition accuracy.
[0006] In order to achieve the above technical objectives, the technical solution adopted by the present invention is:
[0007] The present invention provides an image recognition method for each animal in a livestock farm in an edge scene, comprising the following steps:
[0008] Step 1: Obtain an image dataset of each animal in a livestock farm in an edge scenario;
[0009] Step 2: Establish a fusion target detection system;
[0010] Step 3: training the fusion target detection system by using the image data set to obtain different target detection models;
[0011] Step 4: Input the image data to be detected into the fusion target detection system, select a corresponding trained target detection model as the best model according to the current scene and requirements, and obtain the target detection result after the image data to be detected is detected by the best model;
[0012] Step 5: The continuously generated target detection results are accumulated and integrated through the cumulative confidence algorithm to obtain the detection and recognition results.
[0013] Furthermore, the step 1 specifically includes:
[0014] Step 11: Determine the types of environmental data that need to be collected through edge scenarios;
[0015] Step 12: According to various types of environmental data, a corresponding environmental perception module is used to obtain video files of various animals in the livestock farm under different environmental types in the edge scene;
[0016] Step 13: preprocess the target number of video files to obtain an image data set;
[0017] Step 14: annotate and enhance each image data in the image data set;
[0018] Step 15: Divide the labeled image dataset into a training set, a test set, and a validation set according to a set ratio.
[0019] Furthermore, the step 2 specifically includes:
[0020] Step 21, the fusion target detection system is established based on the YOLOv5 model; the network structure of the YOLOv5 model is divided into a backbone network, a feature pyramid network and a prediction head;
[0021] The backbone network adopts CSPDarknet53, which consists of a series of convolutional layers and residual blocks;
[0022] The feature pyramid network is used to detect objects of different sizes using features of different scales. A set of feature pyramids is generated by adding a series of convolutional layers and upsampling operations on top of the backbone network.
[0023] Step 22: Based on the YOLOv5 model, a MobileNetV3 module with a lightweight skeleton structure is installed as a lightweight target detection model and installed on the local device;
[0024] Step 23. Based on the YOLOv5 model, a feature attention module is added as a complete target detection model, and is installed in the local device and the cloud. By means of computational offloading, the intermediate data processed by the local device is offloaded to the cloud for further processing; the feature attention module is based on the SE attention mechanism.
[0025] Furthermore, the step 3 specifically includes:
[0026] Step 31, configuring the model training parameters in the fusion target detection system;
[0027] Step 32: input the training set into a fusion target detection system;
[0028] Step 33: During the training process, the lightweight target detection model and the complete target detection model are trained and iteratively optimized according to the configured model training parameters;
[0029] Step 34: Update the weights of the lightweight target detection model and the complete target detection model through back propagation algorithm and gradient descent;
[0030] Step 35: Monitor the training process, input the validation set for validation, and observe the performance of the lightweight object detection model and the complete object detection model on the validation set;
[0031] Step 36: When the lightweight target detection model and the complete target detection model achieve satisfactory performance, save the corresponding trained lightweight target detection model and the complete target detection model.
[0032] Furthermore, the step 4 specifically includes:
[0033] Step 41, inputting the test set into a fusion target detection system;
[0034] Step 42: Generate an appropriate decision according to the current scenario and requirements through the decision module, and select a lightweight target detection model or a complete target detection model trained in the fusion target detection system as the best model for testing according to the decision;
[0035] Step 43: Input the test set into the best model of the fusion target detection system according to the generated strategy;
[0036] Step 44: For the consecutive frames in the test set, use the best model to detect and infer the target, collect and record the target detection results of each frame, and form a series of target detection results within a period of time.
[0037] Furthermore, the target detection result includes a bounding box, a category, and a confidence level of the detected target object.
[0038] Furthermore, the step 5 specifically includes:
[0039] Step 51: for each target category to be detected, initialize a cumulative confidence value, wherein the cumulative confidence value is used to record the detection status of the target category in consecutive frames;
[0040] Step 52: for each target category, the cumulative confidence is updated according to the target detection result of the current frame; when the cumulative confidence reaches the set threshold, the target category is considered to exist in the current scene;
[0041] Step 53: For the target detection results in the continuous frames, the temporal continuity is used for fusion;
[0042] Step 54: Output the final detection and recognition result based on the accumulated confidence and the fused target detection result.
[0043] Furthermore, the steps 51 to 54 specifically include:
[0044] Consider a The target detection and classification task of categories, where the category label is a random variable with a range of Between; for the lightweight target detection model and the complete target detection model, the input data samples is a random sample of a grayscale image with a resolution of 640*640 and follows an unknown probability distribution. The estimated class probability vector for classes To represent the inference results of the lightweight target detection model and the complete target detection model; Indicates that in a given data sample middle, , The conditional probability when ; The entropy of Calculated for the condition , used to measure the target detection results The uncertainty of The confidence level is expressed as:
[0045]
[0046] in, The value of is between 0 and 1;
[0047] make Indicates The target detection results are Indicates the type of target detection model used to detect the target detection result. Indicates that the target detection result is obtained by the complete target detection model, 1 represents the target detection result obtained by the lightweight target detection model. Indicated by Ending The target detection result set; the accumulated target detection results Defined as m The class probability vector of the categories is denoted as ,in Indicates the given of The estimated conditional probability of , Indicates j In the target detection results, the probability of detecting the correct true class is Represents the cumulative probability of the true class target detection result, based on Bayesian estimation, under the conditional independence assumption of different target detection results given the same true class label, It is expressed as:
[0048]
[0049] in, represents the prior probability distribution, Indicates The joint probability density test results are and Represents the lightweight target detection model and the complete target detection model for a given true category The joint probability density of
[0050]
[0051] Each category is described by using a data-driven nonparametric probability density estimation method Function and ;
[0052] First, the labeled training set is divided into m For each specific class of data subset, the lightweight target detection model and the complete target detection model are run to collect the lightweight detection results and the complete detection results as the target detection results, and finally the corresponding subset of the target detection results is used to describe and ;
[0053] Since the denominator in the above formula Unknown, by The properties of normalized calculation , and converts to:
[0054]
[0055] Cumulative object detection results The confidence level is It is called the given confidence level.
[0056] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the image recognition method for each animal in a livestock farm in an edge scenario as described above is implemented.
[0057] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the image recognition method for each animal in a livestock farm in the edge scenario as described above.
[0058] By adopting the above technical solution, the present invention has the following beneficial effects compared with the prior art:
[0059] 1. When the present invention is applied to identify animals in livestock farms under edge scenes, the behavior and feature information of animals in the livestock farms can be effectively extracted, and the animal categories in complex scenes have a good recognition rate.
[0060] 2. The fusion target detection system in the present invention integrates a lightweight target detection model and a complete target detection model. Compared with the traditional target detection model, it can effectively and flexibly select different model algorithms according to the environment in which it is located; if the real-time requirements of the application are high, but the current network environment is not ideal, you can choose to execute the lightweight target detection model locally. If the network environment is good and the cloud computing resources are sufficient, you can consider using the complete target detection model to detect the task, while meeting the real-time requirements, the accuracy of target detection is improved, and it is more suitable for problems such as insufficient computing resources in edge scenes. Compared with the existing algorithms, the performance is more superior, the recognition rate of objects is higher, and the target recognition efficiency is improved. Due to the combination of the lightweight target detection model and the complete target detection model, the structure is more adaptable to the scheduling strategy, and the performance of the two models is different, which is more adaptable to different environments. In particular, the complete target detection model can further solve the problem of resource scheduling according to the allocation ratio between the local and edge networks.
[0061] 3. By supporting cumulative confidence decisions for adaptive devices, based on the continuously accumulated confidence level, the decision module generates a detection strategy, dynamically triggering the local lightweight target detection model or the remote complete target detection model for each device until the cumulative confidence level of the device reaches the predefined threshold. This decision can better determine the existence and location of the target, improve the robustness and accuracy of target detection, and meet customer needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] 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 will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0063] Figure 1 It is an execution flow chart of an image recognition method for each animal in a livestock farm in an edge scenario provided by an embodiment of the present invention.
[0064] Figure 2 It is a schematic diagram of an electronic device provided by an embodiment of the present invention.
[0065] Figure 3 It is a schematic diagram of a computer-readable storage medium provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0066] The present invention will be further described in detail below in conjunction with the accompanying drawings and examples. It is particularly noted that the following examples are only used to illustrate the present invention, but are not intended to limit the scope of the present invention. Similarly, the following examples are only partial embodiments of the present invention rather than all embodiments, and all other embodiments obtained by those of ordinary skill in the art without creative work are within the scope of protection of the present invention.
[0067] See also Figure 1 , a method for image recognition of animals in a livestock farm in an edge scene of the present invention comprises the following steps:
[0068] Step 1: Obtain an image dataset of each animal in a livestock farm in an edge scenario;
[0069] In this embodiment, the step 1 specifically includes:
[0070] Step 11: Determine the types of environmental data that need to be collected through edge scenarios;
[0071] Step 12: Configure corresponding environment perception modules according to multiple types of environment data, and use the corresponding environment perception modules to obtain video files of various animals in the livestock farm under different environment types in the edge scene; the environment perception module is composed of multiple camera devices and various sensors installed in the livestock farm;
[0072] Here, environmental data under different environmental types can be collected in a variety of data types, such as RGB images and infrared images, to increase the types of image data sets.
[0073] Step 13: Preprocess the target number of video files to obtain an image data set; the details are as follows:
[0074] Decompose the video file into multiple separate image frames through a video processing library (such as Opencv), each frame can be used as a time point of the video and as an input of the target detection framework; preprocess the video file with a large amount of data into individual image frames, so as to amplify the data and serve as the data set required by the target detection framework;
[0075] By performing image scaling and color channel conversion on the image frame, the image frame is scaled to s*s (e.g., 640*640) pixels and channels are in RGB format; normalization processing can be facilitated by scaling the pixel values to a specific range (e.g., 0 to 1);
[0076] Each image frame is normalized to obtain multiple processed image frames as an image data set; normalization helps to reduce noise in the data and makes the model easier to process, thereby optimizing the performance of the model.
[0077] Step 14: annotate and enhance each image data in the image data set;
[0078] Each image data includes a label, wherein the label in this example is a box annotation information, and the box annotation information includes different livestock and poultry types and livestock and poultry labels in the livestock farm. And appropriately enhance the image (adjust the brightness, contrast, color, etc. of the image to improve the image quality).
[0079] Step 15: Divide the labeled image dataset into a training set, a test set, and a validation set according to a set ratio.
[0080] The labeled image dataset is randomly divided into training set, test set and validation set in a ratio of 8:1:1. If the number of samples of each category in the training set, test set and validation set is very different, the stratified sampling method can be used to ensure that the proportion of samples of each category in the training set, test set and validation set is similar.
[0081] In this example, the training set, test set, and validation set are all composed of registered RGB images and infrared images, that is, the imaging angles, positions, and visible ranges of the RGB images and infrared images in the training set, test set, and validation set are the same, avoiding the disadvantages of data instability caused by rich data sources.
[0082] Step 2: Establish a fusion target detection system;
[0083] In this embodiment, step 2 specifically includes:
[0084] Step 21, the fusion target detection system is established based on the YOLOv5 model, which integrates two target detection algorithms based on the YOLOv5 model to adapt to the situation of insufficient computing resources in edge scenes; the network structure of the YOLOv5 model is divided into three main parts: backbone network (backone), feature pyramid network (feature pyramid network, FPN) and prediction head (prediction head);
[0085] The backbone network adopts CSPDarknet53, which is a variant of the lightweight Darknet network structure; CSPDarknet53 consists of a series of convolutional layers and residual blocks, which can effectively extract image features. The CSP (CrossStagePartial) structure is introduced to reduce the amount of calculation and improve the expressiveness of features by dividing the feature map into two parts in the channel dimension;
[0086] The feature pyramid network is used to detect objects of different sizes using features of different scales. By adding a series of convolutional layers and upsampling operations on top of the backbone network, a set of feature pyramids is generated; these feature pyramids can capture semantic information of different scales, thereby improving the accuracy of object detection. The main function of adding the FPN structure to the algorithm is to improve the network's detection effect on small objects, but it usually does not have a significant beneficial effect on the detection effect on large objects.
[0087] Step 22: Based on the YOLOv5 model, a MobileNetV3 module with a lightweight skeleton structure is used as a lightweight target detection model and installed on the local device; because it is equipped with a lightweight skeleton structure, the amount of calculation of the algorithm itself is reduced, and the demand for computing resources of the target detection model can be reduced. In this example, the lightweight skeleton structure MobileNetV3 structure is as follows: it introduces the depth separable convolution of MobileNetV1, and divides the standard convolution operation into two steps, namely depth convolution and point-by-point convolution. And it inherits the inverted residual structure of the linear bottleneck of MobileNetV2, which specifically includes first using 1x1 convolution for dimensionality increase (i.e. expansion), then extracting features through a 3x3 depth separable convolution, and finally using 1x1 convolution for dimensionality reduction (i.e. compression). This structural change helps to extract more features in a lightweight network while reducing feature loss. The attention model also uses a lightweight attention model with SE structure and a new activation function h-swish(x). The Swish activation function has the characteristics of no upper bound, lower bound, smoothness, and non-monotonicity, which make the neural network layer have richer expressive capabilities. However, the swish function has a large amount of calculation, so in MobileNet V3, h-swish is used as an approximate function to approximate swish to simplify calculations and improve efficiency.
[0088] In network structure search, combining resource-constrained NAS (platform-aware NAS) and NetAdapt can achieve more efficient and accurate network model design and optimization. Resource-constrained NAS is to search for networks under the premise of limited calculation and parameter quantity. It takes into account the characteristics and limitations of a specific platform and finds the best network structure that adapts to a specific platform through an automated search process. This technology ensures that the searched network model achieves high performance while meeting hardware resource constraints. NetAdapt is an adaptive network optimization technology that can automatically simplify pre-trained networks based on direct indicators (such as latency, energy, memory usage, etc.) to adapt them to hardware resource constraints while maximizing accuracy. NetAdapt incorporates these direct indicators into the adaptive algorithm and generates multiple network proposals in each iteration, and then measures the performance of these proposals on the target platform to guide the next round of network proposal generation. Combining resource-constrained NAS with NetAdapt can give full play to the advantages of both. Resource-constrained NAS is responsible for searching for network structures that adapt to specific platforms globally, while NetAdapt is responsible for fine-tuning the network locally to adapt to hardware resource constraints and maximize performance. This combination can improve the performance of the searched network model while ensuring search efficiency. All of the above structures achieve the goal of reducing model complexity while maintaining high performance. This enables MobileNetV3 to achieve efficient reasoning performance on mobile and embedded devices, providing strong support for various visual tasks.
[0089] Step 23, on the basis of the YOLOv5 model, a feature attention module is added as a complete target detection model, and it is carried in the local device and the cloud. By means of computational offloading, the intermediate data processed by the local device is offloaded to the cloud for further processing; the feature attention module is based on the SE (Squeeze-and-Excitation) attention mechanism. Because in the livestock farm, there are small targets in the livestock and poultry images under the environmental perception module, which are sometimes difficult to distinguish. By adding the SE (Squeeze-and-Excitation) attention module on the basis of YOLOv5, the module can strengthen the channel features of the feature map and enhance the model's attention to important features. Specifically, the SE module adaptively learns the relationship between feature channels and weights the features of different channels, so that the model can more effectively utilize feature information and emphasize important features, which can enable the target detection model to better handle complex scenes and diverse targets, solve the problem of object overlap in livestock scenes to a certain extent, and improve the accuracy and robustness of detection. In addition, the SE module can be easily integrated into the framework of target detection to achieve performance improvement. By offloading computation, the intermediate data processed locally is offloaded to the cloud for further processing to solve the problem of insufficient computing resources. Compared with the lightweight YOLOv5 algorithm, it has higher detection accuracy and can meet the needs of customer tasks.
[0090] Step 3: training the fusion target detection system by using the image data set to obtain different target detection models;
[0091] In this embodiment, step 3 specifically includes:
[0092] Step 31, configuring the model training parameters in the fusion target detection system;
[0093] Step 32: input the training set into a fusion target detection system;
[0094] Step 33: During the training process, the lightweight target detection model and the complete target detection model are trained and iteratively optimized according to the configured model training parameters;
[0095] Step 34: Update the weights of the lightweight target detection model and the complete target detection model through back propagation algorithm and gradient descent;
[0096] Step 35: By monitoring the training process, inputting the validation set for validation, observing the performance of the lightweight target detection model and the complete target detection model on the validation set, such as accuracy, recall rate and other indicators, the generalization capabilities of the lightweight target detection model and the complete target detection model can be evaluated through the validation set;
[0097] Step 36: When the lightweight target detection model and the complete target detection model achieve satisfactory performance, save the corresponding trained lightweight target detection model and the complete target detection model.
[0098] In this example, we try to select training sets in different time periods and different scenes as preprocessing training sets, and use at least one of the RGB images and infrared images taken by the environmental perception module as preprocessing data. Improving the quality of the training set helps to avoid overfitting of the model, and on the other hand, it also avoids the problem of unrecognition caused by a single RGB image input, thereby ensuring that the relevant detection functions can operate normally.
[0099] In this example, the set size is 640*640 pixels. When the image size in any input image does not meet the requirement, the image size is directly adjusted to 640*640, and the feature map is sliced for the next step of processing.
[0100] Step 4: Input the image data to be detected into the fusion target detection system, select a corresponding trained target detection model as the best model according to the current scene and requirements, and obtain the target detection result after the image data to be detected is detected by the best model;
[0101] In this embodiment, step 4 specifically includes:
[0102] Step 41, inputting the test set into a fusion target detection system;
[0103] Step 42, generate appropriate decisions according to the current scenario and requirements through the decision module, and select the lightweight target detection model or complete target detection model trained in the fusion target detection system as the best model for testing according to the decision; the decision module is responsible for selecting the appropriate model for reasoning according to the current scenario and requirements, and can make decisions based on multiple factors, focusing on the real-time bandwidth of the current environment and the task completion and completion time of each device as important indicators for decision making. If the application has high real-time requirements, but the current network environment is not ideal, you can choose to execute the lightweight target detection model locally. If the network environment is good and the cloud computing resources are sufficient, you can consider using the complete target detection model to detect the task, while meeting the real-time requirements and improving the accuracy of target detection. The decision module needs to learn the above characteristics and select the appropriate model strategy according to the changes in the scene. The implementation of the decision module can be based on rules, machine learning algorithms or deep learning algorithms.
[0104] Step 43: Input the test set into the best model of the fusion target detection system according to the generated strategy;
[0105] Step 44: For the continuous frames in the test set, use the best model to detect and infer the target, collect and record the target detection results of each frame, and form a series of target detection results within a period of time; the target detection results include the bounding box, category and confidence of the detected target object.
[0106] Step 5: The continuously generated target detection results are accumulated and integrated through the cumulative confidence algorithm to obtain the detection and recognition results.
[0107] In this embodiment, step 5 specifically includes:
[0108] Step 51: for each target category to be detected, initialize a cumulative confidence value, which is usually set to 0 or a lower initial value; the cumulative confidence value is used to record the detection status of the target category in consecutive frames;
[0109] Step 52: for each target category, the cumulative confidence is updated according to the target detection result of the current frame; when the cumulative confidence reaches the set threshold, the target category is considered to exist in the current scene;
[0110] Step 53: For the target detection results in the continuous frames, the temporal continuity is used for fusion;
[0111] Step 54: Output the final detection and recognition result based on the accumulated confidence and the fused target detection result.
[0112] In this embodiment, the steps 51 to 54 specifically include:
[0113] Consider a The target detection and classification task of categories, where the category label is a random variable with a range of Between; for the lightweight target detection model and the complete target detection model, the input data samples is a random sample of a grayscale image with a resolution of 640*640 and follows an unknown probability distribution. The estimated class probability vector for classes To represent the target detection results of the lightweight target detection model and the complete target detection model; Indicates that in a given data sample middle, , The conditional probability when ; The entropy of Calculated for the condition , used to measure the target detection results The uncertainty of The confidence level is expressed as:
[0114]
[0115] in, The value of is between 0 and 1;
[0116] make Indicates The target detection results are Indicates the type of target detection model used to detect the target detection result. Indicates that the target detection result is obtained by the complete target detection model, 1 represents the target detection result obtained by the lightweight target detection model. Indicated by Ending The target detection result set; the accumulated target detection results Defined as m The class probability vector of the categories is denoted as ,in Indicates the given of The estimated conditional probability of , Indicates j In the target detection results, the probability of detecting the correct true class is Represents the cumulative probability of the true class target detection result, based on Bayesian estimation, under the conditional independence assumption of different target detection results given the same true class label, It is expressed as:
[0117]
[0118] in, represents the prior probability distribution, Indicates The joint probability density test results are and Represents the lightweight target detection model and the complete target detection model for a given true category The joint probability density of is:
[0119]
[0120] By using a data-driven nonparametric probability density estimation method (specifically, the kernel density estimation method (KDE)), each category is described Function and ;
[0121] First, the labeled training set is divided intom For each specific class of data subset, the lightweight target detection model and the complete target detection model are run to collect the lightweight detection results and the complete detection results as the target detection results, and finally the corresponding subset of the target detection results is used to describe and ;
[0122] Since the denominator in the above formula Unknown, by The properties of normalized calculation , and converts to:
[0123]
[0124] Cumulative object detection results The confidence level is It is called the given confidence level.
[0125] By considering a The target detection and classification task of the category can better judge the existence and location of the target by detecting and identifying the existing data set with the preset target detection model, gradually accumulating confidence information in a series of continuous random data sets, extracting image features, preliminary detection, confidence accumulation and positioning and classification of the target. The advantage of the cumulative confidence algorithm is that it can make full use of the information of different detection stages to improve the robustness and accuracy of target detection.
[0126] The present invention also provides an image recognition system for each animal in a livestock farm in an edge scene, comprising: a system for collecting animal image data in a livestock farm; Cameras, multiple sensors, remote (MEC) servers, local devices, user terminals, and a data center;
[0127] Among them, the multiple cameras used by workers in the livestock farm to collect videos are denoted as , assuming that each camera device contains independent tasks, each task can be offloaded to the edge server (Edgeserver), and it can collect data at a specific location of the livestock farm in real time, and can further split the collected video files into continuous video frames (image frames).
[0128] Local device: A lightweight target detection model and a complete target detection model are installed on the local device to detect the video frames transmitted from the camera device for target detection tasks.
[0129] Edge network: The edge network consists of a wireless AP (Access Point) and a general edge server. The edge server is equipped with a complete target detection model to calculate the intermediate data transmitted from the local device for target detection tasks.
[0130] The user side receives the target detection and classification results of the system task, and the user side is connected to a lightweight server with sufficient resources to implement the offloading strategy. By sensing the changes in the environmental state in the system, deep reinforcement learning is used to train the computational offloading decisions in the entire system.
[0131] The camera equipment and various sensors installed in the farm constitute an environmental perception module, which is used to obtain the target number of image data, which includes labels, and the labels include the status information of each animal in the farm. The client and the camera equipment constitute a data augmentation module and a decision model training module, which are used to build an image data set based on all image data. The decision model training module is used to train the computational offloading decision in the entire system by using deep reinforcement learning to perceive the changes in the environmental state in the system.
[0132] The model training module and target detection module are installed on the local device and edge network, which are used to execute the YOLOv5s model equipped with the feature attention module and the YOLOv5 model equipped with the lightweight MobileNetv3 module built based on the training set, and obtain the complete target detection model and the lightweight target detection model after training; by receiving the offloading decision from the client training, it executes the acquisition of the image to be detected and inputs it into the trained target detection model, outputs the detection result, and calculates the cumulative confidence through the cumulative confidence algorithm, and sends it to the client.
[0133] In this system, the target detection model scheme in the local device and edge network can be appropriately adjusted for the specific environmental background, so as to improve the flexibility of the algorithm and the accuracy of target detection, and it can be implemented through the generated system strategy to realize resource scheduling and meet the service needs of the client.
[0134] like Figure 2 As shown, an embodiment of the present invention further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method when executing the program.
[0135] like Figure 3 As shown, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the above method is implemented.
[0136] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0137] 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, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0138] The above descriptions are only some embodiments of the present invention, and are not intended to limit the protection scope of the present invention. Any equivalent device or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for image recognition of animals in a livestock farm in an edge scene, characterized in that: The steps include: Step 1: Obtain an image dataset of each animal in a livestock farm in an edge scenario; Step 2: Establish a fusion target detection system; specifically include: Step 21, the fusion target detection system is established based on the YOLOv5 model; the network structure of the YOLOv5 model is divided into a backbone network, a feature pyramid network and a prediction head; The backbone network adopts CSPDarknet53, which consists of a series of convolutional layers and residual blocks; The feature pyramid network is used to detect objects of different sizes using features of different scales. A set of feature pyramids is generated by adding a series of convolutional layers and upsampling operations on top of the backbone network. Step 22: Based on the YOLOv5 model, a MobileNetV3 module with a lightweight skeleton structure is installed as a lightweight target detection model and installed on the local device; Step 23: Based on the YOLOv5 model, a feature attention module is added as a complete target detection model, and is installed in the local device and the cloud. By means of computation offloading, the intermediate data processed by the local device is offloaded to the cloud for further processing; the feature attention module is based on the SE attention mechanism; Step 3: training the fusion target detection system by using the image data set to obtain different target detection models; Step 4: Input the image data to be detected into the fusion target detection system, select a corresponding trained target detection model as the best model according to the current scene and requirements, and obtain the target detection result after the image data to be detected is detected by the best model; Step 5: Accumulate and fuse the continuously generated target detection results through the cumulative confidence algorithm to obtain the detection and recognition results; specifically including: Step 51: for each target category to be detected, initialize a cumulative confidence value, wherein the cumulative confidence value is used to record the detection status of the target category in consecutive frames; Step 52: for each target category, the cumulative confidence is updated according to the target detection result of the current frame; when the cumulative confidence reaches the set threshold, the target category is considered to exist in the current scene; Step 53: For the target detection results in the continuous frames, the temporal continuity is used for fusion; Step 54: Output the final detection and recognition result based on the accumulated confidence and the fused target detection result.
2. The method for image recognition of animals in a livestock farm in an edge scenario according to claim 1, characterized in that: The step 1 specifically includes: Step 11: Determine the types of environmental data that need to be collected through edge scenarios; Step 12: According to various types of environmental data, a corresponding environmental perception module is used to obtain video files of various animals in the livestock farm under different environmental types in the edge scene; Step 13: preprocess the target number of video files to obtain an image data set; Step 14: annotate and enhance each image data in the image data set; Step 15: Divide the labeled image dataset into a training set, a test set, and a validation set according to a set ratio.
3. The image recognition method for each animal in a livestock farm in an edge scene according to claim 2, characterized in that: The step 3 specifically includes: Step 31, configuring the model training parameters in the fusion target detection system; Step 32: input the training set into a fusion target detection system; Step 33: During the training process, the lightweight target detection model and the complete target detection model are trained and iteratively optimized according to the configured model training parameters; Step 34: Update the weights of the lightweight target detection model and the complete target detection model through back propagation algorithm and gradient descent; Step 35: Monitor the training process, input the validation set for validation, and observe the performance of the lightweight object detection model and the complete object detection model on the validation set; Step 36: When the lightweight target detection model and the complete target detection model achieve satisfactory performance, save the corresponding trained lightweight target detection model and the complete target detection model.
4. The method for image recognition of animals in a livestock farm in an edge scenario according to claim 3, characterized in that: The step 4 specifically includes: Step 41, inputting the test set into a fusion target detection system; Step 42: Generate an appropriate decision according to the current scenario and requirements through the decision module, and select a lightweight target detection model or a complete target detection model trained in the fusion target detection system as the best model for testing according to the decision; Step 43: Input the test set into the best model of the fusion target detection system according to the generated strategy; Step 44: For the consecutive frames in the test set, use the best model to detect and infer the target, collect and record the target detection results of each frame, and form a series of target detection results within a period of time.
5. The method for image recognition of animals in a livestock farm in an edge scenario as claimed in claim 4, characterized in that: The target detection result includes the bounding box, category and confidence level of the detected target object.
6. The method for image recognition of animals in a livestock farm in an edge scenario according to claim 5, characterized in that: The steps 51 to 54 specifically include: Consider a The target detection and classification task of categories, where the category label is a random variable with a range of Between; for the lightweight target detection model and the complete target detection model, the input data samples is a random sample of a grayscale image with a resolution of 640*640 and follows an unknown probability distribution. The estimated class probability vector for each class To represent the inference results of the lightweight target detection model and the complete target detection model; Indicates that in a given data sample middle, , The conditional probability when ; The entropy of Calculated for the condition , used to measure the target detection results The uncertainty of The confidence level is expressed as: in, The value of is between 0 and 1; make Indicates The target detection results are Indicates the type of target detection model used to detect the target detection result. Indicates that the target detection result is obtained by the complete target detection model. 1 represents the target detection result obtained by the lightweight target detection model. Indicated by Ending The target detection result set; the accumulated target detection results Defined as m The class probability vector of the categories is denoted as ,in Indicates the given of The estimated conditional probability of , Indicates j In the target detection results, the probability of detecting the correct true class is Represents the cumulative probability of the true class target detection result, based on Bayesian estimation, under the conditional independence assumption of different target detection results given the same true class label, It is expressed as: in, represents the prior probability distribution, Indicates The joint probability density test results are and Represents the lightweight target detection model and the complete target detection model for a given true category The joint probability density of Each category is described by using a data-driven nonparametric probability density estimation method Function and ; First, the labeled training set is divided into m For each specific class of data subset, the lightweight target detection model and the complete target detection model are run to collect the lightweight detection results and the complete detection results as the target detection results, and finally the corresponding subset of the target detection results is used to describe and ; Since the denominator in the above formula Unknown, by The properties of normalized calculation , and converts to: Cumulative object detection results The confidence level is It is called the given confidence level.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the image recognition method of each animal in a livestock farm in an edge scenario as described in any one of claims 1 to 6 is implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the image recognition method of each animal in a livestock farm in an edge scenario as described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Cutting method for keyword checkout system on basis of confidence
CN102402984A
Unmanned aerial vehicle target detection method based on edge intelligence
CN112488043A
