GDL_code icon indicating copy to clipboard operation
GDL_code copied to clipboard

error during running 03_03_vae_digits_train.ipynb

Open krv76 opened this issue 3 years ago • 1 comments

I've got the following output in cell containing

vae.train(     
    x_train[:1000]
    , batch_size = BATCH_SIZE
    , epochs = EPOCHS
    , run_folder = RUN_FOLDER
    # , print_every_n_batches = PRINT_EVERY_N_BATCHES
    , initial_epoch = INITIAL_EPOCH
)

Could you help me with this? (03_01_autoencoder_train.ipynb works fine; replacing VariationalAutoencoder with models.AE.Autoencoder also helps but I still can't pass through most of book examples; output is pretty big, last line looks the most informative but I can't figure out how to repair this notebook).


TypeError Traceback (most recent call last) in () 5 , run_folder = RUN_FOLDER 6 # , print_every_n_batches = PRINT_EVERY_N_BATCHES ----> 7 , initial_epoch = INITIAL_EPOCH 8 )

d:\jupyter\GDL_code\models\VAE.py in train(self, x_train, batch_size, epochs, run_folder, print_every_n_batches, initial_epoch, lr_decay) 200 , epochs = epochs 201 , initial_epoch = initial_epoch --> 202 , callbacks = callbacks_list 203 ) 204

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing) 1098 _r=1): 1099 callbacks.on_train_batch_begin(step) -> 1100 tmp_logs = self.train_function(iterator) 1101 if data_handler.should_sync: 1102 context.async_wait()

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\def_function.py in call(self, *args, **kwds) 826 tracing_count = self.experimental_get_tracing_count() 827 with trace.Trace(self._name) as tm: --> 828 result = self._call(*args, **kwds) 829 compiler = "xla" if self._experimental_compile else "nonXla" 830 new_tracing_count = self.experimental_get_tracing_count()

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\def_function.py in _call(self, *args, **kwds) 869 # This is the first call of call, so we have to initialize. 870 initializers = [] --> 871 self._initialize(args, kwds, add_initializers_to=initializers) 872 finally: 873 # At this point we know that the initialization is complete (or less

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\def_function.py in _initialize(self, args, kwds, add_initializers_to) 724 self._concrete_stateful_fn = ( 725 self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access --> 726 *args, **kwds)) 727 728 def invalid_creator_scope(*unused_args, **unused_kwds):

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs) 2967 args, kwargs = None, None 2968 with self._lock: -> 2969 graph_function, _ = self._maybe_define_function(args, kwargs) 2970 return graph_function 2971

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\function.py in _maybe_define_function(self, args, kwargs) 3359 3360 self._function_cache.missed.add(call_context_key) -> 3361 graph_function = self._create_graph_function(args, kwargs) 3362 self._function_cache.primary[cache_key] = graph_function 3363

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes) 3204 arg_names=arg_names, 3205 override_flat_arg_shapes=override_flat_arg_shapes, -> 3206 capture_by_value=self._capture_by_value), 3207 self._function_attributes, 3208 function_spec=self.function_spec,

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\func_graph.py in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes) 988 _, original_func = tf_decorator.unwrap(python_func) 989 --> 990 func_outputs = python_func(*func_args, **func_kwargs) 991 992 # invariant: func_outputs contains only Tensors, CompositeTensors,

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\eager\def_function.py in wrapped_fn(*args, **kwds) 632 xla_context.Exit() 633 else: --> 634 out = weak_wrapped_fn().wrapped(*args, **kwds) 635 return out 636

~\AppData\Roaming\Python\Python36\site-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:

C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training.py:805 train_function  *
    return step_function(self, iterator)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training.py:795 step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\distribute\distribute_lib.py:1259 run
    return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\distribute\distribute_lib.py:2730 call_for_each_replica
    return self._call_for_each_replica(fn, args, kwargs)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\distribute\distribute_lib.py:3417 _call_for_each_replica
    return fn(*args, **kwargs)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training.py:788 run_step  **
    outputs = model.train_step(data)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training.py:756 train_step
    y, y_pred, sample_weight, regularization_losses=self.losses)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\compile_utils.py:238 __call__
    total_loss_metric_value, sample_weight=batch_dim)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\utils\metrics_utils.py:90 decorated
    update_op = update_state_fn(*args, **kwargs)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\metrics.py:177 update_state_fn
    return ag_update_state(*args, **kwargs)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\metrics.py:364 update_state  **
    sample_weight, values)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\ops\weights_broadcast_ops.py:155 broadcast_weights
    values = ops.convert_to_tensor(values, name="values")
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\profiler\trace.py:163 wrapped
    return func(*args, **kwargs)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\ops.py:1540 convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\constant_op.py:339 _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\constant_op.py:265 constant
    allow_broadcast=True)
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\constant_op.py:283 _constant_impl
    allow_broadcast=allow_broadcast))
C:\Users\user\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\tensor_util.py:435 make_tensor_proto
    values = np.asarray(values)
C:\Users\user\Anaconda3\lib\site-packages\numpy\core\_asarray.py:83 asarray
    return array(a, dtype, copy=False, order=order)
C:\Users\user\AppData\Roaming\Python\Python36\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.

krv76 avatar Mar 19 '21 22:03 krv76

I found the solution here Solved this by adding the statements

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

at the beginning of the notebook.

skaringa avatar Apr 17 '21 16:04 skaringa