From a84179c49da4edf661b4a2dd5c2b5a74743bcefc Mon Sep 17 00:00:00 2001 From: Matthew Fisher <11fishem@gmail.com> Date: Wed, 7 Apr 2021 17:11:39 -0600 Subject: [PATCH 1/3] Corrected typos for dropdown in notebook Some of the names were mispelled, so I corrected the typos --- .../mapper_playground-checkpoint.ipynb | 284 ++++++++++++++++++ notebooks/mapper_playground.ipynb | 191 ++++++------ 2 files changed, 385 insertions(+), 90 deletions(-) create mode 100644 notebooks/.ipynb_checkpoints/mapper_playground-checkpoint.ipynb diff --git a/notebooks/.ipynb_checkpoints/mapper_playground-checkpoint.ipynb b/notebooks/.ipynb_checkpoints/mapper_playground-checkpoint.ipynb new file mode 100644 index 0000000..400b6d2 --- /dev/null +++ b/notebooks/.ipynb_checkpoints/mapper_playground-checkpoint.ipynb @@ -0,0 +1,284 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "IncTbhtkAEvy" + }, + "source": [ + "# Text-Guided Editing of Images (Using CLIP and StyleGAN)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "E4Whhw8pZYtg", + "outputId": "872c1c09-7680-4706-eb4c-738697ac4a33" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cloning into 'StyleCLIP_encoder'...\n", + "remote: Enumerating objects: 283, done.\u001b[K\n", + "remote: Counting objects: 100% (283/283), done.\u001b[K\n", + "remote: Compressing objects: 100% (245/245), done.\u001b[K\n", + "remote: Total 283 (delta 60), reused 252 (delta 32), pack-reused 0\u001b[K\n", + "Receiving objects: 100% (283/283), 32.07 MiB | 46.84 MiB/s, done.\n", + "Resolving deltas: 100% (60/60), done.\n", + "Collecting ftfy\n", + "\u001b[?25l Downloading https://files.pythonhosted.org/packages/04/06/e5c80e2e0f979628d47345efba51f7ba386fe95963b11c594209085f5a9b/ftfy-5.9.tar.gz (66kB)\n", + "\u001b[K |████████████████████████████████| 71kB 6.4MB/s \n", + "\u001b[?25hRequirement already satisfied: regex in /usr/local/lib/python3.7/dist-packages (2019.12.20)\n", + "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (4.41.1)\n", + "Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from ftfy) (0.2.5)\n", + "Building wheels for collected packages: ftfy\n", + " Building wheel for ftfy (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for ftfy: filename=ftfy-5.9-cp37-none-any.whl size=46451 sha256=e683f29e406a1cf82dd291064a285d9db2d4d54cddd11588b681fe38aa250203\n", + " Stored in directory: /root/.cache/pip/wheels/5e/2e/f0/b07196e8c929114998f0316894a61c752b63bfa3fdd50d2fc3\n", + "Successfully built ftfy\n", + "Installing collected packages: ftfy\n", + "Successfully installed ftfy-5.9\n", + "Collecting git+https://github.com/openai/CLIP.git\n", + " Cloning https://github.com/openai/CLIP.git to /tmp/pip-req-build-0pncp513\n", + " Running command git clone -q https://github.com/openai/CLIP.git /tmp/pip-req-build-0pncp513\n", + "Requirement already satisfied: ftfy in /usr/local/lib/python3.7/dist-packages (from clip==1.0) (5.9)\n", + "Requirement already satisfied: regex in /usr/local/lib/python3.7/dist-packages (from clip==1.0) (2019.12.20)\n", + "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from clip==1.0) (4.41.1)\n", + "Collecting torch~=1.7.1\n", + "\u001b[?25l Downloading https://files.pythonhosted.org/packages/90/5d/095ddddc91c8a769a68c791c019c5793f9c4456a688ddd235d6670924ecb/torch-1.7.1-cp37-cp37m-manylinux1_x86_64.whl (776.8MB)\n", + "\u001b[K |████████████████████████████████| 776.8MB 22kB/s \n", + "\u001b[33mWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/torchvision/\u001b[0m\n", + "\u001b[?25hCollecting torchvision~=0.8.2\n", + "\u001b[?25l Downloading https://files.pythonhosted.org/packages/94/df/969e69a94cff1c8911acb0688117f95e1915becc1e01c73e7960a2c76ec8/torchvision-0.8.2-cp37-cp37m-manylinux1_x86_64.whl (12.8MB)\n", + "\u001b[K |████████████████████████████████| 12.8MB 239kB/s \n", + "\u001b[?25hRequirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from ftfy->clip==1.0) (0.2.5)\n", + "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torch~=1.7.1->clip==1.0) (1.19.5)\n", + "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch~=1.7.1->clip==1.0) (3.7.4.3)\n", + "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.7/dist-packages (from torchvision~=0.8.2->clip==1.0) (7.1.2)\n", + "Building wheels for collected packages: clip\n", + " Building wheel for clip (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for clip: filename=clip-1.0-cp37-none-any.whl size=1368708 sha256=7ef643f86dbddfc35725e71d3eee8c0ba192afe4a1d4e2c812f375517fb6aef1\n", + " Stored in directory: /tmp/pip-ephem-wheel-cache-5vsnh608/wheels/79/51/d7/69f91d37121befe21d9c52332e04f592e17d1cabc7319b3e09\n", + "Successfully built clip\n", + "\u001b[31mERROR: torchtext 0.9.1 has requirement torch==1.8.1, but you'll have torch 1.7.1 which is incompatible.\u001b[0m\n", + "Installing collected packages: torch, torchvision, clip\n", + " Found existing installation: torch 1.8.1+cu101\n", + " Uninstalling torch-1.8.1+cu101:\n", + " Successfully uninstalled torch-1.8.1+cu101\n", + " Found existing installation: torchvision 0.9.1+cu101\n", + " Uninstalling torchvision-0.9.1+cu101:\n", + " Successfully uninstalled torchvision-0.9.1+cu101\n", + "Successfully installed clip-1.0 torch-1.7.1 torchvision-0.8.2\n" + ] + } + ], + "source": [ + "!git clone https://@github.com/orpatashnik/StyleCLIP.git\n", + "\n", + "import os\n", + "os.chdir(f'./StyleCLIP')\n", + "\n", + "!pip install ftfy regex tqdm\n", + "!pip install git+https://github.com/openai/CLIP.git" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "VPrB9xDGaaMP" + }, + "outputs": [], + "source": [ + "from utils import ensure_checkpoint_exists\n", + "from mapper.scripts.inference import run" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jysy8MjiCco8" + }, + "source": [ + "We provide several pretrained mappers. We also provide sample latent codes, of 6 celebs. 'n_images' allows to choose the number of latent codes (from the path provided in 'latent_path') that will be edited. If n_images is None then all the latent codes will be edited." + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "cellView": "form", + "id": "ixBiRP0s6Lxy" + }, + "outputs": [], + "source": [ + "meta_data = {\n", + " 'afro': ['afro', False, False, True], \n", + " 'angry': ['angry', False, False, True], \n", + " 'Beyonce': ['beyonce', False, False, False], \n", + " 'bobcut': ['bobcut', False, False, True], \n", + " 'bowlcut': ['bowlcut', False, False, True], \n", + " 'curly hair': ['curly_hair', False, False, True], \n", + " 'Hillary Clinton': ['hillary_clinton', False, False, False],\n", + " 'Johnny Depp': ['depp', False, False, False], \n", + " 'mohawk': ['mohawk', False, False, True],\n", + " 'purple hair': ['purple_hair', False, False, False], \n", + " 'surprised': ['surprised', False, False, True], \n", + " 'Taylor Swift': ['taylor_swift', False, False, False],\n", + " 'trump': ['trump', False, False, False], \n", + " 'Mark Zuckerberg': ['zuckerberg', False, False, False] \n", + "}\n", + "\n", + "edit_type = 'surprised' #@param ['afro', 'angry', 'Beyonce', 'bobcut', 'bowlcut', 'curly hair', 'Hilary Clinton', 'Jhonny Depp', 'mohawk', 'purple hair', 'surprised', 'Taylor Swift', 'trump', 'Mark Zuckerberg']\n", + "edit_id = meta_data[edit_type][0]\n", + "os.makedirs(\"mapper/pretrained\", exist_ok=True)\n", + "ensure_checkpoint_exists(f\"mapper/pretrained/{edit_id}.pt\")\n", + "latent_path = \"example_celebs.pt\" #@param {type:\"string\"}\n", + "if latent_path == \"example_celebs.pt\":\n", + " ensure_checkpoint_exists(\"example_celebs.pt\")\n", + "n_images = 1#@param\n", + "\n", + "args = {\n", + " \"exp_dir\": \"results/\",\n", + " \"checkpoint_path\": f\"mapper/pretrained/{edit_id}.pt\",\n", + " \"couple_outputs\": True,\n", + " \"mapper_type\": \"LevelsMapper\",\n", + " \"no_coarse_mapper\": meta_data[edit_type][1],\n", + " \"no_medium_mapper\": meta_data[edit_type][2],\n", + " \"no_fine_mapper\": meta_data[edit_type][3],\n", + " \"stylegan_size\": 1024,\n", + " \"test_batch_size\": 1,\n", + " \"latents_test_path\": latent_path,\n", + " \"test_workers\": 1,\n", + " \"n_images\": n_images\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "3g6eiXsMdYf5", + "outputId": "706791ac-afdb-4a0a-df70-7de0644d81ba" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\r", + " 0%| | 0/6 [00:00" + ] + }, + "execution_count": 47, + "metadata": { + "tags": [] + }, + "output_type": "execute_result" + } + ], + "source": [ + "from PIL import Image\n", + "result = Image.open(f\"results/inference_results/00000.jpg\")\n", + "result = result.resize((int(result.width * 0.5), int(result.height * 0.5)))\n", + "grid = Image.new(\"RGB\", (result.width, result.height * n_images))\n", + "grid.paste(result, (0, 0))\n", + "for i in range(1, n_images):\n", + " result = Image.open(f\"results/inference_results/{str(i).zfill(5)}.jpg\")\n", + " result = result.resize((int(result.width * 0.5), int(result.height * 0.5)))\n", + " grid.paste(result, (0, int(result.height * i)))\n", + "grid" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "collapsed_sections": [], + "name": "mapper_playground.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/notebooks/mapper_playground.ipynb b/notebooks/mapper_playground.ipynb index 416c851..400b6d2 100644 --- a/notebooks/mapper_playground.ipynb +++ b/notebooks/mapper_playground.ipynb @@ -1,22 +1,4 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "accelerator": "GPU", - "colab": { - "name": "mapper_playground.ipynb", - "provenance": [], - "collapsed_sections": [], - "toc_visible": true - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" - } - }, "cells": [ { "cell_type": "markdown", @@ -29,6 +11,7 @@ }, { "cell_type": "code", + "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -36,35 +19,26 @@ "id": "E4Whhw8pZYtg", "outputId": "872c1c09-7680-4706-eb4c-738697ac4a33" }, - "source": [ - "!git clone https://@github.com/orpatashnik/StyleCLIP.git\n", - "\n", - "import os\n", - "os.chdir(f'./StyleCLIP')\n", - "\n", - "!pip install ftfy regex tqdm\n", - "!pip install git+https://github.com/openai/CLIP.git" - ], - "execution_count": 1, "outputs": [ { + "name": "stdout", "output_type": "stream", "text": [ "Cloning into 'StyleCLIP_encoder'...\n", - "remote: Enumerating objects: 283, done.\u001B[K\n", - "remote: Counting objects: 100% (283/283), done.\u001B[K\n", - "remote: Compressing objects: 100% (245/245), done.\u001B[K\n", - "remote: Total 283 (delta 60), reused 252 (delta 32), pack-reused 0\u001B[K\n", + "remote: Enumerating objects: 283, done.\u001b[K\n", + "remote: Counting objects: 100% (283/283), done.\u001b[K\n", + "remote: Compressing objects: 100% (245/245), done.\u001b[K\n", + "remote: Total 283 (delta 60), reused 252 (delta 32), pack-reused 0\u001b[K\n", "Receiving objects: 100% (283/283), 32.07 MiB | 46.84 MiB/s, done.\n", "Resolving deltas: 100% (60/60), done.\n", "Collecting ftfy\n", - "\u001B[?25l Downloading https://files.pythonhosted.org/packages/04/06/e5c80e2e0f979628d47345efba51f7ba386fe95963b11c594209085f5a9b/ftfy-5.9.tar.gz (66kB)\n", - "\u001B[K |████████████████████████████████| 71kB 6.4MB/s \n", - "\u001B[?25hRequirement already satisfied: regex in /usr/local/lib/python3.7/dist-packages (2019.12.20)\n", + "\u001b[?25l Downloading https://files.pythonhosted.org/packages/04/06/e5c80e2e0f979628d47345efba51f7ba386fe95963b11c594209085f5a9b/ftfy-5.9.tar.gz (66kB)\n", + "\u001b[K |████████████████████████████████| 71kB 6.4MB/s \n", + "\u001b[?25hRequirement already satisfied: regex in /usr/local/lib/python3.7/dist-packages (2019.12.20)\n", "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (4.41.1)\n", "Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from ftfy) (0.2.5)\n", "Building wheels for collected packages: ftfy\n", - " Building wheel for ftfy (setup.py) ... \u001B[?25l\u001B[?25hdone\n", + " Building wheel for ftfy (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for ftfy: filename=ftfy-5.9-cp37-none-any.whl size=46451 sha256=e683f29e406a1cf82dd291064a285d9db2d4d54cddd11588b681fe38aa250203\n", " Stored in directory: /root/.cache/pip/wheels/5e/2e/f0/b07196e8c929114998f0316894a61c752b63bfa3fdd50d2fc3\n", "Successfully built ftfy\n", @@ -77,22 +51,22 @@ "Requirement already satisfied: regex in /usr/local/lib/python3.7/dist-packages (from clip==1.0) (2019.12.20)\n", "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from clip==1.0) (4.41.1)\n", "Collecting torch~=1.7.1\n", - "\u001B[?25l Downloading https://files.pythonhosted.org/packages/90/5d/095ddddc91c8a769a68c791c019c5793f9c4456a688ddd235d6670924ecb/torch-1.7.1-cp37-cp37m-manylinux1_x86_64.whl (776.8MB)\n", - "\u001B[K |████████████████████████████████| 776.8MB 22kB/s \n", - "\u001B[33mWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/torchvision/\u001B[0m\n", - "\u001B[?25hCollecting torchvision~=0.8.2\n", - "\u001B[?25l Downloading https://files.pythonhosted.org/packages/94/df/969e69a94cff1c8911acb0688117f95e1915becc1e01c73e7960a2c76ec8/torchvision-0.8.2-cp37-cp37m-manylinux1_x86_64.whl (12.8MB)\n", - "\u001B[K |████████████████████████████████| 12.8MB 239kB/s \n", - "\u001B[?25hRequirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from ftfy->clip==1.0) (0.2.5)\n", + "\u001b[?25l Downloading https://files.pythonhosted.org/packages/90/5d/095ddddc91c8a769a68c791c019c5793f9c4456a688ddd235d6670924ecb/torch-1.7.1-cp37-cp37m-manylinux1_x86_64.whl (776.8MB)\n", + "\u001b[K |████████████████████████████████| 776.8MB 22kB/s \n", + "\u001b[33mWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/torchvision/\u001b[0m\n", + "\u001b[?25hCollecting torchvision~=0.8.2\n", + "\u001b[?25l Downloading https://files.pythonhosted.org/packages/94/df/969e69a94cff1c8911acb0688117f95e1915becc1e01c73e7960a2c76ec8/torchvision-0.8.2-cp37-cp37m-manylinux1_x86_64.whl (12.8MB)\n", + "\u001b[K |████████████████████████████████| 12.8MB 239kB/s \n", + "\u001b[?25hRequirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from ftfy->clip==1.0) (0.2.5)\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torch~=1.7.1->clip==1.0) (1.19.5)\n", "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch~=1.7.1->clip==1.0) (3.7.4.3)\n", "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.7/dist-packages (from torchvision~=0.8.2->clip==1.0) (7.1.2)\n", "Building wheels for collected packages: clip\n", - " Building wheel for clip (setup.py) ... \u001B[?25l\u001B[?25hdone\n", + " Building wheel for clip (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for clip: filename=clip-1.0-cp37-none-any.whl size=1368708 sha256=7ef643f86dbddfc35725e71d3eee8c0ba192afe4a1d4e2c812f375517fb6aef1\n", " Stored in directory: /tmp/pip-ephem-wheel-cache-5vsnh608/wheels/79/51/d7/69f91d37121befe21d9c52332e04f592e17d1cabc7319b3e09\n", "Successfully built clip\n", - "\u001B[31mERROR: torchtext 0.9.1 has requirement torch==1.8.1, but you'll have torch 1.7.1 which is incompatible.\u001B[0m\n", + "\u001b[31mERROR: torchtext 0.9.1 has requirement torch==1.8.1, but you'll have torch 1.7.1 which is incompatible.\u001b[0m\n", "Installing collected packages: torch, torchvision, clip\n", " Found existing installation: torch 1.8.1+cu101\n", " Uninstalling torch-1.8.1+cu101:\n", @@ -101,22 +75,30 @@ " Uninstalling torchvision-0.9.1+cu101:\n", " Successfully uninstalled torchvision-0.9.1+cu101\n", "Successfully installed clip-1.0 torch-1.7.1 torchvision-0.8.2\n" - ], - "name": "stdout" + ] } + ], + "source": [ + "!git clone https://@github.com/orpatashnik/StyleCLIP.git\n", + "\n", + "import os\n", + "os.chdir(f'./StyleCLIP')\n", + "\n", + "!pip install ftfy regex tqdm\n", + "!pip install git+https://github.com/openai/CLIP.git" ] }, { "cell_type": "code", + "execution_count": 2, "metadata": { "id": "VPrB9xDGaaMP" }, + "outputs": [], "source": [ "from utils import ensure_checkpoint_exists\n", "from mapper.scripts.inference import run" - ], - "execution_count": 2, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -129,10 +111,12 @@ }, { "cell_type": "code", + "execution_count": 45, "metadata": { - "id": "ixBiRP0s6Lxy", - "cellView": "form" + "cellView": "form", + "id": "ixBiRP0s6Lxy" }, + "outputs": [], "source": [ "meta_data = {\n", " 'afro': ['afro', False, False, True], \n", @@ -141,8 +125,8 @@ " 'bobcut': ['bobcut', False, False, True], \n", " 'bowlcut': ['bowlcut', False, False, True], \n", " 'curly hair': ['curly_hair', False, False, True], \n", - " 'Hilary Clinton': ['hilary_clinton', False, False, False],\n", - " 'Jhonny Depp': ['depp', False, False, False], \n", + " 'Hillary Clinton': ['hillary_clinton', False, False, False],\n", + " 'Johnny Depp': ['depp', False, False, False], \n", " 'mohawk': ['mohawk', False, False, True],\n", " 'purple hair': ['purple_hair', False, False, False], \n", " 'surprised': ['surprised', False, False, True], \n", @@ -174,12 +158,11 @@ " \"test_workers\": 1,\n", " \"n_images\": n_images\n", "}\n" - ], - "execution_count": 45, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": 46, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -187,51 +170,52 @@ "id": "3g6eiXsMdYf5", "outputId": "706791ac-afdb-4a0a-df70-7de0644d81ba" }, - "source": [ - "from argparse import Namespace\n", - "run(Namespace(**args))" - ], - "execution_count": 46, "outputs": [ { + "name": "stderr", "output_type": "stream", "text": [ - "\r 0%| | 0/6 [00:00" ] }, + "execution_count": 47, "metadata": { "tags": [] }, - "execution_count": 47 + "output_type": "execute_result" } + ], + "source": [ + "from PIL import Image\n", + "result = Image.open(f\"results/inference_results/00000.jpg\")\n", + "result = result.resize((int(result.width * 0.5), int(result.height * 0.5)))\n", + "grid = Image.new(\"RGB\", (result.width, result.height * n_images))\n", + "grid.paste(result, (0, 0))\n", + "for i in range(1, n_images):\n", + " result = Image.open(f\"results/inference_results/{str(i).zfill(5)}.jpg\")\n", + " result = result.resize((int(result.width * 0.5), int(result.height * 0.5)))\n", + " grid.paste(result, (0, int(result.height * i)))\n", + "grid" ] } - ] -} \ No newline at end of file + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "collapsed_sections": [], + "name": "mapper_playground.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} From e1fdb00974f53d3158353c6534d48f977f10959e Mon Sep 17 00:00:00 2001 From: Matthew Fisher <11fishem@gmail.com> Date: Wed, 7 Apr 2021 17:19:39 -0600 Subject: [PATCH 2/3] Standardized celebrity names and ordered alphabetically by category Categories sorted by Hair, Emotion, then Celebrity, within those categories sorted alphabetically --- notebooks/mapper_playground.ipynb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/notebooks/mapper_playground.ipynb b/notebooks/mapper_playground.ipynb index 400b6d2..dc879ef 100644 --- a/notebooks/mapper_playground.ipynb +++ b/notebooks/mapper_playground.ipynb @@ -119,23 +119,23 @@ "outputs": [], "source": [ "meta_data = {\n", - " 'afro': ['afro', False, False, True], \n", - " 'angry': ['angry', False, False, True], \n", - " 'Beyonce': ['beyonce', False, False, False], \n", - " 'bobcut': ['bobcut', False, False, True], \n", - " 'bowlcut': ['bowlcut', False, False, True], \n", - " 'curly hair': ['curly_hair', False, False, True], \n", - " 'Hillary Clinton': ['hillary_clinton', False, False, False],\n", - " 'Johnny Depp': ['depp', False, False, False], \n", - " 'mohawk': ['mohawk', False, False, True],\n", - " 'purple hair': ['purple_hair', False, False, False], \n", - " 'surprised': ['surprised', False, False, True], \n", - " 'Taylor Swift': ['taylor_swift', False, False, False],\n", - " 'trump': ['trump', False, False, False], \n", - " 'Mark Zuckerberg': ['zuckerberg', False, False, False] \n", + " 'afro': ['afro', False, False, True], \n", + " 'bobcut': ['bobcut', False, False, True], \n", + " 'bowlcut': ['bowlcut', False, False, True], \n", + " 'curly hair': ['curly_hair', False, False, True], \n", + " 'mohawk': ['mohawk', False, False, True],\n", + " 'purple hair': ['purple_hair', False, False, False],\n", + " 'angry': ['angry', False, False, True],\n", + " 'surprised': ['surprised', False, False, True],\n", + " 'Beyonce Knowles': ['beyonce', False, False, False],\n", + " 'Donald Trump': ['trump', False, False, False], \n", + " 'Hillary Clinton': ['hilary_clinton', False, False, False],\n", + " 'Johnny Depp': ['depp', False, False, False], \n", + " 'Mark Zuckerberg': ['zuckerberg', False, False, False],\n", + " 'Taylor Swift': ['taylor_swift', False, False, False],\n", "}\n", "\n", - "edit_type = 'surprised' #@param ['afro', 'angry', 'Beyonce', 'bobcut', 'bowlcut', 'curly hair', 'Hilary Clinton', 'Jhonny Depp', 'mohawk', 'purple hair', 'surprised', 'Taylor Swift', 'trump', 'Mark Zuckerberg']\n", + "edit_type = 'surprised' #@param ['afro', 'bobcut', 'bowlcut', 'curly hair', 'mohawk', 'purple hair', 'angry', 'surprised', 'Beyonce Knowles', 'Donald Trump', 'Hillary Clinton', 'Johnny Depp', 'Mark Zuckerberg', 'Taylor Swift']\n", "edit_id = meta_data[edit_type][0]\n", "os.makedirs(\"mapper/pretrained\", exist_ok=True)\n", "ensure_checkpoint_exists(f\"mapper/pretrained/{edit_id}.pt\")\n", From 197fa5485f430db27feb9600924481bcb74fe5b6 Mon Sep 17 00:00:00 2001 From: Matthew Allen Fisher <11fishem@gmail.com> Date: Fri, 9 Apr 2021 07:52:27 +0900 Subject: [PATCH 3/3] Delete generated checkpoint file This checkpoint file was generated while testing the notebook changes, and was committed unecessarily --- .../mapper_playground-checkpoint.ipynb | 284 ------------------ 1 file changed, 284 deletions(-) delete mode 100644 notebooks/.ipynb_checkpoints/mapper_playground-checkpoint.ipynb diff --git a/notebooks/.ipynb_checkpoints/mapper_playground-checkpoint.ipynb b/notebooks/.ipynb_checkpoints/mapper_playground-checkpoint.ipynb deleted file mode 100644 index 400b6d2..0000000 --- a/notebooks/.ipynb_checkpoints/mapper_playground-checkpoint.ipynb +++ /dev/null @@ -1,284 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "IncTbhtkAEvy" - }, - "source": [ - "# Text-Guided Editing of Images (Using CLIP and StyleGAN)" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "E4Whhw8pZYtg", - "outputId": "872c1c09-7680-4706-eb4c-738697ac4a33" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Cloning into 'StyleCLIP_encoder'...\n", - "remote: Enumerating objects: 283, done.\u001b[K\n", - "remote: Counting objects: 100% (283/283), done.\u001b[K\n", - "remote: Compressing objects: 100% (245/245), done.\u001b[K\n", - "remote: Total 283 (delta 60), reused 252 (delta 32), pack-reused 0\u001b[K\n", - "Receiving objects: 100% (283/283), 32.07 MiB | 46.84 MiB/s, done.\n", - "Resolving deltas: 100% (60/60), done.\n", - "Collecting ftfy\n", - "\u001b[?25l Downloading https://files.pythonhosted.org/packages/04/06/e5c80e2e0f979628d47345efba51f7ba386fe95963b11c594209085f5a9b/ftfy-5.9.tar.gz (66kB)\n", - "\u001b[K |████████████████████████████████| 71kB 6.4MB/s \n", - "\u001b[?25hRequirement already satisfied: regex in /usr/local/lib/python3.7/dist-packages (2019.12.20)\n", - "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (4.41.1)\n", - "Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from ftfy) (0.2.5)\n", - "Building wheels for collected packages: ftfy\n", - " Building wheel for ftfy (setup.py) ... \u001b[?25l\u001b[?25hdone\n", - " Created wheel for ftfy: filename=ftfy-5.9-cp37-none-any.whl size=46451 sha256=e683f29e406a1cf82dd291064a285d9db2d4d54cddd11588b681fe38aa250203\n", - " Stored in directory: /root/.cache/pip/wheels/5e/2e/f0/b07196e8c929114998f0316894a61c752b63bfa3fdd50d2fc3\n", - "Successfully built ftfy\n", - "Installing collected packages: ftfy\n", - "Successfully installed ftfy-5.9\n", - "Collecting git+https://github.com/openai/CLIP.git\n", - " Cloning https://github.com/openai/CLIP.git to /tmp/pip-req-build-0pncp513\n", - " Running command git clone -q https://github.com/openai/CLIP.git /tmp/pip-req-build-0pncp513\n", - "Requirement already satisfied: ftfy in /usr/local/lib/python3.7/dist-packages (from clip==1.0) (5.9)\n", - "Requirement already satisfied: regex in /usr/local/lib/python3.7/dist-packages (from clip==1.0) (2019.12.20)\n", - "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from clip==1.0) (4.41.1)\n", - "Collecting torch~=1.7.1\n", - "\u001b[?25l Downloading https://files.pythonhosted.org/packages/90/5d/095ddddc91c8a769a68c791c019c5793f9c4456a688ddd235d6670924ecb/torch-1.7.1-cp37-cp37m-manylinux1_x86_64.whl (776.8MB)\n", - "\u001b[K |████████████████████████████████| 776.8MB 22kB/s \n", - "\u001b[33mWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/torchvision/\u001b[0m\n", - "\u001b[?25hCollecting torchvision~=0.8.2\n", - "\u001b[?25l Downloading https://files.pythonhosted.org/packages/94/df/969e69a94cff1c8911acb0688117f95e1915becc1e01c73e7960a2c76ec8/torchvision-0.8.2-cp37-cp37m-manylinux1_x86_64.whl (12.8MB)\n", - "\u001b[K |████████████████████████████████| 12.8MB 239kB/s \n", - "\u001b[?25hRequirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from ftfy->clip==1.0) (0.2.5)\n", - "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torch~=1.7.1->clip==1.0) (1.19.5)\n", - "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch~=1.7.1->clip==1.0) (3.7.4.3)\n", - "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.7/dist-packages (from torchvision~=0.8.2->clip==1.0) (7.1.2)\n", - "Building wheels for collected packages: clip\n", - " Building wheel for clip (setup.py) ... \u001b[?25l\u001b[?25hdone\n", - " Created wheel for clip: filename=clip-1.0-cp37-none-any.whl size=1368708 sha256=7ef643f86dbddfc35725e71d3eee8c0ba192afe4a1d4e2c812f375517fb6aef1\n", - " Stored in directory: /tmp/pip-ephem-wheel-cache-5vsnh608/wheels/79/51/d7/69f91d37121befe21d9c52332e04f592e17d1cabc7319b3e09\n", - "Successfully built clip\n", - "\u001b[31mERROR: torchtext 0.9.1 has requirement torch==1.8.1, but you'll have torch 1.7.1 which is incompatible.\u001b[0m\n", - "Installing collected packages: torch, torchvision, clip\n", - " Found existing installation: torch 1.8.1+cu101\n", - " Uninstalling torch-1.8.1+cu101:\n", - " Successfully uninstalled torch-1.8.1+cu101\n", - " Found existing installation: torchvision 0.9.1+cu101\n", - " Uninstalling torchvision-0.9.1+cu101:\n", - " Successfully uninstalled torchvision-0.9.1+cu101\n", - "Successfully installed clip-1.0 torch-1.7.1 torchvision-0.8.2\n" - ] - } - ], - "source": [ - "!git clone https://@github.com/orpatashnik/StyleCLIP.git\n", - "\n", - "import os\n", - "os.chdir(f'./StyleCLIP')\n", - "\n", - "!pip install ftfy regex tqdm\n", - "!pip install git+https://github.com/openai/CLIP.git" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "id": "VPrB9xDGaaMP" - }, - "outputs": [], - "source": [ - "from utils import ensure_checkpoint_exists\n", - "from mapper.scripts.inference import run" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "jysy8MjiCco8" - }, - "source": [ - "We provide several pretrained mappers. We also provide sample latent codes, of 6 celebs. 'n_images' allows to choose the number of latent codes (from the path provided in 'latent_path') that will be edited. If n_images is None then all the latent codes will be edited." - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": { - "cellView": "form", - "id": "ixBiRP0s6Lxy" - }, - "outputs": [], - "source": [ - "meta_data = {\n", - " 'afro': ['afro', False, False, True], \n", - " 'angry': ['angry', False, False, True], \n", - " 'Beyonce': ['beyonce', False, False, False], \n", - " 'bobcut': ['bobcut', False, False, True], \n", - " 'bowlcut': ['bowlcut', False, False, True], \n", - " 'curly hair': ['curly_hair', False, False, True], \n", - " 'Hillary Clinton': ['hillary_clinton', False, False, False],\n", - " 'Johnny Depp': ['depp', False, False, False], \n", - " 'mohawk': ['mohawk', False, False, True],\n", - " 'purple hair': ['purple_hair', False, False, False], \n", - " 'surprised': ['surprised', False, False, True], \n", - " 'Taylor Swift': ['taylor_swift', False, False, False],\n", - " 'trump': ['trump', False, False, False], \n", - " 'Mark Zuckerberg': ['zuckerberg', False, False, False] \n", - "}\n", - "\n", - "edit_type = 'surprised' #@param ['afro', 'angry', 'Beyonce', 'bobcut', 'bowlcut', 'curly hair', 'Hilary Clinton', 'Jhonny Depp', 'mohawk', 'purple hair', 'surprised', 'Taylor Swift', 'trump', 'Mark Zuckerberg']\n", - "edit_id = meta_data[edit_type][0]\n", - "os.makedirs(\"mapper/pretrained\", exist_ok=True)\n", - "ensure_checkpoint_exists(f\"mapper/pretrained/{edit_id}.pt\")\n", - "latent_path = \"example_celebs.pt\" #@param {type:\"string\"}\n", - "if latent_path == \"example_celebs.pt\":\n", - " ensure_checkpoint_exists(\"example_celebs.pt\")\n", - "n_images = 1#@param\n", - "\n", - "args = {\n", - " \"exp_dir\": \"results/\",\n", - " \"checkpoint_path\": f\"mapper/pretrained/{edit_id}.pt\",\n", - " \"couple_outputs\": True,\n", - " \"mapper_type\": \"LevelsMapper\",\n", - " \"no_coarse_mapper\": meta_data[edit_type][1],\n", - " \"no_medium_mapper\": meta_data[edit_type][2],\n", - " \"no_fine_mapper\": meta_data[edit_type][3],\n", - " \"stylegan_size\": 1024,\n", - " \"test_batch_size\": 1,\n", - " \"latents_test_path\": latent_path,\n", - " \"test_workers\": 1,\n", - " \"n_images\": n_images\n", - "}\n" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "3g6eiXsMdYf5", - "outputId": "706791ac-afdb-4a0a-df70-7de0644d81ba" - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\r", - " 0%| | 0/6 [00:00" - ] - }, - "execution_count": 47, - "metadata": { - "tags": [] - }, - "output_type": "execute_result" - } - ], - "source": [ - "from PIL import Image\n", - "result = Image.open(f\"results/inference_results/00000.jpg\")\n", - "result = result.resize((int(result.width * 0.5), int(result.height * 0.5)))\n", - "grid = Image.new(\"RGB\", (result.width, result.height * n_images))\n", - "grid.paste(result, (0, 0))\n", - "for i in range(1, n_images):\n", - " result = Image.open(f\"results/inference_results/{str(i).zfill(5)}.jpg\")\n", - " result = result.resize((int(result.width * 0.5), int(result.height * 0.5)))\n", - " grid.paste(result, (0, int(result.height * i)))\n", - "grid" - ] - } - ], - "metadata": { - "accelerator": "GPU", - "colab": { - "collapsed_sections": [], - "name": "mapper_playground.ipynb", - "provenance": [], - "toc_visible": true - }, - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.6" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -}