eriklindernoren / Keras-GAN

Keras implementations of Generative Adversarial Networks.
MIT License
9.18k stars 3.14k forks source link

DCGAN FailedPreconditionError #219

Closed ParthS28 closed 4 years ago

ParthS28 commented 4 years ago

Hi, I was trying to implement DCGAN on the EMNIST dataset. I am using google colabs for this. I am not quite sure what this error means. Thank you!

/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'
---------------------------------------------------------------------------
FailedPreconditionError                   Traceback (most recent call last)
<ipython-input-7-9c9c5f1eea60> in <module>()
----> 1 dcgan.train(epochs = 4000, batch_size = 256, save_interval = 100)

7 frames
<ipython-input-4-df37f047bd37> in train(self, epochs, batch_size, save_interval)
    120 
    121             # Train the discriminator (real classified as ones and generated as zeros)
--> 122             d_loss_real = self.discriminator.train_on_batch(imgs, valid)
    123             d_loss_fake = self.discriminator.train_on_batch(gen_imgs, fake)
    124             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 _AnonymousVar65 from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/_AnonymousVar65/N10tensorflow3VarE does not exist.
     [[node mul_23/ReadVariableOp (defined at /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_5112]

Function call stack:
keras_scratch_graph

Update: works fine locally, any idea why colab is giving me this error?

GilianPonte commented 4 years ago

Can you try to use: from tensorflow.keras.optimizers import Adam

Let me know if it works!

newzealandpaul commented 4 years ago

That worked for me thanks

CauchyChen commented 4 years ago

tensorflow.keras

Yes,it works, the same problems happens in bigan. Thanks.