A method for detecting safety signs in chemical plants based on improved YOLOv5
By improving the YOLOv5 network and utilizing the k-means++ clustering algorithm, CARAFE upsampling, and Focal-EIOU Loss, the accuracy and speed issues of safety sign recognition in chemical plants were resolved, enabling rapid and accurate detection of safety signs within chemical plants and ensuring the safety of rescue personnel.
Patent Information
- Application Number
- CN202310669747.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-07
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2043-06-07
AI Technical Summary
Existing target detection methods struggle to balance accuracy and speed in identifying safety signs in chemical plant environments, potentially leading rescue personnel to mistakenly enter dangerous areas at accident sites and posing safety hazards.
An improved YOLOv5 network is adopted, anchor boxes are calculated using the k-means++ clustering algorithm, a lightweight upsampling operator CARAFE is added, and the Focal-EIOU Loss function is used to improve the model's recognition accuracy and speed.
In a chemical plant environment, the rapid and accurate identification of safety signs was achieved, reducing the false identification rate, improving the identification accuracy and recall rate, and ensuring the safety of rescue personnel.
Smart Images

Figure CN116681942B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of target detection and relates to a method for detecting safety signs in chemical plants based on an improved YOLOv5. Background Technology
[0002] Object detection is a crucial task in computer vision, aiming to understand and abstract image content by analyzing images and identifying objects within them. Two-stage and single-stage object detection methods represent two distinct approaches. Two-stage methods divide the object detection task into two stages: region extraction and classification / detection. In the first stage, algorithms extract candidate regions from the image, which are areas that may contain objects. In the second stage, classifiers (such as convolutional neural networks) are often used to classify and locate objects in the image based on the extracted candidate regions. In contrast, single-stage object detection methods directly detect and locate objects in the entire image. These algorithms typically employ convolutional neural networks (such as SSD, YOLO, and RetinaNet), performing classification and localization within a single network. In summary, two-stage methods offer high accuracy but are computationally intensive and slower, making them suitable for scenarios requiring high precision. Single-stage methods offer fast detection speeds but relatively lower accuracy, making them suitable for real-time detection scenarios.
[0003] With the development and expansion of chemical plants, chemical safety management has become increasingly important. Safety signs are an indispensable and important component of chemical production. Within a chemical plant, various areas are equipped with corresponding safety signs. For example, areas with a lot of electrical equipment have "Caution: Electric Shock" signs; areas with flammable and explosive materials have "No Smoking" signs; confined spaces have "Do Not Enter" signs; and areas with a lot of dangerous equipment have "Caution: Machinery Injury" signs. These signs facilitate daily management. However, in the event of an accident, such as a localized fire, rescue personnel unfamiliar with the chemical plant site may mistakenly enter confined spaces or flammable and explosive areas, causing danger. To ensure the safety of rescue personnel, this invention was designed to prevent such accidents. Summary of the Invention
[0004] This invention addresses the issue of whether drones can accurately identify safety signs in chemical plants, thereby reducing casualties and ensuring the safety of rescue personnel in the event of an accident. It proposes a method for detecting safety signs in chemical plants based on an improved YOLOv5. This invention can quickly and accurately identify safety signs in chemical plants. The technical solution of the method for detecting safety signs in chemical plants based on an improved YOLOv5 is as follows:
[0005] (1) Take a dataset: Go inside the chemical plant and take a dataset of safety sign recognition data in the workshop inside the chemical plant.
[0006] (2) Process the dataset to obtain a dataset that can be used for training;
[0007] (3) Improve the network by using the k-means++ clustering algorithm to calculate anchor boxes suitable for the model, and replace the original nine anchor boxes with the newly obtained nine anchor boxes. Add the lightweight upsampling operator CARAFE, and replace the original model's CIOU Loss with Focal-EIOU Loss as the loss function;
[0008] (4) Train the network: Train the improved network from step (3) and save the training results. Use the trained model to detect safety signs in the chemical plant;
[0009] Furthermore, step (1) includes the following steps:
[0010] A dataset of safety signs was collected by traveling to a chemical plant. Cameras were positioned in fixed locations within the plant to mimic the use of drone cameras for sign recognition. Images of safety signs were taken both during the day and at night with the lights on. After collection, the dataset was reviewed, and images that were particularly blurry or did not contain the necessary safety signs were removed.
[0011] Furthermore, step (2) includes the following steps:
[0012] The script was used to number the images in the folder, and the Labelimg annotation tool was used to annotate the numbered images. Four safety signs were prepared for recognition in this model: confined space, Beware of Machinery Injuries, No Smoking, and Electric Shock Carefully. The annotated images were generated into an XML file, and then a Python script was used to convert the XML file into a TXT file that the YOLOv5 model could recognize. Finally, a Python script was used to divide the dataset into training, testing, and validation sets in an 8:1:1 ratio.
[0013] Furthermore, step (3) includes the following steps:
[0014] (3-1) Use the k-means++ clustering algorithm to calculate the anchor boxes that are suitable for the model, and replace the original nine anchor boxes with the newly obtained nine anchor boxes.
[0015] (3-2) The lightweight upsampling operator CARAFE is added. The original YOLOv5 model uses nearest neighbor interpolation or commonly used bilinear interpolation, which does not utilize the semantic information of the feature map. It only uses the spatial position of the pixel to determine the upsampling kernel, and the receptive field is very small. CARAFE can aggregate contextual information in a larger receptive field, and it is lightweight and fast in computation.
[0016] (3-3) This model uses Focal-EIOU Loss instead of the original CIOU Loss. Since poor-quality anchor boxes generate large gradients, affecting the training process, Focal-EIOU Loss, from the perspective of gradients, distinguishes between high-quality and low-quality anchor boxes, accelerating convergence and improving regression accuracy. The formula for calculating Focal-EIOU Loss is:
[0017]
[0018] C 2 =(w c ) 2 +(h c ) 2
[0019]
[0020]
[0021] L Focal-EIOU =IOU γ L EIOU
[0022] Among them, b and b gt Here, w and w' are the coordinates of the center points of the predicted bounding box and the target bounding box, respectively. gt Let h and h' be the widths of the predicted bounding box of the object and the target bounding box, respectively. gt w represents the height of the predicted bounding box of the object and the height of the target bounding box, respectively. c and h c Let ρ be the width and height of the smallest bounding rectangle that can be formed by the predicted bounding box and the target bounding box of the object, respectively. 2 (b,b gt ρ represents the square of the Euclidean distance between the predicted bounding box of the object and the center point of the object's target bounding box. 2 (w,w gt ρ represents the square of the difference between the width of the predicted bounding box of the predicted object and the width of the object's target bounding box. 2 (h,h gt) represents the square of the difference between the height of the predicted bounding box and the height of the object's target bounding box. γ is a hyperparameter used to control the curvature of the curve; γ = 0.5 allows the model to achieve the optimal trade-off.
[0023] Furthermore, step (4) includes the following steps:
[0024] After modifying the network model, it was trained, and the weight file and global average precision (map) of the trained model were saved. Compared with the map value obtained after training the original model, the map value increased from 0.965 to 0.995. Compared with the precision of the original model, the precision increased from 0.949 to 0.984. Compared with the recall of the original model, the recall increased from 0.958 to 0.981. Using the improved model to detect safety signs in a chemical plant, the recognition accuracy was significantly improved compared with the original model, and the false recognition rate was also much lower.
[0025] This invention has the following advantages:
[0026] (1) The data collection is divided into daytime collection and nighttime collection under light so that the model can have better recognition ability in different environments.
[0027] (2) By adding the lightweight upsampling operator CARAFE, the detection accuracy of the model is improved to a certain extent and the safety signs can be accurately detected in complex environments.
[0028] (3) The Focal-EIOU Loss was used instead of the original CIOU Loss, which accelerated convergence and improved the accuracy of regression. In addition, the accuracy after training was also significantly improved compared with EIOU Loss.
[0029] (4) Using the k-means++ clustering algorithm to calculate the anchor boxes suitable for the model can improve the recognition efficiency and accuracy of the model.
[0030] (5) Applying this network to chemical plants can enable safer and more effective management. Applying it to drones allows for the reconnaissance of accident scenes, enabling rescue personnel to avoid entering dangerous areas and effectively preventing casualties. Attached Figure Description
[0031] Figure 1 This is a flowchart of a method for detecting safety signs in chemical plants based on an improved YOLOv5.
[0032] Figure 2 A simplified network framework diagram for a method of detecting safety signs in chemical plants based on an improved YOLOv5;
[0033] Figure 3 The effect of identifying safety signs in chemical plants on the original network. Figure 1 ;
[0034] Figure 4 To improve the effectiveness of the security flag recognition method in YOLOv5 networks Figure 1 ;
[0035] Figure 5 The effect of identifying safety signs in chemical plants on the original network. Figure 2 ;
[0036] Figure 6 To improve the effectiveness of the security flag recognition method in YOLOv5 networks Figure 2 ; Detailed Implementation
[0037] To make the technical solution of the present invention clearer, the present invention will be further described below with reference to the accompanying drawings. Figure 1 As shown, the present invention is implemented according to the following specific steps:
[0038] The first step is to capture a dataset of safety signs.
[0039] A dataset of safety signs was collected by traveling to a chemical plant. Cameras were positioned in fixed locations within the plant to mimic the use of drone cameras for sign recognition. Images of safety signs were taken both during the day and at night with the lights on. After collection, the dataset was reviewed, and images that were particularly blurry or did not contain the necessary safety signs were removed.
[0040] The second step is to process the dataset captured in the first step.
[0041] The script was used to number the images in the folder. The numbered images were then labeled using the Labelimg annotation tool. Four safety signs were prepared for recognition in this model: confined space, Beware of Machinery Injuries, no smoking, and Electric shock carefully. The labeled images were then generated into XML files and placed in the Annotations folder. A Python script was then used to convert the XML files into TXT files that the YOLOv5 model could recognize. These TXT files were placed in the Labels folder. Finally, a Python script was used to divide the dataset into training, testing, and validation sets in an 8:1:1 ratio, generating train.txt, test.txt, and val.txt files with randomly distributed datasets. The paths to the images in the dataset were also generated in the ImageSets folder to facilitate image reading by the model.
[0042] The third step is to improve the YOLOv5 network.
[0043] (3-1) Use the k-means++ clustering algorithm to calculate anchor boxes suitable for the model, and replace the original nine anchor boxes with the newly obtained nine anchor boxes. The k-means++ algorithm is an improved k-means clustering algorithm. This algorithm is simple, fast, and particularly suitable for use on regular datasets. It is a method to avoid weak clustering that sometimes occurs when using the k-means algorithm. It improves the accuracy of clustering results through an intelligent initialization method. The steps of the k-means++ algorithm are as follows:
[0044] 1. Randomly select a sample point from the input dataset as the first cluster center.
[0045] 2. For each remaining sample point, calculate its shortest distance to each of the selected cluster centers.
[0046] 3. Select a new cluster center such that the probability of its selection is proportional to the square of the shortest distance to the selected cluster center.
[0047] 4. Repeat steps 2 and 3 until k cluster centers are selected.
[0048] 5. Run the standard k-means clustering algorithm using the selected k cluster centers.
[0049] This intelligent initialization method makes it easier for the algorithm to avoid local optima, thereby improving the accuracy of clustering results.
[0050] (3-2) The addition of the lightweight upsampling operator CARAFE addresses the issue that the original YOLOv5 model uses nearest neighbor interpolation or commonly used bilinear interpolation, which do not utilize the semantic information of the feature map and only use the spatial location of pixels to determine the upsampling kernel, resulting in a very small receptive domain. CARAFE, on the other hand, can aggregate contextual information in a larger receptive domain and is lightweight and computationally fast. In tasks such as image classification and object detection, CARAFE can significantly improve the performance and accuracy of the model, demonstrating its wide range of applications.
[0051] (3-3) This model uses Focal-EIOU Loss instead of the original CIOU Loss. Since poor-quality anchor boxes generate large gradients, affecting the training process, Focal-EIOU Loss, from the perspective of gradients, distinguishes between high-quality and low-quality anchor boxes, accelerating convergence and improving regression accuracy. Compared to training with EIOU Loss, using Focal-EIOU Loss improves accuracy by 4.3% under otherwise unchanged conditions, and compared to training with CIOU Loss, it improves accuracy by 3.5% under otherwise unchanged conditions. The formula for calculating Focal-EIOU Loss is:
[0052]
[0053] C 2 =(w c ) 2 +(h c ) 2
[0054]
[0055]
[0056] L Focal-EIOU =IOU γ L EIOU
[0057] Among them, b and b gt Here, w and w' are the coordinates of the center points of the predicted bounding box and the target bounding box, respectively. gt Let h and h' be the widths of the predicted bounding box of the object and the target bounding box, respectively. gt w represents the height of the predicted bounding box of the object and the height of the target bounding box, respectively. c and h cLet ρ be the width and height of the smallest bounding rectangle that can be formed by the predicted bounding box and the target bounding box of the object, respectively. 2 (b,b gt ρ represents the square of the Euclidean distance between the predicted bounding box of the object and the center point of the object's target bounding box. 2 (w,w gt ρ represents the square of the difference between the width of the predicted bounding box of the predicted object and the width of the object's target bounding box. 2 (h,h gt ) represents the square of the difference between the height of the predicted bounding box and the height of the object's target bounding box. γ is a hyperparameter used to control the curvature of the curve; γ = 0.5 allows the model to achieve the optimal trade-off.
[0058] The fourth step is to train the improved network.
[0059] After modifying the network model, the improved network was trained, and the weight file and global average precision (map) of the trained model were saved. The new weight file was also saved for easy use in identifying safety signs. Compared to the original model's trained map value, the map value increased from 0.965 to 0.995. Compared to the original model's trained precision, the precision increased from 0.949 to 0.984. Compared to the original model's trained recall, the recall increased from 0.958 to 0.981. Using the improved model to detect safety signs in a chemical plant, the recognition accuracy was significantly improved compared to the original model, and the false recognition rate was also much lower.
[0060] The fifth step involves the application of drones in identifying hazard signs, such as... Figure 3-6 As shown,
[0061] With the continuous development of automation technology, drones can be used to survey accident sites in the event of localized fires or other accidents in factories. Chemical plants often contain numerous robotic arms and dangerous equipment, as well as a large quantity of flammable and explosive materials. Blindly attempting rescue operations without understanding the situation through safety signs could lead to unpredictable casualties. By capturing real-time footage of the accident site using drones, the video can be transmitted to a computer. Using this computer model, hazardous scenes can be identified, allowing rescue personnel to understand which areas are particularly dangerous and avoid entering or staying away from them during rescue operations. This prevents personnel from accidentally entering dangerous areas and effectively ensures their safety.
[0062] The main steps to deploy the improved YOLOv5 model to the computer connected to the drone are:
[0063] (1) Configure the deep learning environment for the computer. Since the PyTorch framework can be better deployed in production, install the PyTorch framework on the computing platform during configuration, and install various tool packages required by the model. After the deep learning environment is installed, test the environment to ensure that the model can run successfully after being deployed to the computer.
[0064] (2) Connect the drone camera to the computer, test whether the camera on the drone can be used normally, ensure that the images captured by the drone can be displayed on the computer, and save the video recorded by the drone for scene reconnaissance.
[0065] (3) Deploy the model to the computing platform inside the vehicle, and replace the weight file path of the weights module in the detect.py file with the path of the already trained best.py weight file. Then change the path of the source module in the detect.py file to the path of the video recorded by the drone in step (2).
[0066] (4) In order to compare the effect of the model on safety sign recognition before and after training, the weight file path of the weights module in the detect.py file was replaced with the best.py weight file path obtained by training the improved model and the best.py weight file path obtained by training the original model, respectively. The safety signs in the video were identified and compared using the weight files of the original model and the improved model, respectively.
[0067] (5) After using the original model and the improved model to identify videos containing safety signs in a chemical plant, it was found that the improved YOLOv5 model has better detection accuracy and robustness when identifying safety signs. The comparison of the recognition of the same scene by the original network and the improved network is shown in the figure below. Figure 3-6 As shown. In use, the improved YOLOv5 model is retained. The drone's camera will acquire image information of safety signs within the chemical plant and transmit the safety sign information to the computer. Then, the video recorded by the drone will be transmitted to the improved YOLOv5 model already deployed on the computer. The improved YOLOv5 model will identify the current data and output the detection results of the safety signs.
[0068] The above-described embodiments further illustrate the purpose, technical solution, and advantages of the present invention. It should be understood that the above-described embodiments are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made to the present invention within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for detecting safety signs in chemical plants based on an improved YOLOv5, characterized in that, Includes the following steps: Step 1: Take a dataset. Go inside the chemical plant and take a dataset related to safety sign recognition in the workshops inside the chemical plant. Step 2: Process the dataset to obtain a dataset suitable for training. Step 3: Improve the network. (3-1) Use the k-means++ clustering algorithm to calculate the anchor boxes suitable for the model, and replace the original nine anchor boxes with the newly obtained nine anchor boxes; (3-2) The lightweight upsampling operator CARAFE is added. The original YOLOv5 model uses nearest neighbor interpolation or commonly used bilinear interpolation, which does not utilize the semantic information of the feature map. It only uses the spatial position of the pixel to determine the upsampling kernel, and the receptive field is very small. CARAFE can aggregate contextual information in a larger receptive field, and it is lightweight and fast in computation. (3-3) The loss function uses Focal-EIOU Loss instead of the original CIOU Loss. Since poor-quality anchor boxes generate large gradients, affecting the training process, Focal-EIOU Loss distinguishes between high-quality and low-quality anchor boxes from the perspective of gradients, accelerating convergence and improving regression accuracy. The formula for calculating Focal-EIOU Loss is as follows: ; ; ; ; ; in, and These are the coordinates of the center points of the predicted bounding box and the target bounding box, respectively. and These are the widths of the predicted bounding box of the object and the target bounding box, respectively. and These are the height of the predicted bounding box of the object and the height of the target bounding box, respectively. and These are the width and height of the smallest bounding rectangle that can be formed by the predicted bounding box of the object and the target bounding box of the object, respectively. The square of the Euclidean distance between the predicted bounding box of the object and the center point of the object's target bounding box. This represents the square of the difference between the width of the predicted bounding box of the predicted object and the width of the object's target box. This represents the square of the difference between the height of the predicted bounding box of the object and the height of the object's target bounding box. It is a hyperparameter used to control the curvature of the curve. A value of 0.5 allows the model to achieve the optimal trade-off. Step 4: Train the network. Train the improved network from Step 3 and save the training results. Deploy the trained model on a drone to detect the chemical plant where the accident occurred and output the results.
2. The method for detecting safety signs in chemical plants based on an improved YOLOv5, as described in claim 1, is characterized in that... In step 1, a dataset of safety signs is taken at a chemical plant. The camera is placed in a fixed position at the chemical plant to simulate the use of a drone camera to identify safety signs in the plant. During the shooting, pictures of safety signs in the workshop are taken during the day and at night with the lights on. After the shooting is completed, the obtained dataset is checked and pictures that are particularly unclear or do not contain the safety signs that need to be detected are deleted.
3. The method for detecting safety signs in chemical plants based on an improved YOLOv5, as described in claim 1, is characterized in that... In step 2, a script is used to number the images in the folder. The numbered images are then labeled using the Labelimg annotation tool. Four safety signs are prepared for identification in this model, including confined space, Beware of Machinery Injuries, no smoking, and Electric shock carefully. The above image labels are generated into an XML file. Then, a Python script is used to convert the XML file into a TXT file that the YOLOv5 model can recognize. Finally, a Python script is used to divide the dataset into training, testing, and validation sets in a ratio of 8:1:
1.
4. The method for detecting safety signs in chemical plants based on improved YOLOv5 as described in claim 1, characterized in that, Step 4 includes the following steps: training the network, training the improved network from step 3, saving the training results, and using the trained model to identify safety signs in the chemical plant.
5. The method for detecting safety signs in chemical plants based on an improved YOLOv5 as described in claim 1, characterized in that, When using drones to identify safety signs inside a chemical plant where an accident has occurred, a trained model is deployed on a computer that can receive video transmitted by the drone. The drone's camera identifies safety signs and the surrounding environment within the chemical plant, and the video information obtained by the camera is transmitted to the computer. The computer saves the video information obtained from the camera and transmits the video information to the model. At the same time, the model outputs the recognition result of the safety sign and transmits the recognition result to the rescue personnel.