Difficulty importing data from Tensorflow Hub


I’m having difficulty importing data from Tensorflow Hub.

The data comes from a tf.dataset that contains a pd.Dataframe and images aggregated in the tf.dataset. When I use it with cropnet it says:

Only instances of keras.Layer can be added to a Sequential model. Received: <tensorflow_hub.keras_layer.KerasLayer object at 0x7fadc741d550> (of type <class ‘tensorflow_hub.keras_layer.KerasLayer’>)

A KerasTensor is symbolic: it’s a placeholder for a shape an a dtype. It doesn’t have any actual numerical value. You cannot convert it to a NumPy array

And the data input is the following layer:

img_input = keras.Input(shape=(*CFG.image_size, 3), name=“images”)

I already tried to add cardinality, but it didn’t work. Neither does the shape of the tensors.

Do you know how to solve this?

I rely heavily on this cropnet to develop a neural network model ensemble.

I’m using Keras 3.0.4, Tensorflow 2.15.0 and Keras-CV 0.8.2

Thanks in advance.

Hi @Andre_Galhardo, Thank you for reporting this bug. while reproducing the issue we have also observed the same. As an alternative i recommend you to use tf.keras which does not provide any error.

classifier = hub.KerasLayer('https://tfhub.dev/google/cropnet/classifier/cassava_disease_V1/2')

Thank You.