我已经使用tkinter(gui)和tensorflow(ML)制作了一个应用,以制作花卉分类器。我无法打开脚本pyiboot01_bootstrap错误。我已经尝试过针对类似问题给出的解决方案,但它对我不起作用。另外,我正在使用pyttsx3启用音频和枕头以打开图像。 我的代码:
from tkinter import *
from tkinter.filedialog import askopenfilename
import tkinter.font as font
import pyttsx3
import tensorflow as tf
from keras.preprocessing import image
from tensorflow import keras
from PIL import ImageTk,Image
model = keras.models.load_model('C:\\Users\\dell\\Desktop\\jps\\best_model.h5')
import numpy as np
import sys
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[0].id)
def speak(text):
print(text)
engine.say(text)
engine.runAndWait()
WIN = Tk()
WIN.geometry("350x350")
WIN.resizable(0,0)
WIN.title("Flower classifier")
load = Image.open('Webp.net-resizeimage.jpg')
render = ImageTk.PhotoImage(load)
img = Label(WIN,image=render)
img.place(x=0,y=0)
WIN.iconbitmap('iconfinder_icon-80-document-file-ai_315878.ico')
Label(WIN,text="Flower classifier",font=("Cambria
bold",25),fg="SpringGreen4",bg="#f8f8ff",pady=10).pack()
l = Label(WIN,text="",font=("Arial",20),fg='white',bg="red")
myFont = font.Font(family='Helvetica', size=22, weight='bold')
l['font'] = myFont
def open():
global WIN
myFont = font.Font(family='Helvetica', size=15, weight='bold')
filename = askopenfilename(initialdir="/Pictures", filetypes =[('jpeg files', '*.jpg'),("all
files","*.*")])
path = filename
print(path)
img = image.load_img(path, target_size=(200, 200))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
img = np.vstack([x])
global download
global model
classes = model.predict(img)
global l
l.place(x=110,y=130)
for y in classes:
if y[0] == 1:
print("It's a Lotus")
l['text'] = "It's a Lotus"
speak("It's a Lotus")
elif y[1] == 1:
print("It's a Rose")
l['text'] = "It's a Rose"
speak("It's a Rose")
elif y[2] == 1:
print("It's a Sunflower")
l['text'] = "It's a Sunflower"
speak("It's a Sunflower")
else:
print("I am not sure")
l['text'] = "I am not sure"
speak("I am not sure")
download['text'] = "Open another image"
download['font'] = myFont
download.place(x=25,y=230)
def exit():
sys.exit()
exit = Button(WIN,text="Exit",fg='white',bg="dark orange",command=exit)
exit['font'] = myFont
exit.place(x=280,y=230)
download = Button(WIN,text=' Open image ',font=("Arial bold",22),fg='white',bg="dark
orange",command=open)
download.place(x=70,y=190)
WIN.mainloop()