Hi experts,
Not sure if it’s just me or what but it appears that Colab TF 2.17.0 is also
giving me another error with ungraded lab notebook C3_W4_Lab_3_Saliency.ipynb:
Having done some checks, found the following link that provides some
explanation of incompatibility beween TF 2.16 and onwards with tf_keras from tensorflow_hub:
opened 11:08AM - 17 Mar 24 UTC
stat:awaiting response
type:bug
comp:keras
TF 2.16
### Issue type
Bug
### Have you reproduced the bug with TensorFlow Nightly?
Y… es
### Source
source
### TensorFlow version
2.16.1
### Custom code
No
### OS platform and distribution
Ubuntu 22.04.3 LTS
### Mobile device
_No response_
### Python version
Python 3.11.0rc1
### Bazel version
_No response_
### GCC/compiler version
_No response_
### CUDA/cuDNN version
12.3.0
### GPU model and memory
_No response_
### Current behavior?
I can execute the following code without any issues in TensorFlow 2.15.0 and TensorFlow Hub 1.16.1. However, when I upgrade the TensorFlow version to 2.16.0 or above, I encounter an error stating that `KerasLayer` cannot be added to the Sequential model.
### Standalone code to reproduce the issue
```shell
import tensorflow as tf
import tensorflow_hub as hub
image_size = 224
URL = "https://tfhub.dev/tensorflow/efficientnet/b0/feature-vector/1"
model = tf.keras.Sequential([
hub.KerasLayer(URL, input_shape=(image_size, image_size, 3))
])
```
### Relevant log output
```shell
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[29], line 1
----> 1 model = tf.keras.Sequential([
2 feature_extractor,
3 tf.keras.layers.Dense(2, activation = 'softmax')
4 ])
6 model.build([None, image_size, image_size, 3])
7 model.summary()
File /usr/local/lib/python3.10/dist-packages/keras/src/models/sequential.py:70, in Sequential.__init__(self, layers, trainable, name)
68 if layers:
69 for layer in layers:
---> 70 self.add(layer, rebuild=False)
71 self._maybe_rebuild()
File /usr/local/lib/python3.10/dist-packages/keras/src/models/sequential.py:92, in Sequential.add(self, layer, rebuild)
90 layer = origin_layer
91 if not isinstance(layer, Layer):
---> 92 raise ValueError(
93 "Only instances of `keras.Layer` can be "
94 f"added to a Sequential model. Received: {layer} "
95 f"(of type {type(layer)})"
96 )
97 if not self._is_layer_name_unique(layer):
...
101 "the name of a layer in this model. Update the `name` argument "
102 "to pass a unique name."
103 )
ValueError: Only instances of `keras.Layer` can be added to a Sequential model. Received: <tensorflow_hub.keras_layer.KerasLayer object at 0x7a4ac7e30f40> (of type <class 'tensorflow_hub.keras_layer.KerasLayer'>)
```
So, I rolled back TF to 2.15.0, restarted kernel and it fixed the issue for that cell:
The rest of the notebook runs to completion with no further error.
BTW, “pip install --upgrade tensorflow_hub” and leaving TF at 2.17.0 did not resolve the compatibility issue.
Rgds,
MCW
Yes @Mun_Chung_Wong
There is version issue with C3 assignment and you did the right way to resolve your issue.
Another way would be
Learners can reload the colab from the classroom or just add these lines at the top of their existing notebook (then run everything again to generate a new model file):
!pip install tf-keras==2.15 --quiet
!pip install tensorflow==2.15 --quiet
!pip install keras==2.15 --quiet
This would be required with course 3 as well as course 4 assignment but not all assignment.
Regards
DP
Thanks DP for clarifying at least I know it’s not just me having the issue
Cheers,
MCW