Home » c# » c# – Python.Runtime.PythonException: Expected to see 2 array(s), for inputs ['image1', 'image1'] but instead got the following list of 1 arrays

c# – Python.Runtime.PythonException: Expected to see 2 array(s), for inputs ['image1', 'image1'] but instead got the following list of 1 arrays

Posted by: admin February 21, 2020 Leave a comment

Questions:

how can I passe 2 arrays in the Predict method of BaseModel? (C#)

This is the error:

Python.Runtime.PythonException: ValueError : Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), for inputs [‘image1’, ‘image2′] but instead got the following list of 1 arrays: [array([[[[0.85423136],
[0.8542314 ],
[0.8542314 ],
…,
[0.8542314 ],
[0.8542314 ],
[0.85423136]],
[[0.85423136],
[0.8542314 ],…’

code:

image1 = image1.Resize(IMG_SIZE, IMG_SIZE, Inter.Linear); //Image<Gray, float>
image2 = image2.Resize(IMG_SIZE, IMG_SIZE, Inter.Linear); //Image<Gray, float>
NDarray reshapedImage1 = np.array(image1.Data).astype(np.float32);
NDarray reshapedImage2 = np.array(image2.Data).astype(np.float32);
reshapedImage1 /= 255;
reshapedImage2 /= 255;

NDarray imageConcat = np.concatenate((reshapedImage1, reshapedImage2));
imageConcat = imageConcat.reshape(2, IMG_SIZE, IMG_SIZE, 1);

var prediction = _baseModel.Predict(imageConcat); //error here
How to&Answers: