# Deep Learning-Based Method for Accurate Real-Time Seed Detection in Glass Bottle Manufacturing
## 3 Materials and Methods
### Proposed SW Solution: The Image Algorithm
#### 3.3.3 Deep Learning-Based Classification Model
The \"seed\" class includes a wide spectrum of seeds of different sizes, shapes and orientations, and with a well-defined contour in most cases, while the \"non-seed\" class has grouped grease stains, marks, joint areas and, in general, any element that, due to its appearance, could lead to a false positive detection. Figure 7 shows examples of images belonging to both classes. The generation of the dataset was carefully executed. The correct identification of an image to one class or the other is not always easy, since they can often have very similar appearance, and can be confusing even to a trained eye with no more information than that of a small crop with a set of dark pixels. Several revisions were performed to make sure proper assignment of the images is executed. It must be considered that some of the images shown in Figure 6 can be very small, not bigger than 10 \(\times\) 10 pixels size. As stated above, the good performance of the models lies in the robustness and proper annotation of the dataset. In this case, the annotation of the dataset has consisted of assigning a category label to every image. The final used dataset contains 3771 images, where 1399 images represent seeds or blisters and 2372 represent other elements not being seeds, such as joints, marks, stains, etc. The dataset was generated from images of bottles having different colors and hues, dimensions, and being circular of squared shape bottles. The aim of this is that the dataset may cover all the possible variability the model might find in the real production stage. The aim of this approach is that there is a unique model capable of identifying seeds and blisters in the whole range of bottles that are manufactured in all lines of Vidrala sites. The development of separate models for all of the colors of the bottles is not desired. This would add difficulty for the scalability, maintenance and, in the end, adoption of the system by the users. Figure 7: Examples of images of both classes existing in the dataset. Training of the Model  
The training task consists of showing the dataset to a convolutional network, which will iteratively extract unambiguous characteristics of each of the classes in the dataset. The training process ends when the weights and parameters of that network provide a small error in the prediction, that is, a reduced loss value in the validation subset. The different models trained in the project were generated with the deep learning library of MVTech's Halcon software. Specific hardware (GPU) was also used to speed up the process, which would otherwise take considerably longer. The original dataset is split up into three groups (training, validation and test), so that the network is able to assess and correct the quality of learning during the training itself. Halcon's deep learning libraries in version 18.11 provide three types of networks, from least to most complex. Based on the tests carried out, the networks with more processing layers introduced greater delay when generating the predictions of the classes, which would cause congestion problems at times with a high number of seed candidates. This problem does not occur with the network in compact format, so this was the final chosen architecture. Other design considerations of the model that imply a preprocessing of the input image are:  
* Image rescaling. The networks available in Halcon are configured by default to work with three channel images with a resolution of 224 \(\times\) 224 pixels, which far exceeds the average size of the candidate clippings produced by the system. This fact negatively affects the system in two ways: on the one hand, the computational cost introduces an additional time to that of the inference of the model itself, being fatal in real time applications; and on the other, rescaling to such a large size introduces unnecessary noise into the image. In fact, it was observed that with smaller image sizes where resolution is barely reconditioned, the error calculated after model training is lower.