forked from WongKinYiu/yolov7
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
86 lines (80 loc) · 2.93 KB
/
config.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import json
import os
import platform
DEFAULT_CONFIG = {
"system": "linux",
"cam_id": 0,
"weight": "runs/train/exp/weights/best.pt",
"conf_thres": 0.25,
"iou_thres": 0.45,
"size": 736,
"arduino_pin": 9,
"servo_offset": -13,
"servo_ratio": 5,
"servo_com": "/dev/ttyUSB0/",
"trace": True
}
class Config:
def __init__(self, path="config_linux.json"):
self.path=path
self.system = "windows"
self.cam_id = 0
self.camera_width_angle = 113
self.width = 1280
self.height = 720
self.weight = ""
self.tensorrt = False
self.tensorrt_weight = "2.3k-1440-400-tiny.engine"
self.k4a = False
self.conf_thres = 0.25
self.iou_thres = 0.45
self.img_size = 736
self.arduino_pin = 9
self.servo_offset = -13
self.servo_ratio = 5
self.servo_com = "COM18"
self.trace = True
self.ros = False
def load_config(self, path):
sync = False
if not os.path.exists(path):
os.makedirs(os.path.dirname(path), exist_ok=True)
print("Config not find")
with open(path, "w", encoding="utf-8") as config_file:
json.dump(DEFAULT_CONFIG, config_file, indent=4)
return DEFAULT_CONFIG
with open(path, "r", encoding="utf-8") as config_file:
data = dict(json.load(config_file))
for keys in DEFAULT_CONFIG.keys():
if keys not in data.keys():
print(f"Config {keys} not found, use default value {DEFAULT_CONFIG[keys]}")
data.update({keys: DEFAULT_CONFIG[keys]})
sync = True
if sync:
with open(path, "w", encoding="utf-8") as config_file:
json.dump(data, config_file, indent=4)
return data
def init_config(self):
config_data = self.load_config(self.path)
self.system = config_data["system"]
self.cam_id = config_data["cam_id"]
self.camera_width_angle = config_data["camera_width_angle"]
self.width = config_data["width"]
self.height = config_data["height"]
self.weight = config_data["weight"]
self.tensorrt = config_data["tensorrt"]
self.tensorrt_weight = config_data["tensorrt_weight"]
self.k4a = config_data["k4a"]
self.ros = config_data["ros"]
self.conf_thres = config_data["conf_thres"]
self.iou_thres = config_data["iou_thres"]
self.img_size = config_data["size"]
self.arduino_pin = config_data["arduino_pin"]
self.servo_offset = config_data["servo_offset"]
self.servo_ratio = config_data["servo_ratio"]
if platform.system() == "Windows":
self.servo_com = config_data["windows"]["servo_com"]
else:
self.servo_com = config_data["linux"]["servo_com"]
print(f"Using {platform.system()} as os")
self.trace = config_data["trace"]