-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
162 lines (125 loc) · 5.41 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import os
import libraries.common as cv
import libraries.create as create
import libraries.test as test
import libraries.player as player
try:
if __name__ == "__main__":
print("welcome to the drone object detector!")
selection = input(
"\nwhat would you like to do?\n1. create a new model\n2. train an existing model\n3. test an existing model\n4. watch a completed test\n5. exit\n"
)
if selection == "1":
selection = input(
"\nwould you like to set the model's parameters manually? (y/n)\n"
)
if selection == "y":
epochs = int(input("\nhow many epochs would you like to train for?\n"))
if epochs <= 0:
raise ValueError
if epochs > 500:
selection = input(
"WARNING: training for more than 500 epochs may cause overfitting.\nwould you like to continue? (y/n)\nchoice: "
)
if selection == "n":
exit()
batch_size = int(input("what batch size would you like to use?\n"))
if batch_size < 1:
raise ValueError
learning_rate = float(
input("what learning rate would you like to use? (0 - 1)\n")
)
if learning_rate < 0 or learning_rate > 1:
raise ValueError
optimizer = input(
"what optimizer would you like to use? (SGD, Adam, Adamax, AdamW, NAdam, RAdam, RMSProp, auto)\n"
)
choices = [
"SGD",
"Adam",
"Adamax",
"AdamW",
"NAdam",
"RAdam",
"RMSProp",
"auto",
]
if optimizer not in choices:
raise ValueError
device = input(
"what device would you like to use? (0 = gpu, cpu = cpu, mps = apple silicon gpu)\n"
)
print(device)
if device != "0" and device != "cpu" and device != "mps":
raise ValueError
create.main(epochs, batch_size, learning_rate, optimizer, device)
elif selection == "n":
create.main()
else:
raise ValueError
elif selection == "2":
print("this feature is not yet implemented. please try again later.")
exit()
elif selection == "3":
# selecting the model
models = []
for file in os.listdir(cv.MODELS_DIR):
if file.endswith(".pt"):
models.append(file)
if len(models) == 0:
print("no models found. please create a model first.")
exit()
counter = 1
print("found the following models:")
for model in models:
print(f"{counter}: {model}")
counter += 1
selection = input("which model would you like to test? (enter the number)\n")
selection = int(selection)
if selection < 1 or selection > len(models):
raise ValueError
# selecting the test video
videos = []
for file in os.listdir(cv.VIDEOS_DIR):
if file.endswith(".mp4"):
videos.append(file)
if len(videos) == 0:
print("no videos found. please add a video to the video directory.")
exit()
counter = 1
print("found the following videos:")
for video in videos:
print(f"{counter}: {video}")
selection = input("which video would you like to test? (enter the number)\n")
selection = int(selection)
if selection < 1 or selection > len(videos):
raise ValueError
# running the test
print("\nrunning test...")
test.main(models[selection - 1], videos[selection - 1])
elif selection == "4":
# selecting the test video
videos = []
for file in os.listdir(cv.TESTS_DIR):
if file.endswith(".mp4"):
videos.append(file)
if len(videos) == 0:
print("no videos found. please add a video to the video directory.")
exit()
counter = 1
print("found the following videos:")
for video in videos:
print(f"{counter}: {video}")
selection = input("which video would you like to watch? (enter the number)\n")
selection = int(selection)
if selection < 1 or selection > len(videos):
raise ValueError
# playing the video
print("\nplaying video...")
player.main(videos[selection - 1])
elif selection == "5":
print("exiting...")
exit()
except Exception as e:
print(f"an error occurred: {e}")
exit()