A distraction driving detection method based on improved YOLOv5

By improving the YOLOv5 algorithm, introducing AIFI and TFE modules to optimize feature interaction, and combining the Shape-IoU loss function, the problem of balancing accuracy and speed in distracted driving detection is solved, the detection capability for small targets and complex environments is improved, and higher detection accuracy and robustness are achieved.

CN122454540APending Publication Date: 2026-07-24LUOYANG SHIQI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
LUOYANG SHIQI TECH CO LTD
Filing Date
2024-08-05
Publication Date
2026-07-24

AI Technical Summary

Technical Problem

Existing distracted driving detection algorithms struggle to balance detection accuracy and speed, especially when dealing with small targets at different scales and in complex environments. Furthermore, the traditional IOU loss function cannot accurately pinpoint the driver's distracted posture.

Method used

The AIFI module is introduced into the YOLOv5 algorithm to optimize deep feature interaction, the TFE module is added for feature fusion, and the Shape-IoU loss function is used to optimize bounding box regression, thereby improving the detection accuracy of small targets and complex scenes.

Benefits of technology

It improves the accuracy and robustness of distracted driving detection, is suitable for real-time application scenarios, and can better capture subtle changes and characteristics of the driver, enhancing the ability to identify occluded and deformed targets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122454540A_ABST
    Figure CN122454540A_ABST
Patent Text Reader

Abstract

The application provides a distraction driving detection method based on improved YOLOv5, which detects key points by analyzing the head posture and body posture of the driver. First, an AIFI module is introduced based on YOLOv5. The module can better capture subtle changes and fine features of the driver's behavior by optimizing the interaction between deep layers of the same feature map, avoiding the complex overall performance evaluation and data analysis process in the SPPF module, and thus being more efficient in calculation and suitable for real-time application scenarios. Second, the original Concat module of the neck layer is replaced with a TFE module, which fuses feature maps through adaptive scale adjustment and channel attention weighting, thereby improving the accuracy of small target detection such as mobile phones and cups. Finally, a shape-IoU module that considers shape information is introduced, which enhances the robustness of the target with occlusion, deformation or partial occlusion, and provides more stable performance compared to the original IoU.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision technology, and in particular to a distracted driving detection method based on an improved YOLOv5. Background Technology

[0002] With the continuous development of automotive technology, in-vehicle safety systems are playing an increasingly important role in enhancing the driving experience and ensuring driving safety. However, distracted driving has become one of the main causes of traffic accidents. Distracted driving includes, but is not limited to, using a mobile phone, talking to passengers, and adjusting the central control screen. These behaviors lead to a lack of driver concentration and increase the risk of traffic accidents. Therefore, accurate and real-time detection of distracted driving is crucial.

[0003] Currently, distracted driving detection is mainly divided into three categories: 1) Detection based on driving behavior: This type of method determines whether the driver is distracted by monitoring the driver's behavior, such as vehicle speed, steering wheel rotation, lane departure, etc. This method typically uses onboard sensors or internal vehicle systems to acquire data and analyzes it using machine learning or pattern recognition algorithms. This method can only indirectly reflect the driver's distracted behavior, and its accuracy may not be high. For certain distracted behaviors, such as looking at a mobile phone, it may not be effective in detection. 2) Detection based on physiological signals: This type of method assesses the driver's attention and focus by monitoring physiological signals, such as heart rate, eye movements, and brain waves. For example, eye-tracking technology can monitor the driver's eye movements to determine whether they are staring at the road or looking at a mobile phone. This method requires the driver to wear a physiological monitoring device, which is inconvenient. Physiological signals are affected by various factors and may contain noise and interference. 3) Detection based on image processing: This type of method determines whether the driver is distracted by analyzing features such as facial expressions, eye movements, head posture, and body posture. Common methods include using computer vision techniques and deep learning models, such as convolutional neural networks (CNNs) and recurrent neural networks (RNNs), to identify and analyze images of drivers.

[0004] Image-based distraction detection not only offers the advantage of being non-contact but also intuitively reflects the driver's distraction state, making it a current research hotspot. Zhang et al. pioneered the use of supervised machine learning to differentiate driving states, employing a decision tree classifier to distinguish between normal driving and distracted driving, achieving an accuracy of 78.4% and reducing detection time by 40%. Wu et al. provided four single-stage target recognition models that can identify the driver's eye opening and closing patterns to determine whether the driver is alert or fatigued. Experimental results show that YOLOv4 achieves a detection accuracy of 90.3%. Qin et al. extracted HOG features from images that retain only driver action information as input and proposed a convolutional neural network (CNN) with a reduced kernel size, enabling distraction detection in embedded systems. Tang et al. improved the detection accuracy of distraction by extracting multi-granularity and mid-level features, fully utilizing driver image information. Xiang et al. proposed a fatigue driving detection system based on a three-dimensional convolutional neural network combined with a channel attention mechanism, including squeeze and excitation modules, optimizing function weights using the attention mechanism module, and achieving 95% discrimination accuracy on the FDF dataset, significantly improving fatigue detection performance. Huang et al. collaborated with CNN, feature fusion, and feature classification modules to extract multi-scale features, perform deep feature fusion, and capture key elements of the fused feature vector, thus achieving distracted driving detection.

[0005] While deep learning-based distracted driver detection has made significant progress over the years, current algorithms still exhibit relatively low detection accuracy, making improving accuracy a crucial challenge in the field. Furthermore, detection speed is a key performance indicator, and existing algorithms often struggle to strike a balance between accuracy and speed. Summary of the Invention

[0006] The purpose of this invention is to provide a distracted driving detection method based on an improved YOLOv5, which demonstrates better ability to predict and identify different types of distracted driving and can effectively and accurately identify distracted driving behavior.

[0007] To achieve the above objectives, the technical solution adopted by this invention is: a distracted driving detection method based on an improved YOLOv5, comprising the following steps: Step 1: Improve the YOLOv5 algorithm, including the following steps: Step 101: Perform data preprocessing; Step 102: Add the AIFI module to the backbone network to optimize the interaction between deep scales within the same feature map; Step 103: After adding the TFE module to the neck network, feature maps are fused using adaptive scale adjustment and channel attention weighting. Step 104: The head network performs model prediction training; Step 105: Obtain the trained YOLOv5-ATS model and its performance; Step 2: Obtain a frame image from the driver behavior video and input it into the trained YOLOv5-ATS model for object detection; Step 3: Determine whether the driver's body and head are present in this frame image. If not, it is determined to be a distracted driving behavior. If present, obtain the coordinate information of the driver's body and head, and determine whether the driver is in a distracted posture. Step 4: Determine whether the driver's body and head are present in this frame image. If not, it is determined to be a distracted driving behavior. If present, obtain the coordinate information of the driver's body and head, and determine whether the driver is in a distracted posture. Step 5: If the driver is in a distracted posture in this frame, the distraction count is incremented by one; otherwise, the distraction count is reset, and the detection of the next frame of the video begins. Step 6: If the driver is in a distracted state in this frame, determine whether the distraction count is equal to the video frame rate. If it is equal, determine that the driver is in a distracted driving state. If it is not equal, continue to detect the next frame of the video.

[0008] Preferably, the data preprocessing in step 101 includes processing the dataset images and performing scale transformation on the images.

[0009] Preferably, the AIFI module in step 102 performs intrascale interaction on the deepest features, applies self-attention operation to high-level features with richer semantic concepts, captures the connections between conceptual entities in the image, and uses them for subsequent modules to detect and recognize objects in the image.

[0010] Preferably, the AIFI module takes the output of the fourth C3 module as input in the backbone, and then uses pos_embed to add the input to the positional encoding. The value obtained after addition is used to calculate Q and K in the multi-head autonomous attention mechanism. Then, self_attn is used to calculate the multi-head self-attention mechanism, and the result is added to the original input and then normalized. After obtaining the result, an ffn module is executed. After obtaining the result, a cross-layer connection is made and the previously normalized result is added. After addition, normalization is performed, and finally the encoder output is obtained.

[0011] Preferably, in step 103, before feature encoding, the TFE module first adjusts the number of feature channels to match the main scale features; after processing the large feature map, its number of channels is adjusted to 1C, and then downsampling is performed using a hybrid structure of max pooling and average pooling; for the small feature map, the convolution module is also used to adjust the number of channels, and then upsampling is performed using the nearest neighbor interpolation method; finally, the three feature maps of the same size (large, medium, and small) are convolved once, and then concatenated along the channel dimension.

[0012] Preferably, in step 1, the YOLOv5-ATS model uses the Shape-IoU loss function to calculate the loss by focusing on the shape and size of the bounding box itself, thereby making the bounding box regression more accurate.

[0013] Preferably, the bounding box regression loss is as follows: L Shape-IoU =1-IoU+distance shape +0.5×Ω shape IoU is used to measure the overlap between the predicted bounding box or mask and the ground truth label; ww and hh represent the weight coefficients in the horizontal and vertical directions, respectively, and their values ​​are related to the shape of the ground truth box. When the ground truth box is a square, both ww and hh are equal to 1.

[0014] Preferably, the IoU calculation formula is as follows:

[0015] Preferably, the calculation formulas for ww and hh are as follows: Here, scale is a scaling factor that is related to the size of the target in the dataset. The smaller the target, the greater the influence of the absolute shape on the IoU value of the small target, and the scale value should also increase accordingly. Generally, the value is between 0 and 1.5.

[0016] Preferably, the performance evaluation metrics for the YOLOv5-ATS model in step 105 typically include accuracy, recall, and inference time.

[0017] The beneficial effects of this invention are:

[0018] This solution performs keypoint detection by analyzing the driver's head and body posture. First, an AIFI module is introduced on top of YOLOv5. This module optimizes the interaction between deep scales within the same feature map, better capturing subtle changes and nuances in driver behavior. It avoids the complex overall performance evaluation and data analysis process of the SPPF module, making it more computationally efficient and suitable for real-time applications. Second, the original Concat module in the neck layer is replaced with a TFE module. Feature maps are fused through adaptive scale adjustment and channel attention weighting, improving the accuracy of detecting small targets such as mobile phones and water cups. Finally, a shape-IoU module that considers shape information is introduced, enhancing robustness to targets with occlusion, deformation, or partial occlusion, providing more stable performance compared to the original IoU module. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a flowchart of the distracted driving detection process based on the improved YOLOv5 of this invention.

[0021] Figure 2 This is a flowchart of the improved YOLOv5 algorithm of this invention.

[0022] Figure 3 This is a diagram of the YOLOv5 network structure of the present invention.

[0023] Figure 4 This is a diagram of the improved YOLOv5 network structure of this invention.

[0024] Figure 5 This is a flowchart of the AIFI module of the present invention.

[0025] Figure 6 This is a structural diagram of the TFE module of the present invention.

[0026] Figure 7 This is a diagram of the Shape-IoU structure of the present invention.

[0027] Figure 8 This is a diagram showing the recognition status of the distracted driving dataset of the present invention.

[0028] Figure 9 This is a comparison chart of the label distribution of the distracted driving dataset of this invention.

[0029] Figure 10 This is a comparison chart of the PR curves of YOLOv5 and YOLOv5-ATS of the present invention. Detailed Implementation

[0030] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.

[0031] This invention discloses a distracted driving detection method based on an improved YOLOv5. For example... Figure 1 As shown, the embodiment includes the following steps: Step 1: Improve the YOLOv5 algorithm; Step 2: Obtain a frame image from the driver behavior video and input it into the trained YOLOv5-ATS model for object detection; Step 3: Determine whether the driver's body and head are present in this frame image. If not, it is determined to be a distracted driving behavior. If present, obtain the coordinate information of the driver's body and head, and determine whether the driver is in a distracted posture. Step 4: Determine whether the driver's body and head are present in this frame image. If not, it is determined to be a distracted driving behavior. If present, obtain the coordinate information of the driver's body and head, and determine whether the driver is in a distracted posture. Step 5: If the driver is in a distracted posture in this frame, the distraction count is incremented by one; otherwise, the distraction count is reset, and the detection of the next frame of the video begins. Step 6: If the driver is in a distracted state in this frame, determine whether the distraction count is equal to the video frame rate. If it is equal, determine that the driver is in a distracted driving state. If it is not equal, continue to detect the next frame of the video.

[0032] like Figure 2 As shown, the process of improving the YOLOv5 algorithm includes the following steps: Step 101: Perform data preprocessing, including processing the dataset images and scaling the images; Step 102: To address the issue of poor performance when processing targets with inconsistent scales, the AIFI module is added to the backbone network. By optimizing the interaction between deep scales within the same feature map, it is possible to better capture subtle changes and nuances in driver behavior. Step 103: To address the problem of not being able to identify small objects in complex environments, a TFE module is added to the neck network, and feature maps are fused through adaptive scale adjustment and channel attention weighting, thereby improving the accuracy of small object detection. Step 104: The head network performs model prediction training; Step 105: Obtain the trained YOLOv5-ATS model and its performance. Performance evaluation metrics typically include accuracy, recall, and inference time.

[0033] YOLOv5 is a deep learning-based object detection algorithm. Its model is designed using a lightweight detection model within the Python framework, and its network architecture is as follows: Figure 3 As shown. While YOLOv7 and YOLOv8 offer better performance, their computational demands are also higher, which may compromise the normal operation of embedded devices. Therefore, YOLOv5 is chosen as the base algorithm. As an efficient, lightweight, easy-to-use, and high-performance object detection algorithm, it is well-suited for distracted driving detection. It can achieve real-time detection while maintaining accuracy, and it has a small model size and low computational resource consumption, meeting the performance and efficiency requirements of in-vehicle systems. Based on model size, there are five models: YOLOv5s, YOLOv5m, YOLOv5l, YOLOv5x, and YOLOv5n. The YOLOv5 model framework consists of four parts: Input, Backbone, Neck, and Output. This paper uses YOLOv5s, which has the smallest network structure and the fastest speed, as the base algorithm.

[0034] The input stage of YOLOv5 marks the beginning of its object detection process. At this stage, the algorithm receives raw image data, which can come from various sources and formats. To improve the model's generalization ability and detection performance, YOLOv5 employs a data augmentation method called Mosaic. This method generates a new training image by randomly scaling, cropping, and arranging four images. This not only enriches the background of the detected object but also increases the number of small targets, thereby improving the model's detection accuracy. The Backbone uses a deep convolutional neural network (CNN) structure, transforming the input image data into a series of feature maps through convolutional layers, pooling layers, and other components. These feature maps contain various information about the image, such as edges, textures, and shapes, providing a foundation for subsequent object detection. The Neck's main function is to further process and fuse the feature maps extracted by the Backbone to generate feature representations more suitable for object detection. The Neck typically consists of a series of network layers that mix and combine image features, such as the FPN structure. These network layers improve the model's ability to detect objects at different scales by fusing and optimizing feature maps at different levels. The Output section of YOLOv5 is responsible for generating the final detection results. It receives the feature map after Neck processing and, through a series of convolutional and fully connected layers, generates the position, size, and class information for each predicted bounding box. YOLOv5 employs strategies such as anchors and confidence thresholds at the Output level. Anchors are a pre-defined series of fixed-size rectangles used to predict the position and size of the target; the confidence threshold filters out predictions below a certain threshold, thereby improving detection accuracy.

[0035] The YOLOv5 algorithm also has the following problems: 1) In the vehicle environment, there may be targets of different scales and sizes. The original YOLOv5 performs poorly when handling targets of inconsistent scales, causing some small-scale distraction behaviors to be ignored or falsely detected. Moreover, distraction behavior detection requires effective feature extraction of the driver's behavior in order to accurately classify and identify it. If the feature extraction is insufficient, it will lead to a decrease in algorithm performance and an inability to effectively distinguish different distraction behaviors. 2) In the original YOLOv5, there is a loss of interaction information between targets, resulting in insufficient overall understanding of the driver's behavior. This will affect the algorithm's ability to recognize complex scenes and multi-target interactions. 3) In vehicle distraction behavior detection, the driver's distraction behaviors have different poses, and a simple IOU loss function cannot accurately locate these targets, resulting in low detection accuracy.

[0036] The YOLO algorithm source code is highly decoupled, allowing for easy addition and modification of modules to address different problems. By deeply studying the algorithm and the AIFI, TFE, and Shape-IoU modules, it is possible to improve the algorithm's performance, increase detection accuracy, and enhance computational efficiency. The improved network structure is as follows: Figure 4 As shown.

[0037] To address the issue of poor performance when handling targets with inconsistent scales, this invention incorporates an attention-based intra-scale feature interaction (AIFI) module. The AIFI module further reduces computational redundancy by performing intra-scale interactions only on the deepest features. Applying self-attention to high-level features with richer semantic concepts captures the connections between conceptual entities in the image, facilitating object detection and recognition by subsequent modules. Simultaneously, due to the lack of semantic concepts, there is a risk of duplication and confusion with interactions on high-level features; therefore, intra-scale interactions on low-level features are unnecessary.

[0038] Figure 5 The flowchart of AIFI's modules is shown. In the backbone, the output of the fourth C3 module is used as input. Then, `pos_embed` adds the input to the positional encoding. The resulting sum is used to calculate Q and K in the multi-head self-attention mechanism. Next, `self_attn` is used to calculate the multi-head self-attention mechanism, and the result is added to the initial input and then normalized. After obtaining the result, an `ffn` module is executed. The result is then added to the previously normalized result via a cross-layer connection, normalized again, and finally, the encoder's output is obtained.

[0039] To address the problem of failing to recognize small objects in complex environments, image magnification can be used to reference and compare shape or appearance changes at different scales. Since different feature layers in the backbone network have different sizes, conventional FPN fusion mechanisms only upsample small-sized feature maps and then split or add them to the features of the previous layer, ignoring the rich details of larger-sized feature layers. Therefore, a Triple Feature Encoding (TFE) module is used. This module splits large, medium, and small features, adds large-sized feature maps, and magnifies the features to enhance detailed feature information.

[0040] Figure 6The structure of the TFE module is demonstrated. Before feature encoding, the number of feature channels is first adjusted to match the main scale features. After processing the large feature map (Large), its number of channels is adjusted to 1C, and then downsampling is performed using a hybrid structure of max pooling and average pooling. This helps preserve high-resolution features and the effectiveness and diversity of the image. For the small feature map (Small), a convolution module is also used to adjust the number of channels, and then upsampling is performed using the nearest neighbor interpolation method. This helps maintain the richness of local features in the low-resolution image and prevents the loss of feature information of small objects. Finally, the three feature maps of the same size (large, medium, and small) are convolved once and then concatenated along the channel dimension.

[0041] To address the problem of inaccurate target localization, the algorithm training process of this invention utilizes Shape-IoU loss to optimize the model. This method calculates the loss by focusing on the shape and size of the bounding box itself, thereby making the bounding box regression more accurate. The formula for calculating the shape structure is derived from... Figure 7 It can be known that...

[0042] Interchange of Union (IoU) is one of the most common metrics in object detection, used to measure the degree of overlap between two shapes. In object detection and image segmentation tasks, it is often used to measure the overlap between the predicted bounding box or mask and the ground truth label. The formula for calculating IoU is:

[0043] ww and hh represent the weighting coefficients in the horizontal and vertical directions, respectively. Their values ​​are related to the shape of the ground truth (GT) box. When the GT box is a square, both ww and hh are equal to 1. The calculation formula is as follows:

[0044] Here, `scale` is a scaling factor, related to the size of the targets in the dataset. The smaller the target, the greater the impact of the absolute shape on the IoU value of the small target, and the `scale` value should increase accordingly. It is generally set between 0 and 1.5. The corresponding bounding box regression loss is as follows: L Shape-IoU =1-IoU+distance shape +0.5×Ω shape (7)

[0045] Experimental Results and Analysis

[0046] Experimental Data: With the increasing sophistication of electronic devices in automobiles and the growing reliance on mobile phones and other electronic devices, drivers need to acquire and process more information while driving. The current public dataset, State Farm Distracted Driver Detection, contains 640×480 images of nine distraction behaviors: texting to the right (C1), texting to the left (C2), calling to the right (C3), calling to the left (C4), adjusting the radio (C5), drinking water (C6), reaching for the back seat (C7), touching hair and applying makeup (C8), and talking to passengers (C9). This study is based on the publicly available dataset, State Farm Distracted Driver Detection.

[0047] This dataset aims to improve driving safety by detecting and predicting distracted driving behaviors through analysis of driver actions. It contains images of drivers in various driving scenarios, captured in real-world driving environments. Drivers in the images are categorized into different driving states, including normal driving, using a mobile phone, adjusting the radio, drinking beverages, and more. There are a total of nine different categories. The dataset includes over 20,000 images, covering various weather conditions, lighting conditions, and driving scenarios. These images have a resolution of 640×480 pixels. Furthermore, the dataset provides additional image information, such as the driver's gender and age, to expand the analysis of driving behavior.

[0048] Before algorithm training, the labeling tool labelimg was used to label different types of distracted driving behaviors in the data. The label file format is YOLO, and its distraction dataset identification is as follows: Figure 8 As shown. The label file data has five items: label category, x-coordinate, center point of the label box, y-coordinate, width, and height. According to the experimental requirements, the data is divided into a training set and an 8:2 validation set. The distribution of the label centroid coordinates, label width, and height for the nine distracted driving behavior categories in the training set is shown below. Figure 9 As shown.

[0049] Experimental Environment and Evaluation Metrics: This experiment was conducted in a Linux environment, specifically Ubuntu 18.04 operating system; Nvidia 3080Ti 12GB graphics card; and the YOLOv5 algorithm based on Python. Parameter settings are shown in Table 1. To better evaluate detection performance, we used four metrics: precision (P), recall (R), mean precision (mAP), and F1 score. Table 1 Parameter Setting Table Parametername Parameter value Learningrate 0.01 Batchsize 16 Weightdecay 0.005 Epochs 300 Momentum 0.937

[0050] In this context, precision P refers to the proportion of samples that the model predicts as positive, but which are actually positive. In object detection, precision P indicates how many of the detected targets are true targets. The calculation formula is as follows:

[0051] Recall R refers to the proportion of positive class samples that the model successfully predicts. In object detection, recall represents the proportion of true positive targets that the model can successfully detect. The calculation formula is as follows:

[0052] mAP is a comprehensive metric used to evaluate the detection performance of an object detection model across different classes. It first calculates the AP for each class, then averages the APs across all classes to obtain the MAP. AP is the area under the Precision-Recall curve, representing the model's detection accuracy in a single class. A higher MAP indicates better model performance across all classes. The calculation formula is as follows:

[0053] F1 is the harmonic mean of precision and recall, used to comprehensively evaluate model performance. It combines precision and recall, taking into account both the accuracy and completeness of the model. The value of F1 ranges from 0 to 1, with higher values ​​indicating better model performance. The calculation formula is as follows:

[0054] Experimental Results Analysis: To verify the performance of the proposed YOLOv5-ATS, we compared the YOLOv5-ATS algorithm with popular algorithms such as YOLOv3, YOLOv4, and YOLOv5 on the same dataset, with a fixed training iteration time of 300 epochs. The mAP value was used to verify the model's comprehensive detection capability, representing its detection performance. After 300 epochs, both the proposed YOLOv5-ATS and YOLOv5 reached stability, with the former exhibiting a higher mAP, indicating that the proposed YOLOv5-ATS is superior in detecting distracted driving behavior.

[0055] As shown in Table 2, the proposed YOLOv5-ATS algorithm outperforms YOLOv5 in terms of F1 score, mAP, precision, and recall, by 1.7%, 1.4%, 1.8%, and 1.5%, respectively. During testing, PR curves of the model before and after improvement were plotted to evaluate the model. Figure 10As shown, the proposed YOLOv5-ATS algorithm significantly outperforms the YOLOv5 algorithm. While Faster-RCNN has the lowest accuracy, it has a higher recall rate than YOLOv3 and YOLOv4. This is mainly because the lightweight model has fewer network layers, resulting in lower feature extraction and learning capabilities. The proposed YOLOv5-ATS algorithm has the highest mAP, 0.2% higher than Faster-RCNN, and 2.8% and 5% higher than YOLOv3 and YOLOv4, respectively, indicating strong generalization ability. In real-world distracted driving behavior detection, the algorithm achieves high accuracy, slightly higher than YOLOv5 (though small), but significantly higher than other algorithms. In this invention, the YOLOv5-ATS algorithm outperforms other mainstream object recognition algorithms, including Faster-RCNN, YOLOv3, and YOLOv4, in terms of accuracy and other aspects. Table 2 Performance Comparison of Different Models

[0056] It should be noted that the parts not described in detail in the above embodiments are all prior art.

[0057] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention should be covered within the protection scope of the present invention.

Claims

1. A distracted driving detection method based on an improved YOLOv5, characterized in that: Includes the following steps: Step 1: Improve the YOLOv5 algorithm, including the following steps: Step 101: Perform data preprocessing; Step 102: Add the AIFI module to the backbone network to optimize the interaction between deep scales within the same feature map; Step 103: After adding the TFE module to the neck network, feature maps are fused using adaptive scale adjustment and channel attention weighting. Step 104: The head network performs model prediction training; Step 105: Obtain the trained YOLOv5-ATS model and its performance; Step 2: Obtain a frame image from the driver behavior video and input it into the trained YOLOv5-ATS model for object detection; Step 3: Determine whether the driver's body and head are present in this frame image. If not, it is determined to be a distracted driving behavior. If present, obtain the coordinate information of the driver's body and head, and determine whether the driver is in a distracted posture. Step 4: Determine whether the driver's body and head are present in this frame image. If not, it is determined to be a distracted driving behavior. If present, obtain the coordinate information of the driver's body and head, and determine whether the driver is in a distracted posture. Step 5: If the driver is in a distracted posture in this frame, the distraction count is incremented by one; otherwise, the distraction count is reset, and the detection of the next frame of the video begins. Step 6: If the driver is in a distracted state in this frame, determine whether the distraction count is equal to the video frame rate. If it is equal, determine that the driver is in a distracted driving state. If it is not equal, continue to detect the next frame of the video.

2. The distracted driving detection method based on improved YOLOv5 according to claim 1, characterized in that: The data preprocessing in step 101 includes processing the dataset images and performing scale transformation on the images.

3. The distracted driving detection method based on improved YOLOv5 according to claim 1, characterized in that: In step 102, the AIFI module performs intrascale interaction on the deepest features, applies self-attention operations to high-level features with richer semantic concepts, captures the connections between conceptual entities in the image, and uses them for subsequent modules to detect and recognize objects in the image.

4. The distracted driving detection method based on improved YOLOv5 according to claim 3, characterized in that: The AIFI module takes the output of the fourth C3 module as input in the backbone, and then uses pos_embed to add the input to the positional encoding. The result of this addition is used to calculate Q and K in the multi-head autonomous attention mechanism. Then, self_attn is used to calculate the multi-head self-attention mechanism, and the result is added to the initial input and then normalized. After obtaining the result, an ffn module is executed, and after obtaining the result, a cross-layer connection is made to add the previously normalized result, and after this addition, normalization is performed again. Finally, the encoder output is obtained.

5. The distracted driving detection method based on improved YOLOv5 according to claim 1, characterized in that: In step 103, before feature encoding, the TFE module first adjusts the number of feature channels to match the main scale features. After processing the large feature map, its number of channels is adjusted to 1C, and then downsampling is performed using a hybrid structure of max pooling and average pooling. For the small feature map, the convolution module is also used to adjust the number of channels, and then upsampling is performed using the nearest neighbor interpolation method. Finally, the three feature maps of the same size (large, medium, and small) are convolved once and then concatenated along the channel dimension.

6. The distracted driving detection method based on improved YOLOv5 according to claim 5, characterized in that: In step 1, the YOLOv5-ATS model uses the Shape-IoU loss function to calculate the loss by focusing on the shape and size of the bounding box itself, thereby making the bounding box regression more accurate.

7. The distracted driving detection method based on improved YOLOv5 according to claim 6, characterized in that: The bounding box regression loss is as follows: L Shape-IoU =1-IoU+distance shape +0.5×Ω shape IoU is used to measure the overlap between the predicted bounding box or mask and the ground truth label; ww and hh represent the weight coefficients in the horizontal and vertical directions, respectively, and their values ​​are related to the shape of the ground truth box. When the ground truth box is a square, both ww and hh are equal to 1.

8. The distracted driving detection method based on improved YOLOv5 according to claim 7, characterized in that: The formula for calculating IoU is:

9. The distracted driving detection method based on improved YOLOv5 according to claim 7, characterized in that: The formulas for calculating ww and hh are as follows: Here, scale is a scaling factor that is related to the size of the target in the dataset. The smaller the target, the greater the influence of the absolute shape on the IoU value of the small target, and the scale value should also increase accordingly. Generally, the value is between 0 and 1.

5.

10. The distracted driving detection method based on improved YOLOv5 according to claim 1, characterized in that: The performance evaluation metrics for the YOLOv5-ATS model in step 105 typically include accuracy, recall, and inference time.