Training class preparation

The training class initialization step will be described in the following section—here are the steps to create the bare bones training class:

  1.  Import all of the necessary packages to run the training class:
#!/usr/bin/env python3
from gan import GAN
from generator import Generator
from discriminator import Discriminator
from keras.datasets import mnist
from random import randint
import numpy as np
import matplotlib.pyplot as plt
import h5py
# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
from voxelgrid import VoxelGrid
  1. Define the Trainer class with a few input values:
class Trainer:
def __init__(self, side=16, latent_size=32, epochs =100, batch=32,
checkpoint=50, data_dir = ''):

Here's a description of each of the input values:

    • side: This is the length of the cube side as defined by the input data.
    • latent_size: This is the size of the encoder output from earlier in this chapter.
    • epochs: This is the number of iterations we want the training script to go over the data.
    • batch: This is the size of the data that we want to gather for each of the epochs.
    • checkpoint: This is how often we want to graph the results of our training.

  1. After the import, create the internal variables that we'll use throughout the class:
     self.SIDE=side
self.EPOCHS = epochs
self.BATCH = batch
self.CHECKPOINT = checkpoint
self.LATENT_SPACE_SIZE = latent_size
self.LABELS = [1]
  1. We're going to use internal methods to load our data for use throughout the class:
self.load_3D_MNIST(data_dir)
self.load_2D_encoded_MNIST()
  1. We'll instantiate the generator and discriminator classes with their input:
self.generator = Generator(latent_size=self.LATENT_SPACE_SIZE)
self.discriminator = Discriminator(side=self.SIDE)
  1. Create the GAN model using Generator and Discriminator that we just instantiated:
self.gan = GAN(generator=self.generator.Generator,   
discriminator=self.discriminator.Discriminator)

Now that we have the basic training class structure, we will move on to developing helper functions.

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

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