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

02_neural_network_classification_with_tensorflow - wrong shape in model_3 #366

Closed lenka-cizkova closed 2 years ago

lenka-cizkova commented 2 years ago

We are doing binary classification, expecting the predictions to be 0 or 1. For model_2, the shape of model_2.predict(X) is (1000, 1), i.e., for each input row we get a scalar result. However, the first layer in the TF 2.7.0+ tweak to model_3,

tf.keras.layers.Dense(100, input_shape=(None, 1))

seems to be wrong: the shape of model_3.predict(X) is (1000, 2, 1), i.e., for each input row we now get 2 numbers. This is also indicated by the function plot_decision_boundary(), saying 'doing multiclass classification...' and showing different contours than those shown in the video.

Based on the documentation of Dense and Input, I believe that the input_shape should be (2,), i.e., using

tf.keras.layers.Dense(100, input_shape=(2,))

or we can just keep the model as it was originally, with

tf.keras.layers.Dense(100)

This throws no errors and produces the same plot as shown in the video, with 'doing binary classification'.

Compare the original plot to the plot corresponding to the tweaked version:

image

image

mrdbourke commented 2 years ago

Thank you for noting this.

Will check it out properly this week.

mrdbourke commented 2 years ago

Fix here: https://github.com/mrdbourke/tensorflow-deep-learning/commit/264d8179734d317efc6f44abf5e44a82b4d4bf24

The updated plot_decision_boundary() function should work in the notebook here now: https://github.com/mrdbourke/tensorflow-deep-learning/blob/main/02_neural_network_classification_in_tensorflow.ipynb