Pig inventory method, device, equipment and storage medium

By constructing a fusion inventory model, the problem of degradation of detection accuracy caused by different density in pig inventory is solved, and accurate counting is achieved in high-density scenarios.

CN114492664BActive Publication Date: 2025-08-15SICHUAN NEW HOPE ANIMAL NUTRITION TECH CO LTD +2
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210139355.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-15
Publication Date
2025-08-15
Estimated Expiration
2042-02-15

AI Technical Summary

Technical Problem

The existing pig inventory method has reduced detection accuracy in high-density scenarios and is difficult to count accurately. Especially when the density is high, the target is small, and the occlusion is severe, the traditional method is prone to errors.

Method used

Build a fusion inventory model, obtain images for preprocessing, perform pig outline labeling, establish a Gaussian density map, build an initial fusion inventory model for training, generate a fusion inventory model, and combine pig population and density map for detection.

Benefits of technology

The detection accuracy of pig inventory is improved, the impact of different pig density on detection is reduced, and the counting accuracy is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114492664B_ABST
    Figure CN114492664B_ABST
Patent Text Reader

Abstract

The present invention provides a pig counting method, apparatus, device, and storage medium. The method comprises obtaining an image to be counted from each pen, performing a first preprocessing on the image to generate a preprocessed image, annotating the outline of each pig in the preprocessed image to obtain pig outline annotation information, and establishing a Gaussian model based on the pig outline annotation information to obtain a Gaussian density map and the number of pigs. An initial fused counting model is constructed and trained based on the preprocessed image, the Gaussian density map, the number of pigs, and the pig outline annotation information to generate a fused counting model. The preprocessed image is input into the fused counting model to obtain a pig counting result for the image to be counted in each pen. Compared with the prior art, the construction of the fused counting model reduces the impact of different pig densities on detection and improves detection accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of breeding, and in particular to a pig inventory method, device, equipment and storage medium. Background Art

[0002] Live pigs are of vital importance to a company's biological assets, and their number directly reflects the size of the company's assets. Therefore, pig farming companies are required to conduct regular pig counts. Traditionally, these counts are manual, with managers performing counts farm by farm and then adding up the totals. This is time-consuming, labor-intensive, and inefficient, and prone to human errors and false reporting, making accuracy uncertain. With the advancement of computer technology, especially the recent implementation of computer vision and deep learning in engineering applications, methods for pig counting using computer technology have emerged. These methods involve installing data acquisition equipment or track inspection equipment on pig pens to capture images. These equipment then use regression, object detection, segmentation, density mapping, and other methods to identify pigs in the images or videos, and then calculate the target number of pigs.

[0003] The target detection and segmentation techniques mentioned above are designed for scenarios with large targets, small numbers, and low density. If the targets are small or numerous with high density, the accuracy of this method will decrease. The main reasons are high density, severe occlusion, small exposed area, low recognition rate, and difficulty in labeling. In addition, pigs are often densely packed in the nursery stage, and the counting accuracy of target detection and segmentation techniques drops sharply in high-density stacking scenarios. The counting method using the density map method is much more accurate than target detection, and the density map method is suitable for this high-density counting scenario. However, the accuracy of counting pigs in the fattening stage with low density and large targets is far lower than that of target detection technology. Summary of the Invention

[0004] The technical problem to be solved by the present invention is: to provide a pig inventory method, device, equipment and storage medium, and to solve the problem of decreased detection accuracy caused by different pig densities in existing pig inventory detection by constructing a fusion inventory model. It can reduce the impact of different pig densities on detection and improve detection accuracy.

[0005] In order to solve the above technical problems, the present invention provides a pig inventory method, device, equipment and storage medium, including:

[0006] Acquire an image to be counted of each column, perform a first preprocessing on the image to be counted, and generate a preprocessed image;

[0007] Performing pig outline annotation on each pig in the preprocessed image to obtain pig outline annotation information, establishing a Gaussian model based on the pig outline annotation information, and obtaining a Gaussian density map and the number of pigs;

[0008] Building an initial fusion inventory model, and performing model training on the initial fusion inventory model according to the preprocessed image, the Gaussian density map, the number of pigs, and the pig outline annotation information to generate a fusion inventory model;

[0009] The pre-processed images are input into the fusion inventory model to obtain the pig inventory results of the images to be counted in each pen.

[0010] Furthermore, the image to be counted of each column is obtained, and the image is subjected to a first preprocessing to generate a preprocessed image, specifically:

[0011] Obtaining the image to be counted for each column, matching the image to be counted with the corresponding column number, and marking the column outline of the image to be counted to generate a column outline dataset;

[0012] The column segmentation model is pre-trained based on the column outline data set, and the image to be counted is segmented based on the column outline to obtain the image within the column outline and generate a pre-processed image.

[0013] Furthermore, the outline of each pig in the preprocessed image is annotated to obtain pig outline annotation information, and a Gaussian model is established based on the pig outline annotation information to obtain a Gaussian density map and the number of pigs, specifically:

[0014] Marking the outline of each pig in the preprocessed image to obtain pig outline marking information, and simultaneously obtaining the number of pig outline markings to obtain a counting result of the number of pigs in the preprocessed image;

[0015] According to the pig outline annotation information, the angle of the pig outline is calculated, and the direction of the pig is obtained based on the angle; at the same time, multiple coordinate points are selected for the pig outline, and a Gaussian model is established in combination with the pig direction and the multiple coordinate points to obtain and calculate the integral result of the number of pigs based on the Gaussian density map.

[0016] Furthermore, the pre-processed images are input into the fusion inventory model to obtain the pig inventory results of the images to be counted in each pen, specifically:

[0017] Inputting the preprocessed image into the fusion inventory model, and outputting the integral result, counting result and model inventory result of the number of pigs in the preprocessed image;

[0018] Obtaining the pig density in the pre-processed image according to the integration result, and comparing the pig density with a preset density threshold to obtain the corresponding pig counting result of the image to be counted in each pen; or

[0019] According to the integration result and the counting result, the pig counting result of the image to be counted in each pen is calculated according to a preset formula.

[0020] Furthermore, the present invention also provides a pig inventory device, comprising: an image preprocessing module, a pig outline annotation module, a fusion inventory model training module and a result output module;

[0021] The image preprocessing module is used to obtain the image to be counted of each column, perform a first preprocessing on the image to be counted, and generate a preprocessed image;

[0022] The pig outline annotation module is used to perform pig outline annotation on each pig in the preprocessed image to obtain pig outline annotation information, establish a Gaussian model based on the pig outline annotation information, and obtain a Gaussian density map and the number of pigs;

[0023] The fusion inventory model training module is used to build an initial fusion inventory model, perform model training on the initial fusion inventory model according to the preprocessed image, the Gaussian density map, the number of pigs and the pig outline annotation information, and generate a fusion inventory model;

[0024] The result output module is used to input the pre-processed images into the fusion inventory model to obtain the pig inventory results of the images to be counted in each pen.

[0025] Furthermore, the image preprocessing module is used to obtain the image to be counted of each column, perform a first preprocessing on the image, and generate a preprocessed image, specifically:

[0026] Obtaining the image to be counted for each column, matching the image to be counted with the corresponding column number, and marking the column outline of the image to be counted to generate a column outline dataset;

[0027] The column segmentation model is pre-trained based on the column outline data set, and the image to be counted is segmented based on the column outline to obtain the image within the column outline and generate a pre-processed image.

[0028] Furthermore, the pig outline annotation module is used to perform pig outline annotation on each pig in the preprocessed image to obtain pig outline annotation information, and establish a Gaussian model based on the pig outline annotation information to obtain a Gaussian density map and the number of pigs, specifically:

[0029] Marking the outline of each pig in the preprocessed image to obtain pig outline marking information, and simultaneously obtaining the number of pig outline markings to obtain a counting result of the number of pigs in the preprocessed image;

[0030] According to the pig outline annotation information, the angle of the pig outline is calculated, and the direction of the pig is obtained based on the angle; at the same time, multiple coordinate points are selected for the pig outline, and a Gaussian model is established in combination with the pig direction and the multiple coordinate points to obtain and calculate the integral result of the number of pigs based on the Gaussian density map.

[0031] Furthermore, the result output module is used to input the pre-processed image into the fusion inventory model to obtain the pig inventory result of the image to be counted in each pen, specifically:

[0032] Inputting the preprocessed image into the fusion inventory model, and outputting the integral result, counting result and model inventory result of the number of pigs in the preprocessed image;

[0033] Obtaining the pig density in the pre-processed image according to the integration result, and comparing the pig density with a preset density threshold to obtain the corresponding pig counting result of the image to be counted in each pen; or

[0034] According to the integration result and the counting result, the pig counting result of the image to be counted in each pen is calculated according to a preset formula.

[0035] Furthermore, the present invention also provides a terminal device, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the pig inventory method as described in any one of the above items is implemented.

[0036] Furthermore, the present invention also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the pig inventory method as described in any one of the above items.

[0037] The pig inventory method, device, equipment, and storage medium of the embodiments of the present invention have the following beneficial effects compared with the prior art:

[0038] By obtaining the images to be counted from each pen, performing a first preprocessing on the images to be counted to generate preprocessed images; labeling the outline of each pig in the preprocessed images to obtain pig outline labeling information; building a Gaussian model based on the pig outline labeling information to obtain a Gaussian density map and the number of pigs; building an initial fusion inventory model, training the initial fusion inventory model based on the preprocessed images, Gaussian density map, the number of pigs, and the pig outline labeling information to generate a fusion inventory model; inputting the preprocessed images into the fusion inventory model to obtain the pig inventory results for the images to be counted in each pen. Compared with the existing technology, by constructing a fusion inventory model, the problem of reduced detection accuracy caused by different pig densities in existing pig inventory detection is solved, the impact of different pig densities on detection is reduced, and the detection accuracy is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 This is a flow chart of an embodiment of a pig inventory method provided by the present invention;

[0040] Figure 2 This is a structural diagram of an embodiment of a pig inventory counting device provided by the present invention;

[0041] Figure 3 Schematic diagram of the image to be counted for each column provided by an embodiment of the present invention;

[0042] Figure 4 is a schematic diagram of a preprocessed image provided by an embodiment of the present invention;

[0043] Figure 5 is a schematic diagram of an elliptical Gaussian provided by an embodiment of the present invention;

[0044] Figure 6 It is a Gaussian density map provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0045] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.

[0046] Example 1

[0047] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of an embodiment of a pig inventory method provided by the present invention. Figure 1 As shown, the method includes steps 101 to 104, which are specifically as follows:

[0048] Step 101: Obtain an image to be counted of each column, perform a first preprocessing on the image to be counted, and generate a preprocessed image.

[0049] In this embodiment, before obtaining the image to be counted of each pen, based on the multiple pig houses divided into the breeding grounds, tracks and image acquisition equipment are installed above each pig house pen and along the top of the center line of each pen, so that the image acquisition equipment can run horizontally along the track.

[0050] In this embodiment, magnetic tiles for positioning are installed at the center points of each column corresponding to the track, and a mapping relationship between the column number and the magnetic tile sequence number is established, such as column number C01: magnetic tile sequence number 1, column number C02: magnetic tile sequence number 2, ..., column number Cmn: magnetic tile sequence number mn.

[0051] In this embodiment, during operation, the image acquisition device moves on the track and uses a Hall sensor to monitor and collect magnetic flux. When a magnetic tile is detected, a counter is incremented by one, and the counter is used to represent the current magnetic tile sequence number. At the same time, the image to be counted of each column is obtained and the column number is matched and recorded. The image to be counted of each column and the column number collected are called through the switch to the cloud server interface and uploaded to the cloud server. The image to be counted of each column, such as Figure 3 shown.

[0052] In this embodiment, a Wi-Fi module and a 4G communication module are added to the image acquisition device. The Wi-Fi module is used as the main data transmission channel, and the 4G module is used as a backup network link. In the event of an abnormal network environment of the Wi-Fi module, the data transmission task is automatically switched to the 4G module.

[0053] In this embodiment, the column outline of the image to be counted is annotated to generate a column outline dataset, wherein the column outline dataset includes the collected image to be counted and the corresponding column outline annotation information; based on the column outline dataset, a column segmentation model is pre-trained to generate and segment the image to be counted based on the column outline, and the image outside the column outline is removed to obtain the image inside the column outline as the preprocessed image, wherein the preprocessed image is as follows: Figure 4 shown.

[0054] Step 102: labeling the outline of each pig in the preprocessed image to obtain pig outline labeling information, establishing a Gaussian model based on the pig outline labeling information, and obtaining a Gaussian density map and the number of pigs.

[0055] In this embodiment, the outline of each pig in the preprocessed image is annotated to obtain the pig outline annotation information, and the number of pig outline annotations in the preprocessed image is obtained at the same time. The number of pig outline annotations is used as the number of pigs to obtain the counting result of the number of pigs in the preprocessed image.

[0056] In this embodiment, the angle of the pig's outline is calculated based on the pig's outline annotation information, and the pig's direction is obtained based on the angle; at the same time, the major and minor axes and the center point of the pig are obtained based on the outline annotation information, and multiple coordinate point information of the pig's outline is established based on the major and minor axes and the center point of the pig. An elliptical Gaussian is generated by combining the pig's direction and the multiple coordinate points, and a Gaussian model is established. The sum of the Gaussian pixels of each pig is set to 1 based on the Gaussian density map, which represents a count of 1. The Gaussian density map is integrated to obtain the integral result of the number of pigs, where the elliptical Gaussian map is as follows: Figure 5 As shown, the Gaussian density map is as follows Figure 6 shown.

[0057] Step 103: Building an initial fusion inventory model, and performing model training on the initial fusion inventory model according to the preprocessed image, the Gaussian density map, the number of pigs, and the pig outline annotation information to generate a fusion inventory model.

[0058] In this embodiment, an initial fusion inventory model is constructed, wherein the initial fusion inventory model is a multi-task training model, including a segmentation training task and a density training task. The preprocessed image, Gaussian density map, number of pigs, and pig outline annotation information obtained in step 102 are combined and randomly divided into a training set, a test set, and a validation set. The training set is used as the input of the initial fusion inventory model, and the initial fusion inventory model is trained. When the initial fusion inventory model is trained, the loaded image data, Gaussian density map, and annotated outline information are loaded, and the loaded data is subjected to data augmentation processing such as flipping transformation, random pruning, translation transformation, scaling transformation, noise perturbation, and rotation transformation.

[0059] In this embodiment, the loss function of the initial fusion inventory model is set as follows:

[0060] L=L mask +L density +L count ;

[0061] Among them, L mask and L density The same as the common segmentation and density method, no detailed explanation is given here. At the same time, the deviation of the inventory result is calculated, and the settlement result is as follows:

[0062] dif=|Count-Count GT |;

[0063] Among them, dif refers to the deviation of the model inventory result, Count refers to the model inventory result, Count GT Refers to the number of pigs marked on the pig outline.

[0064] In this embodiment, the Lcount multi-stage loss function is used to give a grade according to the deviation of the inventory result, and the grade is divided into multiple stages for scoring, wherein the multiple stages are s1, s2, s3...; the larger the deviation, the greater the penalty value, that is, the larger the corresponding Scores, the corresponding model will update the parameters for gradient descent. On the contrary, if the deviation of the inventory result is small, the penalty value is small, the corresponding Scores are small or even 0, and the corresponding model will not update the parameters, making the model inventory more accurate. As an example in this embodiment, L count =Scores1*(dif>s1)+Scores2*(dif>s2)+Scores3*(dif>s3).

[0065] In this embodiment, to improve the accuracy of the output inventory results, a preset verification accuracy is set for the validation set. When the accuracy of the validation set reaches the preset accuracy, the training of the initial fusion inventory model is terminated, the current parameters are saved, the initial fusion inventory model is updated, and a trained fusion inventory model is generated. The accuracy of the validation set is mainly verified by the accuracy of the inventory results. This is mainly done by inferring the data set in the validation set and statistically analyzing the inventory results of the data. The statistical formula is as follows:

[0066]

[0067] In this embodiment, after the trained fusion inventory model is generated, pruning, quantization and other processing are performed on the fusion inventory model, and the fusion inventory model is converted to a framework adapted to the edge device.

[0068] Step 104: Input the pre-processed images into the fusion inventory model to obtain the pig inventory results of the images to be counted in each pen.

[0069] In this embodiment, the images to be counted collected in real time by the image acquisition device are connected to the edge device, and the pen number is recorded. The images to be counted collected in real time are input into the pen segmentation model pre-trained in step 101 to obtain preprocessed images. The preprocessed images are input into the fusion inventory model, and the integral result, counting result and model inventory result of the number of pigs in the preprocessed images are output.

[0070] In this embodiment, the pig density per unit area in the preprocessed image is determined based on the integral result output by the model. This pig density is then compared to a preset density threshold. The integration result is then used to calculate the pig density per unit area. The preset density threshold is a value selected from empirical business experience. When the pig density is greater than or equal to the preset density threshold, indicating a high concentration of pigs in the pen, the integral result is used as the pig count result for the image to be counted in that pen. If the pig density is less than the preset density threshold, the count result is used as the pig count result for the image to be counted in that pen.

[0071] As another example in this embodiment, for the pig counting result, in addition to using the above-mentioned preset density threshold to calculate, it is also possible to calculate according to a preset formula, and use the calculation result as the pig counting result of the image to be counted. The calculation formula is as follows:

[0072] D*a+(1-a)*M;

[0073] Among them, a is a trainable hyperparameter, D is the integration result, and M is the counting result.

[0074] In this embodiment, after calculating the pig counting results of the images to be counted, it is necessary to obtain a preset number of images to be counted for each pig pen according to the preset daily acquisition times of the preset image acquisition equipment, and output the pig counting results of the preset number of images to be counted. The preset number of pig counting results of each pig pen are counted, and the average value or median value of the statistical results is obtained as the final pig counting result of the pig pen on that day. The final pig counting results of each pig pen are counted to complete the pig inventory task of the breeding site.

[0075] See also Figure 2 , Figure 2 FIG. 1 is a schematic structural diagram of an embodiment of a pig inventory counting device provided by the present invention. Figure 2 As shown, the device includes an image preprocessing module 201, a pig outline annotation module 202, a fusion inventory model training module 203 and a result output module 204, which are specifically as follows:

[0076] The image pre-processing module 201 is used to obtain the image to be counted of each column, perform a first pre-processing on the image to be counted, and generate a pre-processed image.

[0077] In this embodiment, before obtaining the image to be counted of each pen, based on the multiple pig houses divided into the breeding grounds, tracks and image acquisition equipment are installed above each pig house pen and along the top of the center line of each pen, so that the image acquisition equipment can run horizontally along the track.

[0078] In this embodiment, magnetic tiles for positioning are installed at the center points of each column corresponding to the track, and a mapping relationship between the column number and the magnetic tile sequence number is established, such as column number C01: magnetic tile sequence number 1, column number C02: magnetic tile sequence number 2, ..., column number Cmn: magnetic tile sequence number mn.

[0079] In this embodiment, during operation, the image acquisition device moves on the track and uses a Hall sensor to monitor and collect magnetic flux. When a magnetic tile is detected, a counter is incremented by one, and the counter is used to represent the current magnetic tile sequence number. At the same time, the image to be counted of each column is obtained and the column number is matched and recorded. The image to be counted of each column and the column number collected are called through the switch to the cloud server interface and uploaded to the cloud server. The image to be counted of each column, such as Figure 3 shown.

[0080] In this embodiment, a Wi-Fi module and a 4G communication module are added to the image acquisition device. The Wi-Fi module is used as the main data transmission channel, and the 4G module is used as a backup network link. In the event of an abnormal network environment of the Wi-Fi module, the data transmission task is automatically switched to the 4G module.

[0081] In this embodiment, the column outline of the image to be counted is annotated to generate a column outline dataset, wherein the column outline dataset includes the collected image to be counted and the corresponding column outline annotation information; based on the column outline dataset, a column segmentation model is pre-trained to generate and segment the image to be counted based on the column outline, and the image outside the column outline is removed to obtain the image inside the column outline as the preprocessed image, wherein the preprocessed image is as follows: Figure 4 shown.

[0082] The pig outline marking module 202 is used to mark the outline of each pig in the preprocessed image to obtain pig outline marking information, establish a Gaussian model based on the pig outline marking information, and obtain a Gaussian density map and the number of pigs.

[0083] In this embodiment, the outline of each pig in the preprocessed image is annotated to obtain the pig outline annotation information, and the number of pig outline annotations in the preprocessed image is obtained at the same time. The number of pig outline annotations is used as the number of pigs to obtain the counting result of the number of pigs in the preprocessed image.

[0084] In this embodiment, the angle of the pig's outline is calculated based on the pig's outline annotation information, and the pig's direction is obtained based on the angle; at the same time, the major and minor axes and the center point of the pig are obtained based on the outline annotation information, and multiple coordinate point information of the pig's outline is established based on the major and minor axes and the center point of the pig. An elliptical Gaussian is generated by combining the pig's direction and the multiple coordinate points, and a Gaussian model is established. The sum of the Gaussian pixels of each pig is set to 1 based on the Gaussian density map, which represents a count of 1. The Gaussian density map is integrated to obtain the integral result of the number of pigs, where the elliptical Gaussian map is as follows: Figure 5 As shown, the Gaussian density map is as follows Figure 6 shown.

[0085] The fusion inventory model training module 203 is used to build an initial fusion inventory model, perform model training on the initial fusion inventory model according to the preprocessed image, the Gaussian density map, the number of pigs and the pig outline annotation information, and generate a fusion inventory model.

[0086] In this embodiment, an initial fusion inventory model is constructed, wherein the initial fusion inventory model is a multi-task training model, including a segmentation training task and a density training task. The preprocessed image, Gaussian density map, pig number, and pig outline annotation information obtained by the pig outline annotation module 202 are combined and randomly divided into a training set, a test set, and a validation set. The training set is used as the input of the initial fusion inventory model, and the initial fusion inventory model is trained. When the initial fusion inventory model is trained, the loaded image data, Gaussian density map, and annotation outline information are loaded, and the loaded data is subjected to data augmentation processing such as flipping transformation, random pruning, translation transformation, scaling transformation, noise perturbation, and rotation transformation.

[0087] In this embodiment, the loss function of the initial fusion inventory model is set as follows:

[0088] L=L mask +L density +L count ;

[0089] Among them, L mask and L density The same as the common segmentation and density method, no detailed explanation is given here. At the same time, the deviation of the inventory result is calculated, and the settlement result is as follows:

[0090] dif=|Count-Count GT |;

[0091] Among them, dif refers to the deviation of the model inventory result, Count refers to the model inventory result, Count GT Refers to the number of pigs marked on the pig outline.

[0092] In this embodiment, the Lcount multi-stage loss function is used to give a grade according to the deviation of the inventory result, and the grade is divided into multiple stages for scoring, wherein the multiple stages are s1, s2, s3...; the larger the deviation, the greater the penalty value, that is, the larger the corresponding Scores, the corresponding model will update the parameters for gradient descent. On the contrary, if the deviation of the inventory result is small, the penalty value is small, the corresponding Scores are small or even 0, and the corresponding model will not update the parameters, making the model inventory more accurate. As an example in this embodiment, L count =Scores1*(dif>s1)+Scores2*(dif>s2)+Scores3*(dif>s3).

[0093] In this embodiment, to improve the accuracy of the output inventory results, a preset verification accuracy is set for the validation set. When the accuracy of the validation set reaches the preset accuracy, the training of the initial fusion inventory model is terminated, the current parameters are saved, the initial fusion inventory model is updated, and a trained fusion inventory model is generated. The accuracy of the validation set is mainly verified by the accuracy of the inventory results. This is mainly done by inferring the data set in the validation set and statistically analyzing the inventory results of the data. The statistical formula is as follows:

[0094]

[0095] In this embodiment, after the trained fusion inventory model is generated, pruning, quantization and other processing are performed on the fusion inventory model, and the fusion inventory model is converted to a framework adapted to the edge device.

[0096] The result output module 204 is used to input the pre-processed images into the fusion inventory model to obtain the pig inventory results of the images to be counted in each pen.

[0097] In this embodiment, the images to be counted collected in real time by the image acquisition device are connected to the edge device, and the pen number is recorded. The images to be counted collected in real time are input into the pre-trained pen segmentation model in the image preprocessing module 201 to obtain the preprocessed images. The preprocessed images are input into the fusion inventory model, and the integral result, counting result and model inventory result of the number of pigs in the preprocessed images are output.

[0098] In this embodiment, the pig density per unit area in the preprocessed image is determined based on the integral result output by the model. This pig density is then compared to a preset density threshold. The integration result is then used to calculate the pig density per unit area. The preset density threshold is a value selected from empirical business experience. When the pig density is greater than or equal to the preset density threshold, indicating a high concentration of pigs in the pen, the integral result is used as the pig count result for the image to be counted in that pen. If the pig density is less than the preset density threshold, the count result is used as the pig count result for the image to be counted in that pen.

[0099] As another example in this embodiment, for the pig counting result, in addition to using the above-mentioned preset density threshold to calculate, it is also possible to calculate according to a preset formula, and use the calculation result as the pig counting result of the image to be counted. The calculation formula is as follows:

[0100] D*a+(1-a)*M;

[0101] Among them, a is a trainable hyperparameter, D is the integration result, and M is the counting result.

[0102] In this embodiment, after calculating the pig counting results of the images to be counted, it is necessary to obtain a preset number of images to be counted for each pig pen according to the preset daily acquisition times of the preset image acquisition equipment, and output the pig counting results of the preset number of images to be counted. The preset number of pig counting results of each pig pen are counted, and the average value or median value of the statistical results is obtained as the final pig counting result of the pig pen on that day. The final pig counting results of each pig pen are counted to complete the pig inventory task of the breeding site.

[0103] In an embodiment of the present invention, a device for pig inventory is also provided, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the above-mentioned pig inventory method is implemented.

[0104] In an embodiment of the present invention, a computer-readable storage medium is further provided. The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the above-mentioned pig inventory method.

[0105] For example, the computer program can be divided into one or more modules, which are stored in the memory and executed by the processor to implement the present invention. The one or more modules can be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program in the pig inventory device.

[0106] The pig inventory device can be a computing device such as a desktop computer, laptop, PDA, or cloud server. The pig inventory device can include, but is not limited to, a processor, a memory, and a display. Those skilled in the art will appreciate that the aforementioned components are merely examples of pig inventory devices and do not constitute a limitation on the pig inventory device. The device can include more or fewer components than those described above, or a combination of certain components, or different components. For example, the pig inventory device can also include input and output devices, network access devices, buses, and the like.

[0107] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor. The processor serves as the control center of the livestock inventory device, connecting various parts of the livestock inventory device using various interfaces and lines.

[0108] The memory can be used to store the computer programs and / or modules. The processor implements the various functions of the pig inventory device by running or executing the computer programs and / or modules stored in the memory and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store an operating system and at least one application required for a function (such as a sound playback function, a text conversion function, etc.); the data storage area can store data generated based on the use of the mobile phone (such as audio data, text message data, etc.). In addition, the memory can include high-speed random access memory and non-volatile memory, such as a hard disk, internal memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, at least one disk storage device, a flash memory device, or other volatile solid-state storage device.

[0109] If the module integrated into the pig inventory device is implemented as 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 present invention can implement all or part of the process steps in the above-mentioned method embodiments by using a computer program to instruct the relevant hardware. The computer program can be stored in a computer-readable storage medium. When executed by a processor, the computer program can implement the steps of each of the above-mentioned method embodiments. The computer program includes computer program code, which can be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal, and software distribution medium. It should be noted that the content of the computer-readable medium can be appropriately increased or decreased based on the requirements of legislation and patent practice in a jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media does not include electric carrier signals and telecommunication signals.

[0110] It should be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art can understand and implement the present invention without inventive effort.

[0111] In summary, the present invention provides a pig inventory method, device, equipment, and storage medium. The method obtains an image to be counted in each pen, performs a first preprocessing on the image to be counted, and generates a preprocessed image. The method labels the outline of each pig in the preprocessed image to obtain pig outline labeling information. Based on the pig outline labeling information, a Gaussian model is established to obtain a Gaussian density map and the number of pigs. An initial fusion inventory model is built, and the initial fusion inventory model is trained based on the preprocessed image, the Gaussian density map, the number of pigs, and the pig outline labeling information to generate a fusion inventory model. The preprocessed image is input into the fusion inventory model to obtain the pig inventory results of the image to be counted in each pen. Compared with the existing technology, by constructing a fusion inventory model, the problem of reduced detection accuracy caused by different pig densities in existing pig inventory detection is solved, the impact of different pig densities on detection can be reduced, and the detection accuracy can be improved.

[0112] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and substitutions can be made without departing from the technical principles of the present invention. These improvements and substitutions should also be regarded as the scope of protection of the present invention.

Claims

1. A pig inventory method, characterized in that: include: Acquire an image to be counted of each column, perform a first preprocessing on the image to be counted, and generate a preprocessed image; Performing pig outline annotation on each pig in the preprocessed image to obtain pig outline annotation information, establishing a Gaussian model based on the pig outline annotation information, and obtaining a Gaussian density map and the number of pigs; Building an initial fusion inventory model, and performing model training on the initial fusion inventory model according to the preprocessed image, the Gaussian density map, the number of pigs, and the pig outline annotation information to generate a fusion inventory model; Inputting the pre-processed images into the fusion inventory model to obtain the pig inventory results of the images to be counted in each pen; The pre-processed images are input into the fusion inventory model to obtain the pig inventory results of the images to be counted in each pen, specifically: Inputting the preprocessed image into the fusion inventory model, and outputting the integral result, counting result and model inventory result of the number of pigs in the preprocessed image; Obtaining the pig density in the preprocessed image according to the integration result, comparing the pig density with a preset density threshold to obtain the corresponding pig counting result of the image to be counted in each pen, wherein comparing the pig density with the preset density threshold to obtain the corresponding pig counting result of the image to be counted in each pen includes: when the pig density is greater than or equal to the preset density threshold, using the integration result as the pig counting result of the image to be counted; when the pig density is less than the preset density threshold, using the counting result as the pig counting result of the image to be counted; or According to the integration result and the counting result, the pig counting result of the image to be counted in each pen is calculated according to a preset formula, wherein the preset formula is: D*a+(1-a)*M Among them, a is a trainable hyperparameter, D is the integration result, and M is the counting result.

2. A pig inventory method according to claim 1, characterized in that: The step of obtaining an image to be counted for each column and performing a first preprocessing on the image to generate a preprocessed image is as follows: Obtaining the image to be counted for each column, matching the image to be counted with the corresponding column number, and marking the column outline of the image to be counted to generate a column outline dataset; The column segmentation model is pre-trained based on the column outline data set, and the image to be counted is segmented based on the column outline to obtain the image within the column outline and generate a pre-processed image.

3. A pig inventory method according to claim 1, characterized in that: The pig outline is labeled for each pig in the pre-processed image to obtain pig outline labeling information, and a Gaussian model is established based on the pig outline labeling information to obtain a Gaussian density map and the number of pigs, specifically: Marking the outline of each pig in the preprocessed image to obtain pig outline marking information, and simultaneously obtaining the number of pig outline markings to obtain a counting result of the number of pigs in the preprocessed image; According to the pig outline annotation information, the angle of the pig outline is calculated, and the direction of the pig is obtained based on the angle; at the same time, multiple coordinate points are selected for the pig outline, and a Gaussian model is established in combination with the pig direction and the multiple coordinate points to obtain and calculate the integral result of the number of pigs based on the Gaussian density map.

4. A pig inventory device, characterized in that: include: Image preprocessing module, pig outline annotation module, fusion inventory model training module and result output module; The image preprocessing module is used to obtain the image to be counted of each column, perform a first preprocessing on the image to be counted, and generate a preprocessed image; The pig outline annotation module is used to perform pig outline annotation on each pig in the preprocessed image to obtain pig outline annotation information, establish a Gaussian model based on the pig outline annotation information, and obtain a Gaussian density map and the number of pigs; The fusion inventory model training module is used to build an initial fusion inventory model, perform model training on the initial fusion inventory model according to the preprocessed image, the Gaussian density map, the number of pigs and the pig outline annotation information, and generate a fusion inventory model; The result output module is used to input the pre-processed image into the fusion inventory model to obtain the pig inventory result of the image to be counted in each pen; The result output module is used to input the pre-processed images into the fusion inventory model to obtain the pig inventory results of the images to be counted in each pen, specifically: Inputting the preprocessed image into the fusion inventory model, and outputting the integral result, counting result and model inventory result of the number of pigs in the preprocessed image; Obtaining the pig density in the preprocessed image according to the integration result, comparing the pig density with a preset density threshold to obtain the corresponding pig counting result of the image to be counted in each pen, wherein comparing the pig density with the preset density threshold to obtain the corresponding pig counting result of the image to be counted in each pen includes: when the pig density is greater than or equal to the preset density threshold, using the integration result as the pig counting result of the image to be counted; when the pig density is less than the preset density threshold, using the counting result as the pig counting result of the image to be counted; or According to the integration result and the counting result, the pig counting result of the image to be counted in each pen is calculated according to a preset formula, wherein the preset formula is: D*a+(1-a)*M Among them, a is a trainable hyperparameter, D is the integration result, and M is the counting result.

5. A pig inventory device as claimed in claim 4, characterized in that: The image preprocessing module is used to obtain the image to be counted of each column, perform a first preprocessing on the image, and generate a preprocessed image, specifically: Obtaining the image to be counted for each column, matching the image to be counted with the corresponding column number, and marking the column outline of the image to be counted to generate a column outline dataset; The column segmentation model is pre-trained based on the column outline data set, and the image to be counted is segmented based on the column outline to obtain the image within the column outline and generate a pre-processed image.

6. A pig inventory device as claimed in claim 4, characterized in that: The pig outline annotation module is used to perform pig outline annotation on each pig in the preprocessed image to obtain pig outline annotation information, establish a Gaussian model based on the pig outline annotation information, and obtain a Gaussian density map and the number of pigs, specifically: Marking the outline of each pig in the preprocessed image to obtain pig outline marking information, and simultaneously obtaining the number of pig outline markings to obtain a counting result of the number of pigs in the preprocessed image; According to the pig outline annotation information, the angle of the pig outline is calculated, and the direction of the pig is obtained based on the angle; at the same time, multiple coordinate points are selected for the pig outline, and a Gaussian model is established in combination with the pig direction and the multiple coordinate points to obtain and calculate the integral result of the number of pigs based on the Gaussian density map.

7. A terminal device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the pig inventory method according to any one of claims 1 to 3 is implemented.

8. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the pig inventory method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Livestock inventory method, device and equipment apparatus and storage medium

    CN111340801A