如何加载自定义 yolo v-7 模型。
这就是我知道如何加载 yolo v-5 模型的方法:
model = torch.hub.load('ultralytics/yolov5', 'custom', path='yolov5/runs/train/exp15/weights/last.pt', force_reload=True)
Run Code Online (Sandbox Code Playgroud)
我在网上看到视频,他们建议使用这个:
!python detect.py --weights runs/train/yolov7x-custom/weights/best.pt --conf 0.5 --img-size 640 --source final_test_v1.mp4
Run Code Online (Sandbox Code Playgroud)
但我希望它像普通模型一样加载,并给我它找到对象的边界框坐标。
这就是我在 yolo v-5 中的做法:
from models.experimental import attempt_load
yolov5_weight_file = r'weights/rider_helmet_number_medium.pt' # ... may need full path
model = attempt_load(yolov5_weight_file, map_location=device)
def object_detection(frame):
img = torch.from_numpy(frame)
img = img.permute(2, 0, 1).float().to(device) #convert to required shape based on index
img /= 255.0
if img.ndimension() == 3:
img = img.unsqueeze(0)
pred = model(img, augment=False)[0]
pred = …Run Code Online (Sandbox Code Playgroud)