mrdbourke / tensorflow-deep-learning

All course materials for the Zero to Mastery Deep Learning with TensorFlow course.
https://dbourke.link/ZTMTFcourse
MIT License
5.14k stars 2.53k forks source link

ValueError: logits and labels must have the same shape, received ((None, 15, 1) vs (None,)). #496

Open latheeshvm opened 1 year ago

latheeshvm commented 1 year ago
inputs = tf.keras.layers.Input(shape=(1,), dtype=tf.string)
x = text_vectorizer(inputs)
x = embedding(x)  # Create an embed
outputs = tf.keras.layers.Dense(1, activation="sigmoid")(x)
model_1 = tf.keras.Model(inputs, outputs, name="model_1_dense")
model_1.compile(loss="binary_crossentropy",
                optimizer=tf.keras.optimizers.Adam(), metrics=["accuracy"])

model_1_history = model_1.fit(x=train_sentences, y=train_labels, epochs=5, validation_data=(
    val_sentences, val_labels), callbacks=[create_tensorboard_callback(dir_name="model_logs", experiment_name="model_1_dense")])

this works in the video but is broken in TensorFlow 2.90, expanding solves it, but I don't understand why. might be worth adding a note here? https://academy.zerotomastery.io/courses/learn-tensorflow/lectures/32197595

In the later part of the video : x = tf.keras.layers.GlobalAveragePooling1D()(x) is added which will solve the problem but it's not mentioned