Generator

The Generator class only has two notable differences—one in the initialization step of the class, where we can choose either simple GAN or convolutional GAN, while the other difference is that we need to actually build the DCGAN model, giving us an additional stubbed-out function in the class that develops the model.

Now, let's move on and build a simple pseudocode example using the following steps:

  1. First, initialize the class as normal, including imports, as follows:
#!/usr/bin/env python3
imports
  1. Create a class for the generator that allows us to toggle the type of model with the following model_type flag:
class Generator(object):
def __init__(self, width = 28, height= 28, channels = 1,
latent_size=100, model_type = 'simple'):
# Initialize Class Variables
  1. Write a simple example of how to toggle between the two different styles of models, as follows:
if model_type=='simple':
# Initialize Simple Generator
elif model_type=='DCGAN':
# Initialize Convolutional Generator
  1. The model architecture for the Generator itself will go inside the following method:
    def dc_model(self):
# Convolutional Generator
return model
  1. As we plan to keep the original model we built, let's compare the two different methods as follows:
    def model(self, block_starting_size=128,num_blocks=4):
# Simple GAN
return model
  1. Finally, introduce helper methods to each one of the classes to help provide a summary, and then save the model, as follows:
    def summary(self):
# Summary Helper Function

def save_model(self):
# Model Saver Helper Function
..................Content has been hidden....................

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