Pork is the largest meat consumer in China. The stable supply of pork is closely related to the national life. Therefore, the health of pigs in pig enterprises is particularly important. By monitoring the behavior of pigs, we can find out the diseases of pigs and intervene in time to reduce the losses of enterprises and ensure the stable supply of pork in the market. This paper presents an improved yolov5 pig behavior recognition method, which can automatically recognize five behaviors of pigs:standing, ventral lying, lateral lying, sitting and climbing. Firstly,in the yolov5 network structure, a branch is added to its original C3 module to extract more original features. Secondly, the Convolutional Block Attention Module (CBAM) attention mechanism module is introduced and further integrated with the C3 module to obtain the new CBAMC3 module, which enhances the recognition capability of the model for obstructed targets. Meanwhile, the neck module in You Only Live Once (YOLO) v5 is improved and the Cneck module is proposed. By adding the feature fusion layer, the neck can obtain a greater number of underlying image features, provide more image features for the prediction layer, and enhance the recognition capability of the model. The improved YOLOv5 model was tested on the pig behavior dataset built in this study, and the outcome indicated that the recognition accuracy of the method for the five behaviors in the validation set was 99.1%, 95.3%, 97.4%, 88.7% and 99.5%, respectively, with an average accuracy of 96.0%, which was 1.2% more than the yolov5 model, and the proposed method has more merits. The method proposed in this paper has more merits and is beneficial to practical applications.