Reputation: 47
Background: I am building an anti-virus based on a machine learning model. I build a program that makes a List(vector) that has 486 values.
For example this is how shortened version looks(the acutal vector has 486 values):
[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 1.00000000e+00 1.00000000e+00 5.33333333e-01
0.00000000e+00 5.88235294e-02 3.49019608e-01 7.96078431e-01
5.88235294e-02 3.49019608e-01 8.07843137e-01 5.88235294e-02
3.45098039e-01 9.45098039e-01 5.88235294e-02 1.56862745e-01
8.00000000e-01 5.88235294e-02 7.60784314e-01 5.09803922e-02
2.50980392e-01 3.92156863e-03 5.33333333e-01 0.00000000e+00
2.35294118e-02 5.88235294e-02 3.13725490e-01 7.56862745e-01
5.88235294e-02 3.41176471e-01 9.49019608e-01 5.21568627e-01
7.52941176e-01 4.58823529e-01 2.78431373e-01 2.00000000e-01
1.00000000e+00 5.21568627e-01 1.00000000e+00 4.58823529e-01
5.88235294e-02 5.88235294e-02 1.56862745e-01 7.76470588e-01
5.05882353e-01 7.68627451e-01 9.72549020e-01 0.00000000e+00
0.00000000e+00 0.00000000e+00 3.56862745e-01 3.72549020e-01
5.45098039e-01 8.98039216e-01 3.64705882e-01 7.64705882e-01
5.88235294e-02 1.60784314e-01 1.56862745e-02 1.41176471e-01
5.88235294e-02 1.60784314e-01 4.54901961e-01 1.41176471e-01
2.50980392e-01 4.54901961e-01 9.01960784e-01 1.45357859e-01
1.27626518e-02 5.25954600e-03 5.29496962e-03 1.07052096e-02
3.08893971e-03 3.26031344e-03 2.54954328e-03 9.53584717e-03
1.62738028e-03 4.26500391e-03 1.86711202e-03 6.17443280e-03
2.24815529e-03 1.28635612e-03 1.18420206e-02 1.02462344e-02]
I finished building the model with a data base, an xlsx file, that I pulled from each row.
The problem: Now i'm trying to predict if a file is a virus or not and I built a vector for that file and tried to use the model.predict(pe) function(pe is my vector) and I get an error saying that my vector doesn't match the shape that was expected:
' 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]
here is my code:
from tensorflow import keras
import vector_build #custom code that I made
model = keras.models.load_model("anti_virus_model.h5")
pe = vector_build.encode_pe("C:\\Windows\\System32\\calc.exe")
print(model.predict(pe))
I don't really know what to do and how to change the shape of the vector. Maybe when I pulled data from the .xlsx file it didn't recognize it as the same format vector?
If you need me to add anything to be more clear please tell me!
Would love to hear what you think! Thanks in advance!
Upvotes: 1
Views: 47
Reputation: 10474
You probably trained your model on batches of data? That is, your input had shape [batch_size, 486]
. Keras models always expect a batch axis in their input, even if it's a single example. As such, make sure that the input has a batch axis.
As it is right now (I assume), your input is simply shape [486]
, i.e. it does not have a batch axis -- you just have to add one. You can do it like this: model.predict(pe[None])
. This adds an axis of size 1 in front, making the input shape [1, 486].
Upvotes: 1