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 :: bubble sort in python 
Python :: axvline matplotlib 
Python :: solve linear system python 
Python :: Python Requests Library Delete Method 
Python :: learn basic facts about dataframe | dataframe info 
Python :: how to download file using python using progress bar 
Python :: discord.py events 
Python :: ternary operator in python 
Python :: request post python with api key integration 
Python :: thousand separator python 
Python :: django exclude queryset 
Python :: flask abort 
Python :: python asyncio.run() 
Python :: how to make a list in python 
Python :: python string to list of chars 
Python :: python program to display fibonacci sequence using recursion 
Python :: remove extra blank spaces 
Python :: style django forms with crisp 
Python :: how to end a while loop python 
Python :: np.hstack in python 
Python :: how many numbers greater than 100 using pytho 
Python :: python server 
Python :: matplotlib save figure without showing 
Python :: objects.filter django 
Python :: print to screen 
Python :: how to add trailing zeros in python 
Python :: pytorch get non diag element 
Python :: python save image pytelegrambotapi 
Python :: list of dictionary values 
Python :: from string to flaot python numpy 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =