from ultralytics import YOLO
model = YOLO('best.pt', task='detect')
model(source='photo.jpg', save=True, save_txt=True, conf=0.2)
以上代码使用pyinstaller打包完成之后双击运行程序,会多次重复启动,打开任务管理器会发现虽然程序没有走下去没有识别出结果但是,后台已经开启了很多同名的进程
from ultralytics import YOLO
from tkinter import Button, Frame
class PT(object):
pts = 0
def __init__(self, win):
PT.pts += 1
self.frm = Frame(win)
print(PT.pts)
self.frm.place(relx=0, rely=0, relwidth=1, relheight=1)
Button(self.frm, text='识别', command=self.shibie).place(relx=0.4, rely=0.4, relwidth=0.2, relheight=0.2)
def shibie(self):
image = '(24).jpg'
model = YOLO('last.pt', task="detect")
model.predict(image, save=True, save_txt=True, conf=0.5, device="cpu")
if __name__ == '__main__':
from tkinter import Tk
a = Tk()
a.geometry('800x800+0+0')
pt = PT(a)
a.mainloop()
将程序放在gui界面中后代码如上,打包完成点击识别按钮,会跳出来一个新的窗口,只有关掉这个窗口才能得到识别结果,过点击新窗口的识别按钮将会继续打开新的gui界面,无线套娃
以上问题经过排查后发现是在加载模型后第一次识别模型的时候遇到的问题,不知道在座的各位大佬是如何解决这个问题的