Home > Enterprise >  How to convert ndarray of shape (row, y, z) from mnist to pandas dataframe for tensorflow model pred
How to convert ndarray of shape (row, y, z) from mnist to pandas dataframe for tensorflow model pred

Time:11-22

I am trying to predict model trained for mnist via mlflow

loaded_model = mlflow.pyfunc.load_model(logged_model)

(x_train, y_train), (x_test, y_test) = mnist.load_data()

I tried to create dataframe via

x = pd.DataFrame(x_test)

but i got

ValueError: Must pass 2-d input. shape=(10000, 28, 28)

but if I reshape

xtest2 = x_test.reshape(10000, 784)
x = pd.DataFrame(xtest2)
loaded_model.predict(x)

I get input not aligned

ValueError: Input 0 of layer "sequential_2" is incompatible with the layer: expected shape=(None, 28, 28), found shape=(None, 784)

this make sense since, the layer is setup like

    model = tf.keras.Sequential([
        tf.keras.layers.Conv2D(32, 3, activation='relu', input_shape=(28, 28, 1)),

but how do I satisfy both pandas requirement and tensorflow requirement?

CodePudding user response:

You could try reshaping before calling model.predict:

x = pd.DataFrame(xtest2)

model.predict(tf.keras.layers.Reshape((28, 28, 1))(x))
  • Related