I already trained and got weight file in folder. I would like to know how to automatically detect the photos in the folder instead of running the code manually, and every time I add a photo to the folder, it will detect the new photo and save the result.
Please tell me how to do it, thank you.
Below is my code to detect photos
import glob
import torch
import cv2
import numpy as np
model = torch.hub.load('ultralytics/yolov5', 'custom', path='yolov5/runs/train/exp8/weights/best.pt',force_reload=True)
# print(model)
for img in glob.glob("C:/Users/csie/PycharmProjects/Fridge/testdata/*png"):
cv_img =cv2.imread(img)
results = model(cv_img)
results.save()