1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Arguments `target` and `output` must have the same rank (ndim)

Discussão em 'Python' iniciado por Stack, Outubro 2, 2024 às 08:22.

  1. Stack

    Stack Membro Participativo

    i'm working with a multioutput tensorflow model, just for learning purposes, that should output 1 numerical and 1 categorical data (6 classes).

    everything seems to be fine, well-defined, but when i fit the model it errors saying "ValueError: Arguments target and output must have the same rank (ndim). Received: target.shape=(None,), output.shape=(None, 6)"

    for simplicity, on output layers I have:

    layers.Dense(1, activation='relu', name="output_numerical")(x)
    layers.Dense(6, activation='softmax', name="output_categorical")(x)


    model is compiled as:

    losses = {'output_numerical': 'mse', 'output_categorical': 'categorical_crossentropy'}
    loss_weights = {'output_numerical': 1.0, 'output_categorical': 1.0}
    model.compile(optimizer=optimizer, loss=losses, loss_weights=loss_weights)


    and finally, a sample of features x and labels y:

    input_numerical | input_categorical
    1.0 | 1
    1.1 | 0
    1.2 | 3
    1.5 | 5
    ....


    output_numerical| output_categorical
    2.0 | 5
    1.1 | 4
    3.2 | 3
    4.5 | 2
    ....


    Can anyone help me to fix the problem?

    I expect that softmax outputs just 1 number, the expected category, but I suspect that is outputing the probs for each class.

    Continue reading...

Compartilhe esta Página