alueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 4126 but received input with shape [None, 9]\n"

Hi everyone, this is my first post here - hopefully it is okay to ask for advice as I am still new to Django.

I have this error below when doing a POST for a ML model, I need a bit of help to point me in the right direction, please


raise ValueError(\n\n ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 4126 but received input with shape [None, 9]\n"


Below is my view.py file
def approvereject(request):
try:
mdl = keras.models.load_model(‘C:/Users/belie/Google Drive/Djangodeployment/DjangoAPI/main_model/model’)
mdl.load_weights(“C:/Users/belie/Google Drive/Djangodeployment/DjangoAPI/main_model/model.h5”)
mydata = request.data
unit = np.array(list(mydata.values()))
unit = unit.reshape(-1,0)
scalers = pd.read_pickle(“C:/Users/belie/Google Drive/Djangodeployment/DjangoAPI/main_model/scaler.pkl”)
scalers = StandardScaler()
X = scalers.fit_transform(unit)
#X = scalers.transform(unit)
y_pred = mdl.predict(X)
#y_pred=(y_pred>0.58)
newdf = pd.DataFrame(y_pred, columns= [‘Network Classsification’])
newdf = newdf.replace({0:‘Benign’, 1:‘Malicious’})
return JsonResponse(‘Your Status is {}’.format(newdf), safe=False)
except ValueError as e:
return Response(e.args[0], status.HTTP_400_BAD_REQUEST)

Thank you!

Hi @Believe!
It’s fine to ask for advice even if you’re an experienced developer!

Not really into ML so I can’t help with your specific error but first result on DuckDuckGo
shows a person with the exact same error.

PD:
When posting code here, please encapsulate it between 3 backticks, like this:

imagen

Result:

class CustomView(CreateView):
    parameter = "value"

It will be nicer to read for all of us :+1: