# Design and Implementation of Industrial Accident Detection Model Based on YOLOv4
## 3 Design and Implementation
### Training Data Labeling and Standardization  
After collecting the learning data according to the scenario, to determine whether or not the scenario is hazardous in the risk judgment model, objects (such as workers, trucks, forklifts, and personal protective equipment) in the image must first be extracted. A person must directly label an object in the image for the model to detect the object. Labeling refers to drawing a bounding box for an object in a frame (or image) and naming the object. As a labeling tool, CVAT was used by comparing the three features in Table 1. CVAT is provided as an open-source tool by the OpenCV Foundation [25]. Notably, while labeling, the frames in images with hazardous scenarios are separately organized. Figure 8 summarizes the labeling process and frames related to the hazardous images. The labeling result is output as a frame image of the video and YOLO model format. The most intuitive way to express the bounding box of an object is in the Microsoft \"Common Objects in Context\" (COCO) format. This method uses the object's top-left point (\(x_{c}\), \(y_{c}\)) horizontal size \(w_{c}\), and vertical size \(h_{c}\). In contrast, the YOLO format is expressed in the form of x, y, w, h as the relative values of the center co-ordinates (\(x\), \(y\)) of the object and according to resolution size (\(w_{img}\), \(h_{img}\)) of the entire image. The formula for converting the COCO format to the YOLO format is shown in Equation (2) [30,50]. \[x=\frac{\left(x_{c}+\frac{w_{c}}{w}\right)}{w_{img}},\ y=\frac{\left(y_{c}+ \frac{h_{c}}{2}\right)}{h_{img}},\ w=\frac{w_{c}}{w_{img}},\ h=\frac{h_{c}}{h_{ img}} \tag{2}\]  
The frames, objects appearing in such frames, and risk events are integrated and standardized. We add metadata such as which manufacturer the learning data were recorded from, the number of FPS and format of the recorded video, actual time, and resolution. However, the entire recorded video cannot be used as the training data, so the video is divided. It contains information regarding events and objects occurring in frames obtained from the segmented images. The learning data are written in JSON format to manage this information quickly. JSON is a data exchange format grammar organized by the European Computer Manufacturers Association [51]. The reason for standardizing the learning data as JSON data is to save the results of the object labeling for the images in a form similar to that of the PASCAL Visual Object Classes (VOC) and Microsoft COCO image datasets [50,52]. PASCAL VOC is an extensible markup language, and the Microsoft COCO dataset uses JSON. The standardized final result is schematized in a tree form, as shown in Figure 9.  
Figure 7: Example of video frames containing nine selected objects. Figure 8: Labeling process using “Computer Vision Annotation Tool” (CVAT) and frames in which hazardous situations were filmed. The circle at the front denotes the root node and contains image information (including segmented image information). The video is split because the video taken by the CCTV is transferred by day or week. This video is too large to label all of it at once, so it is cut into frame sections. In this study, the sections comprise 18,000 frames or less. The video information includes the video name, length, number of FPS, total frame length, video format, the location where the video was taken, the start and end times, and the horizontal and vertical length of the video frame. The segmented image information contains the division number given in the order in which the video was cut, along with the start and end numbers of the frames. As innumerable such frames can exist, the video is separated once more. As a result, each frame number contains event information of a risk occurring in the corresponding frame and object information appearing in the corresponding frame. The event information includes the event numbering, name, and unique event number. The event numbering is separated because several events may occur in a frame.