# Computer Vision as a Tool to Support Quality Control and Robotic Handling of Fruit: A Case Study
## 2 Materials and Methods
### Model Training Method  
Figure 4 shows the workflow for training the object detection model, including the creation of annotations, division of the dataset into training (70%), testing (5%), and validation (25%), and all pre-processing tasks, such as auto-orientation and resizing. The choice of a 70-5-25 split was made to ensure a larger validation set (25%) for more comprehensive evaluation of the model's performance across a wider range of samples. We prioritized validation to ensure that the model generalizes well, while the 5% allocated to testing was deemed sufficient to provide a reliable measure of the final model performance after training. Following this, the record file was generated for use in model training.  
\begin{table}
\begin{tabular}{c c c c c} \hline
**Nazzle** & **Layer Height** & **Line Width** & **Wall Thickness** & **Top/Bottom Line Width** \\
0.6 mm & 0.2 mm & 0.58 mm & 1.74 mm & 0.58 mm \\ \hline
**Retraction Distance** & **Retraction Speed** & **Printing Temperature** & **Bed Temperature** & **Flow** \\
4.5 mm & 25 mm/s & 235 \({}^{\circ}\)C & 50 \({}^{\circ}\)C & 200\% \\ \hline
**Print Speed** & **Travel Speed** & **Build Plate Adhesion** & **Cooling Fans** & **Minimum Speed of the** \\
20 mm/s & 150 mm/s & Skirt & 100\% & 10 mm/s \\ \hline \end{tabular}
\end{table}
Table 1: Printing parameters for the soft grippers.  
Figure 3: Gripper’s visualization: (**a**) CAD version; (**b**) printed version.  
The computer vision model was trained using the TensorFlow Object Detection API (Google, Mountain View, CA, USA) [29] with the pre-trained model ssd_mobilenet_v2_fpnlite_320 \(\times\) 320_coco17_tpu-8. This model, which employs a Single Shot MultiBox Detector (SSD) [29] with Mobilenet v2 [30] and FPN-lite as a feature extractor, was selected for its efficiency on devices with limited computing resources, such as the Raspberry Pi 5. The choice of SSD is driven by its balance between speed and accuracy, making it well-suited for real-time applications in resource-constrained environments. Additionally, the TensorFlow Object Detection API is highly optimized to work seamlessly with SSD-based models, offering pre-trained weights, streamlined training pipelines, and efficient inference capabilities. Therefore, SSD is the optimal choice for maintaining real-time performance without sacrificing too much accuracy, given the hardware constraints and the effective integration within the TensorFlow framework.  
The model was trained for 40,000 iterations with a batch size of 16 images per training step. The configuration for training on a TPU-8 aimed to achieve a mean accuracy (mAP) of 0.22 in the validation of COCO17, which required important adjustments:  
1. Definition of the number of classes of objects to be detected.
2. Use of Intersection over Union (IoU) to measure the accuracy between the predicted boxes and the real objects, with a matching threshold of 0.5.
3. Production of anchors in various scales and proportions to capture objects of varying sizes and shapes.
4. Resizing of the images to 320 \(\times\) 320 pixels to standardize the model's input size.
5. Application of a convolutional box predictor, which is adjusted during training to improve detection.
6. Implementation of a loss function that combines weighted sigmoid focal classification loss with smooth L1 localization loss, optimizing accurate detection and localization.  
After training, the model was converted to TensorFlow Lite format, facilitating implementation on devices such as the Raspberry Pi 5 with satisfactory performance. Both models (before and after conversion) were evaluated.