Abstract:In order to solve the problems of large size, single recognition scene and high hardware requirements for deploying application of existing pig behavior recognition models, a lightweight multi-scene group pig behavior recognition model YOLO v5n for pig behavior recognition (YOLO v5n-PBR) was proposed. Firstly, a multi-scene group pig behavior dataset was constructed by shooting and collecting group pig behavior data from different breeding scenes, different pig numbers and different angles, and based on the characteristics of pig behavior objectives in the dataset, the transfer learning method and the optimal transport assignment label assignment method were introduced to train the YOLO v5n model, which accelerated the model convergence speed and improved the model accuracy, and a high-precision multi-scene group pig behavior recognition model was constructed. Then the L1-norm pruning algorithm was used to screen and delete the unimportant channels in the model to remove the redundant parameters. Finally, the performance degradation caused by pruning was removed by fine-tuning training and intermediate feature knowledge distillation, so that the lightweight multi-scene group pig behavior recognition model YOLO v5n-PBR was obtained and deployed as embedded devices. Experimental results showed that the mean average precision (mAP) of the YOLO v5n-PBR model was 96.9%, with parameters, amount of computation, and memory footprint being 4.700×105, 1.20×109, and 1.2 MB, respectively. The deploy real-time recognition frame rates on embedded devices with different systems and hardware configurations were 12.2 frames/s and 66.3 frames/s. Compared with that of the original YOLO v5n model, the mAP was improved by 1.1 percentage points, and parameters, amount of computation, and memory footprint were decreased by 73.3%, 70.7%, and 68.4%, respectively. The deploy real-time recognition frame rates were increased by 74.3% and 83.1%. In addition, the YOLO v5n-PBR model trained based on the multi-scene group pig behavior dataset can reach 98.1% of mAP on four single-scene or dual-scene group pig behavior datasets, and the statistical results of embedded device deployment recognition of six pig behavior videos in two different breeding scenes were similar to those of manual statistics, with an average accuracy and average recall rate of 95.3%, which achieved strong generalization with fewer parameters. The YOLO v5n-PBR model proposed had the advantages of high accuracy, small size, fast speed, and strong generalization, which can meet the deployment requirements of embedded devices and provide a technical basis for real-time and accurate monitoring of pig behavior and the deploying application of pig behavior recognition model.