-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.py
More file actions
160 lines (144 loc) · 5.81 KB
/
Copy pathGUI.py
File metadata and controls
160 lines (144 loc) · 5.81 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
"""GUI for Butterfly Project."""
import os
import gc
from tkinter import Tk, Frame, StringVar, Button, Label, filedialog
from PIL import ImageTk, Image
class GUI(Frame):
"""GUI for Butterfly."""
def __init__(self, master=None):
Frame.__init__(self, master)
master.title('Butterfly Project.py')
master.geometry('800x500')
master.resizable(False, False)
master.configure(background='black')
# There should be a list of function,
# named `self.function`.
self.function = [max, min]
self.func_len = len(self.function)
self.func_txt = StringVar()
self.hit = 0
self.func_txt.set(self.function[self.hit])
self.epo_txt = StringVar()
self.epochs = 100
self.epo_txt.set(self.epochs)
self.img_1 = None
self.img_2 = None
self.a = 1
self.b = 0
self.z = 1
self.r = 0
self.img_o = Label(master, image=self.img_1)
self.img_n = Label(master, image=self.img_2)
self.lbl_l = Label(master, height= 1, width=15, textvariable=self.func_txt)
self.lbl_a = Label(master, height= 1, width= 2, text='a')
self.lbl_b = Label(master, height= 1, width= 2, text='b')
self.lbl_r = Label(master, height= 1, width= 8, text='rotate')
self.btn_o = Button(master, height= 1, width=15, text='open image file',
command=self.opening)
self.btn_l = Button(master, height= 1, width=15, text='load model',
command=self.load)
self.btn_s = Button(master, height= 1, width=15, text='save model',
command=self.save)
self.AE = Button(master, height= 1, width= 6, text='AE')
# self.GAN = Button(master, height= 1, width= 6, text='GAN',
# command=self.butterfly.GAN)
# self.BiGAN = Button(master, height= 1, width= 6, text='BiGAN',
# command=self.butterfly.BiGAN)
self.func = Button(master, height= 1, width= 8, text='function',
command=self.func)
self.lyr_1 = Button(master, height= 1, width= 8, text='1')
self.lyr_2 = Button(master, height= 1, width= 8, text='1')
self.lyr_3 = Button(master, height= 1, width= 8, text='1')
self.lyr_4 = Button(master, height= 1, width= 8, text='1')
self.lyr_5 = Button(master, height= 1, width= 8, text='1')
self.lyr_6 = Button(master, height= 1, width= 8, text='1')
self.lyr_7 = Button(master, height= 1, width= 8, text='1')
self.btn_t = Button(master, height= 1, width= 8, text='train',
command=self.train)
self.btn_e = Button(master, height= 1, width= 8, textvariable=self.epo_txt,
command=self.epoch)
self.btn_g = Button(master, height= 1, width=15, text='garbage collector',
command=gc.collect)
self.btn_p = Button(master, height= 1, width= 8, text='plot',
command=self.plot)
self.btn_o.place(x= 20, y= 20)
self.btn_l.place(x= 20, y= 50)
self.btn_s.place(x= 20, y= 80)
self.img_o.place(x=150, y= 10)
self.img_n.place(x=450, y= 10)
self.AE.place( x= 20, y=130)
# self.GAN.place( x= 20, y=160)
# self.BiGAN.place(x= 20, y=190)
self.func.place( x= 10, y=250)
self.lbl_l.place(x= 10, y=300)
self.lyr_1.place(x= 10, y=325)
self.lyr_2.place(x= 10, y=350)
self.lyr_3.place(x= 10, y=375)
self.lyr_4.place(x= 10, y=400)
self.lyr_5.place(x= 10, y=425)
self.lyr_6.place(x= 10, y=450)
self.lyr_7.place(x= 10, y=475)
self.btn_t.place(x=150, y=300)
self.btn_e.place(x=250, y=300)
self.btn_g.place(x=150, y=350)
self.btn_p.place(x=250, y=350)
def func(self):
"""
There should be a list of function,
named `self.function`.
"""
if self.hit == self.func_len:
self.hit = 0
self.func_txt.set(self.function[self.hit])
self.hit += 1
def opening(self):
"""Import data from `path`."""
path = filedialog.askdirectory(parent=self,
initialdir=os.getcwd(),
title='Choose a file')
# data = import_data(path)
def load(self):
"""Load model from `path`."""
path = filedialog.askdirectory(parent=self,
initialdir=os.getcwd(),
title='Choose a file')
# load(path)
def save(self):
"""Save model from `path`."""
path = filedialog.askdirectory(parent=self,
initialdir=os.getcwd(),
title='Choose a file')
# save(path)
def train(self):
"""Train model."""
# trainer.train(trainer.data, self.epochs)
gc.collect()
def epoch(self):
"""AA."""
epochs_option = {100:300, 300:500, 500:1000, 1000:3000, 3000:100}
self.epochs = epochs_option[self.epochs]
self.epo_txt.set(self.epochs)
# def processing(self):
# self.img = self.img_0 * self.a + self.b
# if self.hit == 1:
# self.img = self.img
# elif self.hit == 2:
# self.img = self.img
# self.img = uint8((self.img).clip(min=0,max=255))
# self.img_2 = self.plot()
# self.img_n.configure(image=self.img_2)
# self.img_n.image=self.img_2
def plot(self):
"""AA."""
if self.img_height > self.img_width:
img = Image.fromarray(self.img).resize(
(int(256*self.img_width/self.img_height), 256))
else:
img = Image.fromarray(self.img).resize(
(256, int(256*self.img_height/self.img_width)))
img = ImageTk.PhotoImage(img)
return img
if __name__=="__main__":
window = Tk()
app = GUI(master=window)
app.mainloop()