This repository was archived by the owner on Sep 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.py
More file actions
70 lines (53 loc) · 1.73 KB
/
Copy pathvalidate.py
File metadata and controls
70 lines (53 loc) · 1.73 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
import argparse
import enum
import os
from datetime import datetime
from ultralytics import YOLO
# Set CUDA Allocation to 512MB
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:512"
# Run script from current working directory
os.chdir(os.path.dirname(os.path.abspath(__file__)))
models = {
"nano": "yolov8n-seg.pt",
"small": "yolov8s-seg.pt",
"medium": "yolov8m-seg.pt",
"large": "yolov8l-seg.pt",
"extralarge": "yolov8x-seg.pt",
}
class ModelSizes(str, enum.Enum):
nano = "nano"
small = "small"
medium = "medium"
large = "large"
extralarge = "extralarge"
def main(arg):
# Create Timer
start_time = datetime.now()
print("› Starting Validation: {}".format(start_time.strftime("%Y-%m-%d %H:%M:%S")))
# Fetch code size from args
code = arg["size"][0]
# Fix code used for naming
if code == "e":
code = "x"
# Load the last model from previous training session
model = YOLO("fbc-ml-models/fbc-seg-{}/weights/last.pt".format(code))
# Evaluate the model's performance on the validation set
model.val()
# Output Run Time
end_time = datetime.now()
time_elapsed = end_time - start_time
print("› Completed: {}".format(end_time.strftime("%Y-%m-%d %H:%M:%S")))
print("› Total Time: {}".format(time_elapsed))
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Validate YOLOv8 Model",
epilog="Find By Color - OID Segmentation Model",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("size", type=ModelSizes)
try:
main(vars(parser.parse_args()))
except KeyboardInterrupt:
print("Exited Application")
exit(0)