ydata-synthetic
ydata-synthetic copied to clipboard
[BUG] NotImplementedError: Cannot convert a symbolic Tensor (Embedder/GRU_1/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported
I am trying to reproduce the TimeGAN tutorial using ydata-synthetic package. The entire code can be accessed to here. I have TensorFlow gpu version: 2.4.1, ydata-synthetic version: 0.7.1
To train the model using the given energy dataset, I have the code:
# number of timesteps-
seq_len = 24
# number of features-
n_seq = 28
# number of hidden (LSTM/GRU) hidden units for generator-
hidden_dim = 24
# Also decides output_units for generator
# Used for discriminator loss-
gamma = 1
# Used by generator as a starter dimension-
noise_dim = 32
# Not used-
dim = 128
batch_size = 128
learning_rate = 5e-4
# Not used-
beta_1 = 0
beta_2 = 1
data_dim = 28
# Define TimeGAN arguments-
gan_args = ModelParameters(
batch_size = batch_size, lr = learning_rate,
noise_dim = noise_dim, layers_dim = dim
)
# Initialize TimeGAN-
model_timeGAN = TimeGAN(
model_parameters = gan_args, hidden_dim = hidden_dim,
seq_len = seq_len, n_seq = n_seq,
gamma = 1
)
# Train model-
model_timeGAN.train(data = energy_data, train_steps = 500)
I get the message + error:
** 2022-06-28 11:50:02.896098: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2022-06-28 11:50:02.898254: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set 2022-06-28 11:50:02.898468: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2022-06-28 11:50:02.898670: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties: pciBusID: 0000:04:00.0 name: NVIDIA GeForce RTX 3080 computeCapability: 8.6 coreClock: 1.71GHz coreCount: 68 deviceMemorySize: 9.78GiB deviceMemoryBandwidth: 707.88GiB/s 2022-06-28 11:50:02.898690: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1 2022-06-28 11:50:02.898711: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10 2022-06-28 11:50:02.898717: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10 2022-06-28 11:50:02.898723: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10 2022-06-28 11:50:02.898729: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10 2022-06-28 11:50:02.898735: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10 2022-06-28 11:50:02.898741: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10 2022-06-28 11:50:02.898747: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7 2022-06-28 11:50:02.898781: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2022-06-28 11:50:02.898957: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2022-06-28 11:50:02.899102: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0 2022-06-28 11:50:02.899115: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1 2022-06-28 11:53:33.072873: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix: 2022-06-28 11:53:33.072890: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0 2022-06-28 11:53:33.072894: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N 2022-06-28 11:53:33.073094: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2022-06-28 11:53:33.073284: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2022-06-28 11:53:33.073435: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2022-06-28 11:53:33.073563: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 9067 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 3080, pci bus id: 0000:04:00.0, compute capability: 8.6)
NotImplementedError Traceback (most recent call last) Input In [21], in <cell line: 2>() 1 # Train model- ----> 2 model_timeGAN.train(data = energy_data, train_steps = 500)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/ydata_synthetic/synthesizers/timeseries/timegan/model.py:230, in TimeGAN.train(self, data, train_steps) 228 def train(self, data, train_steps): 229 # Assemble the model --> 230 self.define_gan() 232 ## Embedding network training 233 autoencoder_opt = Adam(learning_rate=self.g_lr)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/ydata_synthetic/synthesizers/timeseries/timegan/model.py:60, in TimeGAN.define_gan(self) 55 Z = Input(shape=[self.seq_len, self.n_seq], batch_size=self.batch_size, name='RandomNoise') 57 #-------------------------------- 58 # Building the AutoEncoder 59 #-------------------------------- ---> 60 H = self.embedder(X) 61 X_tilde = self.recovery(H) 63 self.autoencoder = Model(inputs=X, outputs=X_tilde)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:951, in Layer.call(self, *args, **kwargs)
945 # Functional Model construction mode is invoked when Layers are called on
946 # symbolic KerasTensors, i.e.:
947 # >> inputs = tf.keras.Input(10)
948 # >> outputs = MyLayer()(inputs) # Functional construction mode.
949 # >> model = tf.keras.Model(inputs, outputs)
950 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
--> 951 return self._functional_construction_call(inputs, args, kwargs,
952 input_list)
954 # Maintains info about the Layer.call stack.
955 call_context = base_layer_utils.call_context()
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:1090, in Layer._functional_construction_call(self, inputs, args, kwargs, input_list)
1086 if keras_tensor.keras_tensors_enabled():
1087 with call_context.enter(
1088 layer=self, inputs=inputs, build_graph=True, training=training_value):
1089 # Check input assumptions set after layer building, e.g. input shape.
-> 1090 outputs = self._keras_tensor_symbolic_call(
1091 inputs, input_masks, args, kwargs)
1093 if outputs is None:
1094 raise ValueError('A layer's call method should return a '
1095 'Tensor or a list of Tensors, not None '
1096 '(layer: ' + self.name + ').')
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:822, in Layer._keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs) 820 return nest.map_structure(keras_tensor.KerasTensor, output_signature) 821 else: --> 822 return self._infer_output_signature(inputs, args, kwargs, input_masks)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:863, in Layer._infer_output_signature(self, inputs, args, kwargs, input_masks)
857 with autocast_variable.enable_auto_cast_variables(
858 self._compute_dtype_object):
859 # Build layer if applicable (if the build method has been
860 # overridden).
861 # TODO(kaftan): do we maybe_build here, or have we already done it?
862 self._maybe_build(inputs)
--> 863 outputs = call_fn(inputs, *args, **kwargs)
865 self._handle_activity_regularization(inputs, outputs)
866 self._set_mask_metadata(inputs, outputs, input_masks,
867 build_graph=False)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/engine/sequential.py:389, in Sequential.call(self, inputs, training, mask) 386 if 'training' in argspec: 387 kwargs['training'] = training --> 389 outputs = layer(inputs, **kwargs) 391 if len(nest.flatten(outputs)) != 1: 392 raise ValueError(SINGLE_LAYER_OUTPUT_ERROR_MSG)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py:660, in RNN.call(self, inputs, initial_state, constants, **kwargs)
654 inputs, initial_state, constants = _standardize_args(inputs,
655 initial_state,
656 constants,
657 self._num_constants)
659 if initial_state is None and constants is None:
--> 660 return super(RNN, self).call(inputs, **kwargs)
662 # If any of initial_state or constants are specified and are Keras
663 # tensors, then add them to the inputs and temporarily modify the
664 # input_spec to include them.
666 additional_inputs = []
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:1012, in Layer.call(self, *args, **kwargs) 1008 self._maybe_build(inputs) 1010 with autocast_variable.enable_auto_cast_variables( 1011 self._compute_dtype_object): -> 1012 outputs = call_fn(inputs, *args, **kwargs) 1014 if self._activity_regularizer: 1015 self._handle_activity_regularization(inputs, outputs)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent_v2.py:439, in GRU.call(self, inputs, mask, training, initial_state) 436 self._validate_args_if_ragged(is_ragged_input, mask) 438 # GRU does not support constants. Ignore it during process. --> 439 inputs, initial_state, _ = self._process_inputs(inputs, initial_state, None) 441 if isinstance(mask, list): 442 mask = mask[0]
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py:859, in RNN._process_inputs(self, inputs, initial_state, constants) 857 initial_state = self.states 858 elif initial_state is None: --> 859 initial_state = self.get_initial_state(inputs) 861 if len(initial_state) != len(self.states): 862 raise ValueError('Layer has ' + str(len(self.states)) + 863 ' states but was passed ' + str(len(initial_state)) + 864 ' initial states.')
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py:642, in RNN.get_initial_state(self, inputs) 640 dtype = inputs.dtype 641 if get_initial_state_fn: --> 642 init_state = get_initial_state_fn( 643 inputs=None, batch_size=batch_size, dtype=dtype) 644 else: 645 init_state = _generate_zero_filled_state(batch_size, self.cell.state_size, 646 dtype)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py:1948, in GRUCell.get_initial_state(self, inputs, batch_size, dtype) 1947 def get_initial_state(self, inputs=None, batch_size=None, dtype=None): -> 1948 return _generate_zero_filled_state_for_cell(self, inputs, batch_size, dtype)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py:2987, in _generate_zero_filled_state_for_cell(cell, inputs, batch_size, dtype) 2985 batch_size = array_ops.shape(inputs)[0] 2986 dtype = inputs.dtype -> 2987 return _generate_zero_filled_state(batch_size, cell.state_size, dtype)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py:3005, in _generate_zero_filled_state(batch_size_tensor, state_size, dtype) 3003 return nest.map_structure(create_zeros, state_size) 3004 else: -> 3005 return create_zeros(state_size)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py:3000, in _generate_zero_filled_state.
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py:201, in add_dispatch_support.
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:2819, in _tag_zeros_tensor.
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:2868, in zeros(shape, dtype, name) 2864 try: 2865 if not context.executing_eagerly(): 2866 # Create a constant if it won't be very big. Otherwise create a fill 2867 # op to prevent serialized GraphDefs from becoming too large. -> 2868 output = _constant_if_small(zero, shape, dtype, name) 2869 if output is not None: 2870 return output
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:2804, in _constant_if_small(value, shape, dtype, name) 2802 def _constant_if_small(value, shape, dtype, name): 2803 try: -> 2804 if np.prod(shape) < 1000: 2805 return constant(value, shape=shape, dtype=dtype, name=name) 2806 except TypeError: 2807 # Happens when shape is a Tensor, list with Tensor elements, etc.
File <array_function internals>:180, in prod(*args, **kwargs)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/numpy/core/fromnumeric.py:3088, in prod(a, axis, dtype, out, keepdims, initial, where) 2970 @array_function_dispatch(_prod_dispatcher) 2971 def prod(a, axis=None, dtype=None, out=None, keepdims=np._NoValue, 2972 initial=np._NoValue, where=np._NoValue): 2973 """ 2974 Return the product of array elements over a given axis. 2975 (...) 3086 10 3087 """ -> 3088 return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out, 3089 keepdims=keepdims, initial=initial, where=where)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/numpy/core/fromnumeric.py:86, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs) 83 else: 84 return reduction(axis=axis, out=out, **passkwargs) ---> 86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
File ~/anaconda3/envs/TimeGAN/lib/python3.8/site-packages/tensorflow/python/framework/ops.py:852, in Tensor.array(self) 851 def array(self): --> 852 raise NotImplementedError( 853 "Cannot convert a symbolic Tensor ({}) to a numpy array." 854 " This error may indicate that you're trying to pass a Tensor to" 855 " a NumPy call, which is not supported".format(self.name))
NotImplementedError: Cannot convert a symbolic Tensor (Embedder/GRU_1/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported **