Objective:To explore the application of machine vision technology in sow behavior recognition and improve the recognition accuracy in occlusion situations.Methods:Based on the YOLOv5s algorithm,a sow behavior recognition model was established for five behaviors,which were standing,sitting,lying,crawling and lying on the stomach of sows.By using image processing technology to optimize the training dataset,the recognition model added CBAM attention module to improve the detection accuracy of the behavior of the shielded sow,and finally realized the behavior recognition of the sow in complex environments,which provideed a reference for judging the current state of the sow.Results:After optimization and repeated training,the accuracy of the final detection of the model was high,reaching 97.58%,the recall rate was 89.69%,and the recognition time of a single image was about 0.047 s,which was 1.23% higher than before optimization.Conclusion:The application of YOLOv5s could realize the behavior recognition of sows,and the accuracy rate was high,the recognition time was short,and the identification results were basically consistent with the manual identification results,which met the actual breeding requirements of pig farms.