[Python] Troubleshoot "Invalid input shape for input Tensor"

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to build a model with keras and tensorflow to play Go:

    training_data = encode_from_file_info(training_files)
    testing_data = encode_from_file_info(testing_files)

    input_shape = (1, 19, 19)
    model = Sequential(
    [
    keras.layers.Input(input_shape),
    keras.layers.ZeroPadding2D(padding=3, data_format='channels_first'),
    ]
    )


    I get the following error when I run this:


    Invalid input shape for input Tensor("Cast:0", shape=(None, 19, 19), dtype=float32). Expected shape (None, 1, 19, 19), but input has incompatible shape (None, 19, 19)
    ​

    I have verified that the generators training_data and testing_data yield tuples of two ndarray with shape (1, 19, 19) and (361,).

    I'm new to tensorflow and it is a black box to me. Obviously I'm missing something and making incorrect assumptions about my training data and the neural network. How do I troubleshoot issues like this? What tools are available to debug my model to find the shape mismatch?

    Continue reading...

Compartilhe esta Página