Plotting the results

With every one of our GAN networks, we want some confirmation that our training is going the right direction. This plotting function allows us to see the style, generated image, and the original image. In these plots, we should be able to confirm that the style is being transferred to the next image and back to the original image.

Here's a list of steps to create this plotting function:

  1.  First, we define the function and create a filename to save at every batch:
  def plot_checkpoint(self,b):
orig_filename = "/out/batch_check_"+str(b)+"_original.png"
  1. Next, we define how many rows and columns we'll need in our graph plus the number of samples we would like to grab for checkpoint evaluation of the models:
    r, c = 3, 3
random_inds = random.sample(range(len(self.X_test_A)),3)
  1. Next, we grab images from our test set and format them to evaluated by our generator:
    imgs_A = self.X_test_A[random_inds].reshape(3, self.W, self.H, self.C )
imgs_B = self.X_test_B[random_inds].reshape(3, self.W, self.H, self.C )
fake_A = self.generator.Generator.predict(imgs_B)
  1. We put all the data into a single array to make plotting easier:
    gen_imgs = np.concatenate([imgs_B, fake_A, imgs_A])
  1. Next, we rescale all of the images to be from 0-1 for plotting:
    # Rescale images 0 - 1
gen_imgs = 0.5 * gen_imgs + 0.5
  1. In this step, we create the titles, configure the plot, and plot each image in the plot:
    titles = ['Style', 'Generated', 'Original']
fig, axs = plt.subplots(r, c)
cnt = 0
for i in range(r):
for j in range(c):
axs[i,j].imshow(gen_imgs[cnt])
axs[i, j].set_title(titles[i])
axs[i,j].axis('off')
cnt += 1
  1. In the last step, we save the figure and close the figure (saves memory on the machine):
    fig.savefig("/out/batch_check_"+str(b)+".png")
plt.close('all')

return

Finally, we will move on to addressing the helper functions in this class.

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

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