-
Notifications
You must be signed in to change notification settings - Fork 0
/
IDH_GUI.py
246 lines (215 loc) · 9.63 KB
/
IDH_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
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
#! /usr/bin/env python
#
# GUI module generated by PAGE version 4.9
# In conjunction with Tcl version 8.6
# Nov 07, 2017 05:52:02 PM
import tensorflow as tf
import numpy as np
import os, glob, cv2
import sys, argparse
import webbrowser
#webbrowser.open('https://goo.gl/maps/HCahr9E4PnH2', new=1)
try:
from Tkinter import *
except ImportError:
from tkinter import *
from tkinter import filedialog
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
import unknown_support
#import tkMessageBox
#import os
from PIL import ImageTk, Image
#import cv2
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = Tk()
top = IDH_Project (root)
unknown_support.init(root, top)
root.mainloop()
w = None
def create_IDH_Project(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = Toplevel (root)
top = IDH_Project (w)
unknown_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_IDH_Project():
global w
w.destroy()
w = None
'''
def checkvalidpath(x):
#print("in ccccccccccc")
if os.path.exists(x):
print("yes a valid path")
return True
else:
print("not a valid path")
'''
class IDH_Project:
'''The main GUI Class'''
def viewmapbutton(self, top=None):
webbrowser.open('https://goo.gl/maps/HCahr9E4PnH2', new=1)
def aboutus(self):
webbrowser.open("file://"+os.getcwd()+"/HTML%20PAGE/index.html")
def uploadbuttonpress(self, top=None):
#root = Tk()
path = filedialog.askopenfilename(initialdir=os.getcwd(), title="Select file", filetypes=((" jpeg files", "*.jpg"),("png files","*.png"),("all files","*.*")))
#root.mainloop()
#if checkvalidpath(path):
#print(os.curdir)
if not os.path.exists(os.curdir+'/GUI_Temp'):
os.mkdir('GUI_Temp')
print(path)
#os.system('cp '+path+' test/testimg.jpg')
i = cv2.imread(path)
i = cv2.resize(i,(350,265))
cv2.imwrite("GUI_Temp/testimg.ppm",i)
cv2.imwrite("GUI_Temp/testimg.jpg",i)
#os.system('rm test/testimg.jpg')
img = PhotoImage(file="GUI_Temp/testimg.ppm")
self.Canvas1.configure(image=img)
self.Canvas1.photo = img
############################################################################################
############################################################################################
############################################################################################
############################################################################################
############################################################################################
models = ['aihole'
,'banshankari'
,'buddhanagudda'
,'hampi'
,'lakkundi'
,'unkal'
]
def predictor(x_batch):
modelpredictions = {}
for model in models:
modelpath = 'Ensemble/'+model
saver = tf.train.import_meta_graph(modelpath+'/model_'+model+'.meta')
saver.restore(sess, tf.train.latest_checkpoint(modelpath+'/'+'./'))
graph = tf.get_default_graph()
y_pred = graph.get_tensor_by_name("y_pred:0")
x= graph.get_tensor_by_name("x:0")
y_true = graph.get_tensor_by_name("y_true:0")
y_test_images = np.zeros((1, 2))
feed_dict_testing = {x: x_batch, y_true: y_test_images}
result=sess.run(y_pred, feed_dict=feed_dict_testing)
modelpredictions[model] = (result[0])[0]
#############################################################
for i in modelpredictions:
print("\n"+i+" : ",modelpredictions[i])
return modelpredictions
filename = "GUI_Temp/testimg.jpg"
image_size=128
num_channels=3
images = []
# Reading the image using OpenCV
image = cv2.imread(filename)
# Resizing the image to our desired size and preprocessing will be done exactly as done during training
image = cv2.resize(image, (image_size, image_size), cv2.INTER_LINEAR)
images.append(image)
images = np.array(images, dtype=np.uint8)
images = images.astype('float32')
images = np.multiply(images, 1.0/255.0)
#The input to the network is of shape [None image_size image_size num_channels]. Hence we reshape.
x_batch = images.reshape(1, image_size,image_size,num_channels)
sess = tf.Session()
results = predictor(x_batch=x_batch)
sess.close()
#############################################################################
##############################################################################
#################################################
aih_p = results['aihole']
ban_p = results['banshankari']
bud_p = results['buddhanagudda']
ham_p = results['hampi']
lak_p = results['lakkundi']
unk_p = results['unkal']
highest_pred = max(results[i] for i in results)
if highest_pred==aih_p:
self.Label3.configure(text='''Aihole temple found''')
if highest_pred==ban_p:
self.Label3.configure(text='''banshankari temple found''')
if highest_pred==bud_p:
self.Label3.configure(text='''buddhanagudda temple found''')
if highest_pred==ham_p:
self.Label3.configure(text='''hampi temple found''')
if highest_pred==lak_p:
self.Label3.configure(text='''lakkundi temple found''')
if highest_pred==unk_p:
self.Label3.configure(text='''unkal temple found''')
font21 = "-family {DejaVu Sans} -size 15 -weight normal -slant" \
" roman -underline 1 -overstrike 0"
####################################################################################################
####################################################################################################
####################################################################################################
####################################################################################################
######
# ##############################################################################################
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#ffffff' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#ffffff' # X11 color: 'gray85'
_ana1color = '#ffffff' # X11 color: 'gray85'
_ana2color = '#ffffff' # X11 color: 'gray85'
font10 = "-family {DejaVu Sans} -size 20 -weight normal -slant" \
" roman -underline 1 -overstrike 0"
font11 = "-family {DejaVu Serif} -size 10 -weight normal " \
"-slant roman -underline 0 -overstrike 0"
font12 = "-family {DejaVu Sans Mono} -size 20 -weight bold " \
"-slant roman -underline 0 -overstrike 0"
font9 = "-family {DejaVu Sans} -size 16 -weight normal -slant " \
"roman -underline 0 -overstrike 0"
font21 = "-family {DejaVu Sans} -size 15 -weight normal -slant" \
" roman -underline 1 -overstrike 0"
top.geometry("700x550+449+169")
top.title("IDH Project")
top.configure(background="#3b9eff")
top.configure(highlightcolor="black")
self.Button1 = Button(top)
self.Button1.place(relx=0.85, rely=0.02, height=50, width=70)
self.Button1.configure(activebackground="#f0f000")
self.Button1.configure(font=font11)
self.Button1.configure(text='''About US''')
self.Button1.configure(command=self.aboutus)
self.UploadButton = Button(top)
self.UploadButton.place(relx=0.75, rely=0.59-0.2, height=83, width=132)
self.UploadButton.configure(activebackground="#ffffff")
self.UploadButton.configure(font=font21)
self.UploadButton.configure(text='''Upload''')
self.UploadButton.configure(command=self.uploadbuttonpress)
#self.Viewmap.
#self.Viewmap.configure(command=self.uploadbuttonpress)
self.Canvas1 = Label(top)
self.Canvas1.place(relx=0.05, rely=0.38-0.18, relheight=0.6, relwidth=0.64)
self.Canvas1.configure(background="white")
self.Canvas1.configure(text='''Your Image will be \ndisplayed here''')
self.Canvas1.configure(borderwidth="2")
self.Canvas1.configure(relief=RIDGE)
#self.Canvas1.configure(selectbackground="#c4c4c4")
self.Canvas1.configure(width=378)
self.Label2 = Label(top)
self.Label2.place(relx=0.24, rely=0.02, height=29+10, width=250+100)
self.Label2.configure(activebackground="#3b9eff")
self.Label2.configure(background="#3b9eff")
self.Label2.configure(font=font12)
self.Label2.configure(text='''Indian Digital Heritage''')
self.Label3 = Label(top)
self.Label3.place(relx=0.05, rely=0.9, height=29, width=378)
self.Label3.configure(activebackground="#f9f9f9")
self.Label3.configure(background="#40d9d9")
self.Label3.configure(font=font9)
self.Label3.configure(text='''Class?''')
if __name__ == '__main__':
vp_start_gui()