GAN Model not training?

When I run the GAN Model ,I am getting the following error. Please help

/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)
in ()
23
24 # Train our Discriminator
—> 25 d_loss_real = discriminator.train_on_batch(real_imgs,real_y)
26 d_loss_fake = discriminator.train_on_batch(fake_imgs,fake_y)
27 d_loss = 0.5d_loss_real + 0.5d_loss_fake

6 frames
/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 _AnonymousVar118 from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/_AnonymousVar118/N10tensorflow3VarE does not exist.
[[node mul_88/ReadVariableOp (defined at /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3009) ]] [Op:__inference_keras_scratch_graph_3778]

Function call stack:
keras_scratch_graph

Hey @Vicky_08012000, yes just change the import statemente, to these statements, with the introduction of tensorflow 2.0 some changes needs to be made.

import tensorflow as tf

tf.compat.v1.disable_eager_execution()

from keras.datasets import mnist
from tensorflow.python.keras.layers import *
from tensorflow.python.keras.layers.advanced_activations import LeakyReLU
from tensorflow.python.keras.models import Sequential,Model
from tensorflow.compat.v1.keras.optimizers import Adam

import matplotlib.pyplot as plt
import math
import numpy as np 

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

2 Likes

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.