我试图通过mlflow预测为mnist训练的模型
loaded_model = mlflow.pyfunc.load_model(logged_model)
(x_train, y_train), (x_test, y_test) = mnist.load_data()
我试图通过
创建数据框架x = pd.DataFrame(x_test)
但是我得到了
ValueError: Must pass 2-d input. shape=(10000, 28, 28)
但是如果我重塑
xtest2 = x_test.reshape(10000, 784)
x = pd.DataFrame(xtest2)
loaded_model.predict(x)
输入没有对齐
ValueError: Input 0 of layer "sequential_2" is incompatible with the layer: expected shape=(None, 28, 28), found shape=(None, 784)
这是有意义的,因为图层设置为
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(32, 3, activation='relu', input_shape=(28, 28, 1)),
但是我如何同时满足pandas要求和tensorflow要求?
您可以在调用model.predict
:
x = pd.DataFrame(xtest2)
model.predict(tf.keras.layers.Reshape((28, 28, 1))(x))