# Automated Detection and Classification of Returnable Packaging Based on YOLOV4 Algorithm
## 2 Materials and Methods
### Description of Methods  
YOLOV4 is the most advanced detection algorithm with a real-time object recognition system that can recognize multiple objects in a single frame [44]. It uses a completely different approach from previous detection systems where it applies one neural network to the whole frame, i.e., the image, and then the neural network divides the image into regions and predicts the boundary frames which then calculates the probability for each possible region, i.e., class of objects. According to [44], the basic idea of the YOLOV4 algorithm is the division of input data into a matrix of a certain dimension by which each matrix address is responsible for predicting objects within the center of that cell where then for \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Class** & **X Center** & **Y Center** & **Width** & **Height** \\ \hline
1 & 0.2855 & 0.8367 & 0.2593 & 0.2282 \\
1 & 0.5844 & 0.6422 & 0.2765 & 0.2217 \\
1 & 0.6008 & 0.3644 & 0.1949 & 0.2619 \\
1 & 0.2977 & 0.3014 & 0.2495 & 0.2511 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Example of YOLOV4 annotations for Figure 5a TXT file. Figure 5: Labeling the dataset (**a**) correct way, (**b**) the incorrect way. every object that algorithm can detect, the probability coefficient is calculated visible from Figure 6.  
As seen in Figure 6, each matrix provides boundary frameworks and calculates a reliability estimate for the corresponding framework. After the reliability estimate is calculated the reliability score is determined which shows how secure the model is and that the frame contains the object [45]. This type of detection algorithm has several advantages: it can recognize several objects in one frame [46], during testing the entire image frame is reviewed so that predictions are based on the global image context and it also provides predictions with a single evaluation of the network as unlikely similar methods such as R-CNN which require thousands of examples of a single image [47; 48]. Due to the aforementioned properties, the YOLOV4 algorithm is extremely fast even up to a thousand times faster than R-CNN, and up to a hundred times faster, than Fast R-CNN [49]. The YOLOV4 design allows end-to-end training and real-time speed while maintaining high average accuracy [50] and its flow chart can be seen in Figure 7.  
The process starts with taking an image from the COCO dataset or custom-labeled dataset where the trained weights are pre-trained so it is necessary to update and adjust,  
Figure 6: An illustration of YOLOV4-based object detection. Figure 7: Diagram of the YOLOV4 algorithm applied for the detection of recyclable packaging. i.e., fine-tune the weights then the process of predicting bounding boxes begins, which results in large boxes and small boxes where the Non-Max Suppression (NMS) procedure obtains the main box that at the end of detection is the result itself [51,52]. NMS is defined as a local maximum where the local maximum is greater than all of its neighbors except himself. For some n neighborhood, any pixel consists of 1-D case, i.e., n pixel left and right and in the case of the square region, it must be centered around the pixel under consideration. NMS consists of several computer vision algorithms [53], some of them are the measure of the selected point in the whole image, and even the entire scale space, and then the local maximum is selected. Efficiency is a major feature in its applications and the only competitor to NMS is the Maximum filter [54] which calculates the value of each pixel of each neighbor, where the process is much slower than NMS. Given the maximum filter response in each pixel, NMS reduces additional comparative values of each pixel with the largest neighbor. After training the YOLOV4, it is necessary to evaluate the obtained results. There are several suitable metrics, but the most important and generally accepted metrics are mAP and IoU.