UI.py
25 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
import torch
import torch.nn as nn
from model import mobilenetv3
from PyQt5.QtCore import pyqtSignal, QThread
from PyQt5 import QtCore, QtGui, QtWidgets
from train import UI_train
from test import UI_validate, UI_test, UI_temp
import threading, _thread
import time
import os
from queue import Queue
import multiprocessing
import logging
threads = []
logger = logging.getLogger('Techwing_log')
######### 눈금까지 기재된 커스터마이징 슬라이더 #########
class LabeledSlider(QtWidgets.QWidget):
def __init__(self, minimum=1, maximum=11, start_value=4, interval=1, orientation=QtCore.Qt.Horizontal,
labels=None, p0=4, parent=None):
super(LabeledSlider, self).__init__(parent=parent)
levels=range(minimum, maximum + interval, interval)
if labels is not None:
if not isinstance(labels, (tuple, list)):
raise Exception("<labels> is a list or tuple.")
if len(labels) != len(levels):
raise Exception("Size of <labels> doesn't match levels.")
self.levels=list(zip(levels,labels))
else:
self.levels=list(zip(levels,map(str,levels)))
if orientation==QtCore.Qt.Horizontal:
self.layout=QtWidgets.QVBoxLayout(self)
elif orientation==QtCore.Qt.Vertical:
self.layout=QtWidgets.QHBoxLayout(self)
else:
raise Exception("<orientation> wrong.")
# gives some space to print labels
self.left_margin=10
self.top_margin=10
self.right_margin=10
self.bottom_margin=10
self.layout.setContentsMargins(self.left_margin,self.top_margin,
self.right_margin,self.bottom_margin)
self.sl=QtWidgets.QSlider(orientation, self)
self.sl.setMinimum(minimum)
self.sl.setMaximum(maximum)
self.sl.setValue(start_value)
self.sl.setSliderPosition(p0)
if orientation==QtCore.Qt.Horizontal:
self.sl.setTickPosition(QtWidgets.QSlider.TicksBelow)
self.sl.setMinimumWidth(300) # just to make it easier to read
else:
self.sl.setTickPosition(QtWidgets.QSlider.TicksLeft)
self.sl.setMinimumHeight(80) # just to make it easier to read
self.sl.setTickInterval(interval)
self.sl.setSingleStep(1)
self.layout.addWidget(self.sl)
def paintEvent(self, e):
super(LabeledSlider,self).paintEvent(e)
style=self.sl.style()
painter=QtGui.QPainter(self)
st_slider=QtWidgets.QStyleOptionSlider()
st_slider.initFrom(self.sl)
st_slider.orientation=self.sl.orientation()
length=style.pixelMetric(QtWidgets.QStyle.PM_SliderLength, st_slider, self.sl)
available=style.pixelMetric(QtWidgets.QStyle.PM_SliderSpaceAvailable, st_slider, self.sl)
for v, v_str in self.levels:
# get the size of the label
rect=painter.drawText(QtCore.QRect(), QtCore.Qt.TextDontPrint, v_str)
if self.sl.orientation()==QtCore.Qt.Horizontal:
# I assume the offset is half the length of slider, therefore
# + length//2
x_loc=QtWidgets.QStyle.sliderPositionFromValue(self.sl.minimum(),
self.sl.maximum(), v, available)+length//2
# left bound of the text = center - half of text width + L_margin
left=x_loc-rect.width()//2+self.left_margin
bottom=self.rect().bottom()
# enlarge margins if clipping
if v==self.sl.minimum():
if left<=0:
self.left_margin=rect.width()//2-x_loc
if self.bottom_margin<=rect.height():
self.bottom_margin=rect.height()
self.layout.setContentsMargins(self.left_margin,
self.top_margin, self.right_margin,
self.bottom_margin)
if v==self.sl.maximum() and rect.width()//2>=self.right_margin:
self.right_margin=rect.width()//2
self.layout.setContentsMargins(self.left_margin,
self.top_margin, self.right_margin,
self.bottom_margin)
else:
y_loc=QtWidgets.QStyle.sliderPositionFromValue(self.sl.minimum(),
self.sl.maximum(), v, available, upsideDown=True)
bottom=y_loc+length//2+rect.height()//2+self.top_margin-3
# there is a 3 px offset that I can't attribute to any metric
left=self.left_margin-rect.width()
if left<=0:
self.left_margin=rect.width()+2
self.layout.setContentsMargins(self.left_margin,
self.top_margin, self.right_margin,
self.bottom_margin)
pos=QtCore.QPoint(left, bottom)
painter.drawText(pos, v_str)
return
class BaseThread(threading.Thread):
def __init__(self, callback=None, callback_args=None, *args, **kwargs):
target = kwargs.pop('target')
super(BaseThread, self).__init__(target=self.target_with_callback, *args, **kwargs)
self.callback = callback
self.method = target
self.callback_args = callback_args
def target_with_callback(self, *args, **kwargs):
self.method(*args, **kwargs)
if self.callback is not None:
self.callback(*self.callback_args)
# dialog log창 핸들러
class QTextEditLogger(logging.Handler):
def __init__(self, parent):
super().__init__()
self.widget = QtWidgets.QTextEdit()
parent.addWidget(self.widget)
self.widget.setReadOnly(True)
def emit(self, record):
msg = self.format(record)
self.widget.append(msg)
QtGui.QGuiApplication.processEvents()
self.widget.moveCursor(QtGui.QTextCursor.End)
# Adding dialog for closeevent.
class Dialog_form(QtWidgets.QDialog):
def __init__(self, parent=None):
super(Dialog_form, self).__init__(parent)
def closeEvent(self, evnt):
super(Dialog_form, self).closeEvent(evnt)
_thread.interrupt_main()
# main Dialog
class Ui_Dialog(QtWidgets.QWidget):
def setupUi(self, Dialog):
######### Default 값 설정 #########
self.mode = "Error"
self.q = Queue()
self.use_checkpoint=False
######### 확인을 하기 위해 Default model 설정 #########
self.model = mobilenetv3(n_class=2, blocknum=4, dropout=0.5)
if torch.cuda.is_available():
torch.cuda.set_device(0)
with torch.cuda.device(0):
self.model = self.model.cuda()
self.model = torch.nn.DataParallel(self.model, device_ids=[0], output_device=[0]) # 모델을 다른 GPU에 뿌려준 다음 Gradient를 한 군데에서 계산하기 때문에 보통 0번 GPU에 많은 메로리가 할당됨.
# 하나의 GPU에 많은 메모리가 할당되면 batchsize를 늘릴 수 없기 때문에 이를 해결하기 위하여 output_device를 할당.
checkpoint = torch.load("output/Error/2456_model=MobilenetV3-ep=3000-block=4/model_best.pth.tar") # 해당 코드는 데이터의 크기가 작기 때문에 0번에다가 모두 처리하는 것으로 설정.
else:
self.model = torch.nn.DataParallel(self.model)
device = torch.device("cpu")
self.model.to(device)
checkpoint = torch.load("output/Error/2456_model=MobilenetV3-ep=3000-block=4/model_best.pth.tar", map_location=torch.device('cpu'))
self.model.load_state_dict(checkpoint['state_dict'])
######### 다이얼로그 설정 및 로그 버튼 프레임 선언 #########
Dialog.resize(1500, 900)
Dialog.setObjectName("Dialog")
hbox = QtWidgets.QHBoxLayout(Dialog)
logframe = QtWidgets.QFrame(self)
buttonframe = QtWidgets.QFrame(self)
logframe.setFrameShape(QtWidgets.QFrame.StyledPanel)
buttonframe.setFrameShape(QtWidgets.QFrame.StyledPanel)
logLayout = QtWidgets.QVBoxLayout()
buttonLayout = QtWidgets.QVBoxLayout()
######### 버튼 선언 #########
# Train
self.pushButton = QtWidgets.QPushButton()
self.pushButton.setFixedHeight(50)
# Validation
self.pushButton_2 = QtWidgets.QPushButton()
self.pushButton_2.setFixedHeight(50)
# Test (dir)
self.pushButton_3 = QtWidgets.QPushButton()
self.pushButton_3.setFixedHeight(50)
# Test (file)
self.pushButton_4 = QtWidgets.QPushButton("Test (file)")
self.pushButton_4.setFixedHeight(50)
# Temp Test for consistent model
self.pushButton_5 = QtWidgets.QPushButton("Temp Test")
self.pushButton_5.setFixedHeight(50)
######### 모델 실행 버튼 UI #########
model_control_layout = QtWidgets.QHBoxLayout()
model_control_layout.addWidget(self.pushButton)
model_control_layout.addWidget(self.pushButton_2)
model_control_layout.addWidget(self.pushButton_3)
model_control_layout.addWidget(self.pushButton_4)
#model_control_layout.addWidget(self.pushButton_5)
self.model_control_container = QtWidgets.QWidget()
self.model_control_container.setLayout(model_control_layout)
self.model_control_container.setFixedHeight(60)
######### DATA PATH 관련 UI (dir) #########
self.dirpathlabel = QtWidgets.QLabel("data path (dir):")
self.dirselectedpath = QtWidgets.QLineEdit("no data")
self.dirselectedpath.setReadOnly(True)
self.data_dir_select_btn = QtWidgets.QPushButton("...")
self.dirpathlayout = QtWidgets.QHBoxLayout()
self.dirpathlayout.addWidget(self.dirpathlabel)
self.dirpathlayout.addWidget(self.dirselectedpath)
self.dirpathlayout.addWidget(self.data_dir_select_btn)
self.dirpathcontainer = QtWidgets.QWidget()
self.dirpathcontainer.setLayout(self.dirpathlayout)
self.dirpathcontainer.setFixedHeight(40)
######### DATA PATH 관련 UI (file) #########
self.filepathlabel = QtWidgets.QLabel("data path (file):")
self.fileselectedpath = QtWidgets.QLineEdit("no data")
self.fileselectedpath.setReadOnly(True)
self.data_file_select_btn = QtWidgets.QPushButton("...")
self.filepathlayout = QtWidgets.QHBoxLayout()
self.filepathlayout.addWidget(self.filepathlabel)
self.filepathlayout.addWidget(self.fileselectedpath)
self.filepathlayout.addWidget(self.data_file_select_btn)
self.filepathcontainer = QtWidgets.QWidget()
self.filepathcontainer.setLayout(self.filepathlayout)
self.filepathcontainer.setFixedHeight(40)
######### CHECKPOINT PATH 관련 UI #########
self.ck_pathlabel = QtWidgets.QLabel("checkpoint path :")
self.ck_selectedpath = QtWidgets.QLineEdit("no checkpoint")
self.ck_selectedpath.setReadOnly(True)
self.ck_select_btn = QtWidgets.QPushButton("...")
self.ck_pathlayout = QtWidgets.QHBoxLayout()
self.ck_pathlayout.addWidget(self.ck_pathlabel)
self.ck_pathlayout.addWidget(self.ck_selectedpath)
self.ck_pathlayout.addWidget(self.ck_select_btn)
self.ck_pathcontainer = QtWidgets.QWidget()
self.ck_pathcontainer.setLayout(self.ck_pathlayout)
self.ck_pathcontainer.setFixedHeight(40)
######### Blocknum 조절 #########
self.blocknum_slider = LabeledSlider()
######### 경로 관련 widget들 groupbox에 할당 #########
self.path_groupbox = QtWidgets.QGroupBox("경로")
self.path_layout = QtWidgets.QVBoxLayout()
self.path_layout.addWidget(self.dirpathcontainer)
self.path_layout.addWidget(self.filepathcontainer)
self.path_layout.addWidget(self.ck_pathcontainer)
self.path_groupbox.setLayout(self.path_layout)
self.path_groupbox.setFixedHeight(140)
######### model parameter groupbox에 할당 #########
self.model_groupbox = QtWidgets.QGroupBox("모델 블록")
self.blocknum_layout = QtWidgets.QVBoxLayout()
self.blocknum_layout.addWidget(self.blocknum_slider)
self.model_groupbox.setLayout(self.blocknum_layout)
self.model_groupbox.setFixedHeight(80)
######### Model 기능 관련 UI ######### (All, Error, ErrorType)
self.modelayout = QtWidgets.QHBoxLayout()
self.Errorbtn = QtWidgets.QRadioButton("에러 검출")
self.Typebtn = QtWidgets.QRadioButton("에러 타입")
self.Allbtn = QtWidgets.QRadioButton("전체 타입 검출")
self.Errorbtn.setChecked(True)
self.modelayout.addWidget(self.Errorbtn)
self.modelayout.addWidget(self.Typebtn)
self.modelayout.addWidget(self.Allbtn)
self.modecontainer = QtWidgets.QGroupBox("모델 종류")
self.modecontainer.setLayout(self.modelayout)
self.modecontainer.setFixedHeight(70)
######### 학습 파라미터 관련 UI #########
self.train_parameters_layout = QtWidgets.QHBoxLayout()
self.epoch_label = QtWidgets.QLabel("Epoch :")
self.epoch_input = QtWidgets.QLineEdit("3000")
self.epoch_input.setValidator(QtGui.QIntValidator(1,3001))
self.optim_label = QtWidgets.QLabel("Optim :")
self.optim_input = QtWidgets.QComboBox()
self.optim_input.addItem("SGD")
self.optim_input.addItem("Adam")
self.optim_input.setFixedWidth(100)
self.lr_label = QtWidgets.QLabel("Learning rate :")
self.lr_input = QtWidgets.QLineEdit("0.001")
self.lr_input.setValidator(QtGui.QDoubleValidator(999999, -999999, 8))
self.batch_label = QtWidgets.QLabel("batch size :")
self.batch_input = QtWidgets.QLineEdit("256")
self.batch_input.setValidator(QtGui.QIntValidator(1,1025))
self.imagesize_label = QtWidgets.QLabel("Image size :")
self.imagesize_input = QtWidgets.QLineEdit("64")
self.imagesize_input.setValidator(QtGui.QIntValidator(1,1025))
self.train_parameters_layout.addWidget(self.epoch_label)
self.train_parameters_layout.addWidget(self.epoch_input)
self.train_parameters_layout.addWidget(self.optim_label)
self.train_parameters_layout.addWidget(self.optim_input)
self.train_parameters_layout.addWidget(self.lr_label)
self.train_parameters_layout.addWidget(self.lr_input)
self.train_parameters_layout.addWidget(self.batch_label)
self.train_parameters_layout.addWidget(self.batch_input)
self.train_parameters_layout.addWidget(self.imagesize_label)
self.train_parameters_layout.addWidget(self.imagesize_input)
self.train_parameters = QtWidgets.QGroupBox("학습 파라미터")
self.train_parameters.setLayout(self.train_parameters_layout)
self.train_parameters.setFixedHeight(60)
######### 구성한 Container들 Dialog에 추가 #########
buttonLayout.addWidget(self.model_control_container)
buttonLayout.addWidget(self.path_groupbox)
buttonLayout.addWidget(self.model_groupbox)
buttonLayout.addWidget(self.train_parameters)
buttonLayout.addWidget(self.modecontainer)
######### logger format 설정 ######### (파일로 저장되는 Log랑 다른 Logger이기 때문에 화면에 출력되는 Log와 저장되는 Log랑은 다름)
logTextBox = QTextEditLogger(logLayout)
logTextBox.setFormatter(logging.Formatter('%(asctime)s - %(message)s'))
logging.getLogger('Techwing_log').addHandler(logTextBox)
logging.getLogger('Techwing_log').setLevel(logging.INFO)
######### log Widget, Button Widget 비율 설정 부분 #########
logframe.setLayout(logLayout)
buttonframe.setLayout(buttonLayout)
splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
splitter.addWidget(logframe)
splitter.addWidget(buttonframe)
splitter.setSizes([600,200])
hbox.addWidget(splitter)
Dialog.setLayout(hbox)
QtWidgets.QApplication.setStyle(QtWidgets.QStyleFactory.create('Cleanlooks'))
# 버튼 input word 설정
self.retranslateUi(Dialog)
######### 버튼 기능 설정 부분 #########
self.Errorbtn.clicked.connect(self.modeBtnClicked)
self.Typebtn.clicked.connect(self.modeBtnClicked)
self.Allbtn.clicked.connect(self.modeBtnClicked)
self.pushButton.clicked.connect(self.Train_btn_clicked)
self.pushButton_2.clicked.connect(self.Val_btn_clicked)
self.pushButton_3.clicked.connect(lambda: self.Test_btn_clicked('dir'))
self.pushButton_4.clicked.connect(lambda: self.Test_btn_clicked('file'))
self.pushButton_5.clicked.connect(self.temp_btn_clicked)
self.data_dir_select_btn.clicked.connect(self.Path_btn_clicked)
self.data_file_select_btn.clicked.connect(self.filePath_btn_clicked)
self.ck_select_btn.clicked.connect(self.checkpoint_btn_clicked)
######### Log 입력해주는 쓰레드 설정 #########
c = threading.Thread(target=self.write, args=(self.q,), daemon=True)
c.start()
QtCore.QMetaObject.connectSlotsByName(Dialog)
######### 버튼 UI 설정 #########
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "Train"))
self.pushButton_2.setText(_translate("Dialog", "Validate"))
self.pushButton_3.setText(_translate("Dialog", "Test (dir)"))
######### Radio 버튼 동작 이벤트 처리 #########
def modeBtnClicked(self):
if self.Errorbtn.isChecked():
self.q.put("set error")
self.mode = "Error"
self.blocknum_slider.sl.setValue(4)
self.blocknum_slider.sl.setSliderPosition(4)
self.imagesize_input.setText("64")
elif self.Typebtn.isChecked():
self.q.put("set Type")
self.mode = "Type"
self.blocknum_slider.sl.setValue(4)
self.blocknum_slider.sl.setSliderPosition(4)
self.imagesize_input.setText("64")
else:
self.q.put("set All processing")
self.mode = "All"
self.blocknum_slider.sl.setValue(6)
self.blocknum_slider.sl.setSliderPosition(6)
self.imagesize_input.setText("224")
######### Train 버튼 동작 이벤트 #########
def Train_btn_clicked(self):
if self.dirselectedpath.text() != "no data":
self.set_all_btn_enabled(False)
logging.info("train start")
blocknum = self.blocknum_slider.sl.value()
kwargs = {"resume": self.use_checkpoint, "blocknum": blocknum}
kwargs["data_path"] = self.dirselectedpath.text()
kwargs["epoch"] = int(self.epoch_input.text())
kwargs["lr"] = float(self.lr_input.text())
kwargs["batch_size"] = int(self.batch_input.text())
kwargs["optim"] = str(self.optim_input.currentText())
kwargs["size"] = int(self.imagesize_input.text())
if self.use_checkpoint:
kwargs["ck_path"] = self.ck_selectedpath.text()
t = BaseThread(target=UI_train, callback=self.set_all_btn_enabled, callback_args=(True,),
args=(self.mode, self.q), kwargs=kwargs)
threads.append(t)
t.start()
self.q.join()
else:
self.q.put("데이터를 입력해 주세요.")
######### Test 버튼 동작 이벤트 #########
def Test_btn_clicked(self, file_mode):
if self.use_checkpoint:
self.set_all_btn_enabled(False)
logging.info('Test start')
blocknum = self.blocknum_slider.sl.value()
kwargs = {"use_ck": self.use_checkpoint, "blocknum": blocknum}
kwargs["size"] = int(self.imagesize_input.text())
kwargs["ck_path"] = self.ck_selectedpath.text()
logging.info(f"start test using path : {self.ck_selectedpath.text()}")
if file_mode == 'dir':
if self.dirselectedpath.text() != "no data":
t = BaseThread(target=UI_test, callback=self.set_all_btn_enabled, callback_args=(True,)
,args=(self.mode, self.dirselectedpath.text(), file_mode, self.q), kwargs=kwargs)
t.start()
self.q.join()
else:
self.q.put("데이터를 입력해 주세요.")
self.set_all_btn_enabled(True)
else:
if self.fileselectedpath.text() != "no data":
t = BaseThread(target=UI_test, callback=self.set_all_btn_enabled, callback_args=(True,)
,args=(self.mode, self.fileselectedpath.text(), file_mode, self.q), kwargs=kwargs)
t.start()
self.q.join()
else:
self.q.put("데이터를 입력해 주세요.")
self.set_all_btn_enabled(True)
else:
self.q.put("체크포인트를 입력해 주세요.")
######### Validation 버튼 동작 이벤트 #########
## path가 설정되어 있어야된다.
def Val_btn_clicked(self):
if self.use_checkpoint:
if self.dirselectedpath.text() != "no data":
self.set_all_btn_enabled(False)
blocknum = self.blocknum_slider.sl.value()
kwargs = {"blocknum": blocknum}
kwargs["data_path"] = self.dirselectedpath.text()
kwargs["size"] = int(self.imagesize_input.text())
kwargs["ck_path"] = self.ck_selectedpath.text()
logging.info('val start')
t = BaseThread(target=UI_validate, callback=self.set_all_btn_enabled, callback_args=(True,),
args=(self.mode, self.q), kwargs=kwargs)
t.start()
self.q.join()
else:
self.q.put("데이터를 입력해 주세요.")
else:
self.q.put("체크포인트를 입력해 주세요.")
def temp_btn_clicked(self):
self.set_all_btn_enabled(False)
t = BaseThread(target=UI_temp, callback=self.set_all_btn_enabled, callback_args=(True,),
args=(self.fileselectedpath.text(), self.q, self.model.module))
t.start()
self.q.join()
######### 데이터 디렉토리 선택 이벤트 #########
def Path_btn_clicked(self):
fname = QtWidgets.QFileDialog.getExistingDirectory(self, 'Open dir')
if len(fname) != 0:
logging.info(f"{fname} Test dir submitted")
self.dirselectedpath.setText(fname)
else:
QtWidgets.QMessageBox.about(self, "Warning", "Do not select Directory!")
######### 데이터 파일 선택 이벤트 #########
def filePath_btn_clicked(self):
fname = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', "",
"All Files(*);; Bitmap files(*.bmp);; Jpg files(*.jpg);; Png files(*.png)")
if fname[0]:
logging.info(f"{fname[0]} test file submitted")
self.fileselectedpath.setText(fname[0])
else:
QtWidgets.QMessageBox.about(self, "Warning", "do not select file!")
######### 체크포인트 파일 선택 이벤트 #########
def checkpoint_btn_clicked(self):
fname = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', "",
"All Files(*)")
if fname[0]:
self.ck_path = fname
self.use_checkpoint = True
logging.info(f"{fname[0]} checkpoint file submitted")
self.ck_selectedpath.setText(fname[0])
else:
QtWidgets.QMessageBox.about(self, "Warning", "do not select file!")
######### 딥러닝 모델이 작동하였을 때 다른 버튼을 누르면 안되므로 버튼 제어 #########
def set_all_btn_enabled(self, mode):
self.pushButton.setEnabled(mode)
self.pushButton_2.setEnabled(mode)
self.pushButton_3.setEnabled(mode)
self.pushButton_4.setEnabled(mode)
self.data_dir_select_btn.setEnabled(mode)
self.data_file_select_btn.setEnabled(mode)
self.ck_select_btn.setEnabled(mode)
######### Dialog 로그창 입력 함수 #########
def write(self, q):
while True:
try:
log = q.get()
logger.info(log)
q.task_done()
except Queue.Empty:
pass
if __name__ == "__main__":
import sys
import multiprocessing
multiprocessing.freeze_support()
app = QtWidgets.QApplication(sys.argv)
Dialog = Dialog_form()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())