forked from Yusepp/YOLOv8-Face
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
33 lines (24 loc) · 886 Bytes
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from ultralytics import YOLO
import torch
import cv2
import argparse
def parse_variables():
parser = argparse.ArgumentParser(description='Run Inference YOLOv8 for Face Detection')
parser.add_argument('-w', '--weights', type=str, help='Path to trained weights',
default='yolov8m_200e.pt')
args = parser.parse_args()
variables = vars(args)
return variables
def main():
# Parse the command line arguments
variables = parse_variables()
# Select device
device = 'cuda' if torch.cuda.is_available() else 'cpu'
device = 'mps' if torch.backends.mps.is_available() else device
# Load the pretrained model
model = YOLO(variables['weights'])
model.to(device)
# Run inference on the webcam
results = model.predict('0', verbose=True)
if __name__ == '__main__':
main()