<jupyter_start><jupyter_text>Imports<jupyter_code># TODO import stuff<jupyter_output><empty_output><jupyter_text>Import the necessary functionsThis cell will import the predefined functions needed for the execution of the notebook.If you want to call a function that is defined in this notebook, delete the headed underscore from the function's name<jupyter_code>%%capture
%rm -r adf93f9900d1dcfb6d76c83adec74a85
!git clone https://gist.github.com/dkatsios/adf93f9900d1dcfb6d76c83adec74a85.git
!pip install import_ipynb
import import_ipynb
%cd /content/adf93f9900d1dcfb6d76c83adec74a85
from simple_gan_gist import *
%cd /content<jupyter_output><empty_output><jupyter_text>Function to build the generator<jupyter_code>def _build_generator():
  """
  function that takes as input
  the noise_size (integer) and the img_shape (tuple of integers)
  and returns a keras Model.
  The model has 3 blocks of Dense, BatchNormalization and LeakyReLU layers.
  The units at the Dense layers are 256, 512 and 1024 respectively.
  The alpha parameter at the LeakyReLU layers is 0.2.
  The activation of the last layer is tanh.
  The model (generator) takes as input a tensor of shape (noise_size,)
  and returns a tensor of shape img_shape.
  """
  # TODO write function
  
  pass<jupyter_output><empty_output><jupyter_text>Function to build the discriminator<jupyter_code>def _build_discriminator(img_shape):
  """
  function that takes as input the img_shape (tuple of integers)
  and returns a keras Model.
  The model has 3 blocks of Dense and LeakyReLU layers.
  The units at the Dense layers are 1024, 512, and 256 respectively.
  The alpha parameter at the LeakyReLU layers is 0.2
  The activation of the last layer is sigmoid.
  The model (discriminator) takes as input a tensor of shape img_shape
  and returns a tensor of shape 1
  """
  # TODO write function
  
  pass<jupyter_output><empty_output><jupyter_text>Function to compile the models<jupyter_code>def _get_compiled_models(generator, discriminator, noise_size):
  """
  function that takes as input
  the generator (keras.Model)
  the discriminator (keras.Model)
  and the noise_size (integer)
  and return the generator, the compiled discriminator and the compiled comnbined models.
  The combined model takes as input noise (tensor of shape (noise_size,))
  and outputs the validity (output of the discriminator)
  of the internally generated image (output of the generator).
  For both models the optimizer is Adam with learning rate 0.0002 and beta_1 0.5
  and the loss function is binary_crossentropy.
  The discriminator has accuracy as metric.
  """
  # TODO write function
  
  pass<jupyter_output><empty_output><jupyter_text>Function to sample and save generated images<jupyter_code>def _sample_imgs(generator, noise_size, step):
  """
  function that takes as input the generator (keras.Model), the noise_size (integer)
  and the step (integer) and generates and saves samples of the generated images.
  Sample images must be normilized to [0, 1] (output of generator is in [-1, 1]).
  The images are in a 5x5 grid and are saved at ./images/{step}.png
  """
  # TODO write function
  
  pass<jupyter_output><empty_output><jupyter_text>Function to train the models<jupyter_code>def _train(models, noise_size, img_shape, batch_size, steps):
  """
  function that takes as input the models (tuple of generator, discriminator, combined),
  the noise_size, the img_shape, the batch_size and the steps and trains the models
  for this number of steps on batches of size batch_size.
  The training data are from mnist (keras.datasets).
  For preprocessing, the data are normalized in [-1, 1] (original in [0, 255]).
  Every 100 steps the models loss and accuracy is printed and samples are saved.
  """
  # TODO write function
  
  pass<jupyter_output><empty_output><jupyter_text>Define hyperparameters<jupyter_code>%rm -r /content/images
%mkdir /content/images
noise_size = 100
img_shape = 28, 28
batch_size = 64
steps = 1000<jupyter_output><empty_output><jupyter_text>Generate the models<jupyter_code>generator = build_generator(noise_size, img_shape)
discriminator = build_discriminator(img_shape)
compiled_models = get_compiled_models(generator, discriminator, noise_size)<jupyter_output><empty_output><jupyter_text>Train the models<jupyter_code>train(compiled_models, noise_size, img_shape, batch_size, steps)<jupyter_output><empty_output><jupyter_text>Display samples<jupyter_code>Image('/content/images/%d.png' % 1000)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06956136464333186, 'fraction_numerical': 0.025476295968099246, 'mean_word_length': 5.404255319148936, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '474943', 'license': 'MIT', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1392, 'n_words': 495, 'path': 'Simple_GAN/Simple_GAN_4.ipynb', 'repo_name': 'gnuevo/Intro-to-GANs', 'size': '4514'}