Replies: 3 comments 2 replies
-
wow, I was running into this problem while taking the mrdbourke youtube tensorflow course, I did a Google search, and landed on this page which has the fix! Nice! |
Beta Was this translation helpful? Give feedback.
-
I don't think we should add the |
Beta Was this translation helpful? Give feedback.
-
If you've upgraded to TensorFlow 2.7.0 (the default in Google Colab from November 2021), you might run into this issue whilst going through notebook 02 when running
model_3
.Original Code (errors after 2.7.0)
[Fix 1] After TensorFlow 2.7.0 & using
tf.keras.losses.BinaryCrossEntropy()
If using
tf.keras.losses.BinaryCrossEntropy()
(classification) and your input data is one dimensional ([0, 1, 2, 3, 4, 5...]
), you need to specify theinput_shape
to the model.And then expand the dimensions of the input:
[Fix 2] After TensorFlow 2.7.0 & using
tf.keras.losses.mae
If you're using
tf.keras.losses.mae
and your data is one dimensional ([1, 2, 3, 4, 5...]
) you only have to expand the dimensions of the input data.Why this happens
When TensorFlow 2.7.0 was released one of the major breaking changes was:
This means that inputs with shape
(batch_size,)
won't automatically be upranked to become(batch_size, 1)
.In notebook 02,
X_reg_train
is of shape(150, )
which is like(batch_size=150, )
.So for the model to work we have to uprank it on the last dimension to be
(batch_size=150, 1)
:If you get any shape issues through the notebook and are running TensorFlow 2.7.0 this is likely one of the causes.
See this Google Colab notebook for more: https://colab.research.google.com/drive/1_dlrB_DJOBS9c9foYJs49I0YwN7LTakl?usp=sharing
The course notebooks have been updated to reflect these changes.
Beta Was this translation helpful? Give feedback.
All reactions