Pine Wilt Disease (PWD) is one of the most dangerous and destructive disease in the global forest ecosystems. Based on a dataset of pine wilt disease infected trees that we collected and produced, we developed new technology derived from YOLOv5s to promote the detection performance of the PWD infected trees in this work, in which attention mechanisms, random backgrounds and modifications of the loss functions are integrated. In our strategy, six different attention mechanisms, i.e., SE, CA, CBAM, ECA, SimAM and NAM, are added to improve the detection of YOLOv5s algorithm. These mechanisms are added by embedding in the previous layer of the spatial pyramid pooling-fast structure and replacing all C3 layers in the backbone, respectively. All attention mechanisms added in various ways improves the detection results of PWD infected pine trees. Among them, SE, CBAM and NAM attention mechanisms show the most significant improvements. Because all these three attention mechanisms can specifically enhance the ability of the model to focus on the critical feature for densely distributed or complex pine forests with red broad-leaved trees with diseased and withered pine trees. Five other loss functions are adopted to replace CIoU loss function in the original YOLOv5 networks to examine their interactions in the detection of PWD infected trees. Among the five replaced loss functions, SIoU and WIoU losses are sensitive to color changes in the target, allowing them to effectively capture the distinctions of diseased trees, thereby increasing detection precision. Also, we acquired a model trained by incorporating a 10 % ratio of random backgrounds into our original dataset. This training approach can improve the precision of recognition in different environments, thereby enhancing its generalization capability. Therefore, our new developed method can contribute important works to prevent and control of these diseases in real applications.