Weeds are among the major problems in agriculture for crop production; they appear every- where randomly in the fields and compete with sunlight, water, fertiliser, and space. Detecting weeds have become a major concern for producers. Controlling weeds early is especially im- portant in order to prevent yield losses. Nowadays, by using intelligent technology, smart agriculture has become imperative due to its ability to accurately determine weeds distribution in the field, perform weeds control tasks in specific areas, and thus enhance the efficacy of her- bicides as well as the economic benefits of agricultural products. In this study, we conducted a comparative analysis of four different models of YOLO (YOLOv5s, YOLOv6, YOLOv7, and YOLOv8s) using standardized hyperparameters on a corn dataset consist of 1268 images. We evaluated the models based on precision, recall, and mean average precision (mAP). In general, all the models achieved a good accuracy for detecting weeds. The detection accuracy on corn dataset in terms of mAP@0.5 ranged from 0.963 obtained by Yolov6 to 0.992 by Yolov7. The results showed that YOLOv7 achieved the highest detection accuracy. Then we examined the performance of YOLOv7 on different image sizes, including 415, 640, and 800. The evaluation indicated that image resolution of 640-pixels was the optimal image size for achieving the best results. Furthermore, we expanded our analysis by presenting a new dataset consisting of 950 images of three classes (okra, eggplant and weeds) collected from farms in Saudi Arabia. When evaluating the performance of the model on this dataset, it achieved an mAP@0.5 of 0.88, in- dicating its effectiveness in accurately detecting and classifying objects in the context of weeds detection in okra and eggplant fields.