davidADSP / GDL_code

The official code repository for examples in the O'Reilly book 'Generative Deep Learning'

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in 03_03 VAE_train

jadolfbr opened this issue · comments

Running the vanilla notebook, I get the following at the train.fit step:

TypeError Traceback (most recent call last)
Cell In[10], line 1
----> 1 vae.train(
2 x_train
3 , batch_size = BATCH_SIZE
4 , epochs = EPOCHS
5 , run_folder = RUN_FOLDER
6 , print_every_n_batches = PRINT_EVERY_N_BATCHES
7 , initial_epoch = INITIAL_EPOCH
8 )

File ~/projects/generative_book/GDL_code/models/VAE.py:195, in VariationalAutoencoder.train(self, x_train, batch_size, epochs, run_folder, print_every_n_batches, initial_epoch, lr_decay)
191 checkpoint2 = ModelCheckpoint(os.path.join(run_folder, 'weights/weights.h5'), save_weights_only = True, verbose=1)
193 callbacks_list = [checkpoint1, checkpoint2, custom_callback, lr_sched]
--> 195 self.model.fit(
196 x_train
197 , x_train
198 , batch_size = batch_size
199 , shuffle = True
200 , epochs = epochs
201 , initial_epoch = initial_epoch
202 , callbacks = callbacks_list
203 )

File ~/miniforge3/envs/generative/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.traceback)
68 # To get the full stack trace, call:
69 # tf.debugging.disable_traceback_filtering()
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb

File /var/folders/x0/8d985bj50sgd0mgq51l3m0d40000gp/T/autograph_generated_filev67pwrag.py:15, in outer_factory..inner_factory..tf__train_function(iterator)
13 try:
14 do_return = True
---> 15 retval
= ag
_.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False

TypeError: in user code:

File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/engine/training.py", line 1160, in train_function  *
    return step_function(self, iterator)
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/engine/training.py", line 1146, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/engine/training.py", line 1135, in run_step  **
    outputs = model.train_step(data)
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/engine/training.py", line 994, in train_step
    loss = self.compute_loss(x, y, y_pred, sample_weight)
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/engine/training.py", line 1052, in compute_loss
    return self.compiled_loss(
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/engine/compile_utils.py", line 317, in __call__
    self._total_loss_mean.update_state(
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/utils/metrics_utils.py", line 77, in decorated
    update_op = update_state_fn(*args, **kwargs)
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/metrics/base_metric.py", line 143, in update_state_fn
    return ag_update_state(*args, **kwargs)
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/metrics/base_metric.py", line 486, in update_state  **
    sample_weight = tf.__internal__.ops.broadcast_weights(
File "/Users/jadolfbr/miniforge3/envs/generative/lib/python3.10/site-packages/keras/engine/keras_tensor.py", line 283, in __array__
    raise TypeError(

TypeError: You are passing KerasTensor(type_spec=TensorSpec(shape=(), dtype=tf.float32, name=None), name='Placeholder:0', description="created by layer 'tf.cast_2'"), 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.

I was trying a newer version of TF where I needed to add this to VAE.py:

from tensorflow.python.framework.ops import disable_eager_execution
disable_eager_execution()