Intelligent kitchen target detection method based on YOLOv5
By adding the CBAM attention mechanism and SIoU loss function to the YOLOv5 model, the object detection interference problem caused by the complexity of the kitchen environment is solved, and the identification accuracy and alarm speed of pest animals in the kitchen are improved to ensure food safety.
Patent Information
- Application Number
- CN202410987775.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-19
AI Technical Summary
The kitchen environment is complex, and the target detection is interfered with by factors such as occlusion, lighting changes, background clutter and motion blur, which affects the monitoring effect and makes it difficult to effectively solve food safety problems.
Adding the CBAM attention mechanism to the C3 layer of the YOLOv5 network model, and combining the SIoU loss function, enhance feature extraction and importance learning, suppressing irrelevant areas through the channel and spatial attention modules, improving detection accuracy and recognition accuracy.
It improves the accuracy of identification of harmful animals in the kitchen and alarm speed, ensures food safety, reduces kitchen losses, and enhances the effectiveness of the kitchen intelligent monitoring system.
Smart Images

Figure CN118982776A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of target detection, and in particular to a smart kitchen target detection method based on YOLOv5. Background Art
[0002] The rapid development of the catering industry has once again made food safety a focus. Pests such as rats and cockroaches are often reported in restaurant kitchens. In addition, my country's special cooking methods make Chinese food rich in variety and flavor, which makes it easier to cause food safety problems, seriously affecting people's health.
[0003] With the advancement of science and technology, traditional kitchens are beginning to move towards smart kitchens. By deploying real-time monitoring systems and alarm systems in the kitchen, real-time monitoring and timely warning of the temperature and humidity of lockers, kitchen gas stoves, and kitchen rodents can be achieved, which improves the safety and intelligence of the kitchen and effectively ensures food safety. However, due to the complex kitchen environment, in the process of tracking rodents, insects, etc., the targets are interfered by factors such as partial occlusion, lighting changes, background clutter, motion blur, etc., which seriously affects the monitoring effect to a certain extent. For this reason, the present invention provides a smart kitchen target detection method based on YOLOv5. Summary of the invention
[0004] The purpose of the present invention is to provide a smart kitchen target detection method based on YOLOv5 to solve the problems raised in the above background technology.
[0005] To achieve the above object, the present invention provides the following technical solutions:
[0006] A smart kitchen target detection method based on YOLOv5, comprising the following steps:
[0007] S1. Build a network model for target detection and train it. Add the CBAM attention mechanism to the C3 layer of the backbone network of the YOLOv5 network structure to obtain the C3CBAM layer to enhance the network model's ability to extract features and learn the importance of features.
[0008] S2, monitoring real-time video preprocessing: obtain real-time video stream through the monitoring system, split it into separate frames, and resize the video frames to match the input size of the YOLOv5 model;
[0009] S3, monitor real-time video processing; load the constructed target detection network model, perform real-time detection, analysis and output results of the range of the monitoring system;
[0010] S4. Add alarm objects to the alarm system; set animals that endanger kitchen hygiene and safety in the kitchen as alarm objects;
[0011] S5. Synchronize the network model with the alarm system; synchronously transmit the output result in step S3 to the alarm system, and when the output result matches the alarm object in the alarm system, the alarm system is automatically triggered.
[0012] Preferably, the CBAM attention mechanism includes two sub-modules: channel attention and spatial attention, so as to perform channel and spatial attention respectively.
[0013] Preferably, the CBAM attention mechanism is combined with a channel attention module in front and a spatial attention module in the back, and the weight of each channel and each position is adaptively adjusted, thereby enhancing the model's ability to extract features and learn the importance of features.
[0014] Preferably, the channel attention module performs weighted processing on the features of each channel based on global maximum pooling and global average pooling operations to obtain the maximum feature and average feature of each channel, learns the size of the attention weight of each channel through a shared fully connected layer, obtains the final attention weight, and multiplies it with the original feature of each channel, suppresses irrelevant channels through the learned weights, and obtains the weighted channel features.
[0015] Preferably, the spatial attention module uses pooling operations on feature maps along the channel dimension based on global maximum pooling and average pooling to generate contextual scale features; different contextual scales are spliced, and then the spatial attention weights are obtained by convolution operations on the spliced features, and the spatial attention weights are multiplied by the original features. The irrelevant areas are suppressed through the learned weights to highlight the target image area.
[0016] Preferably, SIoU is used in YOLOv5 to improve training speed and reasoning accuracy.
[0017] Preferably, the SIoU includes angle loss, distance loss, shape loss, and IoU loss;
[0018] The SIoU formula is:
[0019]
[0020] Where Δ is the distance loss and Ω is the shape loss;
[0021] The IoU formula is:
[0022]
[0023] Where A is the intersection of the predicted box and the true box, and B is the union of the predicted box and the true box.
[0024] Preferably, the formula for the angle loss is:
[0025]
[0026] In the formula, c h is the height difference between the center point of the real box and the predicted box, σ is the distance between the center point of the real box and the predicted box, c h The formula for and σ is:
[0027]
[0028]
[0029] In the formula, is the center coordinate of the real box, are the center coordinates of the prediction box.
[0030] Preferably, the formula for distance loss is:
[0031]
[0032]
[0033]
[0034] In the formula, c w is the width of the minimum bounding rectangle of the real box and the predicted box, c h is the height of the minimum bounding rectangle of the real box and the predicted box, Λ is the angle loss; ρ x represents the x-coordinate of the center point of the prediction box, ρ y Indicates the y coordinate of the center point of the prediction box.
[0035] Preferably, the formula for shape loss is:
[0036]
[0037]
[0038]
[0039] Where (w,h) is the width and height of the prediction box, (w gt ,h gt ) is the width and height of the real box, and θ is the degree of attention paid to shape loss.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] The present invention adds the CBAM attention mechanism to form a new C3CBAM layer to replace the original C3 layer, thereby enhancing the model's ability to extract features and learn the importance of features, so that Attention pays more attention to the target object to improve the accuracy of detection; the channel attention module and the spatial attention module are fully utilized to increase the attention weight, suppress irrelevant areas, highlight the target image area, and improve recognition accuracy; the improved SIoU is used to increase the training speed and reasoning accuracy, thereby improving the recognition speed and accuracy of alarm objects in the kitchen, making it more convenient and worry-free to use;
[0042] By synchronizing with the alarm system, timely alarms can be issued for animals that are harmful to kitchen hygiene and safety, such as rodents and insects, that appear in the kitchen. The alarm system can be used to drive them away, and the staff can be reminded to drive them away in time, thus ensuring kitchen hygiene and safety and reducing kitchen losses. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 This is the structural diagram of the CBAM attention mechanism of the present invention;
[0044] Figure 2 Schematic diagram of the C3CBAM layer after the CBAM attention mechanism is added to the present invention;
[0045] Figure 3 This is the YOLOv5 backbone network structure diagram after adding the CBAM attention mechanism in the present invention. DETAILED DESCRIPTION
[0046] Embodiment 1:
[0047] See also Figure 1-3 ,The present invention provides a technical solution: a smart kitchen target detection method based on YOLOv5;
[0048] The following steps are involved:
[0049] S1. Build a network model for target detection and train it. Add the CBAM (Convolutional Block Attention Module) attention mechanism (also called CBAM) to the C3 layer of the backbone network of the YOLOv5 network structure to obtain the C3CBAM layer to enhance the network model's ability to extract features and learn the importance of features. CBAM is a lightweight attention module that can perform attention operations in spatial and channel dimensions, so that Attention can focus more on the target object to improve detection accuracy.
[0050] S2, monitoring real-time video preprocessing: obtain real-time video stream through the monitoring system, split it into separate frames, and resize the video frames to match the input size of the YOLOv5 model;
[0051] S3, monitor real-time video processing; load the constructed target detection network model, perform real-time detection, analysis and output results of the range of the monitoring system;
[0052] S4. Add alarm objects to the alarm system; set animals that endanger kitchen hygiene and safety in the kitchen as alarm objects;
[0053] S5. Synchronize the network model with the alarm system; synchronously transmit the output result in step S3 to the alarm system, and when the output result matches the alarm object in the alarm system, the alarm system is automatically triggered.
[0054] Specifically, the CBAM attention mechanism includes two sub-modules: channel attention CAM (Channel Attention Module) and spatial attention SAM (SpartialAttention Module). Channel attention CAM (ChannelAttention Module) and spatial attention SAM (SpartialAttention Module) can also be called channel attention and spatial attention, which respectively perform channel and spatial attention; after adding the CBAM attention mechanism module to the YOLOv5 detection algorithm, the Attention can pay more attention to the target object to improve the accuracy of detection; the CBAM attention mechanism is combined with the channel attention module in front and the spatial attention module in the back, and the weight of each channel and each position is adaptively adjusted, thereby enhancing the model's ability to extract features and learn the importance of features; the channel attention module performs weighted processing on the features of each channel based on the global maximum pooling and global average pooling operations to obtain each The maximum feature and average feature of the channel are learned through a shared fully connected layer to learn the size of the attention weight of each channel to obtain the final attention weight, which is finally multiplied with the original feature of each channel. The learned weights are used to suppress irrelevant channels to obtain weighted channel features. The spatial attention module uses maximum pooling and average pooling to perform pooling operations on the feature map along the channel dimension to generate contextual scale features. Different contextual scales are spliced, and then the spatial attention weight is obtained by convolving the spliced features. Similarly, the spatial attention weight is multiplied with the original feature, and the learned weights are used to suppress irrelevant areas and highlight the target image area.
[0055] Specifically, SIoU is used in YOLOv5. SIoU further considers the vector angle between the real box and the predicted box on the basis of IoU, and redefines the relevant loss function to improve the training speed and reasoning accuracy; SIoU includes angle loss, distance loss, shape loss, and IoU loss;
[0056] The SIoU formula is:
[0057]
[0058] Where Δ is the distance loss and Ω is the shape loss;
[0059] The IoU formula is:
[0060]
[0061] Where A is the intersection of the predicted box and the true box, and B is the union of the predicted box and the true box;
[0062] The formula for angle loss is:
[0063]
[0064] In the formula, c h is the height difference between the center point of the real box and the predicted box, σ is the distance between the center point of the real box and the predicted box, c h The formula for and σ is:
[0065]
[0066]
[0067] In the formula, is the center coordinate of the real box, is the center coordinate of the prediction box;
[0068] The formula for distance loss is:
[0069]
[0070]
[0071]
[0072] In the formula, c w is the width of the minimum bounding rectangle of the real box and the predicted box, c h is the height of the minimum bounding rectangle of the real box and the predicted box, Λ is the angle loss; ρ x represents the x-coordinate of the center point of the prediction box, ρ y Indicates the y coordinate of the center point of the prediction box;
[0073] The formula for shape loss is:
[0074]
[0075]
[0076]
[0077] Where (w,h) is the width and height of the prediction box, (w gt ,h gt ) is the width and height of the real box, and θ is the degree of attention paid to shape loss.
[0078] Example 2
[0079] Based on Example 1, this model is compared with other models;
[0080]
[0081] By comparison, it can be seen that the model has improved in terms of precision, recall, harmonic mean and average detection accuracy, while the number of parameters is basically consistent with the YOLOv5 model, which reflects the performance advantage of this model.
Claims
1. A smart kitchen target detection method based on YOLOv5, characterized by: The following steps are involved: S1. Build a network model for target detection and train it. Add the CBAM attention mechanism to the C3 layer of the backbone network of the YOLOv5 network structure to obtain the C3CBAM layer to enhance the network model's ability to extract features and learn the importance of features. S2, monitoring real-time video preprocessing: obtain real-time video stream through the monitoring system, split it into separate frames, and resize the video frames to match the input size of the YOLOv5 model; S3, monitor real-time video processing; load the constructed target detection network model, perform real-time detection, analysis and output results of the range of the monitoring system; S4. Add alarm objects to the alarm system; set animals that endanger kitchen hygiene and safety in the kitchen as alarm objects; S5. Synchronize the network model with the alarm system; synchronously transmit the output result in step S3 to the alarm system, and when the output result matches the alarm object in the alarm system, the alarm system is automatically triggered.
2. According to a YOLOv5-based smart kitchen target detection method according to claim 1, it is characterized in that: The CBAM attention mechanism includes two sub-modules: channel attention and spatial attention, which perform channel and spatial attention respectively.
3. The smart kitchen target detection method based on YOLOv5 according to claim 1, characterized in that: The CBAM attention mechanism is combined with a channel attention module in front and a spatial attention module in the back to adaptively adjust the weight of each channel and each position.
4. The smart kitchen target detection method based on YOLOv5 according to claim 3, characterized in that: The channel attention module performs weighted processing on the features of each channel based on global maximum pooling and global average pooling operations to obtain the maximum feature and average feature of each channel, learns the size of the attention weight of each channel through a shared fully connected layer, obtains the final attention weight, and multiplies it with the original feature of each channel. The learned weights are used to suppress irrelevant channels to obtain weighted channel features.
5. The smart kitchen target detection method based on YOLOv5 according to claim 3, characterized in that: The spatial attention module uses global maximum pooling and average pooling to perform pooling operations on feature maps along the channel dimension to generate context scale features; different context scales are spliced, and then the spatial attention weights are obtained by convolution operations on the spliced features. The spatial attention weights are multiplied by the original features, and the irrelevant areas are suppressed through the learned weights to highlight the target image area.
6. The smart kitchen target detection method based on YOLOv5 according to claim 1, characterized in that: SIoU is used in YOLOv5 to improve training speed and inference accuracy.
7. The smart kitchen target detection method based on YOLOv5 according to claim 6, characterized in that: The SIoU includes angle loss, distance loss, shape loss, and IoU loss; The SIoU formula is: Where Δ is the distance loss and Ω is the shape loss; The IoU formula is: Where A is the intersection of the predicted box and the true box, and B is the union of the predicted box and the true box.
8. The smart kitchen target detection method based on YOLOv5 according to claim 7, characterized in that: The formula for the angle loss is: In the formula, c h is the height difference between the center point of the real box and the predicted box, σ is the distance between the center point of the real box and the predicted box, c h The formula for and σ is: In the formula, is the center coordinate of the real frame, are the center coordinates of the prediction box.
9. The smart kitchen target detection method based on YOLOv5 according to claim 7, characterized in that: The formula for distance loss is: In the formula, c w is the width of the minimum bounding rectangle of the real box and the predicted box, c h is the height of the minimum bounding rectangle of the real box and the predicted box, Λ is the angle loss; ρ x represents the x-coordinate of the center point of the prediction box, ρ y Indicates the y coordinate of the center point of the prediction box.
10. The smart kitchen target detection method based on YOLOv5 according to claim 7, characterized in that: The formula for shape loss is: Where (w,h) is the width and height of the prediction box, (w gt ,h gt ) is the width and height of the real box, and θ is the degree of attention paid to shape loss.
