I am following a YouTube tutorial on transfer learning with TensorFlow and TensorFlow Hub. I am trying to use the MobileNet V2 model as a feature extractor in a keras.Sequential
model. However, I encounter a ValueError
stating that only instances of keras.Layer
can be added to a Sequential model, despite using hub.KerasLayer
. The relevant part of my code is:
import tensorflow_hub as hub
from tensorflow import keras
feature_extractor_model = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4"
model_without_top_layer = hub.KerasLayer(
feature_extractor_model,
input_shape=(224, 224, 3),
trainable=False
)
num_of_flowers = 5
model = keras.Sequential([
model_without_top_layer,
keras.layers.Dense(num_of_flowers)
])
model.summary()
I noticed the code runs when i comment model_without_top_layer
out. I’m not sure what’s going on
234 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.