## 2 Materials and Methods
### Methods
#### 2.3.3 Training and Validation  
The training and validation process is a critical phase in the development of these models, as it determines the model's ability to characterise new data. To optimise this process, various techniques and strategies have been implemented, including setting an appropriate learning rate, using callbacks and applying class weights.  
For the training sessions, utilising either VGG or MobileNet architectures, the foundational hyperparameters exhibit considerable overlap, reflecting common practices in DL for image classification. The number of epochs was set at 50, a value often found to be effective when using pre-trained weights through transfer learning. This duration allows the model to adapt to the new dataset while preventing excessive overfitting, a process monitored closely with early stopping criteria. The batch size was early defined at 32 for local training, and later increased to 64 for server-side training. The Categorical Cross-Entropy loss function was employed, paired with a Softmax activation in the final layer to output probability distributions over the classes.  
The learning rate is a fundamental hyperparameter that controls the magnitude of the updates to the model weights during training. An adequate learning rate is crucial to ensuring efficient and effective convergence. If it is too high, it can make excessive updates, resulting in instability and difficulty in finding the best solution. On the other hand, if it is too low, training will be slow, and the model may find a solution that is not the best possible [47]. For both models, VGG16, VGG19 and MobileNetV2, a learning rate of \(1\times 10^{-5}\) was used, which was chosen after several tuning attempts to find the best configuration. All the models were adapted to use the Adam optimiser, an algorithm that automatically adjusts the learning rates for each parameter, allowing for faster and more stable convergence during training [51].  
In order to improve efficiency and monitor the model's performance, callbacks were used, functions that allow actions to be carried out at certain points during training. The following functions were applied [52]:  
* Early Stopping: used to stop training when the validation metric has not improved after a certain number of epochs, known as patience. This ensures that the model does not continue to train unnecessarily after reaching its best performance. It was configured with a patience of 10 epochs for both models;
* Reduce Learning Rate on Plateau: reduces the learning rate when the validation metric stops improving, allowing the model to make finer adjustments as it approaches convergence;
* Model Checkpoint: saves the model during training whenever the validation metric (in this case, loss) improves. This ensures that the best version of the model is saved.  
A fine-tuning strategy was also used, consisting of initially training the model for 25 epochs, with the convolutional base frozen, meaning only the top layers were updated. This allowed the network to learn task-specific features without altering the pre-trained weights. Then, in the following 25 epochs, fine-tuning was enabled by unfreezing some of the deeper layers of the convolutional base, allowing them to be retrained alongside the top layers. This technique helped the model adjust its learned representations more precisely to the task.  
In an early development stage, training sessions were run on a Windows/Intel machine equipped with an NVIDIA RTX 3050 and CUDA, resulting in processing times ranging from 40 to 60 min. To accelerate development and parameter tuning iterations, the training processes were migrated to Google Colab Pro. By utilising high-performance GPUs, specifically the T4 and A100, it was possible to significantly reduce training time to just 5 to 10 min. This optimisation provided a substantial gain in efficiency, enabling a much faster development cycle.