close

[Solved] Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,))

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,)) in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,)) Error Occurs?

Today I get the following error Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,)) in python.

How To Solve Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,)) Error ?

  1. How To Solve Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,)) Error ?

    To Solve Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,)) Error You eventually need to thin down the network to have the same outputs as your classes. For example, doing OCR for numbers needs and final output of Dense(10) (for numbers 0 to 9).

  2. Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,))

    To Solve Tensorflow estimator ValueError: logits and labels must have the same shape ((?, 1) vs (?,)) Error You eventually need to thin down the network to have the same outputs as your classes. For example, doing OCR for numbers needs and final output of Dense(10) (for numbers 0 to 9).

Solution 1

You should reshape your labels as 2d-tensor (the first dimension will be the batch dimension and the second the scalar label):

# Our vectorized labels
y_train = np.asarray(train_labels).astype('float32').reshape((-1,1))
y_test = np.asarray(test_labels).astype('float32').reshape((-1,1))

Solution 2

Check your network using model.summary()

You eventually need to thin down the network to have the same outputs as your classes. For example, doing OCR for numbers needs and final output of Dense(10) (for numbers 0 to 9).

For example characterizing dogs vs. cats. The final layer has to have two outputs (0-dog, 1-cat)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read