用tkinter做深度学习的测试界面第一版

# -*- coding: utf-8 -*-
"""
Created on Sat Sep 21 14:29:19 2019

@author: zhoulongtao
"""

#coding:utf-8
import time
import cv2
import tensorflow as tf
import numpy as np
from tkinter import *
from traitlets.config.application import catch_config_error
from tkinter.filedialog import askdirectory
import os
root = Tk()
# 设置标题
root.title("方图测试界面")
# 设置大小和位置
frame = Frame(root)
frame.pack()

frame1 = Frame(root)
frame1.pack()
frame3 = Frame(root)
frame3.pack()
frame4 = Frame(root)
frame4.pack()
frame2 = Frame(root)
frame2.pack()
sb = Scrollbar(root)

sb.pack(side=RIGHT, fill=Y)
lb = Listbox(root, yscrollcommand=sb.set)





sb1 = Scrollbar(root)

sb1.pack(side=LEFT, fill=Y)

lb1 = Listbox(root, yscrollcommand=sb1.set)



L5 = Label(frame1, text="样本个数")
L5.pack( )
v5text = StringVar()
v5 = Entry(frame1, text = v5text)
v5.pack()
 
L6 = Label(frame1, text="合格个数")
L6.pack( )
v6text = StringVar()
V6 = Entry(frame1 ,text = v6text )
V6.pack()
 
L7 = Label(frame1, text="不合格个数")
L7.pack( )
v7text = StringVar()
V7 = Entry(frame1 , text = v7text)
V7.pack()
 
L8 = Label(frame1, text="合格百分率")
L8.pack( )
v8text = StringVar()
V8 = Entry(frame1 , text = v8text)
V8.pack()
L9 = Label(frame1, text="平均运行时间")
L9.pack( )
v9text = StringVar()
V9 = Entry(frame1 , text = v9text)
V9.pack()

root.geometry("800x800+200+50")

def read_one_image(path):
    print(path)
    img = cv2.imread(path)
    print(img)
    img = cv2.resize(img,(w,h))
    return np.asarray(img)
def jeg():
     a11=V11.get()
     num=len(os.listdir(a11))
     v5text.set('')
     v5text.set(num)
     data = []
     for i in os.listdir(a11):            
              data1 = read_one_image(a11+"/"+i)
              data.append(data1)
#        lb(root, text=i).pack(side=TOP, fill=X, expand=YES)
#        lb.pack(side=LEFT, fill=BOTH)
     with tf.Session() as sess:
       
       saver = tf.train.import_meta_graph('./3/model.ckpt0.896875.meta')
       saver.restore(sess,tf.train.latest_checkpoint('./3/'))
       graph = tf.get_default_graph()
       x = graph.get_tensor_by_name("x:0")
       feed_dict = {x:data}
       logits = graph.get_tensor_by_name("logits_eval:0")
       start = time.clock()
       classification_result = sess.run(logits,feed_dict)
       elapsed = (time.clock() - start)/num
       v9text.set('')
       v9text.set(elapsed)
    #打印出预测矩阵
      
    #打印出预测矩阵每一行最大值的索引
    #print(tf.argmax(classification_result,1).eval())
    #根据索引通过字典对应人脸的分类
       output = []
       output = tf.argmax(classification_result,1).eval()
       for i in range(len(output)):
           lb1.insert(END, face_dict[output[i]])
           lb1.pack(side=RIGHT, fill=BOTH)
       num1 = str(output.tolist()).count("1")
       v6text.set('')
       v6text.set(num1)
       num2=num-num1
       v7text.set('')
       v7text.set(num2)
       
       ra=num1/num
       v8text.set('')
       v8text.set(ra)
def selectPath2():
        Label(lb1, text=V11.get()).pack(side=TOP, fill=Y, expand=YES)
        lb1.pack(side=RIGHT, fill=BOTH)
        
def selectPath1():
    v11text.set('')
   
    path_ = askdirectory()
    text=v11text.set(path_)
    for i in os.listdir(path_):
#        lb(root, text=i).pack(side=TOP, fill=X, expand=YES)
#        lb.pack(side=LEFT, fill=BOTH)
       lb.insert(END, i)
       lb.pack(side=LEFT, fill=BOTH)
       




L1=Label(frame,text = "目标路径:")
L1.pack()
v11text = StringVar()
V11 = Entry(frame , text = v11text)
V11.pack()

B = Button(frame, text ="选择路标路径", command = selectPath1,background = 'red')
B.pack(side = LEFT)
B = Button(frame2, text ="计算", command = jeg)
B.pack(side = LEFT)
var = StringVar()
label = Label( frame, textvariable=var, relief=RAISED )
var.set("--------------------------------------------------包含图片------------------------------------------------------")
label.pack()

root.mainloop()


















 

用tkinter做深度学习的测试界面第一版

用tkinter做深度学习的测试界面第一版

 

用tkinter做深度学习的测试界面第一版

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

上一篇:glPixelStore 做了什么?


下一篇:python_tkinter组件