Keras-GAN icon indicating copy to clipboard operation
Keras-GAN copied to clipboard

Cannot run the examples

Open lcalcagni opened this issue 4 years ago • 1 comments

I download the repo and I am trying some examples,like AAE or cgan. However, I get these errors and I do not know the reason:

In the case of the AAE:

Model: "sequential_5"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_21 (Dense)             (None, 512)               5632      
_________________________________________________________________
leaky_re_lu_15 (LeakyReLU)   (None, 512)               0         
_________________________________________________________________
dense_22 (Dense)             (None, 256)               131328    
_________________________________________________________________
leaky_re_lu_16 (LeakyReLU)   (None, 256)               0         
_________________________________________________________________
dense_23 (Dense)             (None, 1)                 257       
=================================================================
Total params: 137,217
Trainable params: 137,217
Non-trainable params: 0
_________________________________________________________________
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-9a0cd9a40d47> in <module>()
    187 
    188 if __name__ == '__main__':
--> 189     aae = AdversarialAutoencoder()
    190     aae.train(epochs=20000, batch_size=32, sample_interval=200)

1 frames
<ipython-input-3-9a0cd9a40d47> in __init__(self)
     34 
     35         # Build the encoder / decoder
---> 36         self.encoder = self.build_encoder()
     37         self.decoder = self.build_decoder()
     38 

<ipython-input-3-9a0cd9a40d47> in build_encoder(self)
     70         latent_repr = merge([mu, log_var],
     71                 mode=lambda p: p[0] + K.random_normal(K.shape(p[0])) * K.exp(p[1] / 2),
---> 72                 output_shape=lambda p: p[0])
     73 
     74         return Model(img, latent_repr)

TypeError: 'module' object is not callable

In the case of the cgan:

Model: "sequential_8"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_36 (Dense)             (None, 512)               401920    
_________________________________________________________________
leaky_re_lu_25 (LeakyReLU)   (None, 512)               0         
_________________________________________________________________
dense_37 (Dense)             (None, 512)               262656    
_________________________________________________________________
leaky_re_lu_26 (LeakyReLU)   (None, 512)               0         
_________________________________________________________________
dropout_9 (Dropout)          (None, 512)               0         
_________________________________________________________________
dense_38 (Dense)             (None, 512)               262656    
_________________________________________________________________
leaky_re_lu_27 (LeakyReLU)   (None, 512)               0         
_________________________________________________________________
dropout_10 (Dropout)         (None, 512)               0         
_________________________________________________________________
dense_39 (Dense)             (None, 1)                 513       
=================================================================
Total params: 927,745
Trainable params: 927,745
Non-trainable params: 0
_________________________________________________________________
Model: "sequential_9"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_40 (Dense)             (None, 256)               25856     
_________________________________________________________________
leaky_re_lu_28 (LeakyReLU)   (None, 256)               0         
_________________________________________________________________
batch_normalization_12 (Batc (None, 256)               1024      
_________________________________________________________________
dense_41 (Dense)             (None, 512)               131584    
_________________________________________________________________
leaky_re_lu_29 (LeakyReLU)   (None, 512)               0         
_________________________________________________________________
batch_normalization_13 (Batc (None, 512)               2048      
_________________________________________________________________
dense_42 (Dense)             (None, 1024)              525312    
_________________________________________________________________
leaky_re_lu_30 (LeakyReLU)   (None, 1024)              0         
_________________________________________________________________
batch_normalization_14 (Batc (None, 1024)              4096      
_________________________________________________________________
dense_43 (Dense)             (None, 784)               803600    
_________________________________________________________________
reshape_4 (Reshape)          (None, 28, 28, 1)         0         
=================================================================
Total params: 1,493,520
Trainable params: 1,489,936
Non-trainable params: 3,584
_________________________________________________________________
/usr/local/lib/python3.6/dist-packages/keras/engine/training.py:297: UserWarning: Discrepancy between trainable weights and collected trainable weights, did you set `model.trainable` without calling `model.compile` after ?
  'Discrepancy between trainable weights and collected trainable'
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/indexed_slices.py:434: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
  "Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
0 [D loss: 0.693212, acc.: 29.69%] [G loss: 0.681004]
---------------------------------------------------------------------------
FailedPreconditionError                   Traceback (most recent call last)
<ipython-input-5-d80d5608757d> in <module>()
    183 if __name__ == '__main__':
    184     cgan = CGAN()
--> 185     cgan.train(epochs=100, batch_size=32, sample_interval=200)

7 frames
<ipython-input-5-d80d5608757d> in train(self, epochs, batch_size, sample_interval)
    138 
    139             # Train the discriminator
--> 140             d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid)
    141             d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], fake)
    142             d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)

/usr/local/lib/python3.6/dist-packages/keras/engine/training.py in train_on_batch(self, x, y, sample_weight, class_weight, reset_metrics)
   1512             ins = x + y + sample_weights
   1513         self._make_train_function()
-> 1514         outputs = self.train_function(ins)
   1515 
   1516         if reset_metrics:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py in __call__(self, inputs)
   3790         value = math_ops.cast(value, tensor.dtype)
   3791       converted_inputs.append(value)
-> 3792     outputs = self._graph_fn(*converted_inputs)
   3793 
   3794     # EagerTensor.numpy() will often make a copy to ensure memory safety.

/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py in __call__(self, *args, **kwargs)
   1603       TypeError: For invalid positional/keyword argument combinations.
   1604     """
-> 1605     return self._call_impl(args, kwargs)
   1606 
   1607   def _call_impl(self, args, kwargs, cancellation_manager=None):

/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py in _call_impl(self, args, kwargs, cancellation_manager)
   1643       raise TypeError("Keyword arguments {} unknown. Expected {}.".format(
   1644           list(kwargs.keys()), list(self._arg_keywords)))
-> 1645     return self._call_flat(args, self.captured_inputs, cancellation_manager)
   1646 
   1647   def _filtered_call(self, args, kwargs):

/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
   1744       # No tape is watching; skip to running the function.
   1745       return self._build_call_outputs(self._inference_function.call(
-> 1746           ctx, args, cancellation_manager=cancellation_manager))
   1747     forward_backward = self._select_forward_and_backward_functions(
   1748         args,

/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py in call(self, ctx, args, cancellation_manager)
    596               inputs=args,
    597               attrs=attrs,
--> 598               ctx=ctx)
    599         else:
    600           outputs = execute.execute_with_cancellation(

/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     58     ctx.ensure_initialized()
     59     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60                                         inputs, attrs, num_outputs)
     61   except core._NotOkStatusException as e:
     62     if name is not None:

FailedPreconditionError:  Error while reading resource variable _AnonymousVar440 from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/_AnonymousVar440/N10tensorflow3VarE does not exist.
	 [[node mul_419/ReadVariableOp (defined at /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_23010]

Function call stack:
keras_scratch_graph

lcalcagni avatar Apr 12 '20 21:04 lcalcagni

You need to install these specific packages:

TensorFlow GPU 1.13.1 Keras 2.3.1

Works for me. Running experiments on Ubuntu 18.04 with Python 3.6 inside a conda environment.

hasibzunair avatar Apr 21 '20 18:04 hasibzunair