Initializing the Discriminator class

  1. First, we need to add an argument relating to what model_type we would like to use, as well as provide the ability for users to select either GAN or DCGAN, as follows:
class Discriminator(object):
def __init__(self, width = 28, height= 28, channels = 1, latent_size=100,model_type = 'simple'):
  1. Next, perform the following basic setup within the class, as follows:
self.W = width
self.H = height
self.C = channels
self.CAPACITY = width*height*channels
self.SHAPE = (width,height,channels)
  1. The following is the same code used in Chapter 3My First GAN in Under 100 Lines, except it is wrapped with an if statement to become selectable:
if model_type=='simple':
self.Discriminator = self.model()
self.OPTIMIZER = Adam(lr=0.0002, decay=8e-9)
self.Discriminator.compile(loss='binary_crossentropy',
optimizer=self.OPTIMIZER, metrics=['accuracy'] )
  1. The following else-if statement allows you to select the DCGAN architecture. Here, we use the Adam optimizer, but you can experiment with different types of optimizers:
elif model_type=='DCGAN':
self.Discriminator = self.dc_model()
self.OPTIMIZER = Adam(lr=1e-4, beta_1=0.2)
self.Discriminator.compile(loss='binary_crossentropy',
optimizer=self.OPTIMIZER, metrics=['accuracy'] )
  1. Finally, save the model and provide a summary on the Terminal as follows:
self.save_model()
self.summary()

Remember—if the discriminator or generator loss falls to zero, the model has diverged!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.133.49