In recent years,the concept of smart agriculture has become increasingly popular,and farms have implemented centralized and large-scale management of pigs.Pig counting is a key part of centralized management.Currently,most farms use traditional methods of manual counting.Due to the complex background information in the farms,pigs are densely distributed,move frequently,and cover a large area with each other,making traditional manual counting methods difficult and labor-intensive,And in dense scenes with a large number of pigs,the counting results are prone to errors.Therefore,this article is based on the deep learning Yolov5 s algorithm to study the pig counting problem in dense scenarios,reconstruct the Yolov5 s backbone network and feature fusion layer,and improve work efficiency in large-scale and high-density breeding farms.The specific work of this article is as follows:(1)In response to the problem of complex background information and large occlusion area,this article introduces the CBAM attention mechanism in the Neck layer of Yolov5 s.This module processes the pre fused feature maps,enhances the expression ability of key features in the feature maps,avoids interference from irrelevant background information,and improves the model’s anti-interference ability and recognition accuracy for dense targets.(2)In order to improve the insufficient feature information of pigs in dense scenes,this paper introduces the structural idea of Bi FPN in the Neck layer of the network model.Two cross scale connection paths are added to the original model,making it more sufficient in the feature fusion process compared to the original FPN structure.Its skip connection feature balances the proportion of high-level semantic features and low-level features,enriching the feature information of dense scene targets.(3)Introducing varilocal_loss function,proposed the loss idea of asymmetric treatment of positive and negative samples for dense scene target detection,adjusted the weight of positive and negative samples by setting hyperparameter,thus improving the recognition accuracy of the model in dense scenes.(4)In order to improve the running speed and efficiency of the model,this article proposes to replace the backbone network of Yolov5 s with Shuffle Net V2 and Rep VGG to achieve lightweight.Shuffle Net V2 breaks the criterion of using Flops as a measure of model operation speed,and proposes four guiding principles to reduce MAC,in order to accelerate the inference speed of the model.The Rep VGG structure adopts the idea of structural reparameterization,which integrates the advantages of single path structure and residual structure in the model.The residual structure is used during model training to improve model performance,and the single path structure is used during model inference to accelerate model operation speed.(5)Introducing the target tracking model Deep Sort,based on the self-made dataset Pig,the pig counting and counting algorithm based on the improved model Yolov5-CBV-S was used for experiments and testing.The experimental results proved the effectiveness of the algorithm proposed in this paper. |