scieee AI-readable full text Open interactive document viewer

Deep learning modelling for non-invasive grape bunch detection under diverse occlusion conditions

Íñiguez, Rubén,Gutiérrez Salcedo, Salvador,Poblete Echeverría, Carlos,Hernández, Inés,Barrio, Ignacio,Tardaguila, Javier

Abstract

FPI PhD grants 591/2021 and 1150/2020 by Universidad de La Rioja and Gobierno de La Rioja

Full text

Deep learning modelling for non-invasive grape bunch detection under diverse occlusion conditions Rub´ en ´ I˜ niguez a , Salvador Guti´ errez b,* , Carlos Poblete-Echeverría c , In´ es Hern´ andez a , Ignacio Barrio a , Javier Tard´ aguila a a Televitis Research Group, University of La Rioja, 26006 Logro˜ no, Spain b Department of Computer Science and Artificial Intelligence (DECSAI), Andalusian Research Institute in Data Science and Computational Intelligence (DaSCI), University of Granada (UGR), Granada 18014, Spain c South African Grape and Wine Research Institute (SAGWRI), Stellenbosch University, Private Bag X1, Matieland 7602, South Africa ARTICLE INFO Keywords: Artificial intelligence Yield estimation YOLO Precision viticulture Object detection ABSTRACT Accurately and automatically estimating vineyard yield is a significant challenge. This study focuses on grape bunch counting in commercial vineyards using advanced deep learning techniques and object detection algorithms. The aim is to overcome the limitations of conventional yield estimation techniques, which are labour intensive, costly, and often inaccurate due to the spatial and temporal variability of the vineyard. This research proposes a non-invasive methodology for identifying grape bunches under different occlusion conditions using RGB cameras and deep learning models. The methodology is based on the collection of RGB images captured under field conditions, coupled with the implementation of the YOLOv4 architecture for data processing and analysis. Statistical indicators were used to evaluate the performance of the developed models. The comprehensive model produced a favourable outcome during validation, with an error rate of 1.12 bunches (R 2 =0.83). In the test dataset, the model achieved an error rate of 1.12 (R 2 =0.81). The results highlight the potential of emerging technologies to significantly improve vineyard yield estimation. This approach has the potential to assist vineyard management practices, enabling more informed and efficient decisions that could increase both the quantity and quality of grape production intended for winemaking. 1. Introduction Yield estimation is a crucial topic in agriculture, especially within the wine industry (Dunn & Martin, 2003). It is essential for winegrowers to achieve the desired fruit quantity and quality. Therefore, accurate, objective, and rapid estimation of vineyard yield is highly valuable (Taylor et al., 2019). The early yield estimation of the grapevine provides information to winegrowers in making management decisions to achieve a better quantity and quality of grapes (Laurent et al., 2021). In general, traditional yield forecasts are based on destructive sampling of bunches and manual counting of berries per bunch and bunches per vine. This traditional approach does not provide accurate estimations because the sample of the vineyard cannot represent all the variability that may be present in the plot. These techniques are time-consuming, expensive, and labour-intensive (Martin et al., 2003). The number of bunches per vine is the most significant yield component, accounting for 60 % of the average field yield variability, meanwhile, the number of berries per bunch accounts for 30 % and berry weight accounts for 10 % (Laurent et al., 2021). Clingeleffer et al. (2001) noted that the yield variability could also be partially explained by the number of berries per bunch, the weight of the berries, and the interaction between the bunch count and berry count per bunch, contributing to 11 %, 4 %, and 20 % of yield variability, respectively. This interaction explains the high annual variation in the final yield. In this regard, precision viticulture has brought new opportunities for yield monitoring and prediction, taking advantage of the new sensors, platforms, and modelling techniques (Barriguinha et al., 2021). Understanding spatial variability in vineyards is key for precision viticulture, enhancing sustainable, high-quality grape production by optimizing management practices and resource efficiency (Kamangir et al., 2024). Novel sensing technologies enable an efficient acquisition of data and precise forecasts in agriculture (Palacios et al., 2023), and noninvasive techniques to monitor the cultivars (Victorino et al., 2022). Remote sensing, proximal sensors, and advanced data analysis * Corresponding author. E-mail address: [email protected] (S. Guti´ errez). Contents lists available at ScienceDirect Computers and Electronics in Agriculture journal homepage: www.elsevier.com/locate/compag https://doi.org/10.1016/j.compag.2024.109421 Received 27 March 2024; Received in revised form 17 July 2024; Accepted 29 August 2024 Computers and Electronics in Agriculture 226 (2024) 109421 Available online 6 September 2024 0168-1699/© 2024 The Author(s). Published by Elsevier B.V. This is an open access article under the CC BY-NC license ( http://creativecommons.org/licenses/bync/4.0/ ). technologies mark a significant leap in precision viticulture. These tools allow detailed monitoring of vineyards, facilitating specific management decisions to improve grape yield and quality (Ferro and Catania, 2023). Nowadays one of the most common and successful techniques for monitoring the amount of fruit in viticulture has been computer vision. Computer vision systems are powerful tools to automate inspection tasks in agriculture and food processing (Cubero et al., 2011). Several applications and methods utilizing computer vision and machine learning techniques have been reported in the scientific literature (Berenstein et al., 2010; Luo et al., 2016; Seng et al., 2018; Mohimont et al., 2022). Typical target applications for such systems include grading and yield component monitoring (Nuske et al., 2014). Computer vision systems have been used to estimate grapevine yield at different phenological stages (Aguiar et al., 2021), such as budbreak (Liu et al., 2017), flowering (Palacios et al., 2020), pea-size (Palacios et al., 2023), and harvest (Xin et al., 2020). Moreover, image analysis has been utilised to evaluate yield components, including the determination of berry size (Roscher et al., 2014) and the estimation of the number of berries through direct counting, as well as the estimation of the number of bunches by grouping berries into bunches (Nuske et al., 2011). The classic computer vision-based techniques used for bunch detection are mainly classified into three classes: i) colour-based thresholding and colour features (Hacking et al., 2020); ii) active contour segmentation (Xiong et al., 2018); and iii) colour-based clustering (´ I˜ niguez et al., 2021). In general, computer vision has shown good results for bunch detection; however, the results of these techniques are highly influenced by image acquisition conditions such as background effects and light conditions and intrinsic conditions of the grape canopies such as bunch occlusion (´ I˜ niguez et al., 2021; Liu et al., 2023). In this context, new artificial intelligence techniques can help us to solve these problems. These innovations ensure the connection between the flow of data measured in vineyards by sensors and the information needed by other mobile devices and agricultural machines to perform the steps of a farming production process autonomously (Ferro et al., 2023). Ballesteros et al., (2020) proposed a method for estimating vineyard yield by combining remote sensing, computer vision, and artificial neural network techniques. Deep learning methods have been proven to be highly effective in segmentation (Marani et al., 2021), classification (Zhong et al., 2019), and object detection (Fuentes et al., 2017) tasks. The use of object detection techniques has shown promise in detecting and counting grapevine bunches (Sozzi et al., 2022). Images are often providing ideal conditions for detecting bunches due to their significant exposure and minimal leaf obstruction (Santos et al., 2020; Zabawa et al., 2022; Guo and Zheng, 2023), or because they depict individual bunches with little to no occlusion (Zhang et al., 2023; Badeka et al., 2023), or they may involve vineyards with unconventional training systems where bunches are highly visible (San Woo et al., 2023; Sneha et al., 2024). These scenarios make bunch detection easier under such favourable conditions. However, there has not been extensive research on the impact of defoliation on yield estimation for the same vines. This presents an opportunity to further refine these detection techniques. It is particularly relevant to adapt these methods to real-world conditions prevalent in commercial vineyards with varying levels of occlusion. The objective of this study was to evaluate vineyard grape yield by detecting and identifying the quantity of grape bunches in commercial vineyards accurately, swiftly, and automatically, at different levels of occlusion and varying field conditions using deep learning algorithms. 2. Materials and methods 2.1. Experimental sites and layout The experiment was conducted in 2020 in eleven commercial dryfarmed cv. Tempranillo (Vitis vinifera L.) vineyards located in Rioja wine appellation, Spain. All vineyards were spur pruned and trained on a vertical shoot positioning trellis system (VSP). Uniform standard viticultural practices were employed across all plots throughout the vegetative cycle, including sucker removal, shoot alignment, and shoot trimming. No defoliation was performed before image acquisition at harvest. In each vineyard site, a random selection of 25 individual vines were chosen. These vines were segmented into two distinct 0.5 m sections and labelled correspondingly. Subsequently, the vine canopy was treated with a sequential defoliation process (Fig. 1) wherein leaves were selectively removed in a systematic manner: initially by excising the primary four basal leaves (partial defoliation) (Fig. 1(b)), followed by the removal of the remaining principal foliage and lateral shoots (full defoliation) (Fig. 1(c)). Images were taken in the vineyard for each individual segment before each defoliation step. 2.2. Image acquisition The canopy images were taken with a conventional Digital Single Lens Reflex (DSLR) RGB camera (Canon EOS 5D Mark IV RGB, Canon Inc., Tokyo, Japan) without the application of artificial lighting, thus reflecting uncontrolled ambient conditions. The camera was affixed to a tripod, oriented towards the canopy. The positioning was calibrated at 1.0 m from the row axis and elevated to 1.2 m above the ground level. To mitigate the impact of surrounding vegetation on image clarity, a white backdrop was positioned behind the canopy. The digital images were archived in JPEG format (with losses), configuring the maximum quality resolution setting available on the camera. This configuration provides a good balance between retaining most of the fine details of the image acquired by the sensor and maintaining a manageable file size of about 10MiB per image. The dimensions of the complete image array were 6720 ×4480 pixels (30.1Mpx). While 25 plants were originally selected for each plot, field conditions caused some plots to get fewer sampling segments. However, the average plant selection per plot was still 25 (two segments per plant), as stated in Section 2.1. Finally, the total number of images taken in the field across all sampling segments was 1704. 2.3. Ground truth data and labelling After the image acquisition phase, grape bunches from each vine segment were harvested and their numbers were determined through manual quantification to verify the actual count of bunches. A specific region of interest (ROI) was defined manually to assess the canopy segment for defoliation level. Within this designated ROI, the images were annotated manually, with a focus on identifying and labelling visible bunches using bounding boxes, employing the LabelImg software (Tzutalin, 2015) for precise and efficient labelling. These “visible bunches” can be directly observed and identified in the visual field without obstruction. Consequently, these visible bunches were used as the main reference values, serving as the ground truth for training the different models. 2.4. Dataset creation for training, validation, and testing images From the eleven-vineyard used in the experiment, five vineyards were randomly selected, and images from these vineyards were designated for training. The images from the remaining six vineyards were used for testing. The dataset curated for this study comprised a total of 1704 source images. This dataset was divided into two main subsets: training and testing sets (Table 1). The first subset consisted of 690 images, which accounts for 40 % of the total (five vineyards). This subset was designated as the TrainingDataSet for deep learning models. The remaining 60 % of the images (six vineyards) with a total of 1014 images, were used to evaluate the performance effectiveness of the models and were designated as the TestingDataSet. The images were manually labelled by R. ´ I˜ niguez et al. Computers and Electronics in Agriculture 226 (2024) 109421 2 an expert. To ensure robust model training and validation, these images were further partitioned, with 80 % (552 images) being allocated for training and the 20 % (138 images) designated for validation. Following this organization, the dataset was used for the generation of four distinct subgroups to mirror different leaf occlusion levels of the canopy. These subgroups are UnDefoliatedImages, encompassing images of vines prior to defoliation; PartialDefoliatedImages, which includes those subjected to partial defoliation; FullDefoliatedImages, containing images postcomplete defoliation; and ComprehensiveImages, a collection encapsulating all preceding images. 2.5. Deep learning model development Multiple models were developed to address different occlusion conditions observed in the vineyards. The models were trained using the TrainingDataSet and the labels of visible bunches. The comprehensive Fig. 1. Images of various sampling segments (row-wise) with different levels of occlusion. From left to right, (a) images with no defoliation, (b) partial defoliation, and (c) full defoliation. Table 1 Distribution of the images in the datasets (TrainingDataSet and TestingDataSet), and in the different groups (ComprehensiveImages, UnDefoliatedImages, PartialDefoliatedImages, and FullDefoliatedImages). Groups Datasets TrainingDataSet 40 % (690 images) TestingDataSet 60 % (1014 images) Train 80 % Validation 20 % Test 100 % N N N ComprehensiveImages 552 138 1014 UnDefoliatedImages 184 46 338 PartialDefoliatedImages 184 46 338 FullDefoliatedImages 184 46 338 N: number of samples. R. ´ I˜ niguez et al. Computers and Electronics in Agriculture 226 (2024) 109421 3 model (ComprehensiveM) was trained using the ComprehensiveImages dataset, including images representing all levels of occlusion. Subsequently, three specialized models were separately developed, each focusing on a specific defoliation condition. The undefoliated model (UnDM) was designed to process images of vines without any defoliation, the partial defoliated model (PartialDM) for those with partial defoliation, and the full defoliated model (FullDM) for images of vines that were completely defoliated. For each model, the validation process was executed using the holdout method. The dataset was divided into two parts: 80 % for training and 20 % for validation. The model was trained exclusively on the training set, and its performance was subsequently evaluated using the validation set. This method aims to provide an assessment of how well the model is likely to perform on unseen data, minimizing the risk of overfitting by ensuring it has not been directly trained on the data used for evaluation. Specifically, the ComprehensiveM was allocated 128 images for validation, drawing from a diverse collection across all defoliation levels, ensuring a thorough representation. Conversely, the specialized models utilized a more focused set of 46 images for validation, corresponding precisely to their targeted defoliation condition. This validation strategy ensures each model is rigorously tested against relevant, condition-specific imagery, facilitating an accurate evaluation of its predictive capabilities. To assess the adaptability and robustness of the various models, each was tested against a range of image sets that represented distinct defoliation scenarios (TestingDataSet). This testing process aimed to determine how well each model performs when presented with images that differ from their TrainingDataSet. Specifically, each model underwent testing with four different sets of images. The set of images, ComprehensiveImages, encompasses all images. UnDefoliatedImages is a set exclusively comprising images of no defoliation vines. PartialDefoliatedImages consists of partially defoliated vines. Finally, Full- DefoliatedImages is a set of images where the vines were fully defoliated. This approach facilitated a comprehensive evaluation of the predictive capabilities of each model and its capacity to generalize across different levels of vine occlusion. This provides valuable insights into their potential utility in diverse real-world vineyard conditions and the capacity of each particular model in generalizing. 2.6. Object detection algorithm Object detection was modelled from the YOLOv4 architecture (Bochkovskiy et al., 2020), implemented with darknet (Redmon, 2013) and using a modified configuration from the original Bochkovskjy’s published code (Bochkovskiy, 2020). The input of the network was 320 ×320x3 (height, width, and channels, respectively) with a batch size of 256 images. Regarding the training control parameters, momentum was statically set to 0.9, and the learning rate was dynamically adjusted during the training starting with a value of 0.001 and applying a decay value of 0.0005. The number of training iterations were capped up to 20000, choosing the model that performed best in the validation dataset, in order to keep overfitting to a minimum. A variety of data augmentation techniques were employed with the objective of enhancing the robustness and generalisation of the object detection model. In particular, modifications were made to the colour saturation and exposure with a coefficient of 1.5, and to the hue with a coefficient of 0.1, in order to accommodate the effects of varying lighting and colour conditions. Mosaic augmentation was enabled, which combines four training images into one, thereby significantly increasing the diversity of object contexts. Random blurring was introduced to simulate image defocus. Furthermore, data augmentation was applied in the last YOLO layer of the neural network, with a jitter factor of 0.3 used to resize the image and its aspect ratio, and the network being randomly resized after each 10 iterations. Training was deployed in a compute server with an AMD Ryzen Threadripper 3970X 32-Core 64-Thread Central Procssing Unit (CPU), 32 GB of ECC DDR4 SDRAM and one nVidia GeForce RTX 3090 24 GB Graphics Processing Unit (GPU). The full training process needed around 24 h to complete. 2.7. Statistical analysis and model evaluation To evaluate the performance of training YOLOv4 models for bunch detection, the following indicators were used: i) mean average precision (mAP)(1), which summarizes the precision of the model; ii) the Intersection over Union (IoU)(2), which evaluate the effectiveness in the overlap between the bounding boxes (labelled and predicted); iii) Precision (3), that is the ratio between the number of correctly detected and the total number of objects detected; iv) Recall (4), that is the ratio between the number of correctly detected and the number of all the bunches; and v) F1-score (5), that is defined as the harmonic mean of precision and recall. The calculation formula of the metrics are as follows: mAP =1 n∑ k=n K=1 APk(1) IoU =area of overlap area of union (2) Precision =TP TP +FP (3) Recall =TP TP +FN (4) F1 −score =2×Precision ×Recall (Precision +Recall)(5) where AP k represents the average precision for class k, n denotes the total number of classes, TP (true positive) indicates the number of correctly detected grape bunches, FP (false positive) indicates the number of falsely detected grape bunches, and FN (false negative) indicate the number of missed grape bunches. To evaluate the performance of grape bunch prediction in images, we utilized the coefficient of determination (R 2 ) and Root Mean Square Error (RMSE) metrics. These metrics were applied to images from TrainingDataSet and TestingDataSet. 3. Results and Discussion 3.1. Statistical analysis of the datasets The statistical analysis of the TrainingDataSet and the TestingData- Set is summarized in Table 2. This table and subsequent analysis compare visible bunch counts in RGB images to real field counts across defoliation levels. For the TraningDataSet, each group contained 230 samples, corresponding to the training and validation images of the five commercial vineyards. The findings indicate improved visibility and higher count averages from no to full defoliation, though with increased variability as shown by standard deviations and coefficient of variation (C.V.). The actual count exhibits the highest variability. Median values are generally close to the means, except for the FullDefoliatedImages and Actual bunches, where they are slightly lower, suggesting data skewness. The actual count also shows a wider range, indicating greater real-world variability. Skewness and kurtosis values increase across groups, suggesting a shift towards more skewed and leptokurtic distributions. For the Testing DataSet, comparing visible to actual grape bunch counts across different defoliation stages for 338 samples per group corresponding to six commercial vineyards. The results show a slight increase in mean count from UnDefoliatedImages to Full- DefoliatedImages, indicating better visibility with defoliation. However, higher variability is observed as defoliation progresses. The actual R. ´ I˜ niguez et al. Computers and Electronics in Agriculture 226 (2024) 109421 4 counts exhibit the most significant variation. The median values align with the means, indicating symmetrical data distributions across all defoliation levels. The wides ranges are observed in actual counts, suggesting variable real-world conditions. The metrics for skewness and kurtosis show a slight increase with defoliation levels, indicating a modest shift towards more skewed distributions in defoliated image categories. The sample size of this study consisted of a dataset of 568 sampling segments, which is significantly larger than those used in previously published studies (Di Gennaro et al., 2019). This increase in sample size enhances the robustness and reliability of the analytical framework. The extensive dataset allows for a more comprehensive exploration of the models’ predictive capabilities, broadening the scope and improving the generalizability of the insights obtained. Moreover, it is important to maintain high spatial resolution when applied across multiple vineyards (Kamangir et al., 2024). This enhances the precision of yield estimation and the interpretation of viticultural variables. 3.2. Deep learning model performance The performance of each model was evaluated and is presented in Table 3. This analysis included an evaluation of several key metrics, including mean average precision (mAP), recall, precision, Intersection over Union (IoU), and the F1-score, to provide a comprehensive assessment of model effectiveness across different defoliation scenarios. The models were calibrated to align the visible bunches labelled by an expert on the TrainingDataSet. The ComprehensiveM achieved a high mAP of 91.38 %, indicating its robust ability to accurately detect bunches across all levels of defoliation. Its recall of 0.87 and precision of 0.85 suggest a strong capability in identifying relevant instances and maintaining accuracy in predictions, supported by an IoU of 71.53 %, indicating a substantial overlap between predicted and actual bounding boxes. The F1-score of 0.86 reflects a well-balanced performance between precision and recall. In contrast, the UnDM exhibited moderate effectiveness with a 74.58 % mAP and lower precision of 0.68, indicating a higher rate of false positives, likely due to the challenges of detecting bunches amidst dense foliage. Its recall of 0.74 and an IoU of 51.14 % suggest moderate success in correctly identifying and localizing bunches, with an F1-score of 0.71 indicating a fair balance in detection performance. The PartialDM, demonstrated improved performance compared to the UnDM, with an 82.33 % mAP and a recall of 0.79, indicating better detection capabilities under partial defoliation. Its precision of 0.73 and an IoU of 55.39 % further support its enhanced ability in accurate localization, resulting in a more balanced F1-score of 0.76. The FullDM outperformed the others with the highest mAP of 92.16 %, underscoring its exceptional accuracy in bunch detection. The recall rate of 0.91 and precision of 0.81 demonstrate a high accuracy rate in identifying and correctly predicting bunches, as supported by an IoU of 68.46 % indicating a strong agreement between the predicted and actual bounding boxes. The F1-score of 0.86, which matches that of the ComprehensiveM, indicates an excellent balance between recall and precision. Overall, these findings emphasize the significant impact of foliar occlusion on the effectiveness of grape bunch detection algorithms (I˜ niguez et al., 2021). The FullDM exhibited the highest overall performance, especially in terms of mAP and recall, while the UnDM showed lower effectiveness, particularly in precision and IoU. The ComprehensiveM demonstrated reliable detection of grape bunches across different defoliation levels, achieving a significant correlation between predictions and actual observations. However, performance varied with foliage density, with the FullDM performing better in near-ideal, low-occlusion conditions. Although such scenarios are ideal for detection (Li et al., 2021), they may not always reflect the complexities of real-world vineyards. These insights highlight the need for customizable computer-assisted viticulture models that can be tailored to the specific canopy coverage of each vineyard environment. The effectiveness of detection algorithms is highly dependent on the level of occlusion (Lu et al., 2022), emphasizing the critical importance of model flexibility. Four specific models have been developed for different canopy conditions, which differ with previous approaches (Sozzi et al., 2022; Ariza-Sentís et al., 2023; Pinheiro et al., 2023), where multiple models were developed using various algorithms to process and analyse the same dataset of images. The performance of these four models was compared and evaluated. Our methodology emphasizes the customization of each model to precisely conform to the unique characteristics of the canopy’s different states. This approach facilitates a tailored analysis that is optimally aligned with each condition and allows for a nuanced understanding of how each algorithm performs under varying canopy conditions. By focusing on the distinctiveness of each canopy state, we can achieve a more accurate and insightful analysis. Table 2 Descriptive statistical analysis for the TrainingDataSet and the TestingDataSet of the number of visible bunches at three levels of occlusion counted in RGB images and actual bunches counted in the field in commercial vineyards. TrainingDataSet N Mean C.V. Median Min Max Skewness Kurtosis UnDefoliatedImages 230 4.92 ±2.17 44.01 5.00 0.00 12.00 0.22 −0.02 PartialDefoliatedImages 230 5.55 ±2.42 43.62 5.00 0.00 15.00 0.39 0.57 FullDefoliatedImages 230 6.00 ±2.75 45.83 6.00 0.00 16.00 0.60 0.82 Actual bunches 230 6.81 ±3.41 50.15 6.00 0.00 23.00 0.88 2.04 TestingDataSet N Mean C.V. Median Min Max Skewness Kurtosis UnDefoliatedImages 338 3.33 ±2.18 65.64 3.00 0.00 12.00 0.45 0.02 PartialDefoliatedImages 338 3.90 ±2.38 60.91 4.00 0.00 14.00 0.69 0.80 FullDefoliatedImages 338 4.21 ±2.58 61.35 4.00 0.00 14.00 0.65 0.40 Actual bunches 338 4.48 ±2.76 61.62 4.00 0.00 14.00 0.51 −0.06 N: number of samples; C.V.: coefficient of variation; Min: minimum number of bunches per segment; Max: maximum number of bunches per segment. Table 3 Summary of the performance’s metrics from YOLO training models (ComprehensiveM, UnDM, PartialDM, FullDM) mAP, Recall, Precision, IoU, and F1-score on the TrainingDataSet. Model mAP(%) Recall Precision IoU (%) F1-score ComprehensiveM 91.38 0.87 0.85 71.53 0.86 UnDM 74.58 0.74 0.68 51.14 0.71 PartialDM 82.33 0.79 0.73 55.39 0.76 FullDM 92.16 0.91 0.81 68.46 0.86 mAP: mean average precision; IoU: intersection over union, ComprehensiveM: comprehensive model; UnDM: undefoliated model; PartialDM: partial defoliated model; FullDM: full defoliated model. R. ´ I˜ niguez et al. Computers and Electronics in Agriculture 226 (2024) 109421 5 3.3. Evaluation of model performance across training, validation, and testing phases The results of deep learning models for training, validation and testing are summarized in Table 4, which presents statistical metrics including the R 2 and RMSE. These metrics provide a quantitative comparison between the number of visible grape bunches labelled by an expert (visible bunch expert-labelled) and the number of visible bunches predicted by the algorithm (algorithm-predicted bunches). In the TrainingDataSet, the ComprehensiveM demonstrates a high R 2 of 0.89, indicating a strong correlation between the observed and predicted bunch counts. Its RMSE is 0.89, reflecting a reasonable prediction error margin. The UnDM, PartialDM, and FullDM show similar R 2 values, with the FullDM having a slightly higher R 2 of 0.91, but also a higher RMSE, indicating greater variability in its predictions. For the validation set, the ComprehensiveM performance drops slightly (R 2 of 0.83), with a corresponding increase in RMSE to 1.12, suggesting a decrease in prediction accuracy compared to the training phase. The specialized models exhibit a similar trend, with marginal decreases in R 2 values and increases in RMSE, consistent with the expected tougher conditions of the validation phase. Moving to the TestingDataSet, which assesses model robustness against unseen data, the ComprehensiveM achieves an R 2 of 0.81 and an RMSE of 1.12. Although there is a slight decrease compared to the training phase, the model maintains a strong predictive capacity. The UnDM performed better in the test phase than in the validation phase, indicating improved prediction accuracy in real-world scenarios without vegetation modification. The PartialDM, and FullDM experience slight drops in R 2 in the test phase, with RMSE values rising, which is typical as models are challenged with new data. Furthermore, it was observed that the localisation of bunches using PartialDM was more effective than that of UnDM, resulting in a higher mAP and IoU (Table 3). The discrepancy can be attributed to the superior bunches localisation exhibited by PartialDM, which is a consequence of enhanced visibility resulting from partial defoliation. However, it is less effective at precisely counting bunches (as indicated by lower R2 and higher RMSE values), due to the variability in the visibility of grape bunches in partially defoliated vines encountered during training. The bunches exhibited a range of visibility, from fully exposed to partially or completely obscured by foliage, or even hidden by neighbouring bunches, which increased the analytical challenge. The diversity in visibility presented a significant challenge to the image analysis process, impeding the algorithm’s ability to consistently identify grape bunches with precision. In contrast, UnDM is more susceptible to occlusion from leaves, which may result in poorer localization but potentially more accurate counts by detecting multiple bunches as a single one. Fig. 2 presents a correlation analysis between expert-labelled and algorithm-predicted grape bunches for each model. The ComprehensiveM model (Fig. 2(a)) exhibits slight underestimation of the number of bunches yet demonstrates balanced performance. The data points for UnDM (Fig. 2(b)) are distributed evenly around the regression line, yet the model subtly underestimates due to the challenges posed by occlusion. PartialDM (Fig. 2(c)) and FullDM (Fig. 2(d)) demonstrate uniformity in predicting bunch counts, with regression line slopes near 1, indicating balanced predictions. The models compensate well for underestimations and occasional overestimations caused by foliage occlusion. Overall, each model maintains systematic accuracy across various bunch count scenarios, despite challenges like bunches grouping affecting visibility and algorithmic interpretation. The outcomes of the external testing corroborate the potential of deep learning models to proficiently predict grape bunch detection across stages of vine growth and under different canopy conditions. In contrast to previous studies that used smaller datasets for model development, Ghiani et al. (2021) developed an automated bunch detection method using a considerably larger dataset and compiled various studies featuring datasets with a limited number of images. However, this dataset has a significant limitation as it mainly consists of images of individual bunches. These images are more difficult to acquire and not accurately represent the canopy environment due to the oftenideal image conditions with minimal occlusion (Pinheiro et al., 2023). Similar issues are present in other datasets, which either lack external testing images or have them in very limited numbers (Sozzi et al., 2022; Liu et al., 2023). This situation emphasizes the necessity for datasets that more accurately reflect the complex conditions of vineyard environments, including varied bunch occlusions and canopy coverage, to improve the effectiveness and applicability of automated grape detection systems. Fig. 3 presents an example of YOLOv4 output predictions across different defoliation states: (a) full defoliation, (b) partial defoliation, and (c) no defoliation. The top row shows the original images of the grapevines, followed by the expert annotations with blue bounding boxes that accurately encapsulate visible grape bunches. The bottom row illustrates YOLOv4 predictions, marked by red bounding boxes. The full defoliation images (Fig. 3(a)) allow a clearer view of the grape bunches resulting in a higher correspondence between expert-labelled and algorithm-detected. However, even under these circumstances, occlusions may still occur due to overlapping bunches, and interpreting bunch numbers can become difficult when multiple bunches are closely grouped together. In the images of partial defoliation (Fig. 3(b)), identifying grape bunches that are largely obscured by foliage becomes more challenging. The human expert had difficulty labelling all grape bunches, as did the algorithm in detecting bunches that were almost completely occluded by leaves, as seen in the image. For images without leaf removal (Fig. 3(c)), the occluded bunches are difficult to detect due to the dense foliage. Even human observers struggle to detect them, and the algorithm faces the same challenge. The precision of both expertlabelled and algorithmic-detected methods is heavily affected by the level of foliar coverage. 3.4. Comparative analysis of deep learning models prediction and human identification in bunch detection A detailed analysis was conducted on RGB images to evaluate the efficacy of bunch detection. This entailed contrasting the precision of Table 4 Performance metrics of prediction capability of trained models detecting visible bunches expert-labelled versus algorithm-predicted bunches across training and testing datasets. Visible/predicted TrainingDataSet TestingDataSet Training Validation Test N R 2 RMSE N R 2 RMSE N R 2 RMSE ComprehensiveM 552 0.89 0.89 138 0.83 1.12 1014 0.81 1.12 UnDM 184 0.90 0.73 46 0.72 1.14 338 0.77 1.07 PartialDM 184 0.82 1.09 46 0.79 1.06 338 0.75 1.24 FullDM 184 0.91 0.91 46 0.87 0.94 338 0.78 1.24 N: number of samples, ComprehensiveM: comprehensive model; UnDM: undefoliated model; PartialDM: partial defoliated model; FullDM: full defoliated model. R. ´ I˜ niguez et al. Computers and Electronics in Agriculture 226 (2024) 109421 6 human detection with verifiable in-field bunch counts, and juxtaposing this with the algorithm’s bunch detection accuracy against these in-field counts. The aim was to determine how proficient the algorithms are in identifying grape bunches compared to human observers. To achieve this, we evaluated the effectiveness of the deep learning models presented in Table 5, the focus is on comparing the visible bunch expertlabelled with the actual bunches field counts, as well as comparing the algorithm-predicted bunches with the actual bunches field counts. This evaluation covers both the TrainingDataSet and the TestingDataSet. In the TrainingDataSet, which included 690 images, all models exhibited a degree of variance when comparing expert-labelled bunches and algorithm-predicted bunches to the actual in-field counts. The ComprehensiveM reveals an R 2 of 0.66 when comparing the expertlabelled bunches to the actual field counts, indicating a moderate level of correlation, confirming the difficulty that may arise in detecting grape bunches for the human eye. This difficulty is also reflected in the model prediction, which indicates a significant decrease in R 2 of 0.41 for algorithm-predicted versus actual bunch counts. The RMSE values for this model are 2.40 for expert-labelled and 4.32 for algorithm-predicted, which implies that the model’s predictions deviate from the actual counts. The UnDM exhibits even lower R 2 values (0.55 for expert/ labelled and 0.16 for algorithm-predicted), accompanied by high RMSE values of 2.98 and 4.04, respectively. These figures indicate a significant difference between the expert labelling and the algorithm’s predictions when compared to the actual bunches, confirming the challenge of estimating the total number of bunches from images with dense vegetation and high levels of occlusion. The PartialDM shows some improvement in R 2 (0.71 for expert/labelled and 0.52 for algorithmpredicted) with lower RMSE values of 2.27 and 2.57, respectively. This indicates a better correlation between the model’s detections and the actual field counts than the UnDM, but still with substantial prediction error. The FullDM, specifically designed for fully defoliated vines, performs best in the TrainingDataSet with R 2 values of 0.78 for expert-labelled and 0.74 for algorithm-predicted, and the lowest RMSE values of 1.81 and 1.85, respectively. This suggests that it is more closely aligned with the actual counts and there is greater visibility of the Fig. 2. Correlation scatter plots between the number of visible bunches expert-labelled and the number of algorithm-predicted bunches counts in the four models: a) ComprehensiveM, b) UnDM, c) PartialDM, and d) FullDM. Each graph shows the regression line (solid) with its equation, the line of unity (dashed), and R 2 value and RMSE value. R. ´ I˜ niguez et al. Computers and Electronics in Agriculture 226 (2024) 109421 7 bunches. In the TestingDataSet, which consists of 1014 images and tests the models against new data, we observe a general trend of improved R 2 values. This may be because the conditions of these images are more favourable for identifying bunches, even in non-defoliating conditions. The ComprehensiveM shows an improvement in R 2 (0.76 for expertlabelled and 0.67 for algorithm-predicted) with lower RMSE values of 1.41 and 1.74, respectively. The UnDM exhibit similar trends, with respective R 2 values of 0.71 and 0.62, and RMSE values of 1.88 and 2.13, reflecting a consistent pattern of reduced prediction accuracy with high levels of leaf occlusion. The PartialDM demonstrated good performance when evaluated against expert labelled, achieving an R 2 value of 0.81 and an RMSE of 1.32. However, the algorithm-predictions showed lower precision, with an R 2 of 0.60 and an RMSE of 2.02. The decrease in predictive accuracy can be attributed to the wide range of bunches visibility, which includes bunches that are fully visible as well as those that are partially or completely obscured by foliage or other grape bunches. The FullDM demonstrates that the performance labelled by experts is reliable, exhibiting an R 2 of 0.86 and an RMSE of 1.04. This indicates a high level of reliability in the human-detected bunch counts against the actual in-field counts. As for the algorithm-predicted bunches, the model registers an R 2 of 0.71 and an RMSE of 1.55. Although lower than the expert-labelled performance, it still represents a commendable degree of algorithmic prediction accuracy. The R 2 and RMSE metrics combined provide a comprehensive view of the models’ performance, reflecting not only the degree of correlation but also the extent of errors in prediction. It becomes evident that while there is a strong foundation for detecting grape bunches using deep learning. These results underscore the challenges that occlusion and the varied conditions of vineyards pose for both algorithmic detection and human observation. Ariza-Sentís et al. (2023) highlighted the difficulties for the human eye to distinguish between grape bunches and surrounding vegetation in vineyards. The application of deep learning algorithms has demonstrated substantial capability in accurately detecting grape bunches. This capability has the potential to significantly enhance vineyard management practices. For example, the precise identification of bunch counts can facilitate the strategic zoning of vineyards based on the levels of grape production. Such zoning allows for the implementation of tailored viticultural practices, which in turn enables the differentiation of winemaking approaches across vineyard sections. Furthermore, this technology assists in optimising cultivation strategies by identifying areas with varying bunch densities. Consequently, vineyard areas with disparate bunch counts can be managed in a differentiated manner, with the objective of implementing targeted interventions for the optimal grape yield and quality. Fig. 3. Comparison between the number of visible bunches in an original image, detected and labelled by an expert (blue bounding boxes), and the predicted bunches using YOLOv4 (red bounding boxes) in (a) full defoliation from FullDefoliatedImages dataset, (b) partial defoliation from PartialDefoliatedImages dataset, and (c) no defoliation from UnDefoliatedImages dataset. Table 5 Comparative analysis of performance in detecting actual bunch counts in-field versus visible bunches expert-labelled and algorithm-predicted bunches across training and testing datasets. TrainingDataSet TestingDataSet Expert-labelled Algorithm-predicted Expert-labelled Algorithm-predicted R 2 RMSE R 2 RMSE R 2 RMSE R 2 RMSE ComprehensiveM 0.66 2.40 0.41 4.32 0.76 1.41 0.67 1.74 UnDM 0.55 2.98 0.16 4.04 0.71 1.88 0.62 2.13 PartialDM 0.71 2.27 0.52 2.57 0.81 1.32 0.60 2.02 FullDM 0.78 1.81 0.74 1.85 0.86 1.04 0.71 1.55 ComprehensiveM: comprehensive model; UnDM: undefoliated model; PartialDM: partial defoliated model; FullDM: full defoliated model. R. ´ I˜ niguez et al. Computers and Electronics in Agriculture 226 (2024) 109421 8 3.5. Assessment of deep learning models precision across specific image datasets Fig. 4 displays a colour-coded performance matrix presenting the R 2 and RMSE values for four distinct models when tested against the specific image datasets. The matrix uses a colour gradient to visually represent the performance spectrum of each model. The colour gradient emphasizes the performance of each model, with light colours and big circles indicating higher performance (more correlation and lower error, respectively), and dark colours and small circles indicating worse performance (lower correlation and higher error, respectively). The left part of the Fig. 4 shows the R 2 for the four models, providing a visual representation of how well each model’s predictions correlate with the actual data across different image sets. The ComprehensiveM performed the best in terms of R 2 when evaluated against the FullDefoliatedImages set, indicated by the light pink colour and big circle, reflecting an R 2 value of 0.96. The analysis indicates a strong correlation between the model’s predictions and fully defoliated images. Another strong result is observed with the UnDM on the ComprehensiveImages set, which also shows a light green colour, corresponding to an R 2 value of 0.83. This indicates a strong correlation for a comprehensive set of images and suggests that this model is quite reliable when predicting across varied defoliation scenarios. In contrast, the poorest performance is observed with the FullDM tested against the UnDefoliatedImages set, where the black colour and small circle, signifies an R 2 value of 0.32. This low correlation indicates that the model is not effective at predicting outcomes when no defoliation has occurred, which could be a lack of learned features relevant to undisturbed foliage. Note that despite not achieving the same levels of correlation when compared to the other models, the UnDM achieves an adequate result in every dataset. This behaviour is expected since this model was trained using the most unfavourable conditions, and the rest of the dataset is less challenging, despite depicting completely different situations. The right side of the Fig. 4 shows the evaluates of the precision of the models by examining the RMSE across different test image sets. RMSE values provide insight into the average error magnitude, with lower values indicating a model’s predictions are closer to the actual observed values, hence signifying higher precision. The ComprehensiveM demonstrates commendable accuracy on all sets, as can be seen by the reduced size of the circles and the light green colours, with particularly notable results on the FullDefoliatedImages set, which achieves an RMSE of 0.53. The FullDM, when applied to the FullDefoliatedImages set, exhibits a low RMSE value of 0.94, denoted by a light green and small circle. This result is indicative of a highly precise model that excels when evaluating fully defoliated images. In contrast, the FullDM, when faced with the UnDefoliatedImages set, incurs the highest RMSE value of 2.75, as reflected by a black and big circle. As this model was initially trained on images without foliage occlusion, it shows a higher error rate when tasked with evaluating new images characterised by significant foliage occlusion, as with the PartialDefoliatedImages set, with an RMS of 1.62. 3.6. Future work Considering the results obtained, future work should focus on developing algorithms for grape bunch detection by analysing images where vines are influenced by surrounding vegetation, rather than using a white background. Furthermore, another avenue for future research could involve assessing these algorithms across different vineyard training systems, grape varieties and different phenological stages. Additionally, to improve the model’s accuracy, it is essential to include a wider range of images with varying levels of occlusion in the training dataset. A further significant avenue of enquiry will be to evaluate the performance and efficiency of new YOLO models. The evaluation of disparate versions of YOLO will facilitate the determination of the optimal model, in terms of accuracy, speed, and robustness, for the detection of grape bunches. Future efforts should aim to refine the algorithm’s capability to Fig. 4. Results of the predictive performance of the models in detecting visible bunches, expert-labelled versus algorithm-predicted bunch count, tested in each subgroup of the TrainingDataSet. The left part of the figure shows the R 2 , while the right side presents the RMSE. Both the area of the circles and the colour gradient emphasize the performance of each model, with light colours and big circles indicating higher performance (more correlation and lower error, respectively), and dark colours and small circles indicating worse performance (lower correlation and higher error, respectively). R. ´ I˜ niguez et al. Computers and Electronics in Agriculture 226 (2024) 109421 9