Search code examples
pythontensorflowmultidimensional-arraykerasvalueerror

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])

from the keras.io docs, it says that the shape dimensions for Input() does not include the batch size, and that mdoel.predict() sets batch_size=32 by default.

if model.predict(data) expects data.shape to be (batches, 6,7), what's the difference between model.predict(data, batch_size=1 and model.predict_on_batch(data)


Solution

  • Yes, the batch_shape of your model is (None, 6, 7), three dimensions. The first value None is the batch size (which is free to be any value).

    So it's expecting your data to have 3 dimensions, as the batch_shape determines.