tkinter回调回溯中出现异常

8ulbf1ek  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(288)

tkinter回调异常
回溯(最近一次呼叫)
保存模型验证字符错误率:8.654728%python:3.6.8
我指的是这个代码手写行文字识别使用深入学习。
它基本上是对手写行文本图像进行识别,而不需要预先分割成单词或字符
这是python应用程序gui代码:

from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from PIL import Image, ImageTk
from main import infer_by_app

class Root(Tk):

    def _init_(self):
        super(Root, self)._init_()
        self.title("Hand Written Character Recognition")
        self.minsize(1000, 400)

        self.labelFrame = ttk.LabelFrame(self, text="Choose an Image for Text Prediction:")
        self.labelFrame.grid(column=0, row=1, padx=20, pady=20)

        self.labelFrame2 = ttk.LabelFrame(self, text="Predicted Text:")
        self.labelFrame2.grid(column=0, row=7)
        self.label4 = ttk.Label(self.labelFrame2, text="Prediction Without AutoCorrect : ")
        self.label4.grid(column=0, row=8)
        self.label5 = ttk.Label(self.labelFrame2, text="Prediction With AutoCorrect :")
        self.label5.grid(column=0, row=9)
        self.button()

    def button(self):
        self.button_browse = ttk.Button(self.labelFrame, text="Browse", command=self.fileDialog)
        self.button_browse.grid(column=1, row=1)
        self.button_pred = ttk.Button(self.labelFrame2, text="Predict", command=self.upload)
        self.button_pred.grid(column=0, row=5)

    def fileDialog(self):

        self.filename = None
        self.filename = filedialog.askopenfilename(initialdir="D:\MSc-IT\MScFinalProject\Handwritten-Line-Text-Recognition-using-Deep-Learning-with-Tensorflow-master\data", title="Select A File", filetype=
        (("PNG file", ".png"), ("all files", ".*")))

        self.label = ttk.Label(self.labelFrame, text="Image location:")
        self.label.grid(column=1, row=2)

        self.label1 = ttk.Label(self.labelFrame, text = "")
        self.label1.grid(column = 2, row = 2)
        self.label1.configure(text = self.filename)

        img = Image.open(self.filename)
        img = img.resize((800, 40))
        photo = ImageTk.PhotoImage(img)

        self.label2 = Label(image=photo)
        self.label2.image = photo
        self.label2.grid(column=0, row=4)

    def upload(self):
        self.option = "bestPath"
        self.destination = self.filename
        self.result = self.predText(self.destination, self.option)
        self.withoutCorrection, self.withCorrection = self.result
        #print("Prediction: ", self.withCorrection)
        self.label4.configure(text="Prediction Without AutoCorrect : " + "'" + str(self.withoutCorrection) + "'")
        self.label5.configure(text="Prediction With AutoCorrect : " + "'" + str(self.withCorrection) + "'")

    def predText(self,path,option):
        return infer_by_app(path, option)

root=Root()
root.mainloop()

这是第一个输出

我在第二次输出中出错

upload self.result=self.predtext(self.destination,self.option)中的第56行“使用tensorflow master/src/app gui.py深度学习进行项目/手写行文本识别”

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题