Это продолжение моего вопроса lsat
Я получаю ошибки, говорящие о том, что что-то пошло не так с функцией предсказания, я пытался прочитать об этих ошибках, и я не понимаю что они означают.
У меня есть одномерный массив (вектор), с помощью которого я пытаюсь предсказать, является ли файл вирусом или нет.
это мой теперь улучшенный код (спасибо AKX )
import tkinter as Tk
from tkinter import filedialog
from tensorflow import keras
import vector_build
model = keras.models.load_model("anti_virus_model.h5")
def predict_file(fname):
print(fname) # Debugging
pe = vector_build.encode_pe(fname)
print(pe) # Debugging
result = model.predict(pe)
print(result) # Debugging
return result
def browse_file():
fname = filedialog.askopenfilename(filetypes=(("exe files", "*.exe"),))
result = predict_file(fname)
# TODO: Do something with `result`
def ui_main():
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()
if True: # First make this branch work correctly,
predict_file("C:\\Windows\\System32\\calc.exe")
else: # ... then switch to this.
ui_main()
проблема: Я получаю эту ошибку и не понимаю, что мне делать, чтобы ее решить: (фактический вектор намного больше, я сократил его)
2020-03-07 15:26:58.306607: 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-07 15:26:58.306740: 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-07 15:27:01.172350: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-03-07 15:27:01.172465: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303)
2020-03-07 15:27:01.176427: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-GT2BTVK
2020-03-07 15:27:01.176585: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-GT2BTVK
2020-03-07 15:27:01.176923: 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:\Windows\System32\calc.exe
[1.00000000e+00 1.00000000e+00 1.00000000e+00 0.00000000e+00
1.00000000e+00 1.00000000e+00 1.00000000e+00 1.00000000e+00
1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 5.33333333e-01]
Traceback (most recent call last):
File "C:/Users/0123m/PycharmProjects/anti_virus_project/predictorUI.py", line 34, in <module>
predict_file("C:\\Windows\\System32\\calc.exe")
File "C:/Users/0123m/PycharmProjects/anti_virus_project/predictorUI.py", line 13, in predict_file
result = model.predict(pe)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 1013, in predict
use_multiprocessing=use_multiprocessing)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 498, in predict
workers=workers, use_multiprocessing=use_multiprocessing, **kwargs)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 426, in _model_iteration
use_multiprocessing=use_multiprocessing)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 646, in _process_inputs
x, y, sample_weight=sample_weights)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 2346, in _standardize_user_data
all_inputs, y_input, dict_inputs = self._build_model_with_inputs(x, y)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 2572, in _build_model_with_inputs
self._set_inputs(cast_inputs)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 2659, in _set_inputs
outputs = self(inputs, **kwargs)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 737, in __call__
self.name)
File "C:\Users\0123m\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\keras\engine\input_spec.py", line 213, in assert_input_compatibility
' but received input with shape ' + str(shape))
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 486 but received input with shape [None, 1]
мне нужно изменить формат вектора? или что я должен сделать, чтобы исправить эту ошибку.
Заранее спасибо!