In order to achieve rapid and accurate detection of pedestrians and vehicles under diverse weather conditions, this paper proposes a pedestrian and vehicle detection method based on the improved YOLOv8s. This method aims to flexibly adapt to the identification and detection of target features in different weather conditions. Building upon the YOLOv8s model, we introduce Deformable Convolutional Networks version 2 (DCNv2) deformable convolution and Deformable Attention Transformer (DAT) module (YOLOv8+DCNv2+DAT, referred to as YOLOv8-Def). The model dynamically adjusts the shape, position, and attention weights of convolution kernels and combines methods such as sample splitting and Mosaic data augmentation to enhance detection accuracy. At an Intersection over Union (IoU) of 0.3, the size of the YOLOv8-Def model is 48 MB, with a detection accuracy of 83.4%, a recall rate of 74.8%, and a detection speed of 76 frames per second. The mean Average Precision (mAP@0.5) reaches 82.6%. Compared to the standard YOLOv8s model, the absolute mAP improvement is 5.9%. When compared to Faster-RCNN, the YOLOv8-Def model shows a 3.7% increase in absolute mAP, with a frame per second (FPS) higher than 51. Compared to the RT-DETR model, the YOLOv8-Def model demonstrates a 3.5% increase in absolute mAP, with FPS higher than 25. Experimental results indicate that the YOLOv8-Def model significantly improves detection accuracy while minimizing parameter increase. Moreover, compared to the original YOLOv8s, the detection speed of this model is only reduced by 10 frames per second, demonstrating outstanding practicality. Therefore, this method provides a theoretical foundation for the algorithm research and application of pedestrian and vehicle detection under various adverse weather conditions. © 2024, Politechnica University of Bucharest. All rights reserved.