# Development of Continuum Robot Arm and Gripper for Harvesting Cherry Tomatoes
## 3 Tomato Recognition System  
Recognition of matured tomatoes is also a critical issue among tomato harvesting robots. In this research, we employed machine learning based on neural networks to distinguish matured tomatoes from immature ones and other similar fruits as well. As a tomato classifier, we utilized a neural network YOLO (You Look Only Once) for the recognition of different types of tomatoes. The network architecture of YOLO v5 consists of three consecutive parts: Backbone, Neck, and Head (see Figure 7). All collected datasets are sent to the CSPDarknet for extracting features (Backbone). After obtaining features, data are transferred to the PANet for highlighting features (Neck). In the end, obtained results, such as class, assessment, position, and object dimensions are evaluated (head) [32]. In the Backbone stage, the CSPDarknet uses a modified convolutional neural network for connecting layers of the deep learning network with the effect of alleviating vanishing gradient problems. It uses a CSPNet strategy to split the base layer feature map into two parts and then merges them through an inter-stage hierarchy. This splitting and merging will increase the gradient flow through the network [33]. In the next Neck stage, the PANet is used to improve the instance segmentation process by preserving the spatial information of the object. The PANet is a feature extractor that generates multiple layers of feature map information. It effectively segments and stores spatial information, which helps in localizing pixels to form a mask in the next stage [34]. Figure 6: Gripper working process. Figure 7: Architecture YOLOv5. In the Head stage, the final evaluation is performed. It applies anchor blocks to extract features and generate the final output vectors containing the predicted bounding box coordinates (center, height, width), forecast confidence score, and probability classes. In this research, we classified tomatoes into three classes by digit numbers: \"0\" stands for a red color or matured tomato, \"1\" for a green tomato or immature tomato, and \"2\" for a yellow tomato evaluated as one in turning to the red or matured tomato. In a process of recognizing tomatoes on photographic images obtained by the camera, the neural network will indicate them by circumscribing them with rectangles and classifying them by the above-mentioned digits numbers in the left corner. To assess the performance of the machine learning algorithms, many assessment metrics have been developed. We employ metrics using a confusion matrix (see Figure 8), which contains four combinations: True Positive (TP)--the number of objects that the classifier evaluates as positive and actual positives; True Negative (TN)--the number of objects that were classified as negative and do not belong to the negative class; False Positive (FP)--number of objects classified as positive, but are negative; False Negative (FN)--the number of objects that the classifier evaluates as negative objects, but in reality are positive. Figure 8 shows a confusion matrix with normalization for a multiclass (i.e., three classes) classification. The diagonal shows the number of TP combinations for each class: 94% of objects in class 0, 96% of those in class 1, 92% of those in class 2 were classified correctly. Additionally, 1% of those in class 0 are erroneously predicted as objects in class 1, and another 1%--as objects in class 2. The remaining 4% were not assigned to any class, therefore, they are false negative solutions. For class 1, the remaining 4%, except for TP solutions, are also false negative indicators. And for class 2, 1% of all objects are erroneously classified as objects in class 0, and another 1% of the classifier predicted as objects in class 1. The proportion of false-negative decisions from objects in class 2 is 6%. Based on these matrix combinations, the main metrics of the classification ability of the algorithm are calculated, such as precision, recall, and accuracy; the _Precision metric_ is  
Figure 8: Confusion matrix.