Views
No views yet

1from ultralytics import YOLO
2import cv2
3import matplotlib.pyplot as plt
4
5# Load the YOLO model
6model = YOLO('yolo11x_leaf.pt')
7
8# Run inference on an image or directory
9result = model.predict('file/directory', task="detect", save=False, conf=0.15)
10
11# Load the original image
12image_path = result.path
13image = cv2.imread(image_path)
14image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
15
16# Annotate the image with predictions
17annotated_image = result.plot()
18
19# Display the annotated image
20plt.figure(figsize=(10, 7))
21plt.imshow(annotated_image)
22plt.axis("off")
23plt.title(f"Predictions for Image")
24plt.show()
