-
Notifications
You must be signed in to change notification settings - Fork 3
/
validation.py
53 lines (49 loc) · 1.7 KB
/
validation.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from ultralytics import YOLO
import argparse
import pathlib
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='validation model')
parser.add_argument('--model', type=str, default='model/yolov8n.engine', required=True, help='Path to the .pt')
parser.add_argument('--q', type=str, default='fp16', required=False, help='[fp16, int8]')
parser.add_argument('--data', type=str, default='coco.yaml', required=True, help='Dataset')
args = parser.parse_args()
model = YOLO(args.model, task='detect')
file_extension = pathlib.Path(args.model).suffix
if file_extension == '.engine':
if args.q == 'fp16':
results = model.val(
data=args.data,
batch=1,
imgsz=640,
verbose=False,
half = True
)
elif args.q == 'int8':
results = model.val(
data=args.data,
batch=1,
imgsz=640,
verbose=False,
int8 = True
)
else:
print('\n[ERROR] Make sure "--q" parameter is entered correctly!')
elif file_extension == '.onnx':
if args.q == 'fp16':
results = model.val(
data=args.data,
batch=1,
imgsz=640,
verbose=False,
)
else:
print('\n[ERROR] ONNX supports only FP16 quantization!')
elif file_extension == '.pt':
results = model.val(
data=args.data,
batch=1,
imgsz=640,
verbose=False,
)
else:
print('\n[ERROR] File extensions only support [.engine], [.onnx], [.pt]')