title: new bug in a variational autoencoder (keras)
body: <p>I used to use this code to train variational autoencoder (I found the code on a forum and adapted it to my needs) :</p>
  <pre><code>import pickle
  from pylab import mpl,plt
  
  #lecture des résultats
  
  filename=r'XXX.pic'
  
  data_file=open(filename,'rb')
  X_sec = pickle.load(data_file)#[:,3000:]
  data_file.close()
  
  size=X_sec.shape[0]
  prop=0.75
  
  cut=int(size*prop)
  
  X_train=X_sec[:cut]
  X_test=X_sec[cut:]
  
  std=X_train.std()
  
  X_train /= std
  X_test /= std
  
  import keras
  from keras import layers
  from keras import backend as K
  from keras.models import Model
  import numpy as np
  
  #encoding_dim = 12
  
  sig_shape = (3600,)
  batch_size = 128
  latent_dim = 12
  input_sig = keras.Input(shape=sig_shape)
  
  x = layers.Dense(128, activation='relu')(input_sig)
  x = layers.Dense(64, activation='relu')(x)
  shape_before_flattening = K.int_shape(x)
  
  x = layers.Dense(32, activation='relu')(x)
  
  z_mean = layers.Dense(latent_dim)(x)
  z_log_var = layers.Dense(latent_dim)(x)
  
  encoder=Model(input_sig,[z_mean,z_log_var])
  
  
  
  def sampling(args):
      z_mean, z_log_var = args
      epsilon = K.random_normal(shape=(K.shape(z_mean)[0], latent_dim),
      mean=0., stddev=1.)
      return z_mean + K.exp(z_log_var) * epsilon
  
  z = layers.Lambda(sampling)([z_mean, z_log_var])
  
  decoder_input = layers.Input(K.int_shape(z)[1:])
  x = layers.Dense(np.prod(shape_before_flattening[1:]),activation='relu')(decoder_input)
  x = layers.Reshape(shape_before_flattening[1:])(x)
  x = layers.Dense(128, activation='relu')(x)
  x = layers.Dense(3600, activation='linear')(x)
  
  decoder = Model(decoder_input, x)
  z_decoded = decoder(z)
  
  class CustomVariationalLayer(keras.layers.Layer):
      def vae_loss(self, x, z_decoded):
          x = K.flatten(x)
          z_decoded = K.flatten(z_decoded)
          xent_loss = keras.metrics.mae(x, z_decoded)
          kl_loss = -5e-4 * K.mean(
          1 + z_log_var - K.square(z_mean) - K.exp(z_log_var), axis=-1)
          return K.mean(xent_loss + kl_loss)
      def call(self, inputs):
          x = inputs[0]
          z_decoded = inputs[1]
          loss = self.vae_loss(x, z_decoded)
          self.add_loss(loss, inputs=inputs)
          return x
  
  y = CustomVariationalLayer()([input_sig, z_decoded])
  
  vae = Model(input_sig, y)
  vae.compile(optimizer='rmsprop', loss=None)
  vae.summary()
  vae.fit(x=X_train, y=None,shuffle=True,epochs=100,batch_size=batch_size,validation_data=(X_test, None))
  </code></pre>
  <p>it used to work smoothly but I have updated my librairies and now I get this error :</p>
  <blockquote>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\framework\ops.py&quot;,
  line 1619, in _create_c_op
  c_op = c_api.TF_FinishOperation(op_desc)</p>
  <p>InvalidArgumentError: Duplicate node name in graph:
  'lambda_1/random_normal/shape'</p>
  <p>During handling of the above exception, another exception occurred:</p>
  <p>Traceback (most recent call last):</p>
  <p>File
  &quot;I:\Documents\Nico\Python\finance\travail_amont\autoencoder_variationnel_bruit.py&quot;,
  line 74, in 
  z = layers.Lambda(sampling)([z_mean, z_log_var])</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\keras\backend\tensorflow_backend.py&quot;,
  line 75, in symbolic_fn_wrapper
  return func(*args, **kwargs)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\keras\engine\base_layer.py&quot;,
  line 506, in <strong>call</strong>
  output_shape = self.compute_output_shape(input_shape)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\keras\layers\core.py&quot;,
  line 674, in compute_output_shape
  x = self.call(xs)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\keras\layers\core.py&quot;,
  line 716, in call
  return self.function(inputs, **arguments)</p>
  <p>File
  &quot;I:\Documents\Nico\Python\finance\travail_amont\autoencoder_variationnel_bruit.py&quot;,
  line 71, in sampling
  mean=0., stddev=1.)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\keras\backend\tensorflow_backend.py&quot;,
  line 4329, in random_normal
  shape, mean=mean, stddev=stddev, dtype=dtype, seed=seed)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\keras\backend.py&quot;,
  line 5602, in random_normal
  shape, mean=mean, stddev=stddev, dtype=dtype, seed=seed)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\ops\random_ops.py&quot;,
  line 69, in random_normal
  shape_tensor = tensor_util.shape_tensor(shape)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\framework\tensor_util.py&quot;,
  line 994, in shape_tensor
  return ops.convert_to_tensor(shape, dtype=dtype, name=&quot;shape&quot;)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\framework\ops.py&quot;,
  line 1314, in convert_to_tensor
  ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\ops\array_ops.py&quot;,
  line 1368, in _autopacking_conversion_function
  return _autopacking_helper(v, dtype, name or &quot;packed&quot;)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\ops\array_ops.py&quot;,
  line 1304, in _autopacking_helper
  return gen_array_ops.pack(elems_as_tensors, name=scope)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\ops\gen_array_ops.py&quot;,
  line 5704, in pack
  &quot;Pack&quot;, values=values, axis=axis, name=name)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\framework\op_def_library.py&quot;,
  line 742, in _apply_op_helper
  attrs=attr_protos, op_def=op_def)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\framework\func_graph.py&quot;,
  line 595, in _create_op_internal
  compute_device)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\framework\ops.py&quot;,
  line 3322, in _create_op_internal
  op_def=op_def)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\framework\ops.py&quot;,
  line 1786, in <strong>init</strong>
  control_input_ops)</p>
  <p>File
  &quot;C:\Users\user\AppData\Local\conda\conda\envs\my_root\lib\site-packages\tensorflow_core\python\framework\ops.py&quot;,
  line 1622, in _create_c_op
  raise ValueError(str(e))</p>
  <p>ValueError: Duplicate node name in graph:
  'lambda_1/random_normal/shape'</p>
  </blockquote>
  <p>I do not know this error : &quot;Duplicate node name in graph&quot;. Does anyone has a clue ? Thanks.</p>