Using Keras CV within Keras Core

103 views
Skip to first unread message

Fadi Badine

unread,
Aug 12, 2023, 8:24:22 AM8/12/23
to Keras-users
Hi,

I was trying to convert an example that I have from tf.keras to Keras_core. It's a CV example where I use VGG19 as a base model and then some Dense layers.

I am using Keras CV RandAugment Layer along with other Keras layers for Resizing and Rescaling.
In Keras Core (TF backend), for RandAugment, I am getting the following error:

A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras_core.layers` and `keras_core.operations`). You are likely doing something like:

```
x = Input(...)
...
tf_fn(x) # Invalid.
```

What you should do instead is wrap `tf_fn` in a layer:

```
class MyLayer(Layer):
def call(self, x):
return tf_fn(x)

x = MyLayer()(x)
```


Call arguments received by layer 'rand_augment_4' (type RandAugment):
• inputs=<KerasTensor shape=(None, None, None, 3), dtype=float32, name=keras_tensor_196>


Do we always have to wrap Keras CV layers with a Keras layer?

Thanks!

Regards,
Fadi Badine
Reply all
Reply to author
Forward
0 new messages