In order to achieve accurate identification of cotton pests and diseases in a natural complex environment, a cotton pest and disease detection method based on an improved You Only Look Once version 9(YOLOv9) model was proposed.The RepLanLsk module was constructed and replaced with RepNCSPELAN4 of YOLOv9 to enhance the diversity of feature extraction and establish a larger receptive field network; a weighted bidirectional feature pyramid network(BIFPN) was added to achieve bidirectional connections between feature pyramids, ensure optimal feature fusion, and strengthen key pest and disease features in the target area.The results showed that the model had an accuracy of 93%, a recall rate of 92.4%, and an average precision of 96.4% for detecting pest and disease cotton, which were 1.6%, 0.3%, and 1% higher than the original YOLOv9 network model, respectively;Through comparative experiments, it is concluded that the accuracy of this model is higher than that of YOLOv7, YOLOv8x and other models, and YOLOv9-LSBN can better extract subtle features in cotton pest images, and the misjudgment rate is lower than other models. This model can effectively reduce the interference of complex backgrounds, accurately and quickly detect cotton pest targets in images, and can provide a reference for crop pest detection research with complex backgrounds in natural environments.