Skip to content

Instantly share code, notes, and snippets.

@EnisBerk
Created April 27, 2020 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EnisBerk/58c8c13fc172d7391a1e371cb9ec6a33 to your computer and use it in GitHub Desktop.
Save EnisBerk/58c8c13fc172d7391a1e371cb9ec6a33 to your computer and use it in GitHub Desktop.
Copy of dcgan.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"accelerator": "GPU",
"colab": {
"name": "Copy of dcgan.ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/EnisBerk/58c8c13fc172d7391a1e371cb9ec6a33/copy-of-dcgan.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "rF2x3qooyBTI"
},
"source": [
"# Deep Convolutional Generative Adversarial Network"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "e1_Y75QXJS6h"
},
"source": [
"### Import TensorFlow and other libraries"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "WZKbyU2-AiY-",
"colab": {}
},
"source": [
"import tensorflow as tf"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "wx-zNbLqB4K8",
"colab": {}
},
"source": [
"tf.__version__"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "YzTlj4YdCip_",
"colab": {}
},
"source": [
"# To generate GIFs\n",
"!pip install imageio"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "YfIk2es3hJEd",
"colab": {}
},
"source": [
"import glob\n",
"import imageio\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import os\n",
"import PIL\n",
"from tensorflow.keras import layers\n",
"import time\n",
"\n",
"from IPython import display\n",
"from scipy.io import loadmat\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "iYn4MdZnKCey"
},
"source": [
"### Load and prepare the dataset\n",
"\n",
"You will use the MNIST dataset to train the generator and the discriminator. The generator will generate handwritten digits resembling the MNIST data."
]
},
{
"cell_type": "code",
"metadata": {
"id": "EeWzbr1pRmjn",
"colab_type": "code",
"colab": {}
},
"source": [
"!wget http://ufldl.stanford.edu/housenumbers/train_32x32.mat\n",
"!wget http://ufldl.stanford.edu/housenumbers/test_32x32.mat"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "q-6f6NzyRuH7",
"colab_type": "code",
"colab": {}
},
"source": [
"\n",
"train_data = loadmat('train_32x32.mat')\n",
"test_data = loadmat('test_32x32.mat')"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "hON01DR9R9ND",
"colab_type": "code",
"colab": {}
},
"source": [
"\n",
"X_train, y_train = train_data['X'], train_data['y']\n",
"X_test, y_test = test_data['X'], test_data['y']\n",
"\n",
"X_train.shape"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "L-AW4KP7SGmM",
"colab_type": "code",
"colab": {}
},
"source": [
"# roll axis backward\n",
"\n",
"X_train = np.rollaxis(X_train, 3)\n",
"X_test = np.rollaxis(X_test, 3)\n",
"\n",
"X_train.shape"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "k7rALih_SgPp",
"colab_type": "code",
"colab": {}
},
"source": [
"train_images=np.concatenate([X_train,X_test])\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "a4fYMGxGhrna",
"colab": {}
},
"source": [
"# (train_images, train_labels), (_, _) = tf.keras.datasets.mnist.load_data()"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "grSgoSz_K5TW",
"colab_type": "code",
"colab": {}
},
"source": [
"train_images.shape"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "2aiBSS2qTGSV",
"colab_type": "code",
"colab": {}
},
"source": [
"train_images.shape"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "NFC2ghIdiZYE",
"colab": {}
},
"source": [
"train_images = train_images.reshape(train_images.shape[0], 32, 32, 3).astype('float32')\n",
"train_images = (train_images - 127.5) / 127.5 # Normalize the images to [-1, 1]"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "S4PIDhoDLbsZ",
"colab": {}
},
"source": [
"BUFFER_SIZE = 99289\n",
"BATCH_SIZE = 256"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "-yKCCQOoJ7cn",
"colab": {}
},
"source": [
"# Batch and shuffle the data\n",
"train_dataset = tf.data.Dataset.from_tensor_slices(train_images).shuffle(BUFFER_SIZE).batch(BATCH_SIZE)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "THY-sZMiQ4UV"
},
"source": [
"## Create the models\n",
"\n",
"Both the generator and discriminator are defined using the [Keras Sequential API](https://www.tensorflow.org/guide/keras#sequential_model)."
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "-tEyxE-GMC48"
},
"source": [
"### The Generator\n",
"\n",
"The generator uses `tf.keras.layers.Conv2DTranspose` (upsampling) layers to produce an image from a seed (random noise). Start with a `Dense` layer that takes this seed as input, then upsample several times until you reach the desired image size of 28x28x1. Notice the `tf.keras.layers.LeakyReLU` activation for each layer, except the output layer which uses tanh."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "6bpTcDqoLWjY",
"colab": {}
},
"source": [
"def make_generator_model():\n",
" model = tf.keras.Sequential()\n",
" model.add(layers.Dense(4*4*512, use_bias=False, input_shape=(100,)))\n",
" model.add(layers.BatchNormalization())\n",
" model.add(layers.LeakyReLU())\n",
"\n",
" model.add(layers.Reshape((4, 4, 512)))\n",
" # assert model.output_shape == (None, 7, 7, 256) # Note: None is the batch size\n",
"\n",
" model.add(layers.Conv2DTranspose(256, (5, 5), strides=(2, 2), padding='same', use_bias=False))\n",
" # assert model.output_shape == (None, 7, 7, 128)\n",
" model.add(layers.BatchNormalization())\n",
" model.add(layers.LeakyReLU())\n",
"\n",
" model.add(layers.Conv2DTranspose(128, (5, 5), strides=(2, 2), padding='same', use_bias=False))\n",
" # assert model.output_shape == (None, 14, 14, 64)\n",
" model.add(layers.BatchNormalization())\n",
" model.add(layers.LeakyReLU())\n",
"\n",
" model.add(layers.Conv2DTranspose(3, (5, 5), strides=(2, 2), padding='same', use_bias=False, activation='tanh'))\n",
" assert model.output_shape == (None, 32, 32, 3)\n",
"\n",
" return model"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "GyWgG09LCSJl"
},
"source": [
"Use the (as yet untrained) generator to create an image."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "gl7jcC7TdPTG",
"colab": {}
},
"source": [
"generator = make_generator_model()\n",
"\n",
"noise = tf.random.normal([1, 100])\n",
"generated_image = generator(noise, training=False)\n",
"\n",
"# plt.imshow(generated_image[0, :, :, 0], cmap='gray')\n",
"plt.imshow(tf.cast( generated_image[0, :, :, :] * 127.5 + 127.5,tf.int16))\n"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "D0IKnaCtg6WE"
},
"source": [
"### The Discriminator\n",
"\n",
"The discriminator is a CNN-based image classifier."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "dw2tPLmk2pEP",
"colab": {}
},
"source": [
"def make_discriminator_model():\n",
" model = tf.keras.Sequential()\n",
" model.add(layers.Conv2D(64, (5, 5), strides=(2, 2), padding='same',\n",
" input_shape=[32, 32, 3]))\n",
" model.add(layers.LeakyReLU())\n",
" model.add(layers.Dropout(0.3))\n",
"\n",
" model.add(layers.Conv2D(128, (5, 5), strides=(2, 2), padding='same'))\n",
" model.add(layers.LeakyReLU())\n",
" model.add(layers.Dropout(0.3))\n",
"\n",
" model.add(layers.Conv2D(256, (5, 5), strides=(2, 2), padding='same'))\n",
" model.add(layers.LeakyReLU())\n",
" model.add(layers.Dropout(0.3))\n",
"\n",
" model.add(layers.Flatten())\n",
" model.add(layers.Dense(1))\n",
"\n",
" return model"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "QhPneagzCaQv"
},
"source": [
"Use the (as yet untrained) discriminator to classify the generated images as real or fake. The model will be trained to output positive values for real images, and negative values for fake images."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "gDkA05NE6QMs",
"colab": {}
},
"source": [
"discriminator = make_discriminator_model()\n",
"decision = discriminator(generated_image)\n",
"print (decision)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "0FMYgY_mPfTi"
},
"source": [
"## Define the loss and optimizers\n",
"\n",
"Define loss functions and optimizers for both models.\n"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "psQfmXxYKU3X",
"colab": {}
},
"source": [
"# This method returns a helper function to compute cross entropy loss\n",
"cross_entropy = tf.keras.losses.BinaryCrossentropy(from_logits=True)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "PKY_iPSPNWoj"
},
"source": [
"### Discriminator loss\n",
"\n",
"This method quantifies how well the discriminator is able to distinguish real images from fakes. It compares the discriminator's predictions on real images to an array of 1s, and the discriminator's predictions on fake (generated) images to an array of 0s."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "wkMNfBWlT-PV",
"colab": {}
},
"source": [
"def discriminator_loss(real_output, fake_output):\n",
" real_loss = cross_entropy(tf.ones_like(real_output), real_output)\n",
" fake_loss = cross_entropy(tf.zeros_like(fake_output), fake_output)\n",
" total_loss = real_loss + fake_loss\n",
" return total_loss"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Jd-3GCUEiKtv"
},
"source": [
"### Generator loss\n",
"The generator's loss quantifies how well it was able to trick the discriminator. Intuitively, if the generator is performing well, the discriminator will classify the fake images as real (or 1). Here, we will compare the discriminators decisions on the generated images to an array of 1s."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "90BIcCKcDMxz",
"colab": {}
},
"source": [
"def generator_loss(fake_output):\n",
" return cross_entropy(tf.ones_like(fake_output), fake_output)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "MgIc7i0th_Iu"
},
"source": [
"The discriminator and the generator optimizers are different since we will train two networks separately."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "iWCn_PVdEJZ7",
"colab": {}
},
"source": [
"generator_optimizer = tf.keras.optimizers.Adam(1e-4)\n",
"discriminator_optimizer = tf.keras.optimizers.Adam(1e-4)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "mWtinsGDPJlV"
},
"source": [
"### Save checkpoints\n",
"This notebook also demonstrates how to save and restore models, which can be helpful in case a long running training task is interrupted."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "CA1w-7s2POEy",
"colab": {}
},
"source": [
"checkpoint_dir = './training_checkpoints'\n",
"checkpoint_prefix = os.path.join(checkpoint_dir, \"ckpt\")\n",
"checkpoint = tf.train.Checkpoint(generator_optimizer=generator_optimizer,\n",
" discriminator_optimizer=discriminator_optimizer,\n",
" generator=generator,\n",
" discriminator=discriminator)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Rw1fkAczTQYh"
},
"source": [
"## Define the training loop\n"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "NS2GWywBbAWo",
"colab": {}
},
"source": [
"EPOCHS = 100\n",
"noise_dim = 100\n",
"num_examples_to_generate = 16\n",
"\n",
"# We will reuse this seed overtime (so it's easier)\n",
"# to visualize progress in the animated GIF)\n",
"seed = tf.random.normal([num_examples_to_generate, noise_dim])"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "jylSonrqSWfi"
},
"source": [
"The training loop begins with generator receiving a random seed as input. That seed is used to produce an image. The discriminator is then used to classify real images (drawn from the training set) and fakes images (produced by the generator). The loss is calculated for each of these models, and the gradients are used to update the generator and discriminator."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "3t5ibNo05jCB",
"colab": {}
},
"source": [
"# Notice the use of `tf.function`\n",
"# This annotation causes the function to be \"compiled\".\n",
"@tf.function\n",
"def train_step(images):\n",
" noise = tf.random.normal([BATCH_SIZE, noise_dim])\n",
"\n",
" with tf.GradientTape() as gen_tape, tf.GradientTape() as disc_tape:\n",
" generated_images = generator(noise, training=True)\n",
"\n",
" real_output = discriminator(images, training=True)\n",
" fake_output = discriminator(generated_images, training=True)\n",
"\n",
" gen_loss = generator_loss(fake_output)\n",
" disc_loss = discriminator_loss(real_output, fake_output)\n",
"\n",
" gradients_of_generator = gen_tape.gradient(gen_loss, generator.trainable_variables)\n",
" gradients_of_discriminator = disc_tape.gradient(disc_loss, discriminator.trainable_variables)\n",
"\n",
" generator_optimizer.apply_gradients(zip(gradients_of_generator, generator.trainable_variables))\n",
" discriminator_optimizer.apply_gradients(zip(gradients_of_discriminator, discriminator.trainable_variables))"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "2M7LmLtGEMQJ",
"colab": {}
},
"source": [
"def train(dataset, epochs):\n",
" for epoch in range(epochs):\n",
" start = time.time()\n",
"\n",
" for image_batch in dataset:\n",
" train_step(image_batch)\n",
"\n",
" # Produce images for the GIF as we go\n",
" display.clear_output(wait=True)\n",
" generate_and_save_images(generator,\n",
" epoch + 1,\n",
" seed)\n",
"\n",
" # Save the model every 15 epochs\n",
" if (epoch + 1) % 15 == 0:\n",
" checkpoint.save(file_prefix = checkpoint_prefix)\n",
"\n",
" print ('Time for epoch {} is {} sec'.format(epoch + 1, time.time()-start))\n",
"\n",
" # Generate after the final epoch\n",
" display.clear_output(wait=True)\n",
" generate_and_save_images(generator,\n",
" epochs,\n",
" seed)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "2aFF7Hk3XdeW"
},
"source": [
"**Generate and save images**\n"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "RmdVsmvhPxyy",
"colab": {}
},
"source": [
"def generate_and_save_images(model, epoch, test_input):\n",
" # Notice `training` is set to False.\n",
" # This is so all layers run in inference mode (batchnorm).\n",
" predictions = model(test_input, training=False)\n",
"\n",
" fig = plt.figure(figsize=(4,4))\n",
"\n",
" for i in range(predictions.shape[0]):\n",
" plt.subplot(4, 4, i+1)\n",
" plt.imshow(tf.cast( predictions[i, :, :, :] * 127.5 + 127.5,tf.int16))\n",
" plt.axis('off')\n",
"\n",
" plt.savefig('image_at_epoch_Exp1_{:04d}.png'.format(epoch))\n",
" plt.show()"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "dZrd4CdjR-Fp"
},
"source": [
"## Train the model\n",
"Call the `train()` method defined above to train the generator and discriminator simultaneously. Note, training GANs can be tricky. It's important that the generator and discriminator do not overpower each other (e.g., that they train at a similar rate).\n",
"\n",
"At the beginning of the training, the generated images look like random noise. As training progresses, the generated digits will look increasingly real. After about 50 epochs, they resemble MNIST digits. This may take about one minute / epoch with the default settings on Colab."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "Ly3UN0SLLY2l",
"colab": {}
},
"source": [
"train(train_dataset, EPOCHS)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "4mD6s5DHdSmB",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "mmSOubM9dhk2",
"colab_type": "code",
"colab": {}
},
"source": [
"# # predictions = generator(seed, training=False)\n",
"\n",
"\n",
"# fig = plt.figure(figsize=(4,4))\n",
"\n",
"# for i in range(predictions.shape[0]):\n",
"# plt.subplot(4, 4, i+1)\n",
"# # plt.imshow(predictions[i, :, :, :] * 127.5 + 127.5,)\n",
"# plt.imshow(tf.cast( predictions[i, :, :, :] * 127.5 + 127.5,tf.int16))\n",
"\n",
"# plt.axis('off')\n",
"\n",
"# # plt.savefig('image_at_epoch_{:04d}.png'.format(epoch))\n",
"# plt.show()"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "DvgKPl8DdBCC",
"colab_type": "code",
"colab": {}
},
"source": [
"# # predictions = generator(seed, training=False)\n",
"\n",
"\n",
"# fig = plt.figure(figsize=(4,4))\n",
"\n",
"# for i in range(predictions.shape[0]):\n",
"# plt.subplot(4, 4, i+1)\n",
"# plt.imshow(predictions[i, :, :, 1] * 127.5 + 127.5,)\n",
"# plt.axis('off')\n",
"\n",
"# # plt.savefig('image_at_epoch_{:04d}.png'.format(epoch))\n",
"# plt.show()"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "rfM4YcPVPkNO"
},
"source": [
"Restore the latest checkpoint."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "XhXsd0srPo8c",
"colab": {}
},
"source": [
"checkpoint.restore(tf.train.latest_checkpoint(checkpoint_dir))"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "P4M_vIbUi7c0"
},
"source": [
"## Create a GIF\n"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "WfO5wCdclHGL",
"colab": {}
},
"source": [
"# Display a single image using the epoch number\n",
"def display_image(epoch_no):\n",
" return PIL.Image.open('image_at_epoch_{:04d}.png'.format(epoch_no))"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "5x3q9_Oe5q0A",
"colab": {}
},
"source": [
"display_image(EPOCHS)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "CKspYQCeEn_9",
"colab_type": "code",
"colab": {}
},
"source": [
"last = -1\n",
"for i in range(10):\n",
" frame = 2*(i**0.5)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "NywiH3nL8guF"
},
"source": [
"Use `imageio` to create an animated gif using the images saved during training."
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "IGKQgENQ8lEI",
"colab": {}
},
"source": [
"anim_file = 'dcgan.gif'\n",
"\n",
"with imageio.get_writer(anim_file, mode='I') as writer:\n",
" filenames = glob.glob('image*.png')\n",
" filenames = sorted(filenames)\n",
" last = -1\n",
" for i,filename in enumerate(filenames):\n",
" frame = 2*(i**0.5)\n",
" if round(frame) > round(last):\n",
" last = frame\n",
" else:\n",
" continue\n",
" image = imageio.imread(filename)\n",
" writer.append_data(image)\n",
" image = imageio.imread(filename)\n",
" writer.append_data(image)\n",
"\n",
"import IPython\n",
"if IPython.version_info > (6,2,0,''):\n",
" display.Image(filename=anim_file)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "cGhC3-fMWSwl"
},
"source": [
"If you're working in Colab you can download the animation with the code below:"
]
},
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "uV0yiKpzNP1b",
"colab": {}
},
"source": [
"try:\n",
" from google.colab import files\n",
"except ImportError:\n",
" pass\n",
"else:\n",
" files.download(anim_file)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "k6qC-SbjK0yW"
},
"source": [
"## Next steps\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "xjjkT9KAK6H7"
},
"source": [
"This tutorial has shown the complete code necessary to write and train a GAN. As a next step, you might like to experiment with a different dataset, for example the Large-scale Celeb Faces Attributes (CelebA) dataset [available on Kaggle](https://www.kaggle.com/jessicali9530/celeba-dataset). To learn more about GANs we recommend the [NIPS 2016 Tutorial: Generative Adversarial Networks](https://arxiv.org/abs/1701.00160).\n"
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment