Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

ValueError: logits and labels must have the same shape ((None, 1) vs (None, 2))

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

y_train = np.asarray(train_labels).astype('float32').reshape((-1,1))
y_test = np.asarray(test_labels).astype('float32').reshape((-1,1))
Comment

ValueError: `logits` and `labels` must have the same shape, received ((None, 2) vs (None, 1)).

tf.keras.layers.Dense(1, activation="sigmoid") # binary activation output
Comment

ValueError: `logits` and `labels` must have the same shape, received ((None, 7) vs (None, 1)).

model.add(GlobalAveragePooling2D())
Comment

ValueError: `logits` and `labels` must have the same shape, received ((None, 7) vs (None, 1)).

model.add(Flatten())
Comment

ValueError: `logits` and `labels` must have the same shape, received ((None, 10) vs (None, 1)).

#this problem always related to loss function ,check number of classes if binary or categorical
LOSS='binary_crossentropy' # for binary (2 classes)
LOSS='categorical_crossentropy' # for categorical (3-5)
LOSS = 'sparse_categorical_crossentropy' # for categorical more than 5
model.compile(loss=LOSS,
              optimizer='adam',
              metrics=['acc'])
Comment

PREVIOUS NEXT
Code Example
Python :: how to extract zip file in jupyter notebook 
Python :: random choice dictionary python 
Python :: python open website 
Python :: conda python-telegram-bot 
Python :: python mod inverse 
Python :: show pythonpath 
Python :: Make solutions faster in python 
Python :: python valeur de pi 
Python :: pandas diff between dates 
Python :: python replace regex 
Python :: python image black and white 
Python :: pickle load 
Python :: how to reset a variable in python 
Python :: confusion matrix heat map 
Python :: how to print not equal to in python 
Python :: python strftime iso 8601 
Python :: how to clear screen python 
Python :: permutations python 
Python :: python import specific excel sheet 
Python :: messages django 
Python :: check all python versions ubuntu 
Python :: update python in cmd 
Python :: python check if variables are the same 
Python :: fake migration 
Python :: removing a channel from aconda 
Python :: python select random subset from numpy array 
Python :: argparse example python pyimagesearch 
Python :: python print without space 
Python :: argparse multiple arguments as list 
Python :: code for making an exe file for python 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =