Spaces:
Sleeping
Sleeping
| from ultralytics import YOLO | |
| import cv2 | |
| # ------------------------------- | |
| # Paths (EDIT THESE) | |
| # ------------------------------- | |
| MODEL_PATH = r"D:\Downloads\fastener_detection_run1 (1)\weights\best.pt" | |
| IMAGE_PATH = r"C:\Users\HP\OneDrive\Desktop\screw\object_detection_dataset\test\images\screws_0430.jpg" | |
| # ------------------------------- | |
| # Load model | |
| # ------------------------------- | |
| model = YOLO(MODEL_PATH) | |
| # ------------------------------- | |
| # Run inference | |
| # ------------------------------- | |
| results = model(IMAGE_PATH, conf=0.25) | |
| # ------------------------------- | |
| # Get annotated image | |
| # ------------------------------- | |
| annotated_img = results[0].plot() # draws boxes, labels, confidence | |
| # ------------------------------- | |
| # Show image in VS Code window | |
| # ------------------------------- | |
| cv2.imshow("YOLOv8 Inference Result", annotated_img) | |
| cv2.waitKey(0) | |
| cv2.destroyAllWindows() | |