Input(shape=(6,7)) 在 model.predict 上需要 3 个维度

Input(shape=(6,7)) expects 3 dimensions on model.predict

ValueError: Error when checking input: 
expected input_1 to have 3 dimensions, but got array with shape (6, 7)
_____________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to
==============================================================================
input_1 (InputLayer)            (None, 6, 7)         0

    out1, out2 = model.predict(board)


    inputs = Input(shape=(6,7))
    inputs_reshape = Reshape((6,7,1))(inputs) # channels, batch_size, rows, cols
    net = Conv2D(4, kernel_size=3, activation='relu', 
            padding='same', data_format='channels_last')(inputs_reshape)
    net = Flatten()(net)
    pi = Dense(7, activation='softmax', name='pi')(net) 
    v = Dense(1, activation='tanh', name='v')(net)

    model = Model(inputs=inputs, outputs=[v, pi])

来自 keras.io 文档,它说 Input()shape 维度不包括批量大小,并且 mdoel.predict() 设置 batch_size=32默认。

如果model.predict(data)期望data.shape(batches, 6,7)model.predict(data, batch_size=1model.predict_on_batch(data)

有什么区别

是的,您模型的 batch_shape(None, 6, 7),三个维度。第一个值 None 是批量大小(可以是任意值)。

因此它期望您的数据具有 3 个维度,正如 batch_shape 所确定的那样。