# Automated Detection and Classification of Returnable Packaging Based on YOLOV4 Algorithm
## 2 Materials and Methods
### Dataset Description and Preparation  
The data collection strategy over the life of the service/product is essential for the development of a successful project [26] and it cannot be a series of one-off exercises. Every time a user comes in contact with a desired product or service, it would be desirable to collect data from the interaction [27] to gain a constant flow of data to improve products/programs. Upon reaching that level of data collection, each new customer contributes to the size and diversity of the newly created dataset while the advantage of building this strategy and collecting data is that it becomes difficult for competitors to practically replicate the dataset used in these projects [28]. With larger and more up-to-date data the AI becomes better and much more valuable and because of that the first step was to collect, an original unprocessed packaging is shown in Figure 1. As already stated the part of the dataset was photographed in its natural form, without any processing. These images were created in three steps: Initially, the packaging was photographed without modifications to its original forms. After that, thermal and mechanical processing was applied to obtain different images. Finally, multiple packaging objects, in both processed and unprocessed form were grouped and photographed. It should be noted that the packaging was empty, i.e., did not contain any liquid. The packaging was photographed in several positions: upright, lying down, rotated, or shifted concerning the original position, which contributed to possible conditions during the detection. To expand the dataset, the mechanical and thermal loading on plastic and aluminum packaging was applied to change their shape. The glass packaging could not undergo such modification since it is a hard and brittle material and would shatter under mechanical loading or would crack at higher temperatures. The application of such external loading on packaging greatly increased the dataset size as well as its quality. Additional improvement of dataset quality was conducted by photographing a group of packaging. The examples of packaging deformed by the application of thermal loading, mechanical loading, and a group of all three are shown in Figure 2.  
All the photographs in the dataset are grey-scale because they have small memory size images that have fewer characteristics that can affect the training of YOLOV4 CNN [29; 30]. When creating the original dataset, it is important to pay attention that it should be as diverse as possible [31] so that the ML algorithm has plenty different learning examples as possible [32]. The initial dataset consists of 2838 photographs with an additional 950 which are downloaded from Kaggle [25]. Figure 1: An example of the unprocessed dataset. Figure 2: Physical transformation actions performed on the dataset. The dataset is not sufficient to develop a good AI model [33] and to enlarge it the data augmentation was performed [34; 35]. The methods of geometric augmentation [36] that were used are rotation, blurring, flipping, translating, and zooming (scaling) shown in Figure 3.  
The whole dataset collection was performed using OpenCV [37] library in Python programming language. The number of original images, augmented images, and total images in the dataset is presented in Table 1.  
In Table 1 the number of original, augmented and total images for each class (plastic, glass, and aluminum) is shown. From the number of original images per class, it can be seen that the dataset was not perfectly balanced [38]. The augmentation was used to compensate for the dataset imbalance and improve its quality [39]. After the original dataset was obtained and augmentation performed the next step was labeling the bounding boxes for the YOLOV4 algorithm using Visual Object Tagging Tool (VoTT) [40]. The marking of masks, i.e., border frames for a single image is shown in Figure 4.