# 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
In addition to testing the resolution of 224 \(\times\) 224 pixels, we have worked with sizes of 96 \(\times\) 96 and 48 \(\times\) 48 pixels, the latter being the option ultimately chosen for the input image. * Preprocessing. Along with input image rescaling, another series of transformations are applied to the image with the aim of feeding the network with the more meaningful input. These transformations were achieved by means of traditional image processing techniques and are: (1) Contrast enhancement: this operation scales the image within the range of maximum and minimum gray levels, improving the contrast between light and dark areas. The purpose of applying it is so that the model is valid for all the variability of colours and hues of the bottles, that can vary from white to dark-green or oak; (2) Gaussian filter: 50% of the dataset was passed through a 3 \(\times\) 3 Gaussian filter to cause a certain degree of blurring, both in seeds and in the rest of the elements. This effect makes the system more flexible in situations where the seeds do not appear perfectly focused or defined. In the training process, data augmentation was applied. Data augmentation allows the dataset to be expanded, generating new cuts with slight variations, based on the original images, and prevents possible overfitting. These data augmentation techniques consist of applying transformations to all or part of the images, such as affine transformations of translation and rotation, flipping the image with respect to some axis or other types of operations. Specifically for this project, transformations were applied to rotate and reflect the images, so that the network understands that the characteristics of one class or another are independent of the position and angle at which seeds and spots appear in the image. In our case, it is not convenient to apply strong transformation since the images are very small in size and the features of the seeds and other regions not being seeds is represented in few pixels. The networks used in the different trainings belong to the family of residual networks, named ResNet. They were proposed by [26] and are well known in the scientific community. The compact and smaller network was ultimately chosen. Figure 8 shows the ResNet family network architectures. Finally, the hyper-parameters tuning was tackled in the training process. This set of variables partly determines the configuration of the network and has a direct impact on the quality of the trained model. Some of the used parameters were batch size, learning rate, epochs, momentum, gradient descent and weights initialization. Best results were obtained with batch size of 16 during 100 epochs, learning rate of 0.01, momentum 0.9, and square gradient descent as optimizer of the model in the training process. Training was performed from scratch, and weights of the model were randomly initialized. The curve of the best training is shown in Figure 9.  
The model manages to remove all the false positive in the image due to grass stains, joints and other undesirable factors. Final output image with the detected seeds can be seen in Figure 10. The example bottle is specially chosen to see how good the performance is. The bottles do not usually present so many seeds or stains. Figure 8: Residual Network architectures used in the development (extracted from [26]). The smaller ResNet-18 is the one showing better results and can perform in real time. Figure 9: Training curve of the final classification model.