基于改进实例分割算法的区域养殖生猪计数系统OACSTPCD
A Regional Farming Pig Counting System Based on Improved Instance Segmentation Algorithm
[目的/意义]针对现有规模化猪场生猪计数需求场景多,人工计数效率低、成本高等问题,提出一种基于改进实例分割深度学习算法和微信公众平台的区域养殖生猪计数方法.[方法]首先,利用智能手机拍摄养殖场猪只视频,对视频抽帧进一步生成图像数据集.其次,通过改进卷积块注意力模块(Convolutional Block Attention Module,CBAM)中忽略通道与空间相互作用及通道注意力中降维操作带来的效率较低问题,提出高效全局注意力模块,并将该模块引入基于回归分析的单阶段实例分割网络YOLO(You Only Look Once)v8中对获取的生猪图像进行分割,构建新的识别模型YOLOv8x-Ours,以实现高精度的生猪计数.最后,基于微信公众平台开发微信小程序,并嵌入综合表现最优的生猪计数模型,实现使用智能手机拍摄图像进行生猪快速计数.[结果和讨论]在测试集上的试验结果表明,与现有实例分割模型相比,引入高效全局注意力的YOLOv8x-Ous模型获得66%的平均精度(AP(50∶95)),平均绝对误差(Mean Absolute Error,MAE)、均方根误差(Root Mean Square Error,RMSE)和R2分别为1.727、2.168和0.949,表现出较高的准确性和稳定性.模型计算猪只数量误差小于3头猪的图像数量占测试图像总数量的93.8%,相比两阶段实例分割算法Mask R-CNN(Region Convolutional Neural Network)提升7.6%;单幅图像平均处理时间仅为64 ms,是Mask R-CNN的1/8.[结论]该方法经济高效,为规模化猪场的生猪计数提供了一种技术方案.
[Objective]Currently,pig farming facilities mainly rely on manual counting for tracking slaughtered and stored pigs.This is not only time-consuming and labor-intensive,but also prone to counting errors due to pig movement and potential cheating.As breeding opera-tions expand,the periodic live asset inventories put significant strain on human,material and financial resources.Although methods based on electronic ear tags can assist in pig counting,these ear tags are easy to break and fall off in group housing environments.Most of the existing methods for counting pigs based on computer vision require capturing images from a top-down perspective,ne-cessitating the installation of cameras above each hogpen or even the use of drones,resulting in high installation and maintenance costs.To address the above challenges faced in the group pig counting task,a high-efficiency and low-cost pig counting method was proposed based on improved instance segmentation algorithm and WeChat public platform. [Methods]Firstly,a smartphone was used to collect pig image data in the area from a human view perspective,and each pig's outline in the image was annotated to establish a pig count dataset.The training set contains 606 images and the test set contains 65 images.Secondly,an efficient global attention module was proposed by improving convolutional block attention module(CBAM).The effi-cient global attention module first performed a dimension permutation operation on the input feature map to obtain the interaction be-tween its channels and spatial dimensions.The permuted features were aggregated using global average pooling(GAP).One-dimen-sional convolution replaced the fully connected operation in CBAM,eliminating dimensionality reduction and significantly reducing the model's parameter number.This module was integrated into the YOLOv8 single-stage instance segmentation network to build the pig counting model YOLOv8x-Ours.By adding an efficient global attention module into each C2f layer of the YOLOv8 backbone net-work,the dimensional dependencies and feature information in the image could be extracted more effectively,thereby achieving high-accuracy pig counting.Lastly,with a focus on user experience and outreach,a pig counting WeChat mini program was developed based on the WeChat public platform and Django Web framework.The counting model was deployed to count pigs using images cap-tured by smartphones. [Results and Discussions]Compared with existing methods of Mask R-CNN,YOLACT(Real-time Instance Segmentation),PolarMask,SOLO and YOLOv5x,the proposed pig counting model YOLOv8x-Ours exhibited superior performance in terms of accuracy and sta-bility.Notably,YOLOv8x-Ours achieved the highest accuracy in counting,with errors of less than 2 and 3 pigs on the test set.Specifi-cally,93.8%of the total test images had counting errors of less than 3 pigs.Compared with the two-stage instance segmentation algo-rithm Mask R-CNN and the YOLOv8x model that applies the CBAM attention mechanism,YOLOv8x-Ours showed performance im-provements of 7.6%and 3%,respectively.And due to the single-stage design and anchor-free architecture of the YOLOv8 model,the processing speed of a single image was only 64 ms,1/8 of Mask R-CNN.By embedding the model into the WeChat mini program platform,pig counting was conducted using smartphone images.In cases where the model incorrectly detected pigs,users were given the option to click on the erroneous location in the result image to adjust the statistical outcomes,thereby enhancing the accuracy of pig counting. [Conclusions]The feasibility of deep learning technology in the task of pig counting was demonstrated.The proposed method elimi-nates the need for installing hardware equipment in the breeding area of the pig farm,enabling pig counting to be carried out effortless-ly using just a smartphone.Users can promptly spot any errors in the counting results through image segmentation visualization and easily rectify any inaccuracies.This collaborative human-machine model not only reduces the need for extensive manpower but also guarantees the precision and user-friendliness of the counting outcomes.
张岩琪;周硕;张凝;柴秀娟;孙坦
中国农业科学院 农业信息研究所,北京 100081,中国||农业农村部农业大数据重点实验室,北京 100081,中国
计算机与自动化
生猪计数深度学习微信小程序YOLOv8实例分割
pig countingdeep learningWeChat mini programYOLOv8instance segmentation
《智慧农业(中英文)》 2024 (004)
53-63 / 11
新一代人工智能国家科技重大专项(2022ZD0115702);国家自然科学基金项目(61976219);北京市智慧农业创新团队项目资助(BAIC10-2024);中国农业科学院创新工程(CAAS-ASTIP-2023-AII);中央级公益性科研院所基本科研业务费专项(JBYW-AII-2023-04,JBYW-AII-2022-14) National Science and Technology Major Project(2022ZD0115702);National Natural Science Foundation of China(61976219);Beijing Smart Agriculture Innovation Consortium Project(BAIC10-2024);Innovation Program of Chinese Academy of Agricultural Sciences(CAAS-ASTIP-2023-AII);Central Public-interest Scientific Institution Basal Research Fund(JBYW-AII-2023-04,JBYW-AII-2022-14)
评论