# Automated Detection and Classification of Returnable Packaging Based on YOLOV4 Algorithm
## 2 Materials and Methods
### YOLOV4 Limitations and Accuracy Measures  
Although YOLOV4 seems to be the best algorithm for detecting application objects, it is essential to pay attention to a few problems and limitations that can occur along the way. The detection algorithm has problems separating small objects in images that appear in groups, although the fourth version of the YOLOV4 has been improved a lot compared to its predecessors [55]. The reason for this is that each neural network is limited to detecting an individual object [22] therefore, the above detection algorithm makes it difficult to detect and localize small objects that are naturally found in group images. IoU is one of the significant metrics needed to measure the accuracy and localization of objects in a frame which can be calculated by finding the area that intersects between the limit frame for a particular prediction and the assumed accuracy limits of that area first taken. The total area covered by these two boundary frames (Union), is then calculated. The intersection divided by the union gives the ratio of the overlap to the total area, which gives a relatively good estimate of how close the boundary frame is to the source prediction, and then after the defined terms, IoU [56, 57, 58] can be calculated as Equation (1), where \(A\) is the area of prediction box and \(B\) is the area of target box:  
\[\text{IoU}=\frac{|A\bigcap B|}{|A\bigcup B|} \tag{1}\]  
In Equation (1), the numerator represents the calculation of the intersection/overlap area between the predicted boundary box [59] and the ground-truth bounding box [60] while the Union represents the total union between them. The IoU is in a range from 0 to 100 and the closer the value is to 100 the better it is, as shown in Figure 8.  
Figure 8: Different types of IoU values. Accuracy is measured with an evaluation metric mAP, which measures in what percentage the algorithm predicted the object from all individual classes correctly and it is expressed in percentages that go from 0% to 100%. The mathematical description of mAP can be represented by Equation (2). Where the \(AP_{k}\) is the average Precision of the classes and the \(n\) is the number of classes [61]. \[\text{mAP}=\frac{1}{n}\sum_{k=1}^{k=n}AP_{k}. \tag{2}\]  
The Precision determines how accurate your model is and it can be calculated with the expression [62]:  
\[\text{Precision}=\frac{\text{TP}}{\text{TP}+\text{FP}}. \tag{3}\]  
The recall is a measure that shows how many times the model finds all the positive cases while training Recall [62] and can be calculated with:  
\[\text{Recall}=\frac{\text{TP}}{\text{TP}+\text{FN}}. \tag{4}\]  
Finally, the \(\text{F1}_{\text{score}}\) is an evaluation metric that measures models accuracy in combination with Recall and Precision [63] and can be calculated with the expression:  
\[\text{F1}_{\text{score}}=2\times\frac{\text{Recall}\times\text{Precision}}{ \text{Recall}+\text{Precision}}, \tag{5}\]  
where:  
* TP--True Positive predictions,
* FP--False Positive predictions, and
* FN--False Negative predictions. YOLOV4 has intrusive spatial constraints in terms of bounding box predictions hence each grid cell can only predict two possible boxes and can only have one unique class. This constraint can limit the number of objects that the model can predict. A model can struggle with small objects that appear in groups such as a flock of birds or a group of ants [64]. Configuration, Setup, and Hyper-Parameters Used for YOLOV4 Project  
Before training the YOLOV4 algorithm, it was necessary to define a few configuration files within the YOLOV4 folder. Data folder obj.data contains some vital information where in several lines is described the number of classes that the algorithm must train, the location of the train.txt file that is separated from the total dataset for neural network training, the location of obj.names that containing class names, and test.txt which is used to check or test the neural network.