-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
161 lines (142 loc) · 7.29 KB
/
gui.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
import PySimpleGUI as sg
from json import (load as jsonload, dump as jsondump)
from os import path
from utils.config_tools import *
from main import start_app
from pictures import pictures_window
DEFAULT_SETTINGS = {'dir': 'dir',
'valdir': 'valdir' ,
'traindir': 'traindir' ,
'yolodir': 'yolodir',
'imagesdir': 'imagesdir',
'datayaml' : 'datayaml',
'trainyaml': 'trainyaml',
'traindataid': 'traindataid' ,
'valdataid': 'valdataid',
'yololink' : 'yololink',
'epochs': 'epochs',
'batchsize': 'batchsize' ,
'workers': 'workers',
'devices': 'devices',
'name' : 'name',
'confidence' : 'confidence',
'imgsize': 'imgsize',
'weights': 'weights',
'trainset': 'trainset' ,
'valset': 'valset',
'yolo' : 'yolo',
'train' : 'train',
'detect': 'detect',
}
SETTINGS_KEYS_TO_ELEMENT_KEYS = {'dir': 'dir',
'valdir': 'valdir' ,
'traindir': 'traindir' ,
'yolodir': 'yolodir',
'imagesdir': 'imagesdir',
'datayaml' : 'datayaml',
'trainyaml': 'trainyaml',
'traindataid': 'traindataid' ,
'valdataid': 'valdataid',
'yololink' : 'yololink',
'epochs': 'epochs',
'batchsize': 'batchsize' ,
'workers': 'workers',
'devices': 'devices',
'name' : 'name',
'confidence' : 'confidence',
'imgsize': 'imgsize',
'weights': 'weights',
'trainset': 'trainset' ,
'valset': 'valset',
'yolo' : 'yolo',
'train' : 'train',
'detect': 'detect',
}
##################### Load/Save Settings File #####################
def load_settings(default_settings):
settings = default_settings
save_settings(settings, None)
return settings
def save_settings(settings, values):
if values:
for section in get_sections():
for key, value in get_params(section):
try:
set_config(section, key, str(values[key]))
except Exception as e:
print(f'Problem updating settings from window values. Key = {key}')
sg.popup('Settings saved')
##################### Make a settings window #####################
def create_settings_window(settings):
def TextLabel(text): return sg.Text(text+':', justification='l', size=(30,1))
layout = [ [sg.Text('Settings', font='Any 15')],
[sg.Text('Files', font='Any 13')],
[TextLabel('Main dir'), sg.Input(key='dir'), sg.FolderBrowse(target='dir')],
[TextLabel('Train data dir'),sg.Input(key='traindir'), sg.FolderBrowse(target='traindir')],
[TextLabel('Val data dir'),sg.Input(key='valdir'), sg.FolderBrowse(target='valdir')],
[TextLabel('Yolo Dir'),sg.Input(key='yolodir'), sg.FolderBrowse(target='yolodir')],
[TextLabel('Test images dir'),sg.Input(key='imagesdir'), sg.FolderBrowse(target='imagesdir')],
[TextLabel('data.yaml dir'),sg.Input(key='datayaml'), sg.FolderBrowse(target='datayaml')],
[TextLabel('train.yaml dir'),sg.Input(key='trainyaml'), sg.FolderBrowse(target='trainyaml')],
[sg.Text('Download data', font='Any 13')],
[TextLabel('Train data google drive Id'), sg.Input(key='traindataid')],
[TextLabel('Val data google drive Id'), sg.Input(key='valdataid')],
[TextLabel('Yolo git link'), sg.Input(key='yololink')],
[sg.Text('Yolo training', font='Any 13')],
[TextLabel('Weights'), sg.Input(key='weights'), sg.FolderBrowse(target='weights')],
[TextLabel('Epochs'), sg.Input(key='epochs')],
[TextLabel('Batch size'), sg.Input(key='batchsize')],
[TextLabel('Workers'), sg.Input(key='workers')],
[TextLabel('Devices (CPU/GPU:(0/1/2/3)'), sg.Input(key='devices')],
[TextLabel('Name of dir results'), sg.Input(key='name')],
[TextLabel('object confidence threshold'), sg.Input(key='confidence')],
[TextLabel('Img size'), sg.Input(key='imgsize')],
[sg.Text('Steps', font='Any 13')],
[TextLabel('Download trainset'), sg.Checkbox(text='', key='trainset')],
[TextLabel('Download valset'), sg.Checkbox(text='', key='valset')],
[TextLabel('Download and compile Yolo'), sg.Checkbox(text='', key='yolo')],
[TextLabel('Train data'), sg.Checkbox(text='', key='train')],
[TextLabel('Detect from images dir'), sg.Checkbox(text='', key='detect')],
[sg.Button('Save'), sg.Button('Exit')] ]
window = sg.Window('Settings', layout, keep_on_top=True, finalize=True)
for key in SETTINGS_KEYS_TO_ELEMENT_KEYS:
for section in get_sections():
for key, value in get_params(section):
try:
param = get_config(section, key)
if param == 'True':
param = True
elif param == 'False':
param = False
window[SETTINGS_KEYS_TO_ELEMENT_KEYS[key]].update(value=param)
except Exception as e:
print(f'Problem updating PySimpleGUI window from settings. Key = {key}')
return window
##################### Main Program Window & Event Loop #####################
def create_main_window(settings):
layout = [[sg.T('Yolo automation training')],
[sg.T('Change settings or start this app')],
[sg.B('Exit'), sg.B('Change Settings'), sg.B('Start')]]
return sg.Window('Main Application', layout)
def main():
set_config('Common', 'Dir', path.dirname(__file__))
window, settings = None, load_settings(DEFAULT_SETTINGS)
while True:
if window is None:
window = create_main_window(settings)
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
if event == 'Change Settings':
event, values = create_settings_window(settings).read(close=True)
if event == 'Save':
window.close()
window = None
save_settings(settings, values)
if event == 'Start':
window.close()
start_app()
pictures_window()
window.close()
if __name__ == '__main__':
main()