| from ultralytics import YOLO |
| import os |
|
|
| TEST_NAME = "test13" |
| |
| WEIGHTS_DIRECTORY = "runs/detect/train32/weights/best.pt" |
| |
| |
| IMAGES_DIRECTORY = "datasets/Collected_Images" |
|
|
|
|
| if not os.path.exists(f"test_results/{TEST_NAME}"): |
| os.makedirs(f"test_results/{TEST_NAME}") |
| |
| |
| model = YOLO(WEIGHTS_DIRECTORY) |
|
|
| |
|
|
| for index, image_name in enumerate(os.listdir(IMAGES_DIRECTORY)): |
| if index > 1000: continue |
| |
| results = model.predict( |
| source=f"{IMAGES_DIRECTORY}/{image_name}", device="cuda:0", conf=0.2, |
| ) |
| |
| |
|
|
| for result in results: |
| result.save(f"test_results/{TEST_NAME}/{index}.jpg") |
|
|
|
|
|
|