## 3 Materials and Methods
### Deep Learning Approach
#### 3.2.2 Models Training  
The literature refers to several ML frameworks, an interface, library, or tool that easily creates ML models [46]. In this study, the choice of framework falls on TensorFlow (see [[https://www.tensorflow.org/](https://www.tensorflow.org/)]([https://www.tensorflow.org/](https://www.tensorflow.org/)), accessed on 3 November 2021) [68], an open source easily scalable ML library developed by Google, which provides a collection of workflows to develop and train models using Python, C++, JavaScript, or Java.  
TensorFLow r.1.15.0 was used for the training and inference scripts, which run on Google Collaboratory (Colab) notebooks (see [[https://colab.research.google.com/](https://colab.research.google.com/)]([https://colab.research.google.com/](https://colab.research.google.com/)), accessed on 25 September 2021) that give free access to powerful GPU's (Graphics Processing Unit) and TPU's (Tensor Processing Unit) to develop DL models. Although the GPU's available may vary for each Colab session, in general an NVIDIA Tesla T4 with a VRAM of 12 GB and a computation capability between 3.5 and 7.5 was assigned to all sessions. One pre-trained SSD MobileNet v2 model from the TensorFlow database (see [[https://github.com/tensorflow/models/blob/master/research/object_detection/g3](https://github.com/tensorflow/models/blob/master/research/object_detection/g3)]([https://github.com/tensorflow/models/blob/master/research/object_detection/g3](https://github.com/tensorflow/models/blob/master/research/object_detection/g3)) doc/tf1_detection_zoo.md, accessed on 3 November 2021) and one YOLOv4 model from the Darknet database (see [[https://github.com/zauberzeug/darknet_alexeyAB](https://github.com/zauberzeug/darknet_alexeyAB)]([https://github.com/zauberzeug/darknet_alexeyAB](https://github.com/zauberzeug/darknet_alexeyAB)), accessed on 3 November 2021) were considered in this study. Both models were pre-trained with Google's COCO (Common Objects in Context) dataset (see [[https://cocodataset.org/#home](https://cocodataset.org/#home)]([https://cocodataset.org/#home](https://cocodataset.org/#home)), accessed on 3 November 2021) with an input size of 640 \(\times\) 640 px (SSD MobileNet v2) and 416 \(\times\) 416 px (YOLOv4).  
Through transfer learning, a fine-tune was performed on pre-trained models to detect and classify tomatoes. Slight changes to the default training pipeline were made, such as adjusting the batch size for each model (24 to the SSD MobileNet v2 model and 64 to the YOLOv4 model) and removing data augmentation from the pipeline. The SSD MobileNetv2 model training sessions ran for 35,000 epochs, while the YOLOv4 model training was much  
Figure 3: Different types of transformations applied to the images.  
faster, requiring only 8000 epochs. The number of epochs may vary from model to model, but in this case, was chosen based on the suggestion given by the literature, but mainly taking into account the \"average loss\" training metric, selecting the number of epochs that would be sufficient to converge. As far as the MobileNet v2 SSD model is concerned, an evaluation session occurred at every 50 epochs, following the standard value used by the pre-trained models. Since Darknet had no available validation sessions, it was not considered for the YOLOv4 model. These evaluation sessions are quite useful, since they allow monitoring the evolution of the training, meaning if the evaluation loss started to increase while the training loss decreased or remained constant, the deep learning model was over-fit to the training data.