The utilization of machine learning in vegetable harvesting not only enhances efficiency and precision but also addresses labor shortages and improves overall agricultural productivity. In this study, a machine learning method was developed for harvesting courgette fruit. Courgette is a fruit that can take a long time to select and harvest in the agricultural area where it is grown. The YOLOv5 models (nano, small, medium, and large) were used as a deep learning method. All metric values of the models were analyzed. The most successful model was the one trained with the YOLOv5m algorithm using 20 batches and 160 epochs with 640x640 images. The results of the model scores were analyzed as "metrics/precision", "metrics/recall", "metrics/mAP_0.5" and "metrics/mAP_0.5: 0.95". These metrics are key indicators that measure the recognition success of a model and reflect the performance of the respective model on the validation dataset. The metrics data of the "YOLOv5 medium" model proved to be higher compared to the other models. The measured values were YOLOv5m = size: 640x640, batch: 20, epoch: 160, algorithm: YOLOv5m. It was concluded that "YOLOv5m" is the best recognition model that can be used in robotic courgette harvesting to separate the courgette from the branch.