-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_Q5.py
129 lines (99 loc) · 4.28 KB
/
ui_Q5.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
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import QLabel, QWidget, QLineEdit
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout
from PyQt5.QtWidgets import QPushButton, QGroupBox, QMessageBox
from PyQt5.QtCore import Qt, QMetaObject
import matplotlib.pyplot as plt
from torchvision.utils import make_grid
import cv2 as cv
import glob
import os
import numpy as np
import utils_Q5
import webbrowser
__appname__ = "cvdl Hw2 Q5_N76101012"
class MainWindow(object):
def setupUI(self, MainScreen):
MainScreen.setObjectName("MainScreen")
MainScreen.resize(640,480)
MainScreen.setWindowTitle(__appname__)
grpQuestion5 = QGroupBox("5. Dog & Cate catgorization - RESNET 50")
grpVerticleLayout = QVBoxLayout(grpQuestion5)
self.btnShowStructure = QPushButton("5.1 Show model structure")
self.btnDisplayTensorboard = QPushButton("5.2 Display tensorboard")
grpTest = QGroupBox("5.3 Test")
layoutMain = QVBoxLayout(grpTest)
select_layout, self.edit_5_3 = self.CreateTexBox("Select image: ")
layoutMain.addLayout(select_layout)
self.btnPredict = QPushButton("5.3 Predict")
layoutMain.addWidget(self.btnPredict)
self.btnDisplayRandomEraserImg = QPushButton("5.4 Display Augumentation Random-Eraser images")
grpVerticleLayout.addWidget(self.btnShowStructure)
grpVerticleLayout.addWidget(self.btnDisplayTensorboard)
grpVerticleLayout.addWidget(grpTest)
grpVerticleLayout.addWidget(self.btnDisplayRandomEraserImg)
self.centralwidget = QWidget(MainScreen)
self.centralwidget.setObjectName("centralwidget")
vLayout = QHBoxLayout()
vLayout.addWidget(grpQuestion5)
self.centralwidget.setLayout(vLayout)
MainScreen.setCentralWidget(self.centralwidget)
QMetaObject.connectSlotsByName(MainScreen)
@staticmethod
def CreateTexBox(title:str, unit = "", showUnit= False):
hLayout = QHBoxLayout()
title_label = QLabel(title)
title_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
title_label.setFixedWidth(60)
unit_label = QLabel(unit)
unit_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
unit_label.setFixedWidth(30)
editText = QLineEdit("1")
editText.setFixedWidth(50)
editText.setAlignment(Qt.AlignRight)
editText.setValidator(QIntValidator())
hLayout.addWidget(title_label, alignment=Qt.AlignLeft)
hLayout.addWidget(editText)
if showUnit:
hLayout.addWidget(unit_label)
return hLayout, editText
class MainScreen(QMainWindow, MainWindow):
def __init__(self, parent = None):
super(MainScreen, self).__init__(parent=parent)
self.setupUI(self)
self.initialValue()
self.buildUi()
def buildUi(self):
self.btnShowStructure.clicked.connect(self.ShowModelStructure)
self.btnDisplayTensorboard.clicked.connect(self.show_tensorboard)
self.btnPredict.clicked.connect(self.test)
self.btnDisplayRandomEraserImg.clicked.connect(self.show_augumentation)
def initialValue(self):
pass
def errorMessage(self, title, message):
return QMessageBox.critical(self, title, '<p><b>%s</b></p>%s' % (title, message))
def status(self, message, delay=5000):
self.statusBar().showMessage(message, delay)
def ShowModelStructure(self):
utils_Q5.ShowModelStructure()
def show_tensorboard(self):
webbrowser.open('http://localhost:6006/')
def test(self):
index = int(self.edit_5_3.text())
utils_Q5.predict(index)
def show_augumentation(self):
# for images, labels in utils_Q5.train_data_loader:
# fig, ax = plt.subplots(figsize = (50, 50))
# ax.set_xticks([])
# ax.set_yticks([])
# ax.imshow(make_grid(images, 4).permute(1,2,0))
# break
utils_Q5.show_before_after('C:/Users/Hsin/Desktop/Hw2_CVDL_202112_NCKU-master/Data/compare.txt')
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainScreen()
window.setGeometry(500, 150, 300, 300)
window.show()
sys.exit(app.exec_())