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

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 :: select 2 cols from dataframe python pandas 
Python :: python adding digits 
Python :: install python in centos7 
Python :: shutil move file 
Python :: how to hide a widget in tkinter python 
Python :: create spark dataframe from pandas 
Python :: delete pandas column 
Python :: get rid of unnamed column pandas 
Python :: shebang python 
Python :: xa python 
Python :: calculate angle between 3 points python 
Python :: best pyqt5 book 
Python :: python log10 
Python :: Plot regression line from sklearn 
Python :: python count characters 
Python :: flask flash not working 
Python :: df col to dict 
Python :: how to make getter in python 
Python :: create a dictionary in python 
Python :: how to save the model in python 
Python :: Taking a list of strings as input, our matching function returns the count of the number of strings whose first and last chars of the string are the same. Also, only consider strings with length of 2 or more. python 
Python :: import time in python 
Python :: subprocess.check_output python 
Python :: how to append a number to a list in python 
Python :: python raw string 
Python :: django date formatting 
Python :: how to make a separate list of values from dictionaries in python 
Python :: streamlit python install 
Python :: custom signal godot 
Python :: delete one pymongo 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =