| In recent years,our country’s pig breeding industry has developed towards intensive,large-scale and standardized development.Pig inventory is an important part of management in intensive pig breeding.The traditional manual counting method is more time-consuming and laborious,and it is easy to count errors when the number of pigs is large.The use of non-contact machine vision methods to estimate the number of pigs can reduce direct contact between humans and pigs,improve pig welfare,and at the same time make the counting process more efficient and help improve breeding efficiency.Under the above research background,this paper studies the method of counting high-density pigs.The experiment took binary hybrid piglets as the research object,collected images of pigs,and used deep learning to build a multi-scale perception network to obtain a pig counting network,counted the pigs in the high-density pig herd image and estimated the spatial distribution of the pig herd.The main research contents of this paper are as follows.(1)This paper collected high-density pig herd images,wrote automatic image calibration code and gaussian density map generation code.This paper collected pig herd images in the pig-driving channel of an intensive pig farm,and took the RGB pictures of pigs in different situations from a top-down perspective.Wrote the image calibration program to mark the pig image,stored the ground truth and spatial distribution information of the pigs in the form of coordinate points,generated the primary label file,processed the primary label file,wrote the gaussian density map generation code,performed gaussian convolution on each coordinate point in the label file,and smoothed multiple coordinate points in the label to generate a pig density map as the label of the input convolutional neural network.(2)The spatial pyramid pooling structure was used to complete the extraction of multi-scale features in the image,and to perceive the continuous spatial scale changes in the image of the pig herd images.The spatial pyramid pooling layer of different sizes is added to the network to adaptively extract the context information needed to accurately predict the density map,and to perceive the features of different scales of the image.We used the feature fusion network to fuse the obtained features of different scales.Compared and tested different feature fusion methods and different network sizes.The test results showed that after using the spatial pyramid pooling layer,the model recognition accuracy has been significantly improved.We used the spatial pyramid pooling structure as the middle part,transformed the front-end and back-end networks,and established a pig counting network(PCN).PCN used an improved VGG16 network as the front-end network to extract features,the middle layer used a3-layer spatial pyramid structure to extract multi-scale information in the image,used a parallel structure to fuse feature information,and the back-end network used an improved expanded convolutional network.And compared the different expansion rates of the back-end network.Tests show that the back-end transformation expanded the network’s receptive field,obtained a more accurate predicted density map,and achieves accurate pig counts for the integration of the density map.(3)The pig counting network was validated and compared with other counting models.The results showed that on the test set images with an average number of pigs of 40.71,the accuracy of PCN was better than that of crowd counting networks MCNN,CSRNet and improved Counting CNN pig counting networks.The counting errors MAE and RMSE are 1.74 and 2.28,showing good performance accuracy and robustness.The average recognition time of a single image is 0.108 s,which met the real-time processing requirements of the counting algorithm.It can also accurately count the images of normal,poorly illuminated,and distorted pigs. |