- 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'):
- 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)
- The following is the same code used in Chapter 3, My 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'] )
- 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'] )
- 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!