【发布时间】:2020-03-05 10:48:54
【问题描述】:
背景:
我在 Python 3.6 中使用 Pycharm(不使用更新版本,因为我的库不支持更新版本的 python)。
我为杀毒软件建立了一个 ml 模型并保存(尝试将其保存为 'anti_virus_model.h5' 和文件夹)
我正在尝试为反病毒构建一个 UI,所以我正在使用 tkinter 库。
问题: 我试图加载我的模型(很确定它有效)并预测被选择的文件(在将标题变成向量之后) 我导入了 tensorflow 和 keras,但函数 model.predict(pe) 似乎无法被 pycharm 识别。 [pe 是我的向量]
这是我的代码:
from tkinter import *
from tkinter import filedialog
from tensorflow import keras
import vector_build
import tkinter as Tk
import tensorflow as tf
tf.keras.models.load_model('anti_virus_model.h5')
def browse_file():
fname = filedialog.askopenfilename(filetypes=(("exe files", "*.exe"), ("exe files", "*.exe")))
print(fname)
pe = vector_build.encode_pe(fname)
print(pe)
print(keras.model.predict(pe))
root = Tk.Tk()
root.wm_title("Browser")
broButton = Tk.Button(master=root, text='Browse', width=80, height=25, command=browse_file)
broButton.pack(side=Tk.LEFT, padx=2, pady=2)
Tk.mainloop()
选择文件后出现的错误是:
2020-03-05 12:37:14.611731: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-03-05 12:37:14.611883: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-03-05 12:37:16.837699: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-03-05 12:37:16.837815: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303)
2020-03-05 12:37:16.841558: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-GT2BTVK
2020-03-05 12:37:16.841817: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-GT2BTVK
2020-03-05 12:37:16.842185: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:Sequential models without an `input_shape` passed to the first layer cannot reload their optimizer state. As a result, your model isstarting with a freshly initialized optimizer.
C:/Program Files (x86)/Steam/Steam.exe
*(big vector, no need to include)*
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/0123m/PycharmProjects/anti_virus_project/predictorUI.py", line 18, in browse_file
print(keras.model.predict(pe))
AttributeError: 'numpy.ndarray' object has no attribute 'model'
Process finished with exit code 0
(进程不崩溃,我关闭了)
提前致谢!
【问题讨论】:
-
回溯中的行
print(pe.model.predict())与您粘贴的代码 (print(keras.model.predict(pe))) 不匹配。进行更改后,您是否重新启动了应用? -
你是对的,我编辑它。
-
@Meon 你用 tensorflow 成功部署我的应用了吗?
标签: python tensorflow machine-learning tkinter keras