Chapter 8 Deep Dream issue
moghalis opened this issue · comments
I am trying to run the code for the deep dream and I disable the eager execution to user the gradients. However I got this error:
TypeError Traceback (most recent call last)
in <cell line: 8>()
6
7 # Compute the gradients of the dream with regard to the loss.
----> 8 grads = K.gradients(loss, dream)[0]
9 #grads = K.gradients(loss, model.input)[0]
10
14 frames
/usr/local/lib/python3.10/dist-packages/keras/src/engine/keras_tensor.py in array(self, dtype)
283
284 def array(self, dtype=None):
--> 285 raise TypeError(
286 f"You are passing {self}, an intermediate Keras symbolic "
287 "input/output, to a TF API that does not allow registering custom "
TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='tf.operators.add_3/AddV2:0', description="created by layer 'tf.operators.add_3'"), an intermediate Keras symbolic input/output, to a TF API that does not allow registering custom dispatchers, such as tf.cond
, tf.function
, gradient tapes, or tf.map_fn
. Keras Functional model construction only supports TF API calls that do support dispatching, such as tf.math.add
or tf.reshape
. Other APIs cannot be called directly on symbolic Kerasinputs/outputs. You can work around this limitation by putting the operation in a custom Keras layer call
and calling that layer on this symbolic input/output.