{ "cells": [ { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "11xi8CRmVA1d" }, "source": [ "Deep Learning Models -- A collection of various deep learning architectures, models, and tips for TensorFlow and PyTorch in Jupyter Notebooks.\n", "- Author: Sebastian Raschka\n", "- GitHub Repository: https://github.com/rasbt/deeplearning-models" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "autoexec": { "startup": false, "wait_interval": 0 }, "base_uri": "https://localhost:8080/", "height": 119 }, "colab_type": "code", "executionInfo": { "elapsed": 2889, "status": "ok", "timestamp": 1525034072517, "user": { "displayName": "Sebastian Raschka", "photoUrl": "//lh6.googleusercontent.com/-cxK6yOSQ6uE/AAAAAAAAAAI/AAAAAAAAIfw/P9ar_CHsKOQ/s50-c-k-no/photo.jpg", "userId": "118404394130788869227" }, "user_tz": 240 }, "id": "WuXDfh6UVA1g", "outputId": "80c92b95-76aa-444e-9aa3-9bcf5d000a6e" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sebastian Raschka \n", "\n", "CPython 3.6.8\n", "IPython 7.2.0\n", "\n", "torch 1.0.0\n" ] } ], "source": [ "%load_ext watermark\n", "%watermark -a 'Sebastian Raschka' -v -p torch" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "Cii2luqnVA1s" }, "source": [ "- Runs on CPU (not recommended here) or GPU (if available)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "EYAtjwgyVA1t" }, "source": [ "# Model Zoo -- Convolutional Autoencoder with Nearest-neighbor Interpolation (Trained on CelebA)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "Ke9a_LDUVA1v" }, "source": [ "A convolutional autoencoder using nearest neighbor upscaling layers that compresses 128*128*3=49,152 pixel face images to an intermediate 1000-pixel representation (~50x reduction!). " ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "1iZAQwueVA1x" }, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "autoexec": { "startup": false, "wait_interval": 0 } }, "colab_type": "code", "id": "CO_0yUH6VA1z" }, "outputs": [], "source": [ "import os\n", "import time\n", "import numpy as np\n", "import pandas as pd\n", "from PIL import Image\n", "import matplotlib.pyplot as plt\n", "\n", "import torch\n", "import torch.nn as nn\n", "import torch.nn.functional as F\n", "\n", "from torch.utils.data import Dataset\n", "from torch.utils.data import DataLoader\n", "from torchvision import transforms\n", "\n", "\n", "if torch.cuda.is_available():\n", " torch.backends.cudnn.deterministic = True" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "uhGdecraVA1-" }, "source": [ "## Dataset" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "sxaXYk5cVA2A" }, "source": [ "### Downloading the Dataset" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "T05ELUTiVA2B" }, "source": [ "Note that the ~200,000 CelebA face image dataset is relatively large (~1.3 Gb). The download link provided below was provided by the author on the official CelebA website at http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1) Download and unzip the file `img_align_celeba.zip`, which contains the images in jpeg format.\n", "\n", "2) Download the `list_eval_partition.txt` file, which contains training/validation/test partitioning info" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Preparing the Dataset" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Partition | \n", "
---|---|
Filename | \n", "\n", " |
000001.jpg | \n", "0 | \n", "
000002.jpg | \n", "0 | \n", "
000003.jpg | \n", "0 | \n", "
000004.jpg | \n", "0 | \n", "
000005.jpg | \n", "0 | \n", "