-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
How to repro?
TF version: 2.19.0
- Take an example from https://www.tensorflow.org/probability/api_docs/python/tfp/distributions/PixelCNN#examples
- Create Google Colab
- Past the example into the Google Colab
- Run it
The following exception occurs:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[/tmp/ipython-input-624558695.py](https://localhost:8080/#) in <cell line: 0>()
33
34 # Define the log likelihood for the loss fn
---> 35 log_prob = dist.log_prob(image_input)
36
37 # Define the model
6 frames
<decorator-gen-128> in shape_v2(input, out_type, name)
[/usr/local/lib/python3.12/dist-packages/keras/src/backend/common/keras_tensor.py](https://localhost:8080/#) in __tf_tensor__(self, dtype, name)
154
155 def __tf_tensor__(self, dtype=None, name=None):
--> 156 raise ValueError(
157 "A KerasTensor cannot be used as input to a TensorFlow function. "
158 "A KerasTensor is a symbolic placeholder for a shape and dtype, "
ValueError: 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.layers` and `keras.ops`). 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)
```
Metadata
Metadata
Assignees
Labels
No labels