GANs-in-Action / gans-in-action

Companion repository to GANs in Action: Deep learning with Generative Adversarial Networks
1.01k stars 420 forks source link

Chapter2 code #15

Open acho98 opened 3 years ago

acho98 commented 3 years ago

the below errors occurred when i ran the Chapter_2_Autoencoder.ipynb my env is the colab

Epoch 1/50

TypeError Traceback (most recent call last)

in () 2 shuffle=True, 3 epochs=epochs, ----> 4 batch_size=batch_size) 9 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs) 975 except Exception as e: # pylint:disable=broad-except 976 if hasattr(e, "ag_error_metadata"): --> 977 raise e.ag_error_metadata.to_exception(e) 978 else: 979 raise TypeError: in user code: /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:805 train_function * return step_function(self, iterator) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:795 step_function ** outputs = model.distribute_strategy.run(run_step, args=(data,)) /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:1259 run return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica return self._call_for_each_replica(fn, args, kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica return fn(*args, **kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:788 run_step ** outputs = model.train_step(data) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:756 train_step y, y_pred, sample_weight, regularization_losses=self.losses) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:238 __call__ total_loss_metric_value, sample_weight=batch_dim) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/metrics_utils.py:90 decorated update_op = update_state_fn(*args, **kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/metrics.py:177 update_state_fn return ag_update_state(*args, **kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/metrics.py:364 update_state ** sample_weight, values) /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/weights_broadcast_ops.py:155 broadcast_weights values = ops.convert_to_tensor(values, name="values") /usr/local/lib/python3.6/dist-packages/tensorflow/python/profiler/trace.py:163 wrapped return func(*args, **kwargs) /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:1540 convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py:339 _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py:265 constant allow_broadcast=True) /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py:283 _constant_impl allow_broadcast=allow_broadcast)) /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_util.py:435 make_tensor_proto values = np.asarray(values) /usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py:83 asarray return array(a, dtype, copy=False, order=order) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/keras_tensor.py:274 __array__ 'Cannot convert a symbolic Keras input/output to a numpy array. ' TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.
JakubBialy commented 3 years ago

I tried to debug this, but all i found out is that the problem is in vae_loss function, especially in z_log_var=z_log_var, z_mean. Event tf.print(z_log_var) causes TypeError: Could not build a TypeSpec for <tf.Operation 'tf.print/PrintV2' type=PrintV2> with type Operation

firmamentone commented 3 years ago

I've also encountered this problem. After checking several discussions on the internet, I use the add_loss() to assign the loss function instead of the loss parameter in compile().

it seems to work.

However, I still don't know the difference between the methods and why the original code can not work correctly.

The link is my test notebook https://colab.research.google.com/drive/1wbUljO1qKvuFeWx9rrl75gv58Is51wtB?usp=sharing

Aligh1997 commented 3 years ago

I've also encountered this problem. After checking several discussions on the internet, I use the add_loss() to assign the loss function instead of the loss parameter in compile().

it seems to work.

However, I still don't know the difference between the methods and why the original code can not work correctly.

The link is my test notebook https://colab.research.google.com/drive/1wbUljO1qKvuFeWx9rrl75gv58Is51wtB?usp=sharing Worked for me! Thanks

IDAwaken commented 3 years ago

Just find the same issue. Still don't understand what cause the problem and how to solve it. Really need some help! Here are the error in details. 2021-05-10 11:34:20.296013: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 3799900000 Hz Epoch 1/50 Traceback (most recent call last): File "/home/zephyrus/Documents/Project/models/GAN/gans-in-action-master/chapter-2/c2.py", line 82, in batch_size=batch_size) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 1100, in fit tmp_logs = self.train_function(iterator) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 828, in call result = self._call(*args, kwds) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 871, in _call self._initialize(args, kwds, add_initializers_to=initializers) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 726, in _initialize *args, *kwds)) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 2969, in _get_concrete_function_internal_garbage_collected graphfunction, = self._maybe_define_function(args, kwargs) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3361, in _maybe_define_function graph_function = self._create_graph_function(args, kwargs) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3206, in _create_graph_function capture_by_value=self._capture_by_value), File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 990, in func_graph_from_py_func func_outputs = python_func(func_args, func_kwargs) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 634, in wrapped_fn out = weak_wrapped_fn().wrapped(*args, kwds) File "/home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 977, in wrapper raise e.ag_error_metadata.to_exception(e) TypeError: in user code: / /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py:805 train_function * return step_function(self, iterator) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py:795 step_function * outputs = model.distribute_strategy.run(run_step, args=(data,)) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py:1259 run return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica return self._call_for_each_replica(fn, args, kwargs) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica return fn(args, kwargs) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py:788 run_step outputs = model.train_step(data) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py:756 train_step y, y_pred, sample_weight, regularization_losses=self.losses) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/compile_utils.py:238 call total_loss_metric_value, sample_weight=batch_dim) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/utils/metrics_utils.py:90 decorated update_op = update_state_fn(*args, *kwargs) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/metrics.py:177 update_state_fn return ag_update_state(args, kwargs) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/metrics.py:364 update_state * sample_weight, values) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/ops/weights_broadcast_ops.py:155 broadcast_weights values = ops.convert_to_tensor(values, name="values") /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/profiler/trace.py:163 wrapped return func(args, **kwargs) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/ops.py:1540 convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py:339 _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py:265 constant allow_broadcast=True) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py:283 _constant_impl allow_broadcast=allow_broadcast)) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/tensor_util.py:435 make_tensor_proto values = np.asarray(values) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/numpy/core/_asarray.py:85 asarray return array(a, dtype, copy=False, order=order) /home/zephyrus/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/keras/engine/keras_tensor.py:274 array 'Cannot convert a symbolic Keras input/output to a numpy array. '

TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.

Process finished with exit code 1

wang-jinghui commented 3 years ago

Try this : tf version 2.1.0

vae.compile(optimizer='rmsprop', loss=vae_loss, experimental_run_tf_function = False)
#vae.compile(loss=None,optimizer='rmsprop')
vae.summary()
weichenxi87 commented 2 years ago

I've also encountered this problem. After checking several discussions on the internet, I use the add_loss() to assign the loss function instead of the loss parameter in compile().

it seems to work.

However, I still don't know the difference between the methods and why the original code can not work correctly.

The link is my test notebook https://colab.research.google.com/drive/1wbUljO1qKvuFeWx9rrl75gv58Is51wtB?usp=sharing

thank you! Without your comment , maybe I will drop this book !