{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "Cycle GAN", "provenance": [], "collapsed_sections": [], "toc_visible": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "accelerator": "GPU" }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "AYV_dMVDxyc2" }, "source": [ "[](https://github.com/lab-ml/nn)\n", "[](https://colab.research.google.com/github/lab-ml/nn/blob/master/labml_nn/gan/cycle_gan.ipynb) \n", "\n", "## Cycle GAN\n", "\n", "This is an experiment training Cycle GAN model." ] }, { "cell_type": "markdown", "metadata": { "id": "AahG_i2y5tY9" }, "source": [ "Install the `labml-nn` package" ] }, { "cell_type": "code", "metadata": { "id": "ZCzmCrAIVg0L", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "2fe2685f-731c-4c47-854e-a4f00e485281" }, "source": [ "!pip install labml-nn" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Collecting labml-nn\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/9d/bb/a7a6f69ab6e21de2398b5f6b0b2bb47b430e4a20ae2c8710c489e02813be/labml_nn-0.4.81-py3-none-any.whl (118kB)\n", "\r\u001b[K |██▊ | 10kB 22.6MB/s eta 0:00:01\r\u001b[K |█████▌ | 20kB 14.6MB/s eta 0:00:01\r\u001b[K |████████▎ | 30kB 12.9MB/s eta 0:00:01\r\u001b[K |███████████ | 40kB 12.1MB/s eta 0:00:01\r\u001b[K |█████████████▉ | 51kB 8.2MB/s eta 0:00:01\r\u001b[K |████████████████▋ | 61kB 8.7MB/s eta 0:00:01\r\u001b[K |███████████████████▍ | 71kB 8.9MB/s eta 0:00:01\r\u001b[K |██████████████████████▏ | 81kB 9.9MB/s eta 0:00:01\r\u001b[K |█████████████████████████ | 92kB 8.9MB/s eta 0:00:01\r\u001b[K |███████████████████████████▊ | 102kB 8.0MB/s eta 0:00:01\r\u001b[K |██████████████████████████████▌ | 112kB 8.0MB/s eta 0:00:01\r\u001b[K |████████████████████████████████| 122kB 8.0MB/s \n", "\u001b[?25hRequirement already satisfied: torch in /usr/local/lib/python3.6/dist-packages (from labml-nn) (1.7.0+cu101)\n", "Collecting labml-helpers>=0.4.72\n", " Downloading https://files.pythonhosted.org/packages/ec/58/2b7dcfde4565134ad97cdfe96ad7070fef95c37be2cbc066b608c9ae5c1d/labml_helpers-0.4.72-py3-none-any.whl\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from labml-nn) (1.19.5)\n", "Collecting labml>=0.4.94\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/99/b2/3a424548d74a88ce565b38f6b7e707e7c2f00bf8c7c575a1c251807e4896/labml-0.4.94-py3-none-any.whl (99kB)\n", "\u001b[K |████████████████████████████████| 102kB 8.2MB/s \n", "\u001b[?25hCollecting einops\n", " Downloading https://files.pythonhosted.org/packages/5d/a0/9935e030634bf60ecd572c775f64ace82ceddf2f504a5fd3902438f07090/einops-0.3.0-py2.py3-none-any.whl\n", "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.6/dist-packages (from torch->labml-nn) (3.7.4.3)\n", "Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from torch->labml-nn) (0.16.0)\n", "Requirement already satisfied: dataclasses in /usr/local/lib/python3.6/dist-packages (from torch->labml-nn) (0.8)\n", "Collecting gitpython\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/d7/cb/ec98155c501b68dcb11314c7992cd3df6dce193fd763084338a117967d53/GitPython-3.1.12-py3-none-any.whl (159kB)\n", "\u001b[K |████████████████████████████████| 163kB 9.9MB/s \n", "\u001b[?25hRequirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from labml>=0.4.94->labml-nn) (3.13)\n", "Collecting gitdb<5,>=4.0.1\n", "\u001b[?25l Downloading https://files.pythonhosted.org/packages/48/11/d1800bca0a3bae820b84b7d813ad1eff15a48a64caea9c823fc8c1b119e8/gitdb-4.0.5-py3-none-any.whl (63kB)\n", "\u001b[K |████████████████████████████████| 71kB 8.6MB/s \n", "\u001b[?25hCollecting smmap<4,>=3.0.1\n", " Downloading https://files.pythonhosted.org/packages/d5/1e/6130925131f639b2acde0f7f18b73e33ce082ff2d90783c436b52040af5a/smmap-3.0.5-py2.py3-none-any.whl\n", "Installing collected packages: smmap, gitdb, gitpython, labml, labml-helpers, einops, labml-nn\n", "Successfully installed einops-0.3.0 gitdb-4.0.5 gitpython-3.1.12 labml-0.4.94 labml-helpers-0.4.72 labml-nn-0.4.81 smmap-3.0.5\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "SE2VUQ6L5zxI" }, "source": [ "Imports" ] }, { "cell_type": "code", "metadata": { "id": "0hJXx_g0wS2C" }, "source": [ "import torch\n", "import torch.nn as nn\n", "\n", "from labml import experiment\n", "from labml.configs import option\n", "from labml_helpers.module import Module\n", "from labml.utils.pytorch import get_modules\n", "from labml_nn.gan.cycle_gan import Configs" ], "execution_count": 2, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "Lpggo0wM6qb-" }, "source": [ "Create an experiment" ] }, { "cell_type": "code", "metadata": { "id": "bFcr9k-l4cAg" }, "source": [ "experiment.create(name=\"cycle_gan\")" ], "execution_count": 3, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "-OnHLi626tJt" }, "source": [ "Initialize configurations" ] }, { "cell_type": "code", "metadata": { "id": "Piz0c5f44hRo" }, "source": [ "conf = Configs()" ], "execution_count": 4, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "wwMzCqpD6vkL" }, "source": [ "Set experiment configurations and assign a configurations dictionary to override configurations" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 17 }, "id": "e6hmQhTw4nks", "outputId": "4be767af-0ebd-4c35-8da0-0e532495e037" }, "source": [ "experiment.configs(conf, {'dataset_name': 'summer2winter_yosemite'})" ], "execution_count": 5, "outputs": [ { "output_type": "display_data", "data": { "text/html": [ "
" ], "text/plain": [ "Prepare device...\n",
              "  Prepare device_info...[DONE]\t60.96ms\n",
              "Prepare device...[DONE]\t65.80ms\n",
              "Download...[DONE]\t21,670.04ms\n",
              ""
            ],
            "text/plain": [
              "\n",
              "cycle_gan: 93b11a665d6811ebaac80242ac1c0002\n",
              "\t[dirty]: \"\"\n",
              "\n",
              "--------------------------------------------------\n",
              "LABML WARNING\n",
              "LabML App Warning: empty_token: Please create a valid token at https://web.lab-ml.com.\n",
              "Click on the experiment link to monitor the experiment and add it to your experiments list.\n",
              "--------------------------------------------------\n",
              "Monitor experiment at https://web.lab-ml.com/run?uuid=93b11a665d6811ebaac80242ac1c0002\n",
              "     646:  Train:  52%   884,952ms   loss.generator:  7.01736 loss.generator.cycle: 0.455202 loss.generator.gan: 0.530470 loss.generator.identity: 0.386975 loss.discriminator:  1.06013  884,952ms  0:07m/ 49:02m  "
            ],
            "text/plain": [
              "