Computer_Vision/Chapter13/Customizing_StyleGAN2.ipynb

543 lines
2.6 MiB
Plaintext
Raw Normal View History

2024-02-13 03:34:51 +01:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/PacktPublishing/Hands-On-Computer-Vision-with-PyTorch/blob/master/Chapter13/Customizing_StyleGAN2.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 272
},
"id": "oAmCSXY6dv5W",
"outputId": "608aacb0-6c33-4f2e-aa12-1147bbf34279"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cloning into 'pytorch_stylegan_encoder'...\n",
"remote: Enumerating objects: 71, done.\u001b[K\n",
"remote: Counting objects: 100% (71/71), done.\u001b[K\n",
"remote: Compressing objects: 100% (64/64), done.\u001b[K\n",
"remote: Total 358 (delta 40), reused 15 (delta 6), pack-reused 287\u001b[K\n",
"Receiving objects: 100% (358/358), 56.89 MiB | 19.93 MiB/s, done.\n",
"Resolving deltas: 100% (179/179), done.\n",
"/content/pytorch_stylegan_encoder\n",
"Submodule 'InterFaceGAN' (git://github.com/ShenYujun/InterFaceGAN.git) registered for path 'InterFaceGAN'\n",
"Cloning into '/content/pytorch_stylegan_encoder/InterFaceGAN'...\n",
"Submodule path 'InterFaceGAN': checked out 'b707e942187f464251f855c92f7009b8cf13bf03'\n",
"\u001b[K |████████████████████████████████| 36.7MB 82kB/s \n",
"\u001b[K |████████████████████████████████| 61kB 9.6MB/s \n",
"\u001b[K |████████████████████████████████| 102kB 13.9MB/s \n",
"\u001b[?25h Building wheel for contextvars (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
]
}
],
"source": [
"import os\n",
"if not os.path.exists('pytorch_stylegan_encoder'):\n",
" !git clone https://github.com/jacobhallberg/pytorch_stylegan_encoder.git\n",
" %cd pytorch_stylegan_encoder\n",
" !git submodule update --init --recursive\n",
" !wget -q https://github.com/jacobhallberg/pytorch_stylegan_encoder/releases/download/v1.0/trained_models.zip\n",
" !unzip -q trained_models.zip\n",
" !rm trained_models.zip\n",
" !pip install -qU torch_snippets\n",
" !mv trained_models/stylegan_ffhq.pth InterFaceGAN/models/pretrain\n",
"else:\n",
" %cd pytorch_stylegan_encoder\n",
" \n",
"from torch_snippets import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 170
},
"id": "PhzYGPEId3F-",
"outputId": "f42c9b58-4ebb-4f22-8fd5-77965c62f9ca"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2020-10-13 05:39:11,237][INFO] Loading pytorch model from `InterFaceGAN/models/pretrain/stylegan_ffhq.pth`.\n",
"[2020-10-13 05:39:11,514][INFO] Successfully loaded!\n",
"[2020-10-13 05:39:11,516][INFO] `lod` of the loaded model is 0.0.\n",
"[2020-10-13 05:39:21,174][INFO] Loading pytorch model from `InterFaceGAN/models/pretrain/stylegan_ffhq.pth`.\n",
"[2020-10-13 05:39:21,438][INFO] Successfully loaded!\n",
"[2020-10-13 05:39:21,439][INFO] `lod` of the loaded model is 0.0.\n",
"[2020-10-13 05:39:21,693][INFO] Loading pytorch model from `InterFaceGAN/models/pretrain/stylegan_ffhq.pth`.\n",
"[2020-10-13 05:39:21,926][INFO] Successfully loaded!\n",
"[2020-10-13 05:39:21,927][INFO] `lod` of the loaded model is 0.0.\n"
]
}
],
"source": [
"from InterFaceGAN.models.stylegan_generator import StyleGANGenerator\n",
"from models.latent_optimizer import PostSynthesisProcessing\n",
"\n",
"synthesizer = StyleGANGenerator(\"stylegan_ffhq\").model.synthesis\n",
"mapper = StyleGANGenerator(\"stylegan_ffhq\").model.mapping\n",
"trunc = StyleGANGenerator(\"stylegan_ffhq\").model.truncation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ULK2-BQId4sz"
},
"outputs": [],
"source": [
"post_processing = PostSynthesisProcessing()\n",
"post_process = lambda image: post_processing(image).detach().cpu().numpy().astype(np.uint8)[0]\n",
"\n",
"def latent2image(latent):\n",
" img = post_process(synthesizer(latent))\n",
" img = img.transpose(1,2,0)\n",
" return img"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 303
},
"id": "wRq8ykHtd6Tg",
"outputId": "dcf3adac-11a0-46e5-8e00-fad80b05ae3f"
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAR4AAAEeCAYAAABcyXrWAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9y45kSZKm94monpuZXyIiIzOrqovdNRdw+AB8BT4sF+QbECAXBAYguOGmF0P09LCnqruyMuPi7mbnoqoiXIiaR86C2UQ1UFwwTsAz3cM93O3oUf3ll19+ERd35+v19fp6fb3+kpf+f/0Cvl5fr6/X//+ur8Dz9fp6fb3+4tdX4Pl6fb2+Xn/x6yvwfL2+Xl+vv/j1FXi+Xl+vr9df/PoKPF+vr9fX6y9+5V/65H//P/4PniVzlIJZxd1orWDmmDkqCXNDVElpIOeEWOMoB1uFlEdO40BSx8wwBzOnueFmgONmOI6KowLgmMA/rgf/y+//A3/7w99hY0aWkXE88TB/z3/3u/+Wx3Xj3/9v/yv/18sH9hF4vOf87g3jMpOXhTwmnj5/5rJunB4eWe4eUYFiB5qgNqMWobUDlYYgIIoZuIN4w1vDakNFcSsYDVAUcFp8XA0rzpgVmuCujMsA5tRayJqYlwURwZqRG9xNC+8eHjmnAVxZ8sSb8cT3pzsel4lR4dwapwyanNagtoa1SnKjWaEZWHOq7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K1WWjNKaPRYLzioQCJYpZHAE+oF7KD01KgmOJIwSsjhK
"text/plain": [
"<Figure size 360x360 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light",
"tags": []
},
"output_type": "display_data"
}
],
"source": [
"rand_latents = torch.randn(1,512).cuda()\n",
"show(latent2image(trunc(mapper(rand_latents))), sz=5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 102
},
"id": "7dl5EIlieKvH",
"outputId": "f62b295f-4162-4b8b-99ab-0205a41277a7"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Cloning into 'stylegan-encoder'...\n",
"remote: Enumerating objects: 105, done.\u001b[K\n",
"remote: Total 105 (delta 0), reused 0 (delta 0), pack-reused 105\u001b[K\n",
"Receiving objects: 100% (105/105), 10.39 MiB | 10.51 MiB/s, done.\n",
"Resolving deltas: 100% (27/27), done.\n"
]
}
],
"source": [
"!wget -q https://www.dropbox.com/s/lpw10qawsc5ipbn/MyImage.JPG -O MyImage.jpg\n",
"!git clone https://github.com/sizhky/stylegan-encoder.git\n",
"!mkdir -p stylegan-encoder/raw_images\n",
"!mkdir -p stylegan-encoder/aligned_images\n",
"!mv MyImage.jpg stylegan-encoder/raw_images"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 88
},
"id": "8y0FhdnqenUn",
"outputId": "dfba1af1-8cba-4025-b457-cb6057cd7cf9"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-10-13 05:42:04.958242: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1\n",
"Downloading data from http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2\n",
"64045056/64040097 [==============================] - 38s 1us/step\n"
]
}
],
"source": [
"!python stylegan-encoder/align_images.py stylegan-encoder/raw_images/ stylegan-encoder/aligned_images/\n",
"!mv stylegan-encoder/aligned_images/* ./MyImage.jpg"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 596
},
"id": "lpfu5rONerWG",
"outputId": "8da553b8-6691-4ce6-d8d9-20914818da54"
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAAD3CAYAAADmIkO7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9SaxtyZrf9fsiYq219z7dvTdv9pmvXjWqkuVBDZAwAyQKiQHIAsEECQaWLJDASExA8gxkWUaCKRLgGUxoxAyMjMQAe0BjBrYRduHyq5evy7xd3nPvPefsbjXRMPgi1lp7n3OzeS+r3qviROa+e5+9VxMrIr7u/zUhKSXu2327b796zfyyO3Df7tt9u7vdE+d9u2+/ou2eOO/bffsVbffEed/u269ouyfO+3bffkXbPXHet/v2K9ruifNPSBORvy4i/8F3fezXXOf7IpJExP2i17pv377JvZ/zvr2ticj3gR8DVUrJ/3J78/+/di85/wQ0EbG/7D7ctz/+dk+cv8QmIn9GRP62iFyJyO+LyL+Uv/+vROS/EJG/KSJb4J/N3/212bl/WUSeichTEfk3s/r5W7Pz/1r+/Hsi8oWI/Psi8mU+5y/OrvPnReTvi8iNiHwuIn/lj3cU7tvb2j1x/pKaiFTA3wD+F+A94N8F/msR+Z18yL8O/EfAGfC/HZ37zwP/HvDPAb8F/N7X3O4D4AL4GPg3gP9MRB7m37bAXwAeAH8e+Esi8i//Is92376bdk+cv7z2TwGnwH+cUupTSv8r8D8B/1r+/X9IKf3vKaWYUmqPzv1Xgf8ypfT7KaUd8Fe+5l4D8FdTSkNK6W8CG+B3AFJKfzul9A/yff4f4L8F/pnv5Anv2y/U7onzl9c+Aj5PKcXZdz9FpRvA51937uzvrz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D56uH7J6OBD8kOctThIzRkJMI3EWwhWxGDFj3w1mXGfKMDPTzhLUWiElT0qepmnY7weW7QISDMNATAnjHI+XSy4ePGC32/D6zRtCCPTDgHM1q9UpZ+cX9L3n5eUrYky8994FxlpCDMQUkahCK6aYzQQ4zHs4bN9tbZiUJ+3WgptU3DLBE5Hqy/uBGCND3xNDMdbnisjXSc4JCJqrZHOpOQyqroaszobgFRwKnq7vCCGw2+9Y36x5eXnJy5eXXF9fs93u6buBru8Z+oCfLY4iNcu93tZuSSv9cPBdOe5tBHtMnAdE+pZR+ap+HF/jQBIWZvMW4szfohbeRLBmZnsOg+CdJQRHCC4zMYANUSJJLM3ylNVpoloYwJDQhRtjxIcBHwpwqMyQVPqpa0LNkIloY0qYTJxqYgrO6N9FOipZKrNW7VdAEj54tbeN4fr6hqqu6HsPPmDqihCh7XrWmzVt25JSwlU1IsJisaSqamJMdF3P6ekZZ2dnCDD0A3VVax9iWdtmXJdva9+AOIudOE3UnW38TblnzCjpONmj9JhLTUX4EMF7zzAM1HVNiH5aadkuePvCy8tyTrscSqiUIt4PbDZr2nZPVVWIJLUbgx/7cnNzw+XlK148f8HLL1/y6tUbdtsdbdvTd8rFBx8JMRKDvk+EpAs1pZk9xyHRzaXn8W/zv48/z787lrzH7Zj4vvb3IxNCMh9VaZoOzxtNkmms04w4jQgiBgkyIpIhKAofU1K71OSrGjCu4vR8z8MQy1UwxlBVDpFE8ANhUFBmyDa+DnVBdTJ+kKIy3CzpI4xgn2CwTkgGiEWDUkmWiKoBR5Vuxhj2+x1iDF3XUS8WtF1PEmhWK9re8/r1Fev1G0KMI8NqFg2npyc450gIy+VCnzMlfArEvqNZLDDWIglVbYnwR2VzFoBg/JzVhiIYpRBM4bz540iYxiDRqI1iz
"text/plain": [
"<Figure size 288x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light",
"tags": []
},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Optimizing Latents.\n",
"[2020-10-13 05:54:26,513][INFO] Loading pytorch model from `InterFaceGAN/models/pretrain/stylegan_ffhq.pth`.\n",
"[2020-10-13 05:54:26,773][INFO] Successfully loaded!\n",
"[2020-10-13 05:54:26,773][INFO] `lod` of the loaded model is 0.0.\n",
"Step: 2999, Loss: 1.732578992843628: 100% 3000/3000 [11:01<00:00, 4.53it/s]\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAAD3CAYAAADmIkO7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9W6x12bbX9Wu99zHmnOu71GXvXedCzjngMVwOPKAG8UFfjDcSow8KkQARjUZITOTFGBI0PIBCNCEgJARMADWEmKhRiYmBACZHHvDCgwgI5+y9q2pX1VffbV3nbYzee/Ohtd7HWF9V7Tq7zt5hI2skX9Vac405Lr331tq//duli6rycDwcD8cP3xH+Xj/Aw/FwPByffzwI58PxcPyQHg/C+XA8HD+kx4NwPhwPxw/p8SCcD8fD8UN6PAjnw/Fw/JAeD8L599EhIioi//D3+Zp/XET+w+/zNX+7iPzs9/Oa/yAe6e/1Azwcn3+IyF8B/mtV/S9+kPdR1d/xg7z+w/HVjwfL+XA8HD+kx4Nwfp8OEfkPROQjEbkVkf9XRH6LiBxE5Gurc/5REXkhIkODfiLyn4nIpYh8S0R+g5/3+4F/CvijInInIn90dat/RkT+rohcicgfExFZXf/fFJG/5df7X0Tkp/xzEZE/JCLPReRGRP5vEfk1/rc/LSK/z3/+n/x+7V8Vkd/uf/uVIvIXROS1v99vWt33ayLyP/q1/xrw0z+wgf4H6VDVh3+/yH/ArwA+BH7cf/+l2AL9n4HfuTrvDwH/uf/824EZ+LeBCPxO4GNA/O9/Bfi33riPAn8eeBv4SeAF8C/43/5l4OeAX4W5K78H+Kv+t38e+D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
},
"metadata": {
"needs_background": "light",
"tags": []
},
"output_type": "display_data"
}
],
"source": [
"from PIL import Image\n",
"img = Image.open('MyImage.jpg')\n",
"show(np.array(img), sz=4, title='original')\n",
"\n",
"!python encode_image.py ./MyImage.jpg\\\n",
" pred_dlatents_myImage.npy\\\n",
" --use_latent_finder true\\\n",
" --image_to_latent_path ./trained_models/image_to_latent.pt\n",
"\n",
"pred_dlatents = np.load('pred_dlatents_myImage.npy')\n",
"pred_dlatent = torch.from_numpy(pred_dlatents).float().cuda()\n",
"pred_image = latent2image(pred_dlatent)\n",
"show(pred_image, sz=4, title='synthesized')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 579
},
"id": "hbXD0Ud4e41X",
"outputId": "0283e6a4-e252-47f8-acc4-cf2fbef8f60a"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2020-10-13 06:13:42.436 | INFO | torch_snippets.loader:subplots:359 - plotting 4 images in a grid of 2x2 @ (7, 8)\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAfAAAAIhCAYAAACxJujxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9e8xv23rX9XnGGHP+fu/7rstee5+997m1pyetICBKI6bEREtDA6IkXoLcNEAt0vqHibFYbwFaBYyYBiGStBpsjVy0oE0AhTYFpEYiIgaj0IRQPfvsc/Zae93e6+8y5xxjPP7xjDHm/L17rX057Wm78fck71rv+/vNy5hjPOP5PvcpqsqRjnSkIx3pSEf6eJH7uR7AkY50pCMd6UhH+uh0BPAjHelIRzrSkT6GdATwIx3pSEc60pE+hnQE8CMd6UhHOtKRPoZ0BPAjHelIRzrSkT6GdATwIx3pSEc60pE+hnQE8C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CaQ3PhFFVKaiCkyDDsuzp/x5Om7nD8/Z7O5Ybcf2G633Nxs2G237HZ7hmFkHCJTjGiRF5ohZ0EcuHJtV/j99PSEBw/u8+Ybr/HgtQfcvXOHk9UK7x1OHF0XCMHjpMwfimbbN4LiHYgqKU2Muy3bzQ3nz57z6N0nPHz3KV/88rs8enzBMCWygjiHc46+86z7wNk6cLruWK86TrqOk1Vg3XX0wRH6QBc8oe/ovDc+8Y4ggdB7+nVPCB2h6whdT+gCoe/wYY3vOrzvcF2P8x2+6wndytZQXBEgHsQRQkfXdYRuReh6RBwiHnHOfsQhqmjBAl3gga1fLkutkE1WVuGkTQaDOJNrOStpilzdXPL2F9/i/
"text/plain": [
"<Figure size 504x576 with 4 Axes>"
]
},
"metadata": {
"needs_background": "light",
"tags": []
},
"output_type": "display_data"
}
],
"source": [
"idxs_to_swap = slice(0,3)\n",
"my_latents = torch.Tensor(np.load('pred_dlatents_myImage.npy', allow_pickle=True))\n",
"\n",
"A, B = latent2image(my_latents.cuda()), latent2image(trunc(mapper(rand_latents)))\n",
"generated_image_latents = trunc(mapper(rand_latents))\n",
"\n",
"x = my_latents.clone()\n",
"x[:,idxs_to_swap] = generated_image_latents[:,idxs_to_swap]\n",
"a = latent2image(x.float().cuda())\n",
"\n",
"x = generated_image_latents.clone()\n",
"x[:,idxs_to_swap] = my_latents[:,idxs_to_swap]\n",
"b = latent2image(x.float().cuda())\n",
"\n",
"subplots([A,a,B,b], figsize=(7,8), nc=2, suptitle='Transfer high level features')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"id": "SDB-69Idf53_",
"outputId": "9e2495c3-3518-4577-9476-c20d25540f16"
},
"outputs": [
{
"data": {
"text/plain": [
"slice(0, 2, None)"
]
},
"execution_count": 37,
"metadata": {
"tags": []
},
"output_type": "execute_result"
}
],
"source": [
"idxs_to_swap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 579
},
"id": "QmK_fDY7gAP7",
"outputId": "642c805c-0135-412b-d9d5-ab03be8b692d"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2020-10-13 06:13:52.663 | INFO | torch_snippets.loader:subplots:359 - plotting 4 images in a grid of 2x2 @ (7, 8)\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAfAAAAIhCAYAAACxJujxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9e6y1+3bX9Rm/3+95njnnWuu97Et7UmhrpF6KNEAiVI2xEJuIQGJNDCIxFgLh5iWoBIyNtFQblShaggGDSWsALxViEKKmIYpYtFGIVq0SSu0+t7332fu9rMu8PJffbwz/GL/nmXO9ffe7381pe7qPc+S8Z68113xuv8v4jvEdl0fMjLOc5SxnOctZzvLpkvCVvoGznOUsZznLWc7yyeUM4Gc5y1nOcpazfArlDOBnOctZznKWs3wK5QzgZznLWc5ylrN8CuUM4Gc5y1nOcpazfArlDOBnOctZznKWs3wK5QzgZznLa4qIfK2I/GURuRORf/crfT8/0yIi74jIt/8Mnu8fF5HPi8hWRH75z9R5z3KWs7ikr/QNnOUsryMisj35dQMMQKm//w4z+9M/B7fx24EnwAM7N1B4Hfl3gH/OzP7cl3siETHg7zCzv/nl39ZZzvLVIWcAP8unQszscv5ZRN4BfpuZ/cUXvyciyczyz9JtfCPwf/+tgPfPxH2JSDSz8vHf/LmVVzzbNwI//nN9Py+Tn69jd5azfDlyptDP8qkWEflVIvIFEfn9IvI+8AMi8lhE/oKIfCgiz+vPv/DkmL8kIv+6iPyVSof/sIi8Vf+2EpE/JSJPReRaRP7XSp3/IPCdwO+rlPC3i0gQkX9FRH6yfv+HROSNep6/TURMRH6riHw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": {
"needs_background": "light",
"tags": []
},
"output_type": "display_data"
}
],
"source": [
"idxs_to_swap = slice(4,15)\n",
"my_latents = torch.Tensor(np.load('pred_dlatents_myImage.npy', allow_pickle=True))\n",
"\n",
"A, B = latent2image(my_latents.cuda()), latent2image(trunc(mapper(rand_latents)))\n",
"generated_image_latents = trunc(mapper(rand_latents))\n",
"\n",
"x = my_latents.clone()\n",
"x[:,idxs_to_swap] = generated_image_latents[:,idxs_to_swap]\n",
"a = latent2image(x.float().cuda())\n",
"\n",
"x = generated_image_latents.clone()\n",
"x[:,idxs_to_swap] = my_latents[:,idxs_to_swap]\n",
"b = latent2image(x.float().cuda())\n",
"\n",
"subplots([A,a,B,b], figsize=(7,8), nc=2, suptitle='Transfer granular features')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 579
},
"id": "sm1_33A_kNtw",
"outputId": "0d914a49-b26a-4111-f37a-8776797aff2e"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2020-10-13 06:14:10.776 | INFO | torch_snippets.loader:subplots:359 - plotting 4 images in a grid of 2x2 @ (7, 8)\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAfAAAAIhCAYAAACxJujxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9faxt61rY9Xved4wx51z765zLx0UucAmgDRJIaVKpGgUj0RprSo3aaLSApQWNjUYqNRaVCi3aSFqUKtoKxEJqK9qE1tiQpqWNVqs1VaM1Srn3nLM/z9kfa6291ppzjjHe933843neMcZc5+x99rkXOPdw55Osveec4+P9fL4/XlFVjnCEIxzhCEc4wkcLwofdgSMc4QhHOMIRjvDB4cjAj3CEIxzhCEf4CMKRgR/hCEc4wh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TtusIEujalhgjoJRSiLGh7Tq6dm17I4AWIeVMGkauLk75+m/8TR/kGNHPwwpO14asCRjQcU8Zrkj9jmF/xe7yOU+fPObZ2TOePz9nv73i4mrPrh9JKVGKIgJZIeVMHhM5Z1IBEHIpqCpFIRch50LKSspWbTf4/s6pMOZMKXZvCBi+50yliYY64r8ZyPSvziQ4GL2suE0pTucqXoMEoweqECT4Z6OjKRvtEBFCFLo2EkRoY6RpDbfbJlIcn6XS8Yku27NNFNZdy7qNNI3SxsCqbdisIk0TiTHQhMB63XLzZMPNTceqa2naznG7penWxNUJGhpSUfb7gbPTcz599z53Hz7i6nJHSqOtA0ZrVMVx2yYyqzCkQl/gvN+w6k+IbNnt97Tt2tqKDbkoQ
"text/plain": [
"<Figure size 504x576 with 4 Axes>"
]
},
"metadata": {
"needs_background": "light",
"tags": []
},
"output_type": "display_data"
}
],
"source": [
"idxs_to_swap = slice(16,18)\n",
"my_latents = torch.Tensor(np.load('pred_dlatents_myImage.npy', allow_pickle=True))\n",
"\n",
"A, B = latent2image(my_latents.cuda()), latent2image(trunc(mapper(rand_latents)))\n",
"generated_image_latents = trunc(mapper(rand_latents))\n",
"\n",
"x = my_latents.clone()\n",
"x[:,idxs_to_swap] = generated_image_latents[:,idxs_to_swap]\n",
"a = latent2image(x.float().cuda())\n",
"\n",
"x = generated_image_latents.clone()\n",
"x[:,idxs_to_swap] = my_latents[:,idxs_to_swap]\n",
"b = latent2image(x.float().cuda())\n",
"\n",
"subplots([A,a,B,b], figsize=(7,8), nc=2, suptitle='Transfer general image features')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 854
},
"id": "-O4eN-l1kSml",
"outputId": "09361307-670a-453d-8b50-95a37c36980d"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2020-10-13 06:17:20,651][INFO] Initializing generator.\n",
"[2020-10-13 06:17:20,887][INFO] Loading pytorch model from `InterFaceGAN/models/pretrain/stylegan_ffhq.pth`.\n",
"[2020-10-13 06:17:21,161][INFO] Successfully loaded!\n",
"[2020-10-13 06:17:21,161][INFO] `lod` of the loaded model is 0.0.\n",
"[2020-10-13 06:17:24,246][INFO] Preparing boundary.\n",
"[2020-10-13 06:17:24,250][INFO] Preparing latent codes.\n",
"[2020-10-13 06:17:24,250][INFO] Load latent codes from `pred_dlatents_myImage.npy`.\n",
"[2020-10-13 06:17:24,251][INFO] Editing 1 samples.\n",
"[2020-10-13 06:17:26,461][INFO] Successfully edited 1 samples.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2020-10-13 06:17:26.979 | INFO | torch_snippets.loader:subplots:359 - plotting 20 images in a grid of 4x5 @ (10, 10)\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAsgAAAKUCAYAAAAZ5876AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy915MkR5bu9zvuHhGpqrobjRGYwezOzuzdNaNdI6+RRtJIM/7x9xpX2d5ZhcEAaIXWurpkZkaEKz4c94gsYAR6Xi4fymHo7qrMjIxw//yI7wiXnDM342bcjJtxM27GzbgZN+Nm3Awd5n/0DdyMm3EzbsbNuBk342bcjJvx/6dxYyDfjJtxM27GzbgZN+Nm3IybcTBuDOSbcTNuxs24GTfjZtyMm3EzDsaNgXwzbsbNuBk342bcjJtxM27GwbgxkG/GzbgZN+Nm3IybcTNuxs04GO6PvZjzLmciIUcSkImA0IhDEAQQHJBJBCKJmCMpZX1NwBiLxZDJCEIikXMmpUTKGSMGBFLKJDKSwYdATokYM2RICVJIjGPPbrfj4uKMs9NTnjx6yLOnzzh5d0Lf78khEVOCBJGEQchZr22tYIwh6ZORYyaEyDiOkBMZCCGQcyJn9RyMFchCynpfmYRMc6P/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g/PFMGg4KiGcCanxNQpeqIEi6ouYKoKOWWQFLHG4I3HGoOxUpRA2TgpYQR84wg+ALBYdKxXK46ONqxWa5wzSEI90ZTIUQ1W348Er4ZZCJ7oI2NIgBrkIStLZQScNBASzcKooSGGbb9nl
"text/plain": [
"<Figure size 720x720 with 20 Axes>"
]
},
"metadata": {
"needs_background": "light",
"tags": []
},
"output_type": "display_data"
}
],
"source": [
"!python InterFaceGAN/edit.py\\\n",
" -m stylegan_ffhq\\\n",
" -o results_new_smile\\\n",
" -b InterFaceGAN/boundaries/stylegan_ffhq_smile_w_boundary.npy\\\n",
" -i pred_dlatents_myImage.npy\\\n",
" -s WP\\\n",
" --steps 20\n",
"\n",
"generated_faces = glob.glob('results_new_smile/*.jpg')\n",
"\n",
"subplots([read(im,1) for im in sorted(generated_faces)],figsize=(10,10))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "pvLkri7TmvsM"
},
"outputs": [],
"source": []
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"include_colab_link": true,
"name": "Customizing StyleGAN2.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}