'logits' and 'labels' must have the same shape, received error during deep learning

Asked 2 weeks ago, Updated 2 weeks ago, 0 views


import pandas as pd
import tensorflow as tf
import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)

df = pd.read_csv('C:\\Users\\operator09\\PycharmProjects\\pythonProject\\TEST\\data\\clothsize.csv')

df['age'] = df['age'].fillna(df['age'].median())
df['height'] = df['height'].fillna(df['height'].median())

df['size'] = df['size'].map({'M': 0, 'S': 1, 'XXXL': 2, 'XL': 3, 'L': 4, 'XXS': 5, 'XXL': 6})

x = df.drop("size", axis=1)
y = df['size']

model = tf.keras.models.Sequential([tf.keras.layers.Dense(64, activation='relu'),
                                    tf.keras.layers.Dense(128, activation='relu'),
                                    tf.keras.layers.Dense(1028, activation='relu'),
                                    tf.keras.layers.Dropout(0.2),
                                    tf.keras.layers.Dense(64, activation='relu'),
                                    tf.keras.layers.Dense(6, activation='softmax')
                                    ])
opt = tf.keras.optimizers.Adam(learning_rate=0.0001)
model.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])
model.fit(x, y, epochs=1000)

I'm practicing making a program that predicts the size of my weight, height, and age ValueError: logits and labels must have the same shape, received ((None, 6) vs (None, 1)). There's an error like that. What should I do?

python deep-learning

2022-09-20 12:34

1 Answers

The last floor of the Keras model ends with six outputs. By the way, the label is one size number. Therefore, it seems that an error occurred that the shape is not correct.

Add your answers.

It's a classification question. We're not going to fix the network, we're going to have to change the target y of the input to one- There are 7 classes from 0 to 6, so the network end should be 7 outputs.

Have a nice day.


2022-09-20 12:34

If you have any answers or tips


© 2022 pinfo. All rights reserved.