├── .gitattributes ├── .github └── FUNDING.yml ├── GPU_Barycentric_Cross_Network_Interpolation_with_different_layer_interpolation_rates.ipynb ├── Preprocess Danbooru Vectors - StyleGAN Conditional.ipynb ├── StyleGAN2 Network Interpolation.ipynb ├── TADNE_Editor.ipynb ├── TFDNE_Editor_v1_TF_(2).ipynb ├── TFDNE_generate_interpolation_video.ipynb ├── arfafax_Tag_Based_Anime_Generation_(Public_Twitter).ipynb └── danbooru_to_csv.ipynb /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: arfafax 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: arfafax 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /GPU_Barycentric_Cross_Network_Interpolation_with_different_layer_interpolation_rates.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "GPU Barycentric Cross-Network Interpolation with different layer interpolation rates", 7 | "provenance": [], 8 | "collapsed_sections": [ 9 | "vwoaEDAZmx05", 10 | "z-nbM6a9N6_s" 11 | ], 12 | "toc_visible": true, 13 | "include_colab_link": true 14 | }, 15 | "kernelspec": { 16 | "name": "python3", 17 | "display_name": "Python 3" 18 | }, 19 | "accelerator": "GPU" 20 | }, 21 | "cells": [ 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "id": "view-in-github", 26 | "colab_type": "text" 27 | }, 28 | "source": [ 29 | "\"Open" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": { 35 | "id": "PtOVza7H9z3Y", 36 | "colab_type": "text" 37 | }, 38 | "source": [ 39 | "# Barycentric Cross-Network Interpolation with different layer interpolation rates\n", 40 | "\n", 41 | "### Credits\n", 42 | "Thanks to [@shawwn](https://twitter.com/theshawwn) for helping me optimize the cross-network interpolation code.\n", 43 | "\n", 44 | "The code for generating the triangle visualization is from [Brandon Mechtley](https://github.com/bmechtley/barycentric).\n", 45 | "\n", 46 | "### Shameless Plug\n", 47 | "If you enjoyed this and want to see more projects like it in the future, consider supporting me on Ko-fi or Patreon.\n", 48 | "\n", 49 | "-arfa\n", 50 | "\n", 51 | "\n", 52 | "
\n", 53 | "\n", 54 | "\n", 55 | "\n", 56 | "
\n", 57 | "
\n", 58 | "\n", 59 | "\n", 60 | "\n", 61 | "\n", 62 | "\n", 63 | "\n", 64 | "
\n" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "id": "nMVVydZPL051", 71 | "colab_type": "text" 72 | }, 73 | "source": [ 74 | "Select the models to interpolate between. They have all been transfer learned from the same source (ThisFursonaDoesNotExist).\n" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "metadata": { 80 | "id": "pXcjXwwhzJOW", 81 | "colab_type": "code", 82 | "colab": { 83 | "base_uri": "https://localhost:8080/", 84 | "height": 239 85 | }, 86 | "outputId": "8bd3a7ba-2f3d-450d-b334-0c2fe129a8cd" 87 | }, 88 | "source": [ 89 | "import gdown\n", 90 | "network_a_name = \"furry\"\n", 91 | "network_b_name = \"pony\"\n", 92 | "network_c_name = \"anime\"\n", 93 | "# Furry\n", 94 | "gdown.download('https://drive.google.com/uc?id=1t7E8NEqK_gVJwxrWEihR1IcPfekaBc1d', 'network-{}.pkl'.format(network_a_name), quiet=False)\n", 95 | "# Pony\n", 96 | "gdown.download('https://drive.google.com/uc?id=1HmDTPoUlhVcUQ6-D0gkGMiBQZ3nNUBg9', 'network-{}.pkl'.format(network_b_name), quiet=False)\n", 97 | "# Anime\n", 98 | "gdown.download('https://drive.google.com/uc?id=1rfO_Iyg7cfjrs2fUsjjAsGb2_wDLdUYC', 'network-{}.pkl'.format(network_c_name), quiet=False)\n", 99 | "# FFHQ\n", 100 | "#gdown.download('https://drive.google.com/uc?id=1XeY94kGlULuxoHUSHIDWH8BQ4_L1UBKJ', 'network-{}.pkl'.format(network_b_name), quiet=False)\n" 101 | ], 102 | "execution_count": 3, 103 | "outputs": [ 104 | { 105 | "output_type": "stream", 106 | "text": [ 107 | "Downloading...\n", 108 | "From: https://drive.google.com/uc?id=1t7E8NEqK_gVJwxrWEihR1IcPfekaBc1d\n", 109 | "To: /content/network-furry.pkl\n", 110 | "364MB [00:02, 146MB/s]\n", 111 | "Downloading...\n", 112 | "From: https://drive.google.com/uc?id=1HmDTPoUlhVcUQ6-D0gkGMiBQZ3nNUBg9\n", 113 | "To: /content/network-pony.pkl\n", 114 | "364MB [00:02, 146MB/s]\n", 115 | "Downloading...\n", 116 | "From: https://drive.google.com/uc?id=1rfO_Iyg7cfjrs2fUsjjAsGb2_wDLdUYC\n", 117 | "To: /content/network-anime.pkl\n", 118 | "364MB [00:03, 102MB/s] \n" 119 | ], 120 | "name": "stderr" 121 | }, 122 | { 123 | "output_type": "execute_result", 124 | "data": { 125 | "application/vnd.google.colaboratory.intrinsic+json": { 126 | "type": "string" 127 | }, 128 | "text/plain": [ 129 | "'network-anime.pkl'" 130 | ] 131 | }, 132 | "metadata": { 133 | "tags": [] 134 | }, 135 | "execution_count": 3 136 | } 137 | ] 138 | }, 139 | { 140 | "cell_type": "markdown", 141 | "metadata": { 142 | "id": "vwoaEDAZmx05", 143 | "colab_type": "text" 144 | }, 145 | "source": [ 146 | "## Boring tensorflow stuff" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "metadata": { 152 | "id": "XPa2GXzyiSBR", 153 | "colab_type": "code", 154 | "colab": { 155 | "base_uri": "https://localhost:8080/", 156 | "height": 357 157 | }, 158 | "outputId": "37aa8607-fce2-4377-ea2b-acb0cc9c2af2" 159 | }, 160 | "source": [ 161 | "!nvidia-smi" 162 | ], 163 | "execution_count": 1, 164 | "outputs": [ 165 | { 166 | "output_type": "stream", 167 | "text": [ 168 | "Tue Aug 25 21:18:41 2020 \n", 169 | "+-----------------------------------------------------------------------------+\n", 170 | "| NVIDIA-SMI 450.57 Driver Version: 418.67 CUDA Version: 10.1 |\n", 171 | "|-------------------------------+----------------------+----------------------+\n", 172 | "| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n", 173 | "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n", 174 | "| | | MIG M. |\n", 175 | "|===============================+======================+======================|\n", 176 | "| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n", 177 | "| N/A 59C P8 11W / 70W | 0MiB / 15079MiB | 0% Default |\n", 178 | "| | | ERR! |\n", 179 | "+-------------------------------+----------------------+----------------------+\n", 180 | " \n", 181 | "+-----------------------------------------------------------------------------+\n", 182 | "| Processes: |\n", 183 | "| GPU GI CI PID Type Process name GPU Memory |\n", 184 | "| ID ID Usage |\n", 185 | "|=============================================================================|\n", 186 | "| No running processes found |\n", 187 | "+-----------------------------------------------------------------------------+\n" 188 | ], 189 | "name": "stdout" 190 | } 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "metadata": { 196 | "id": "Ixs37iA-Mxf2", 197 | "colab_type": "code", 198 | "colab": { 199 | "base_uri": "https://localhost:8080/", 200 | "height": 102 201 | }, 202 | "outputId": "672f2115-5a8b-47da-c6f1-4ca06c0c37f7" 203 | }, 204 | "source": [ 205 | "!git clone https://github.com/shawwn/stylegan2 -b estimator /content/stylegan2" 206 | ], 207 | "execution_count": 2, 208 | "outputs": [ 209 | { 210 | "output_type": "stream", 211 | "text": [ 212 | "Cloning into '/content/stylegan2'...\n", 213 | "remote: Enumerating objects: 1463, done.\u001b[K\n", 214 | "remote: Total 1463 (delta 0), reused 0 (delta 0), pack-reused 1463\u001b[K\n", 215 | "Receiving objects: 100% (1463/1463), 933.62 KiB | 2.96 MiB/s, done.\n", 216 | "Resolving deltas: 100% (1044/1044), done.\n" 217 | ], 218 | "name": "stdout" 219 | } 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "metadata": { 225 | "id": "w_diRM7Fn1Pa", 226 | "colab_type": "code", 227 | "colab": { 228 | "base_uri": "https://localhost:8080/", 229 | "height": 51 230 | }, 231 | "outputId": "f745c49f-737f-437e-ba24-0b83a63ca6f9" 232 | }, 233 | "source": [ 234 | "%tensorflow_version 1.x\n", 235 | "%cd /content/stylegan2" 236 | ], 237 | "execution_count": 4, 238 | "outputs": [ 239 | { 240 | "output_type": "stream", 241 | "text": [ 242 | "TensorFlow 1.x selected.\n", 243 | "/content/stylegan2\n" 244 | ], 245 | "name": "stdout" 246 | } 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "metadata": { 252 | "id": "Pt4kvzEM39oI", 253 | "colab_type": "code", 254 | "colab": { 255 | "base_uri": "https://localhost:8080/", 256 | "height": 187 257 | }, 258 | "outputId": "46487735-ffbe-47f6-d23e-5e31f9889d3e" 259 | }, 260 | "source": [ 261 | "import os\n", 262 | "import pickle\n", 263 | "import numpy as np\n", 264 | "import PIL.Image\n", 265 | "import dnnlib\n", 266 | "import dnnlib.tflib as tflib\n", 267 | "import scipy\n", 268 | "import tensorflow as tf\n", 269 | "import re" 270 | ], 271 | "execution_count": 5, 272 | "outputs": [ 273 | { 274 | "output_type": "stream", 275 | "text": [ 276 | "WARNING:tensorflow:From /content/stylegan2/tflex.py:314: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.\n", 277 | "\n", 278 | "WARNING:tensorflow:From /content/stylegan2/tflex.py:576: The name tf.train.SaverDef is deprecated. Please use tf.compat.v1.train.SaverDef instead.\n", 279 | "\n", 280 | "attach_debugger \n", 281 | "print_status \n", 282 | "freeze_forever \n", 283 | "quit \n", 284 | "save_and_quit \n", 285 | "throw_exception \n" 286 | ], 287 | "name": "stdout" 288 | } 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "metadata": { 294 | "id": "Mg9DrxVNJ8am", 295 | "colab_type": "code", 296 | "colab": { 297 | "base_uri": "https://localhost:8080/", 298 | "height": 51 299 | }, 300 | "outputId": "dada47a6-a0e0-4d0f-e838-90eaefde6878" 301 | }, 302 | "source": [ 303 | "tflib.init_tf()\n", 304 | "_G1, _D1, Gs1 = pickle.load(open(\"/content/network-{}.pkl\".format(network_a_name), \"rb\"))\n", 305 | "_G2, _D2, Gs2 = pickle.load(open(\"/content/network-{}.pkl\".format(network_b_name), \"rb\"))\n", 306 | "_G3, _D3, Gs3 = pickle.load(open(\"/content/network-{}.pkl\".format(network_c_name), \"rb\"))\n", 307 | "_G, _D, Gs = pickle.load(open(\"/content/network-{}.pkl\".format(network_a_name), \"rb\"))\n" 308 | ], 309 | "execution_count": 6, 310 | "outputs": [ 311 | { 312 | "output_type": "stream", 313 | "text": [ 314 | "Setting up TensorFlow plugin \"fused_bias_act.cu\": Preprocessing... Compiling... Loading... Done.\n", 315 | "Setting up TensorFlow plugin \"upfirdn_2d.cu\": Preprocessing... Compiling... Loading... Done.\n" 316 | ], 317 | "name": "stdout" 318 | } 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "metadata": { 324 | "id": "4MMGMmTdA1Hm", 325 | "colab_type": "code", 326 | "colab": {} 327 | }, 328 | "source": [ 329 | "from dnnlib.tflib import tfutil\n", 330 | "import tflex\n", 331 | "names = []\n", 332 | "\n", 333 | "for name in Gs1.trainables.keys():\n", 334 | " if name not in Gs1.trainables:\n", 335 | " print(\"Not restoring (not present): {}\".format(name))\n", 336 | " elif Gs2.trainables[name].shape != Gs1.trainables[name].shape:\n", 337 | " print(\"Not restoring (different shape): {}\".format(name))\n", 338 | "\n", 339 | " if name in Gs1.trainables and Gs2.trainables[name].shape == Gs1.trainables[name].shape:\n", 340 | " names.append(name)\n" 341 | ], 342 | "execution_count": 17, 343 | "outputs": [] 344 | }, 345 | { 346 | "cell_type": "code", 347 | "metadata": { 348 | "id": "6I7lotL1S5pT", 349 | "colab_type": "code", 350 | "colab": { 351 | "base_uri": "https://localhost:8080/", 352 | "height": 54 353 | }, 354 | "outputId": "660d20e4-86f2-415b-fe72-c1690701fefe" 355 | }, 356 | "source": [ 357 | "print(names)" 358 | ], 359 | "execution_count": 18, 360 | "outputs": [ 361 | { 362 | "output_type": "stream", 363 | "text": [ 364 | "['G_synthesis/4x4/Const/const', 'G_synthesis/4x4/Conv/weight', 'G_synthesis/4x4/Conv/mod_weight', 'G_synthesis/4x4/Conv/mod_bias', 'G_synthesis/4x4/Conv/noise_strength', 'G_synthesis/4x4/Conv/bias', 'G_synthesis/4x4/ToRGB/weight', 'G_synthesis/4x4/ToRGB/mod_weight', 'G_synthesis/4x4/ToRGB/mod_bias', 'G_synthesis/4x4/ToRGB/bias', 'G_synthesis/8x8/Conv0_up/weight', 'G_synthesis/8x8/Conv0_up/mod_weight', 'G_synthesis/8x8/Conv0_up/mod_bias', 'G_synthesis/8x8/Conv0_up/noise_strength', 'G_synthesis/8x8/Conv0_up/bias', 'G_synthesis/8x8/Conv1/weight', 'G_synthesis/8x8/Conv1/mod_weight', 'G_synthesis/8x8/Conv1/mod_bias', 'G_synthesis/8x8/Conv1/noise_strength', 'G_synthesis/8x8/Conv1/bias', 'G_synthesis/8x8/ToRGB/weight', 'G_synthesis/8x8/ToRGB/mod_weight', 'G_synthesis/8x8/ToRGB/mod_bias', 'G_synthesis/8x8/ToRGB/bias', 'G_synthesis/16x16/Conv0_up/weight', 'G_synthesis/16x16/Conv0_up/mod_weight', 'G_synthesis/16x16/Conv0_up/mod_bias', 'G_synthesis/16x16/Conv0_up/noise_strength', 'G_synthesis/16x16/Conv0_up/bias', 'G_synthesis/16x16/Conv1/weight', 'G_synthesis/16x16/Conv1/mod_weight', 'G_synthesis/16x16/Conv1/mod_bias', 'G_synthesis/16x16/Conv1/noise_strength', 'G_synthesis/16x16/Conv1/bias', 'G_synthesis/16x16/ToRGB/weight', 'G_synthesis/16x16/ToRGB/mod_weight', 'G_synthesis/16x16/ToRGB/mod_bias', 'G_synthesis/16x16/ToRGB/bias', 'G_synthesis/32x32/Conv0_up/weight', 'G_synthesis/32x32/Conv0_up/mod_weight', 'G_synthesis/32x32/Conv0_up/mod_bias', 'G_synthesis/32x32/Conv0_up/noise_strength', 'G_synthesis/32x32/Conv0_up/bias', 'G_synthesis/32x32/Conv1/weight', 'G_synthesis/32x32/Conv1/mod_weight', 'G_synthesis/32x32/Conv1/mod_bias', 'G_synthesis/32x32/Conv1/noise_strength', 'G_synthesis/32x32/Conv1/bias', 'G_synthesis/32x32/ToRGB/weight', 'G_synthesis/32x32/ToRGB/mod_weight', 'G_synthesis/32x32/ToRGB/mod_bias', 'G_synthesis/32x32/ToRGB/bias', 'G_synthesis/64x64/Conv0_up/weight', 'G_synthesis/64x64/Conv0_up/mod_weight', 'G_synthesis/64x64/Conv0_up/mod_bias', 'G_synthesis/64x64/Conv0_up/noise_strength', 'G_synthesis/64x64/Conv0_up/bias', 'G_synthesis/64x64/Conv1/weight', 'G_synthesis/64x64/Conv1/mod_weight', 'G_synthesis/64x64/Conv1/mod_bias', 'G_synthesis/64x64/Conv1/noise_strength', 'G_synthesis/64x64/Conv1/bias', 'G_synthesis/64x64/ToRGB/weight', 'G_synthesis/64x64/ToRGB/mod_weight', 'G_synthesis/64x64/ToRGB/mod_bias', 'G_synthesis/64x64/ToRGB/bias', 'G_synthesis/128x128/Conv0_up/weight', 'G_synthesis/128x128/Conv0_up/mod_weight', 'G_synthesis/128x128/Conv0_up/mod_bias', 'G_synthesis/128x128/Conv0_up/noise_strength', 'G_synthesis/128x128/Conv0_up/bias', 'G_synthesis/128x128/Conv1/weight', 'G_synthesis/128x128/Conv1/mod_weight', 'G_synthesis/128x128/Conv1/mod_bias', 'G_synthesis/128x128/Conv1/noise_strength', 'G_synthesis/128x128/Conv1/bias', 'G_synthesis/128x128/ToRGB/weight', 'G_synthesis/128x128/ToRGB/mod_weight', 'G_synthesis/128x128/ToRGB/mod_bias', 'G_synthesis/128x128/ToRGB/bias', 'G_synthesis/256x256/Conv0_up/weight', 'G_synthesis/256x256/Conv0_up/mod_weight', 'G_synthesis/256x256/Conv0_up/mod_bias', 'G_synthesis/256x256/Conv0_up/noise_strength', 'G_synthesis/256x256/Conv0_up/bias', 'G_synthesis/256x256/Conv1/weight', 'G_synthesis/256x256/Conv1/mod_weight', 'G_synthesis/256x256/Conv1/mod_bias', 'G_synthesis/256x256/Conv1/noise_strength', 'G_synthesis/256x256/Conv1/bias', 'G_synthesis/256x256/ToRGB/weight', 'G_synthesis/256x256/ToRGB/mod_weight', 'G_synthesis/256x256/ToRGB/mod_bias', 'G_synthesis/256x256/ToRGB/bias', 'G_synthesis/512x512/Conv0_up/weight', 'G_synthesis/512x512/Conv0_up/mod_weight', 'G_synthesis/512x512/Conv0_up/mod_bias', 'G_synthesis/512x512/Conv0_up/noise_strength', 'G_synthesis/512x512/Conv0_up/bias', 'G_synthesis/512x512/Conv1/weight', 'G_synthesis/512x512/Conv1/mod_weight', 'G_synthesis/512x512/Conv1/mod_bias', 'G_synthesis/512x512/Conv1/noise_strength', 'G_synthesis/512x512/Conv1/bias', 'G_synthesis/512x512/ToRGB/weight', 'G_synthesis/512x512/ToRGB/mod_weight', 'G_synthesis/512x512/ToRGB/mod_bias', 'G_synthesis/512x512/ToRGB/bias', 'G_mapping/Dense0/weight', 'G_mapping/Dense0/bias', 'G_mapping/Dense1/weight', 'G_mapping/Dense1/bias', 'G_mapping/Dense2/weight', 'G_mapping/Dense2/bias', 'G_mapping/Dense3/weight', 'G_mapping/Dense3/bias', 'G_mapping/Dense4/weight', 'G_mapping/Dense4/bias', 'G_mapping/Dense5/weight', 'G_mapping/Dense5/bias', 'G_mapping/Dense6/weight', 'G_mapping/Dense6/bias', 'G_mapping/Dense7/weight', 'G_mapping/Dense7/bias']\n" 365 | ], 366 | "name": "stdout" 367 | } 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "metadata": { 373 | "id": "zQQ_HBFDYgng", 374 | "colab_type": "code", 375 | "colab": { 376 | "base_uri": "https://localhost:8080/", 377 | "height": 54 378 | }, 379 | "outputId": "92237449-31a2-4843-b193-9fb2d2c0aba5" 380 | }, 381 | "source": [ 382 | "# Select the variables to interpolate for each point\n", 383 | "matches = [\n", 384 | " '.*(4x4|8x8|16x16)', #p0\n", 385 | " '.*(32x32|64x64|128x128)', #p1\n", 386 | " '.*(256x256|512x512)' #p2\n", 387 | " ]\n", 388 | "# matches = ['.*(4x4|8x8|16x16|32x32|64x64)',\n", 389 | "# '.*(128x128|256x256|512x512)',\n", 390 | "# '.*Dense'\n", 391 | "#]\n", 392 | "\n", 393 | "filtered_names = []\n", 394 | "bs = []\n", 395 | "ops = []\n", 396 | "for match in matches:\n", 397 | " match_names = [n for n in names if re.match(match, n)]\n", 398 | " filtered_names.append(match_names)\n", 399 | " b_cur = [tf.Variable(0.0), tf.Variable(0.5), tf.Variable(0.5)]\n", 400 | " ops_cur = []\n", 401 | " for name in match_names:\n", 402 | " ops_cur.append(tf.assign(Gs.vars[name], b_cur[0]*Gs1.vars[name] + b_cur[1]*Gs2.vars[name] + b_cur[2]*Gs3.vars[name]))\n", 403 | " bs.append(b_cur)\n", 404 | " ops.append(ops_cur)\n", 405 | "\n", 406 | "print(filtered_names)" 407 | ], 408 | "execution_count": 43, 409 | "outputs": [ 410 | { 411 | "output_type": "stream", 412 | "text": [ 413 | "[['G_synthesis/4x4/Const/const', 'G_synthesis/4x4/Conv/weight', 'G_synthesis/4x4/Conv/mod_weight', 'G_synthesis/4x4/Conv/mod_bias', 'G_synthesis/4x4/Conv/noise_strength', 'G_synthesis/4x4/Conv/bias', 'G_synthesis/4x4/ToRGB/weight', 'G_synthesis/4x4/ToRGB/mod_weight', 'G_synthesis/4x4/ToRGB/mod_bias', 'G_synthesis/4x4/ToRGB/bias', 'G_synthesis/8x8/Conv0_up/weight', 'G_synthesis/8x8/Conv0_up/mod_weight', 'G_synthesis/8x8/Conv0_up/mod_bias', 'G_synthesis/8x8/Conv0_up/noise_strength', 'G_synthesis/8x8/Conv0_up/bias', 'G_synthesis/8x8/Conv1/weight', 'G_synthesis/8x8/Conv1/mod_weight', 'G_synthesis/8x8/Conv1/mod_bias', 'G_synthesis/8x8/Conv1/noise_strength', 'G_synthesis/8x8/Conv1/bias', 'G_synthesis/8x8/ToRGB/weight', 'G_synthesis/8x8/ToRGB/mod_weight', 'G_synthesis/8x8/ToRGB/mod_bias', 'G_synthesis/8x8/ToRGB/bias', 'G_synthesis/16x16/Conv0_up/weight', 'G_synthesis/16x16/Conv0_up/mod_weight', 'G_synthesis/16x16/Conv0_up/mod_bias', 'G_synthesis/16x16/Conv0_up/noise_strength', 'G_synthesis/16x16/Conv0_up/bias', 'G_synthesis/16x16/Conv1/weight', 'G_synthesis/16x16/Conv1/mod_weight', 'G_synthesis/16x16/Conv1/mod_bias', 'G_synthesis/16x16/Conv1/noise_strength', 'G_synthesis/16x16/Conv1/bias', 'G_synthesis/16x16/ToRGB/weight', 'G_synthesis/16x16/ToRGB/mod_weight', 'G_synthesis/16x16/ToRGB/mod_bias', 'G_synthesis/16x16/ToRGB/bias'], ['G_synthesis/32x32/Conv0_up/weight', 'G_synthesis/32x32/Conv0_up/mod_weight', 'G_synthesis/32x32/Conv0_up/mod_bias', 'G_synthesis/32x32/Conv0_up/noise_strength', 'G_synthesis/32x32/Conv0_up/bias', 'G_synthesis/32x32/Conv1/weight', 'G_synthesis/32x32/Conv1/mod_weight', 'G_synthesis/32x32/Conv1/mod_bias', 'G_synthesis/32x32/Conv1/noise_strength', 'G_synthesis/32x32/Conv1/bias', 'G_synthesis/32x32/ToRGB/weight', 'G_synthesis/32x32/ToRGB/mod_weight', 'G_synthesis/32x32/ToRGB/mod_bias', 'G_synthesis/32x32/ToRGB/bias', 'G_synthesis/64x64/Conv0_up/weight', 'G_synthesis/64x64/Conv0_up/mod_weight', 'G_synthesis/64x64/Conv0_up/mod_bias', 'G_synthesis/64x64/Conv0_up/noise_strength', 'G_synthesis/64x64/Conv0_up/bias', 'G_synthesis/64x64/Conv1/weight', 'G_synthesis/64x64/Conv1/mod_weight', 'G_synthesis/64x64/Conv1/mod_bias', 'G_synthesis/64x64/Conv1/noise_strength', 'G_synthesis/64x64/Conv1/bias', 'G_synthesis/64x64/ToRGB/weight', 'G_synthesis/64x64/ToRGB/mod_weight', 'G_synthesis/64x64/ToRGB/mod_bias', 'G_synthesis/64x64/ToRGB/bias', 'G_synthesis/128x128/Conv0_up/weight', 'G_synthesis/128x128/Conv0_up/mod_weight', 'G_synthesis/128x128/Conv0_up/mod_bias', 'G_synthesis/128x128/Conv0_up/noise_strength', 'G_synthesis/128x128/Conv0_up/bias', 'G_synthesis/128x128/Conv1/weight', 'G_synthesis/128x128/Conv1/mod_weight', 'G_synthesis/128x128/Conv1/mod_bias', 'G_synthesis/128x128/Conv1/noise_strength', 'G_synthesis/128x128/Conv1/bias', 'G_synthesis/128x128/ToRGB/weight', 'G_synthesis/128x128/ToRGB/mod_weight', 'G_synthesis/128x128/ToRGB/mod_bias', 'G_synthesis/128x128/ToRGB/bias'], ['G_synthesis/256x256/Conv0_up/weight', 'G_synthesis/256x256/Conv0_up/mod_weight', 'G_synthesis/256x256/Conv0_up/mod_bias', 'G_synthesis/256x256/Conv0_up/noise_strength', 'G_synthesis/256x256/Conv0_up/bias', 'G_synthesis/256x256/Conv1/weight', 'G_synthesis/256x256/Conv1/mod_weight', 'G_synthesis/256x256/Conv1/mod_bias', 'G_synthesis/256x256/Conv1/noise_strength', 'G_synthesis/256x256/Conv1/bias', 'G_synthesis/256x256/ToRGB/weight', 'G_synthesis/256x256/ToRGB/mod_weight', 'G_synthesis/256x256/ToRGB/mod_bias', 'G_synthesis/256x256/ToRGB/bias', 'G_synthesis/512x512/Conv0_up/weight', 'G_synthesis/512x512/Conv0_up/mod_weight', 'G_synthesis/512x512/Conv0_up/mod_bias', 'G_synthesis/512x512/Conv0_up/noise_strength', 'G_synthesis/512x512/Conv0_up/bias', 'G_synthesis/512x512/Conv1/weight', 'G_synthesis/512x512/Conv1/mod_weight', 'G_synthesis/512x512/Conv1/mod_bias', 'G_synthesis/512x512/Conv1/noise_strength', 'G_synthesis/512x512/Conv1/bias', 'G_synthesis/512x512/ToRGB/weight', 'G_synthesis/512x512/ToRGB/mod_weight', 'G_synthesis/512x512/ToRGB/mod_bias', 'G_synthesis/512x512/ToRGB/bias']]\n" 414 | ], 415 | "name": "stdout" 416 | } 417 | ] 418 | }, 419 | { 420 | "cell_type": "code", 421 | "metadata": { 422 | "id": "tnMwa5Zwcjxs", 423 | "colab_type": "code", 424 | "colab": {} 425 | }, 426 | "source": [ 427 | "sess = tf.get_default_session()" 428 | ], 429 | "execution_count": 44, 430 | "outputs": [] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "metadata": { 435 | "id": "zIzjMoMu84Qb", 436 | "colab_type": "code", 437 | "colab": {} 438 | }, 439 | "source": [ 440 | "def barycentric_interp(b_v_low, b_v_med, b_v_high):\n", 441 | " global bs\n", 442 | " global ops\n", 443 | "\n", 444 | " for i in range(len(b_v_low)):\n", 445 | " bs[0][i].load(b_v_low[i])\n", 446 | " bs[1][i].load(b_v_med[i])\n", 447 | " bs[2][i].load(b_v_high[i])\n", 448 | "\n", 449 | " for j in range(len(ops)):\n", 450 | " sess.run(ops[j])\n" 451 | ], 452 | "execution_count": 45, 453 | "outputs": [] 454 | }, 455 | { 456 | "cell_type": "markdown", 457 | "metadata": { 458 | "id": "mdnjmC0BWla4", 459 | "colab_type": "text" 460 | }, 461 | "source": [ 462 | "This is the path each point takes throughout the video. In this case, it's just permutations of the three corner coordinates, but any list of barycentric coordinates should work." 463 | ] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "metadata": { 468 | "id": "yC51hranEPIS", 469 | "colab_type": "code", 470 | "colab": {} 471 | }, 472 | "source": [ 473 | "# This is the path each point takes throughout the video\n", 474 | "A = [0,0,1]\n", 475 | "B = [0,1,0]\n", 476 | "C = [1,0,0]\n", 477 | "points_p0 = [A, A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B, B, C, C, C, C, C, C, C, C, C]\n", 478 | "points_p1 = [A, A, A, B, B, B, C, C, C, A, A, A, B, B, B, C, C, C, A, A, A, B, B, B, C, C, C]\n", 479 | "points_p2 = [A, B, C, A, B, C, A, B, C, A, B, C, A, B, C, A, B, C, A, B, C, A, B, C, A, B, C]\n", 480 | "\n", 481 | "# This function interpolates smoothly between the points in a given list, where t is some value that goes from 0 to 1 throughout the video\n", 482 | "def get_point(t, p_list, duration_sec = 60.0, mp4_fps = 20):\n", 483 | " total_frames = duration_sec * mp4_fps #1200\n", 484 | " frames_per_step = total_frames/(len(p_list)) #200\n", 485 | " current_frame = int(t * total_frames)\n", 486 | " \n", 487 | " p1 = int(current_frame // frames_per_step) % len(p_list)\n", 488 | " p2 = (p1 + 1)%len(p_list)\n", 489 | " lam = (current_frame % frames_per_step) / frames_per_step\n", 490 | " #print(t, total_frames, frames_per_step, current_frame, p1, p2, lam)\n", 491 | " point1 = np.array(p_list[p1])\n", 492 | " point2 = np.array(p_list[p2])\n", 493 | " return (1-lam)*point1 + (lam)*point2 " 494 | ], 495 | "execution_count": 23, 496 | "outputs": [] 497 | }, 498 | { 499 | "cell_type": "code", 500 | "metadata": { 501 | "id": "4UCG9f004EtO", 502 | "colab_type": "code", 503 | "colab": {} 504 | }, 505 | "source": [ 506 | "cur_frame = 0\n", 507 | "def make_video(grid_size = [4, 4], duration_sec = 60.0, mp4_fps = 20, random_seed=397):\n", 508 | " global cur_frame\n", 509 | " cur_frame = 0\n", 510 | "\n", 511 | " image_shrink = 1\n", 512 | " image_zoom = 1\n", 513 | " smoothing_sec = 1.0\n", 514 | " mp4_codec = 'libx264'\n", 515 | " mp4_bitrate = '5M'\n", 516 | " mp4_file = 'random_grid_%s.mp4' % random_seed\n", 517 | " minibatch_size = 8\n", 518 | "\n", 519 | " num_frames = int(np.rint(duration_sec * mp4_fps))\n", 520 | " random_state = np.random.RandomState(random_seed)\n", 521 | "\n", 522 | " # Generate latent vectors\n", 523 | " shape = [num_frames, np.prod(grid_size)] + Gs.input_shape[1:] # [frame, image, channel, component]\n", 524 | " all_latents = random_state.randn(*shape).astype(np.float32)\n", 525 | " import scipy\n", 526 | " all_latents = scipy.ndimage.gaussian_filter(all_latents,\n", 527 | " [smoothing_sec * mp4_fps] + [0] * len(Gs.input_shape), mode='wrap')\n", 528 | " all_latents /= np.sqrt(np.mean(np.square(all_latents)))\n", 529 | "\n", 530 | "\n", 531 | " def create_image_grid(images, grid_size=None):\n", 532 | " assert images.ndim == 3 or images.ndim == 4\n", 533 | " num, img_h, img_w, channels = images.shape\n", 534 | "\n", 535 | " if grid_size is not None:\n", 536 | " grid_w, grid_h = tuple(grid_size)\n", 537 | " else:\n", 538 | " grid_w = max(int(np.ceil(np.sqrt(num))), 1)\n", 539 | " grid_h = max((num - 1) // grid_w + 1, 1)\n", 540 | "\n", 541 | " grid = np.zeros([grid_h * img_h, grid_w * img_w, channels], dtype=images.dtype)\n", 542 | " for idx in range(num):\n", 543 | " x = (idx % grid_w) * img_w\n", 544 | " y = (idx // grid_w) * img_h\n", 545 | " grid[y : y + img_h, x : x + img_w] = images[idx]\n", 546 | " return grid\n", 547 | "\n", 548 | " # Frame generation func for moviepy.\n", 549 | " def make_frame(t):\n", 550 | " global cur_frame\n", 551 | " frame_idx = int(np.clip(np.round(t * mp4_fps), 0, num_frames - 1))\n", 552 | "\n", 553 | " t1 = cur_frame / (num_frames - 1)\n", 554 | " b1 = get_point(t1, points_p0, duration_sec=duration_sec, mp4_fps=mp4_fps)\n", 555 | " b2 = get_point(t1, points_p1, duration_sec=duration_sec, mp4_fps=mp4_fps)\n", 556 | " b3 = get_point(t1, points_p2, duration_sec=duration_sec, mp4_fps=mp4_fps)\n", 557 | " barycentric_interp(b1, b2, b3)\n", 558 | " latents = all_latents[frame_idx]\n", 559 | " #latents = all_latents[0]\n", 560 | " cur_frame += 1\n", 561 | " fmt = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)\n", 562 | " images = Gs.run(latents, None, truncation_psi=0.45, randomize_noise=False, output_transform=fmt)# **synthesis_kwargs\n", 563 | "\n", 564 | " grid = create_image_grid(images, grid_size)\n", 565 | " if image_zoom > 1:\n", 566 | " grid = scipy.ndimage.zoom(grid, [image_zoom, image_zoom, 1], order=0)\n", 567 | " if grid.shape[2] == 1:\n", 568 | " grid = grid.repeat(3, 2) # grayscale => RGB\n", 569 | " return grid\n", 570 | "\n", 571 | " # Generate video.\n", 572 | " import moviepy.editor\n", 573 | " video_clip = moviepy.editor.VideoClip(make_frame, duration=duration_sec)\n", 574 | " video_clip.write_videofile(mp4_file, fps=mp4_fps, codec=mp4_codec, bitrate=mp4_bitrate)\n", 575 | "\n", 576 | " return mp4_file\n" 577 | ], 578 | "execution_count": 26, 579 | "outputs": [] 580 | }, 581 | { 582 | "cell_type": "markdown", 583 | "metadata": { 584 | "id": "g4jjW6B4-c2c", 585 | "colab_type": "text" 586 | }, 587 | "source": [ 588 | "# Generate a grid of cross-network interpolations" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "metadata": { 594 | "id": "IUnU05mr4edb", 595 | "colab_type": "code", 596 | "colab": { 597 | "base_uri": "https://localhost:8080/", 598 | "height": 136 599 | }, 600 | "outputId": "8b4ad742-1cda-4c23-9431-4fcbbffc107b" 601 | }, 602 | "source": [ 603 | "#@title Generate an interpolation video { run: \"auto\", form-width: \"30%\" }\n", 604 | "random_seed = 1234 #@param {type:\"integer\"}\n", 605 | "duration_sec = 60.0 #@param {type:\"number\"}\n", 606 | "mp4_fps = 20 #@param {type:\"integer\"}\n", 607 | "grid_width = 3 #@param {type:\"integer\"}\n", 608 | "grid_height = 3 #@param {type:\"integer\"}\n", 609 | "output_filename = make_video(grid_size=[grid_width,grid_height], duration_sec=duration_sec, mp4_fps=mp4_fps, random_seed=random_seed)" 610 | ], 611 | "execution_count": 27, 612 | "outputs": [ 613 | { 614 | "output_type": "stream", 615 | "text": [ 616 | "1200\n", 617 | "[MoviePy] >>>> Building video random_grid_1237.mp4\n", 618 | "[MoviePy] Writing video random_grid_1237.mp4\n" 619 | ], 620 | "name": "stdout" 621 | }, 622 | { 623 | "output_type": "stream", 624 | "text": [ 625 | "100%|█████████▉| 1200/1201 [12:10<00:00, 1.64it/s]\n" 626 | ], 627 | "name": "stderr" 628 | }, 629 | { 630 | "output_type": "stream", 631 | "text": [ 632 | "[MoviePy] Done.\n", 633 | "[MoviePy] >>>> Video ready: random_grid_1237.mp4 \n", 634 | "\n" 635 | ], 636 | "name": "stdout" 637 | } 638 | ] 639 | }, 640 | { 641 | "cell_type": "code", 642 | "metadata": { 643 | "id": "lp5LucugKXit", 644 | "colab_type": "code", 645 | "colab": { 646 | "base_uri": "https://localhost:8080/", 647 | "height": 17 648 | }, 649 | "outputId": "66d3b19a-0da8-47df-b8d2-179f555a69f3" 650 | }, 651 | "source": [ 652 | "# You may need to run this cell twice to get the video to download\n", 653 | "from google.colab import files\n", 654 | "files.download(output_filename) " 655 | ], 656 | "execution_count": 28, 657 | "outputs": [ 658 | { 659 | "output_type": "display_data", 660 | "data": { 661 | "application/javascript": [ 662 | "\n", 663 | " async function download(id, filename, size) {\n", 664 | " if (!google.colab.kernel.accessAllowed) {\n", 665 | " return;\n", 666 | " }\n", 667 | " const div = document.createElement('div');\n", 668 | " const label = document.createElement('label');\n", 669 | " label.textContent = `Downloading \"${filename}\": `;\n", 670 | " div.appendChild(label);\n", 671 | " const progress = document.createElement('progress');\n", 672 | " progress.max = size;\n", 673 | " div.appendChild(progress);\n", 674 | " document.body.appendChild(div);\n", 675 | "\n", 676 | " const buffers = [];\n", 677 | " let downloaded = 0;\n", 678 | "\n", 679 | " const channel = await google.colab.kernel.comms.open(id);\n", 680 | " // Send a message to notify the kernel that we're ready.\n", 681 | " channel.send({})\n", 682 | "\n", 683 | " for await (const message of channel.messages) {\n", 684 | " // Send a message to notify the kernel that we're ready.\n", 685 | " channel.send({})\n", 686 | " if (message.buffers) {\n", 687 | " for (const buffer of message.buffers) {\n", 688 | " buffers.push(buffer);\n", 689 | " downloaded += buffer.byteLength;\n", 690 | " progress.value = downloaded;\n", 691 | " }\n", 692 | " }\n", 693 | " }\n", 694 | " const blob = new Blob(buffers, {type: 'application/binary'});\n", 695 | " const a = document.createElement('a');\n", 696 | " a.href = window.URL.createObjectURL(blob);\n", 697 | " a.download = filename;\n", 698 | " div.appendChild(a);\n", 699 | " a.click();\n", 700 | " div.remove();\n", 701 | " }\n", 702 | " " 703 | ], 704 | "text/plain": [ 705 | "" 706 | ] 707 | }, 708 | "metadata": { 709 | "tags": [] 710 | } 711 | }, 712 | { 713 | "output_type": "display_data", 714 | "data": { 715 | "application/javascript": [ 716 | "download(\"download_03d21da5-76e7-454c-bc2f-59a94a6f8596\", \"random_grid_1237.mp4\", 37499979)" 717 | ], 718 | "text/plain": [ 719 | "" 720 | ] 721 | }, 722 | "metadata": { 723 | "tags": [] 724 | } 725 | } 726 | ] 727 | }, 728 | { 729 | "cell_type": "markdown", 730 | "metadata": { 731 | "id": "z-nbM6a9N6_s", 732 | "colab_type": "text" 733 | }, 734 | "source": [ 735 | "# Generate the triangle visualization" 736 | ] 737 | }, 738 | { 739 | "cell_type": "code", 740 | "metadata": { 741 | "id": "vZ1nP6eBtWGT", 742 | "colab_type": "code", 743 | "colab": { 744 | "base_uri": "https://localhost:8080/", 745 | "height": 102 746 | }, 747 | "outputId": "0c17a826-76dd-4391-8014-32886b918740" 748 | }, 749 | "source": [ 750 | "%cd /content\n", 751 | "!git clone https://github.com/bmechtley/barycentric.git" 752 | ], 753 | "execution_count": 29, 754 | "outputs": [ 755 | { 756 | "output_type": "stream", 757 | "text": [ 758 | "/content\n", 759 | "Cloning into 'barycentric'...\n", 760 | "remote: Enumerating objects: 42, done.\u001b[K\n", 761 | "remote: Total 42 (delta 0), reused 0 (delta 0), pack-reused 42\u001b[K\n", 762 | "Unpacking objects: 100% (42/42), done.\n" 763 | ], 764 | "name": "stdout" 765 | } 766 | ] 767 | }, 768 | { 769 | "cell_type": "code", 770 | "metadata": { 771 | "id": "93WVgSQptZip", 772 | "colab_type": "code", 773 | "colab": { 774 | "base_uri": "https://localhost:8080/", 775 | "height": 34 776 | }, 777 | "outputId": "98cf019b-426f-4797-981b-ea061c4433a5" 778 | }, 779 | "source": [ 780 | "%cd barycentric" 781 | ], 782 | "execution_count": 30, 783 | "outputs": [ 784 | { 785 | "output_type": "stream", 786 | "text": [ 787 | "/content/barycentric\n" 788 | ], 789 | "name": "stdout" 790 | } 791 | ] 792 | }, 793 | { 794 | "cell_type": "code", 795 | "metadata": { 796 | "id": "Uk4BV1sftdQA", 797 | "colab_type": "code", 798 | "colab": {} 799 | }, 800 | "source": [ 801 | "!cp barycentric/coordinates.py ." 802 | ], 803 | "execution_count": 31, 804 | "outputs": [] 805 | }, 806 | { 807 | "cell_type": "code", 808 | "metadata": { 809 | "id": "74NTNlZetBcL", 810 | "colab_type": "code", 811 | "colab": {} 812 | }, 813 | "source": [ 814 | "%load_ext sympyprinting\n", 815 | "\n", 816 | "import itertools as it\n", 817 | "\n", 818 | "from pylab import *\n", 819 | "\n", 820 | "import coordinates\n", 821 | "#reload(coordinates)\n", 822 | "from coordinates import *\n", 823 | "\n", 824 | "import notebookutils\n", 825 | "#reload(notebookutils)\n", 826 | "from notebookutils import *\n", 827 | "\n", 828 | "set_printoptions(precision=3)" 829 | ], 830 | "execution_count": 32, 831 | "outputs": [] 832 | }, 833 | { 834 | "cell_type": "code", 835 | "metadata": { 836 | "id": "sOI04YRJt8Du", 837 | "colab_type": "code", 838 | "colab": {} 839 | }, 840 | "source": [ 841 | "def polyshow2(\n", 842 | " coords, \n", 843 | " color=None, \n", 844 | " label=None, \n", 845 | " labelvertices=False, \n", 846 | " polycolor=None, \n", 847 | " lines=[]\n", 848 | "):\n", 849 | " '''\n", 850 | " Plot a regular convex polygon surrounding one or more barycentric \n", 851 | " coordinates within the it. Vertices and corners will be labeled\n", 852 | " sequentially starting at 0.\n", 853 | "\n", 854 | " Args:\n", 855 | " coords (np.ndarray or list): one or more barycentric coordinates of \n", 856 | " equal arbitrary dimension. The dimensionality of the coordinates \n", 857 | " will correspond to the number of vertices of the polygon that is\n", 858 | " drawn.\n", 859 | " color (str or list, optional): color in which to draw the coords. If\n", 860 | " color is a list of the same length as coords, each entry will \n", 861 | " correspond to the respective coordinates.\n", 862 | " '''\n", 863 | "\n", 864 | "\n", 865 | " # Defaults.\n", 866 | " coords = np.array(coords)\n", 867 | " if len(coords.shape) < 2: coords = [coords]\n", 868 | " for coord in coords:\n", 869 | " if np.sum(coord) > 0:\n", 870 | " coord /= np.sum(coord)\n", 871 | "\n", 872 | " if color == None: color = 'blue'\n", 873 | " if type(color) == str: color = [color] * len(coords)\n", 874 | "\n", 875 | " if label == None: label = ''\n", 876 | " if type(label) == str: label = [label] * len(coords)\n", 877 | "\n", 878 | " # Number of sides.\n", 879 | " d = len(coords[0])\n", 880 | "\n", 881 | " # Cartesian coordinates of the vertices of the polygon and each point.\n", 882 | " corners = polycorners(d)\n", 883 | " cart = np.array([\n", 884 | " np.sum([\n", 885 | " c * cnr \n", 886 | " for c, cnr in zip(coord, corners)\n", 887 | " ], axis=0) \n", 888 | " for coord in coords\n", 889 | " ])\n", 890 | "\n", 891 | " # Figure/axes setup.\n", 892 | " f = pp.figure(frameon=False)\n", 893 | " ax = pp.axes(frameon=False)\n", 894 | " ax.axis('equal')\n", 895 | " pp.xticks([])\n", 896 | " pp.yticks([])\n", 897 | "\n", 898 | " # Add the polygon and its vertices to the figure.\n", 899 | " ax.add_patch(pp.Polygon(corners, closed=True, fill=False, alpha=0.5))\n", 900 | " #ax.scatter(corners[:,0], corners[:,1], color='red', s=50)\n", 901 | " if labelvertices:\n", 902 | " map(lambda i: verttext(corners[i], '$v_{%d}$' % i), range(len(corners)))\n", 903 | " verttext(corners[0], network_a_name, color='black')\n", 904 | " verttext(corners[1], \"{} \".format(network_b_name), color=\"black\")\n", 905 | " verttext(corners[2], \" {}\".format(network_c_name), color=\"black\")\n", 906 | "\n", 907 | " # Add any extra lines to the figure.\n", 908 | " map(ax.add_line, lines)\n", 909 | "\n", 910 | " # Add the interior points and their labels.\n", 911 | " ax.scatter(cart[:,0], cart[:,1], color=color, s=100)\n", 912 | "\n", 913 | " for c, txt, clr in zip(cart, label, color):\n", 914 | " verttext(c, txt, color=clr)\n", 915 | "\n", 916 | " return f" 917 | ], 918 | "execution_count": 33, 919 | "outputs": [] 920 | }, 921 | { 922 | "cell_type": "code", 923 | "metadata": { 924 | "id": "mPvUd2LktBcU", 925 | "colab_type": "code", 926 | "colab": {} 927 | }, 928 | "source": [ 929 | "def testpoly(p, i, sides=False):\n", 930 | " if type(p) == ndarray and len(p.shape) < 2: p = [p]\n", 931 | " elif type(p) == ndarray and len(p.shape) > 1: \n", 932 | " p = list(array(r) for r in p)\n", 933 | " \n", 934 | " n = len(p) # number of points\n", 935 | " d = len(p[0]) # number of sides\n", 936 | " \n", 937 | " # q-points are bary. coords for the projection of points in p along each edge.\n", 938 | " q = concatenate([baryedges(pi) for pi in p]) if sides else np.array([])\n", 939 | " \n", 940 | " # Which point each projected point references.\n", 941 | " qindices = (arange(n) * ones((d, n), dtype=int)).T.flatten() if sides else np.array([])\n", 942 | " \n", 943 | " # Labels for every point.\n", 944 | " plabels = ['$p_{%d}$' % i for i in range(n)]\n", 945 | " qlabels = [\n", 946 | " '$q_{%d,%d%d}$' % (a, b, c) \n", 947 | " for (a, (b, c)) in list(it.product(\n", 948 | " range(n), \n", 949 | " zip(\n", 950 | " range(d), \n", 951 | " [i % d for i in range(1, d + 1)]\n", 952 | " )\n", 953 | " ))\n", 954 | " ] if sides else []\n", 955 | " \n", 956 | " # Colors for every point.\n", 957 | " cm = get_cmap(\"hsv\")\n", 958 | " pcolors = [cm(float(i) / n)[0:3] + (.9,) for i in range(n)]\n", 959 | " qcolors = [pcolors[i][0:3] + (.5,) for i in qindices] if sides else []\n", 960 | " \n", 961 | " # Cartesian coordinates for points and closest points along the sides.\n", 962 | " pcart = [bary2cart(pi) for pi in p]\n", 963 | " qcart = bary2cart(q) if sides else np.array([])\n", 964 | " \n", 965 | " # Lines that connect each q-point to its reference point.\n", 966 | " lines = [\n", 967 | " Line2D(\n", 968 | " (pcart[i / len(p[0])][0], qcart[i, 0] + .00001),\n", 969 | " (pcart[i / len(p[0])][1], qcart[i, 1]),\n", 970 | " color = qcolors[i]\n", 971 | " ) for i in range(len(qcart))\n", 972 | " ] if sides else []\n", 973 | " \n", 974 | " # Create the view.\n", 975 | " f = polyshow2(\n", 976 | " p + list(q),\n", 977 | " color=pcolors + qcolors,\n", 978 | " label=plabels + qlabels,\n", 979 | " labelvertices=True,\n", 980 | " lines=lines\n", 981 | " )\n", 982 | " plt.savefig('frames/{:04d}.png'.format(i), dpi=200)\n", 983 | " # Show it.\n", 984 | " #svgfig(f)" 985 | ], 986 | "execution_count": 34, 987 | "outputs": [] 988 | }, 989 | { 990 | "cell_type": "code", 991 | "metadata": { 992 | "id": "fNKqb30btBcX", 993 | "colab_type": "code", 994 | "colab": { 995 | "base_uri": "https://localhost:8080/", 996 | "height": 263 997 | }, 998 | "outputId": "706da3c5-03b2-46d7-a3b8-9181be2817fe" 999 | }, 1000 | "source": [ 1001 | "testpoly([np.array([1/3,1/3,1/3]),np.array([1/2,1/2,0]), rand(3), rand(3)], 0, sides=False)" 1002 | ], 1003 | "execution_count": 46, 1004 | "outputs": [ 1005 | { 1006 | "output_type": "display_data", 1007 | "data": { 1008 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAAD2CAYAAAB1JFQuAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIG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pSsikiGVrohIhlS6IiIZ+v8mtmGkYlD/dQAAAABJRU5ErkJggg==\n", 1009 | "text/plain": [ 1010 | "
" 1011 | ] 1012 | }, 1013 | "metadata": { 1014 | "tags": [] 1015 | } 1016 | } 1017 | ] 1018 | }, 1019 | { 1020 | "cell_type": "code", 1021 | "metadata": { 1022 | "id": "lBBcLikcpYfs", 1023 | "colab_type": "code", 1024 | "colab": {} 1025 | }, 1026 | "source": [ 1027 | "def cart2bary(x, y):\n", 1028 | " corners = polycorners(3)\n", 1029 | " x1, y1 = corners[0]\n", 1030 | " x2, y2 = corners[1]\n", 1031 | " x3, y3 = corners[2]\n", 1032 | " l1 = ((y2-y3)*(x-x3)+(x3-x2)*(y-y3))/((y2-y3)*(x1-x3)+(x3-x2)*(y1-y3))\n", 1033 | " l2 = ((y3-y1)*(x-x3)+(x1-x3)*(y-y3))/((y2-y3)*(x1-x3)+(x3-x2)*(y1-y3))\n", 1034 | " l3 = 1-l1-l2\n", 1035 | " return [l1,l2,l3]" 1036 | ], 1037 | "execution_count": 36, 1038 | "outputs": [] 1039 | }, 1040 | { 1041 | "cell_type": "code", 1042 | "metadata": { 1043 | "id": "SNavOqQxowQf", 1044 | "colab_type": "code", 1045 | "colab": { 1046 | "base_uri": "https://localhost:8080/", 1047 | "height": 34 1048 | }, 1049 | "outputId": "180dd74f-35c4-43ef-b01a-f1e269c508f8" 1050 | }, 1051 | "source": [ 1052 | "circumcircle(bary2cart(np.array([0,0,1/2])), bary2cart(np.array([0,1/2,0])), bary2cart(np.array([1/2,0,0])))" 1053 | ], 1054 | "execution_count": 37, 1055 | "outputs": [ 1056 | { 1057 | "output_type": "execute_result", 1058 | "data": { 1059 | "text/plain": [ 1060 | "(0.5, 0.5)" 1061 | ] 1062 | }, 1063 | "metadata": { 1064 | "tags": [] 1065 | }, 1066 | "execution_count": 37 1067 | } 1068 | ] 1069 | }, 1070 | { 1071 | "cell_type": "code", 1072 | "metadata": { 1073 | "id": "3eE5i2OJDMVc", 1074 | "colab_type": "code", 1075 | "colab": {} 1076 | }, 1077 | "source": [ 1078 | "#!rm frames/*.png\n", 1079 | "!mkdir frames" 1080 | ], 1081 | "execution_count": 38, 1082 | "outputs": [] 1083 | }, 1084 | { 1085 | "cell_type": "code", 1086 | "metadata": { 1087 | "id": "HLeuBsCG24PF", 1088 | "colab_type": "code", 1089 | "colab": {} 1090 | }, 1091 | "source": [ 1092 | "frames = duration_sec * mp4_fps\n", 1093 | "for i in range(int(frames)):\n", 1094 | " t = i / frames\n", 1095 | " b1 = get_point(t, points_p0, duration_sec=frames/mp4_fps, mp4_fps=mp4_fps)\n", 1096 | " b2 = get_point(t, points_p1, duration_sec=frames/mp4_fps, mp4_fps=mp4_fps)\n", 1097 | " b3 = get_point(t, points_p2, duration_sec=frames/mp4_fps, mp4_fps=mp4_fps)\n", 1098 | " #testpoly(b2, i, sides=False)\n", 1099 | " testpoly([b1, b2, b3], i, sides=False)" 1100 | ], 1101 | "execution_count": null, 1102 | "outputs": [] 1103 | }, 1104 | { 1105 | "cell_type": "markdown", 1106 | "metadata": { 1107 | "id": "TcWTaeI0lXlk", 1108 | "colab_type": "text" 1109 | }, 1110 | "source": [ 1111 | "# Put the two videos together side-by-side" 1112 | ] 1113 | }, 1114 | { 1115 | "cell_type": "code", 1116 | "metadata": { 1117 | "id": "ZaI21AV-4aOM", 1118 | "colab_type": "code", 1119 | "colab": {} 1120 | }, 1121 | "source": [ 1122 | "!ffmpeg -r 20 -i frames/%04d.png -c:v libx264 -vf fps=20 -vf scale=1536:1200 -pix_fmt yuv420p /content/triangle.mp4" 1123 | ], 1124 | "execution_count": null, 1125 | "outputs": [] 1126 | }, 1127 | { 1128 | "cell_type": "code", 1129 | "metadata": { 1130 | "id": "RhKWHv6zswZT", 1131 | "colab_type": "code", 1132 | "colab": {} 1133 | }, 1134 | "source": [ 1135 | "!ffmpeg -i $(find /content/stylegan2 -name \"*.mp4\") -i /content/triangle.mp4 -filter_complex '[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]' -map [vid] -c:v libx264 -crf 29 /content/output.mp4" 1136 | ], 1137 | "execution_count": null, 1138 | "outputs": [] 1139 | }, 1140 | { 1141 | "cell_type": "code", 1142 | "metadata": { 1143 | "id": "luhk5EYMQuWA", 1144 | "colab_type": "code", 1145 | "colab": { 1146 | "base_uri": "https://localhost:8080/", 1147 | "height": 17 1148 | }, 1149 | "outputId": "d3e10ed8-629c-4335-bea8-cb50662c3819" 1150 | }, 1151 | "source": [ 1152 | "# You may need to run this cell twice to get the video to download\n", 1153 | "from google.colab import files\n", 1154 | "files.download(\"/content/output.mp4\") " 1155 | ], 1156 | "execution_count": 42, 1157 | "outputs": [ 1158 | { 1159 | "output_type": "display_data", 1160 | "data": { 1161 | "application/javascript": [ 1162 | "\n", 1163 | " async function download(id, filename, size) {\n", 1164 | " if (!google.colab.kernel.accessAllowed) {\n", 1165 | " return;\n", 1166 | " }\n", 1167 | " const div = document.createElement('div');\n", 1168 | " const label = document.createElement('label');\n", 1169 | " label.textContent = `Downloading \"${filename}\": `;\n", 1170 | " div.appendChild(label);\n", 1171 | " const progress = document.createElement('progress');\n", 1172 | " progress.max = size;\n", 1173 | " div.appendChild(progress);\n", 1174 | " document.body.appendChild(div);\n", 1175 | "\n", 1176 | " const buffers = [];\n", 1177 | " let downloaded = 0;\n", 1178 | "\n", 1179 | " const channel = await google.colab.kernel.comms.open(id);\n", 1180 | " // Send a message to notify the kernel that we're ready.\n", 1181 | " channel.send({})\n", 1182 | "\n", 1183 | " for await (const message of channel.messages) {\n", 1184 | " // Send a message to notify the kernel that we're ready.\n", 1185 | " channel.send({})\n", 1186 | " if (message.buffers) {\n", 1187 | " for (const buffer of message.buffers) {\n", 1188 | " buffers.push(buffer);\n", 1189 | " downloaded += buffer.byteLength;\n", 1190 | " progress.value = downloaded;\n", 1191 | " }\n", 1192 | " }\n", 1193 | " }\n", 1194 | " const blob = new Blob(buffers, {type: 'application/binary'});\n", 1195 | " const a = document.createElement('a');\n", 1196 | " a.href = window.URL.createObjectURL(blob);\n", 1197 | " a.download = filename;\n", 1198 | " div.appendChild(a);\n", 1199 | " a.click();\n", 1200 | " div.remove();\n", 1201 | " }\n", 1202 | " " 1203 | ], 1204 | "text/plain": [ 1205 | "" 1206 | ] 1207 | }, 1208 | "metadata": { 1209 | "tags": [] 1210 | } 1211 | }, 1212 | { 1213 | "output_type": "display_data", 1214 | "data": { 1215 | "application/javascript": [ 1216 | "download(\"download_d78b707d-faff-488b-b972-a76b31795b56\", \"output.mp4\", 17569249)" 1217 | ], 1218 | "text/plain": [ 1219 | "" 1220 | ] 1221 | }, 1222 | "metadata": { 1223 | "tags": [] 1224 | } 1225 | } 1226 | ] 1227 | } 1228 | ] 1229 | } -------------------------------------------------------------------------------- /Preprocess Danbooru Vectors - StyleGAN Conditional.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import warnings\n", 10 | "import re\n", 11 | "import pandas as pd\n", 12 | "import numpy as np\n", 13 | "from gensim.models.doc2vec import Doc2Vec, TaggedDocument\n", 14 | "from nltk.tokenize import word_tokenize\n", 15 | "from nltk.corpus import stopwords\n", 16 | "import pickle" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 2, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "id,tags,created_at,uploader_id,source,score,up_score,down_score,favs,md5,file_size,file_ext,rating,is_status_locked,is_pending,is_flagged,is_deleted,width,height,has_children,parent_id,pools\n", 29 | "263167,0:1girl 0:ankle_ribbon 5:artist_request 0:bangs 0:barefoot 0:blunt_bangs 0:brown_hair 0:eyes 0:hair_bun 0:hime_cut 0:japanese_clothes 0:long_hair 4:miyu_(vampire_princess_miyu) 0:ribbon 0:solo 3:vampire_princess_miyu 0:yellow_eyes,2008-06-10 03:16:23.64871 UTC,65792,,0,0,0,89268 68238,e5a4b492bc46d8ee9ac1dda94ed43387,52253,jpg,s,False,False,False,False,551,778,False,0,\n", 30 | "332446,0:1boy 0:1girl 5:absurdres 0:animal_print 5:bad_id 5:bad_pixiv_id 0:bat_print 0:bat_wings 0:blood 0:demon_girl 1:harmaline 0:head_wings 5:highres 0:long_hair 4:morrigan_aensland 0:pantyhose 0:print_legwear 0:red_eyes 0:succubus 3:vampire_(game) 0:wings,2008-10-17 02:34:45.35441 UTC,13056,http://img04.pixiv.net/img/takana/1809424.jpg,0,0,0,,69fb3d60085c54b1e8573574c7433991,3912531,jpg,s,False,False,False,False,1600,3300,False,0,\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "!head -n 3 danbooru.csv" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "warnings.filterwarnings('ignore')" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "import urllib.parse\n", 54 | "face_tags = urllib.parse.unquote(\"angry anger_vein annoyed clenched_teeth blush blush_stickers embarrassed bored closed_eyes confused crazy disdain disgust drunk envy expressionless evil facepalm flustered frustrated grimace guilt happy kubrick_stare lonely nervous nosebleed one_eye_closed open_mouth closed_mouth parted_lips pain pout raised_eyebrow rape_face rolling_eyes sad depressed frown gloom_%28expression%29 tears horns scared panicking worried serious sigh sleepy tired sulking thinking pensive wince afterglow ahegao fucked_silly naughty_face torogao smile crazy_smile evil_smile fingersmile forced_smile glasgow_smile grin fang evil_grin light_smile sad_smile seductive_smile stifled_laugh smug doyagao smirk smug troll_face surprised scared %2F%5C%2F%5C%2F%5C color_drain horror_%28expression%29 screaming turn_pale trembling wavy_mouth %3B%29 %3Ad %3Bd xd d%3A %3A%7D %3A%7B %3A3 %3B3 x3 3%3A uwu %3D.w.%3D %3Ap %3Bp %3Aq %3Bq %3E%3A%29 %3E%3A%28 %3At %3Ai %3A%2F %3Ax %3Ac c%3A %3A%3C %3B%3C %3A%3C%3E %3A%3E %3A%3E%3D %3B%3E%3D %3Ao %3Bo %3D %3D%29 %3Dd %3Do %3Dv %7C3 %7Cd %7Co o3o %28-3-%29 %3E3%3C o_o 0_0 ._. %E2%80%A2_%E2%80%A2 solid_circle_eyes %E2%99%A5_%E2%99%A5 heart_eyes %5E_%5E %5Eo%5E %5C%28%5Eo%5E%29%2F %E2%94%94%28%5Eo%5E%29%E2%94%90%E2%89%A1 %5Eq%5E %3E_%3C xd x3 %3Eo%3C %3C_%3E %3B_%3B %40_%40 %3E_%40 %2B_%2B %2B_- -_- %5C_%2F %3D_%3D %3D%5E%3D %3Dv%3D %3Co%3E_%3Co%3E constricted_pupils cross_eyed rectangular_mouth sideways_mouth no_nose no_mouth wavy_mouth wide-eyed mouth_drool awesome_face foodgasm henohenomoheji nonowa portrait profile smiley_face uso_da food_awe breast_awe penis_awe\").split()\n", 55 | "eye_tags = urllib.parse.unquote(\"aqua_eyes black_eyes blue_eyes brown_eyes green_eyes grey_eyes orange_eyes lavender_eyes pink_eyes purple_eyes red_eyes silver_eyes white_eyes yellow_eyes heterochromia multicolored_eyes al_bhed_eyes pac-man_eyes ringed_eyes constricted_pupils dilated_pupils horizontal_pupils no_pupils slit_pupils symbol-shaped_pupils %2B_%2B heart-shaped_pupils star-shaped_pupils blue_sclera black_sclera blank_eyes bloodshot_eyes green_sclera mismatched_sclera orange_sclera red_sclera yellow_sclera bags_under_eyes bruised_eye flaming_eyes glowing_eyes glowing_eye mako_eyes amphibian_eyes button_eyes cephalopod_eyes compound_eyes frog_eyes crazy_eyes empty_eyes heart_eyes nonowa solid_circle_eyes o_o 0_0 jitome tareme tsurime sanpaku sharingan mangekyou_sharingan eye_reflection text_in_eyes missing_eye one-eyed third_eye extra_eyes no_eyes\").split()\n", 56 | "eye_expressions = urllib.parse.unquote(\"%3E_%3C x3 xd o_o 0_0 3_3 6_9 %40_%40 %5E_%5E %5Eo%5E 9848 26237 %3D_%3D %2B_%2B ._. %3Co%3E_%3Co%3E blinking closed_eyes wince one_eye_closed %3B%3C %3B%3E %3Bp\").split()\n", 57 | "eye_other = urllib.parse.unquote(\"covering_eyes hair_over_eyes hair_over_one_eye bandage_over_one_eye blindfold hat_over_eyes eyepatch eyelashes colored_eyelashes fake_eyelashes eyes_visible_through_hair glasses makeup eyeliner eyeshadow mascara eye_contact looking_afar looking_at_another looking_at_breasts looking_at_hand looking_at_mirror looking_at_phone looking_at_viewer looking_away looking_back looking_down looking_out_window looking_over_glasses looking_through_legs looking_to_the_side looking_up akanbe blind cross-eyed drawn_on_eyes eyeball eye_beam eye_poke eye_pop persona_eyes shading_eyes squinting staring uneven_eyes upturned_eyes wall-eyed wide-eyed wince\").split()\n", 58 | "ears_tags = urllib.parse.unquote(\"animal_ears bear_ears bunny_ears cat_ears dog_ears fake_animal_ears fox_ears horse_ears kemonomimi_mode lion_ears monkey_ears mouse_ears raccoon_ears sheep_ears tiger_ears wolf_ears pointy_ears robot_ears extra_ears ear_piercing ear_protection earrings single_earring headphones covering_ears ear_biting ear_licking ear_grab\").split()\n", 59 | "hair_tags = urllib.parse.unquote(\"heartbreak_haircut hand_in_hair adjusting_hair bunching_hair hair_flip hair_grab hair_pull hair_tucking hair_tousle hair_twirling hair_sex hair_brush hair_dryer shampoo bun_cover hairpods chopsticks comb hair_ornament hair_bell hair_bobbles hair_bow hair_ribbon hairclip hairpin hair_flower hair_tubes kanzashi hair_tie hairband hair_weapon headband scrunchie wig facial_hair beard bearded_girl goatee mustache fake_mustache stubble fiery_hair prehensile_hair helicopter_hair tentacle_hair living_hair detached_hair severed_hair floating_hair hair_spread_out wet_hair\").split()\n", 60 | "hair_color_tags = urllib.parse.unquote(\"aqua_hair black_hair blonde_hair blue_hair light_blue_hair brown_hair light_brown_hair green_hair grey_hair magenta_hair orange_hair pink_hair purple_hair lavender_hair red_hair auburn_hair maroon_hair silver_hair white_hair multicolored_hair colored_inner_hair gradient_hair rainbow_hair streaked_hair two-tone_hair highlights colored_tips alternate_hair_color\").split()\n", 61 | "hair_style_tags = urllib.parse.unquote(\"very_short_hair short_hair medium_hair long_hair very_long_hair absurdly_long_hair big_hair bald bald_girl alternate_hairstyle hair_down hair_up curly_hair drill_hair twin_drills flipped_hair hair_flaps messy_hair pointy_hair ringlets spiked_hair wavy_hair bangs asymmetrical_bangs blunt_bangs hair_over_eyes hair_over_one_eye parted_bangs swept_bangs hair_between_eyes hair_intakes sidelocks widow%27s_peak ahoge heart_ahoge huge_ahoge antenna_hair comb_over hair_pulled_back hair_slicked_back mohawk hair_bikini hair_censor hair_in_mouth hair_over_breasts hair_over_one_breast hair_over_crotch hair_over_shoulder hair_scarf bow_by_hair braid braided_bangs front_braid side_braid french_braid crown_braid single_braid multiple_braids twin_braids tri_braids quad_braids hair_bun braided_bun double_bun triple_bun hair_rings half_updo one_side_up two_side_up low-braided_long_hair low-tied_long_hair mizura multi-tied_hair nihongami ponytail folded_ponytail front_ponytail high_ponytail short_ponytail side_ponytail split_ponytail topknot twintails low_twintails short_twintails uneven_twintails tri_tails quad_tails quin_tails bob_cut bowl_cut buzz_cut chonmage crew_cut flattop pixie_cut undercut cornrows hairlocs hime_cut mullet afro huge_afro beehive_hairdo pompadour quiff shouten_pegasus_mix_mori\").split()\n", 62 | "skin_color_tags = urllib.parse.unquote(\"dark_skin pale_skin tan tanlines sun_tattoo black_skin blue_skin green_skin grey_skin orange_skin pink_skin purple_skin red_skin white_skin yellow_skin shiny_skin\").split()\n", 63 | "headwear_tags = urllib.parse.unquote(\"crown hat helmet black_headwear blue_headwear brown_headwear green_headwear grey_headwear orange_headwear pink_headwear purple_headwear red_headwear white_headwear yellow_headwear ajirogasa animal_hat cat_hat penguin_hat baseball_cap beanie beret bicorne boater_hat bowl_hat bowler_hat bucket_hat cabbie_hat chef_hat toque_blanche flat_top_chef_hat cloche_hat cowboy_hat deerstalker deviruchi_hat dixie_cup_hat eggshell_hat fedora female_service_cap flat_cap fur_hat garrison_cap jester_cap kepi mian_guan mitre mob_cap mortarboard nightcap nurse_cap party_hat peaked_cap pillow_hat pirate_hat porkpie_hat pumpkin_hat rice_hat robe_and_wizard_hat sailor_hat santa_hat mini_santa_hat shako_cap shampoo_hat sombrero sun_hat tam_o%27_shanter tate_eboshi tokin_hat top_hat mini_top_hat tricorne ushanka witch_hat mini_witch_hat wizard_hat veil zun_hat baseball_helmet bicycle_helmet brodie_helmet diving_helmet football_helmet hardhat horned_helmet helm kabuto motorcycle_helmet pickelhaube pith_helmet stahlhelm tank_helmet winged_helmet circlet diadem mini_crown saishi tiara aviator_cap bandana bonnet dalachi_%28headdress%29 habit hijab keffiyeh shower_cap visor_cap checkered_hat frilled_hat military_hat mini_hat multicolored_hat police_hat print_hat school_hat straw_hat adjusting_hat hand_on_headwear hands_on_headwear hat_basket hat_loss hat_on_chest hat_over_eyes hat_over_one_eye hat_removed hat_tip holding_hat torn_hat no_hat hat_bow hat_feather hat_flower hat_ribbon hat_with_ears adjusting_hat backwards_hat hat_removed holding_hat torn_hat hair_bow hair_ribbon hairband headband forehead_protector sweatband hachimaki nejiri_hachimaki mongkhon headdress maid_headdress veil hood\").split()\n", 64 | "neckwear_tags = urllib.parse.unquote(\"collarbone nape neck long_neck arm_around_neck arms_around_neck hand_on_another%27s_neck hand_on_own_neck neck_biting necking neck_kiss ascot bolo_tie bowtie choker bell_choker ribbon_choker collar bell_collar dog_collar spiked_collar studded_collar cravat elizabethan_collar feather_boa goggles_around_neck headphones_around_neck lanyard neckerchief necklace chain_necklace flower_necklace lei friendship_charm pearl_necklace pendant amulet locket magatama pentacle neck_ribbon neck_ruff necktie necktie_between_breasts necktie_on_head necktie_grab necktie_removed scarf stole x-shaped_choker ascot bowtie choker neck_ribbon neckerchief necktie aqua_neckwear black_neckwear blue_neckwear brown_neckwear green_neckwear grey_neckwear orange_neckwear pink_neckwear purple_neckwear red_neckwear white_neckwear yellow_neckwear checkered_neckwear plaid_neckwear striped_neckwear collar_grab collar_tug adjusting_collar collared_shirt detached_collar fur_collar high_collar open_collar popped_collar sailor_collar turtleneck sleeveless_turtleneck v-neck wing_collar\").split()\n", 65 | "eyewear_tags = urllib.parse.unquote(\"glasses monocle sunglasses aqua-framed_eyewear black-framed_eyewear blue-framed_eyewear brown-framed_eyewear green-framed_eyewear grey-framed_eyewear orange-framed_eyewear pink-framed_eyewear purple-framed_eyewear red-framed_eyewear white-framed_eyewear yellow-framed_eyewear blue-tinted_eyewear brown-tinted_eyewear green-tinted_eyewear orange-tinted_eyewear pink-tinted_eyewear purple-tinted_eyewear red-tinted_eyewear yellow-tinted_eyewear heart-shaped_eyewear round_eyewear over-rim_eyewear rimless_eyewear semi-rimless_eyewear under-rim_eyewear adjusting_eyewear eyewear_on_head eyewear_removed eyewear_hang eyewear_in_mouth holding_eyewear eyewear_strap eyewear_switch looking_over_eyewear no_eyewear 3d_glasses coke-bottle_glasses diving_mask fancy_glasses heart-shaped_eyewear funny_glasses goggles nodoka_glasses opaque_glasses pince-nez safety_glasses shooting_glasses ski_goggles x-ray_glasses bespectacled kamina_shades star_shades\").split()\n", 66 | "piercings_tags = urllib.parse.unquote(\"ear_piercing eyebrow_piercing anti-eyebrow_piercing eyelid_piercing lip_piercing labret_piercing nose_piercing bridge_piercing tongue_piercing\").split()\n", 67 | "format_tags = urllib.parse.unquote(\"3d animated animated_png flash music_video song video animated_gif non-looping_animation archived_file artbook bmp calendar_%28medium%29 card_%28medium%29 comic 2koma 3koma 4koma multiple_4koma 5koma borderless_panels doujinshi eromanga left-to-right_manga right-to-left_comic silent_comic corrupted_image cover album_cover character_single cover_page doujin_cover dvd_cover fake_cover game_cover magazine_cover manga_cover fake_screenshot game_cg gyotaku_%28medium%29 highres absurdres incredibly_absurdres lowres thumbnail huge_filesize icon logo kirigami lineart no_lineart outline long_image tall_image wide_image mosaic_art photomosaic oekaki official_art phonecard photo papercraft paper_child paper_cutout pixel_art postcard poster revision bad_revision artifacted_revision censored_revision corrupted_revision lossy_revision watermarked_revision scan screencap shitajiki tegaki transparent_background triptych_%28art%29 vector_trace wallpaper dual_monitor ios_wallpaper official_wallpaper phone_wallpaper psp_wallpaper tileable wallpaper_forced widescreen\").split()\n", 68 | "style_tags = urllib.parse.unquote(\"abstract art_deco art_nouveau fine_art_parody flame_painter impressionism nihonga sumi-e ukiyo-e minimalism realistic photorealistic sketch style_parody list_of_style_parodies surreal traditional_media faux_traditional_media work_in_progress backlighting blending bloom bokeh caustics chiaroscuro chromatic_aberration chromatic_aberration_abuse diffraction_spikes depth_of_field dithering drop_shadow emphasis_lines foreshortening gradient halftone lens_flare lens_flare_abuse motion_blur motion_lines multiple_monochrome optical_illusion anaglyph exif_thumbnail_surprise open_in_internet_explorer open_in_winamp stereogram scanlines silhouette speed_lines vignetting\").split()\n", 69 | "all_tags = face_tags+eye_tags+eye_expressions+eye_other+ears_tags+hair_tags+hair_color_tags+hair_style_tags+skin_color_tags+headwear_tags+eyewear_tags+piercings_tags+format_tags+style_tags\n" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "#count = 0\n", 79 | "import csv\n", 80 | "class MyCorpus(object):\n", 81 | " def __init__(self):\n", 82 | " self.count = 0\n", 83 | " def __iter__(self):\n", 84 | " with open('danbooru.csv', newline='', encoding='utf-8') as csvfile:\n", 85 | " reader = csv.DictReader(csvfile)\n", 86 | " for row in reader:\n", 87 | " self.count = self.count + 1\n", 88 | " #fields = line.split(\",\")\n", 89 | " index = int(row['id'])\n", 90 | " tags = str(row['tags']).split()\n", 91 | " # assume there's one document per line, tokens separated by whitespace\n", 92 | " if self.count % 5000 == 0:\n", 93 | " print(self.count, index)\n", 94 | " words = []\n", 95 | " for tag in tags:\n", 96 | " if tag.split(\":\")[0] != '0' or (tag.split(\":\")[1] in all_tags):\n", 97 | " words.append(tag)\n", 98 | " yield TaggedDocument(words=words, tags=[index])" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "# instantiate Doc2Vec model\n", 108 | "\n", 109 | "max_epochs = 20\n", 110 | "vec_size = 128\n", 111 | "alpha = 0.025\n", 112 | "\n", 113 | "model = Doc2Vec(size=vec_size,\n", 114 | " alpha=alpha, \n", 115 | " min_alpha=0.00025,\n", 116 | " min_count=100,\n", 117 | " max_vocab_size=1000000,\n", 118 | " #docvecs_mapfile='danbooru/mapfile1.txt',\n", 119 | " #verbose=True,\n", 120 | " workers=7,\n", 121 | " dm=0) # paragraph vector distributed bag-of-words (PV-DBOW)\n", 122 | " \n" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": { 129 | "scrolled": true 130 | }, 131 | "outputs": [], 132 | "source": [ 133 | "corpus = MyCorpus()\n", 134 | "print(corpus)\n", 135 | "model.build_vocab(corpus, progress_per=10000)" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "metadata": { 142 | "scrolled": true 143 | }, 144 | "outputs": [], 145 | "source": [ 146 | "# train Doc2Vec model\n", 147 | "# stochastic (random initialization), so each run will be different unless you specify seed\n", 148 | "from gensim.test.utils import get_tmpfile\n", 149 | "fname = \"danbooru/danbooru_subset_tags_128.d2v\"\n", 150 | "print('Epoch', end = ': ')\n", 151 | "for epoch in range(max_epochs):\n", 152 | " print(epoch, end = ' ')\n", 153 | " model.train(corpus,\n", 154 | " total_examples=model.corpus_count,\n", 155 | " epochs=model.epochs)\n", 156 | " # decrease the learning rate\n", 157 | " model.alpha -= 0.0002\n", 158 | " # fix the learning rate, no decay\n", 159 | " model.min_alpha = model.alpha\n", 160 | " model.save(fname)\n" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": null, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "len(all_tags)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "# Load model, test with some vectors" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "import pandas as pd\n", 186 | "import numpy as np\n", 187 | "import umap\n", 188 | "import umap.plot\n", 189 | "import matplotlib.pyplot as plt" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "fname = \"danbooru/danbooru_subset_tags_128.d2v\"\n", 199 | "model = Doc2Vec.load(fname)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": null, 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "vecs = model.docvecs.vectors_docs" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": null, 214 | "metadata": {}, 215 | "outputs": [], 216 | "source": [ 217 | "model.docvecs[263167]" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": null, 223 | "metadata": {}, 224 | "outputs": [], 225 | "source": [ 226 | "test_tags = \"0:1girl 0:ankle_ribbon 5:artist_request 0:bangs 0:barefoot 0:blunt_bangs 0:brown_hair 0:eyes 0:hair_bun 0:hime_cut 0:japanese_clothes 0:long_hair 4:miyu_(vampire_princess_miyu) 0:ribbon 0:solo 3:vampire_princess_miyu 0:yellow_eyes\".split()" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": null, 232 | "metadata": {}, 233 | "outputs": [], 234 | "source": [ 235 | "test_words = []\n", 236 | "for tag in test_tags:\n", 237 | " if tag.split(\":\")[0] != '0' or (tag.split(\":\")[1] in all_tags):\n", 238 | " test_words.append(tag)\n", 239 | "test_words" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": null, 245 | "metadata": {}, 246 | "outputs": [], 247 | "source": [ 248 | "vector = model.infer_vector(test_words)\n", 249 | "vector" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": null, 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "sims = model.docvecs.most_similar([vector])" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": null, 264 | "metadata": {}, 265 | "outputs": [], 266 | "source": [ 267 | "sims" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": null, 273 | "metadata": {}, 274 | "outputs": [], 275 | "source": [ 276 | "holo_vec = model.infer_vector([\"0:animal_ears\", \"0:red_eyes\", \"0:wolf_ears\"])\n", 277 | "holo_vec" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": null, 283 | "metadata": {}, 284 | "outputs": [], 285 | "source": [ 286 | "holo_sims = model.docvecs.most_similar([holo_vec])\n", 287 | "holo_sims" 288 | ] 289 | }, 290 | { 291 | "cell_type": "markdown", 292 | "metadata": {}, 293 | "source": [ 294 | "# Get just the vectors we care about" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": null, 300 | "metadata": {}, 301 | "outputs": [], 302 | "source": [ 303 | "import glob\n", 304 | "import sys\n", 305 | "import os\n", 306 | "def _get_all_files(path):\n", 307 | " if os.path.isfile(path):\n", 308 | " return [path]\n", 309 | "\n", 310 | " possible_files = sorted(glob.glob(os.path.join(path, \"*\")))\n", 311 | " return_list = []\n", 312 | " for possible_file in possible_files:\n", 313 | " return_list.extend(_get_all_files(possible_file))\n", 314 | " return return_list" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": null, 320 | "metadata": {}, 321 | "outputs": [], 322 | "source": [ 323 | "portrait_files = _get_all_files(\"portraits\")\n", 324 | "portrait_files" 325 | ] 326 | }, 327 | { 328 | "cell_type": "code", 329 | "execution_count": null, 330 | "metadata": {}, 331 | "outputs": [], 332 | "source": [ 333 | "A = model.docvecs[1000031]\n", 334 | "for file in portrait_files[1:]:\n", 335 | " f = file.split(\"/\")[-1].split(\".\")[0]\n", 336 | " index = int(f[:len(f)-1])\n", 337 | " print(file, index)\n", 338 | " vec = model.docvecs[index]\n", 339 | " A = np.vstack([A, vec])" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": null, 345 | "metadata": {}, 346 | "outputs": [], 347 | "source": [ 348 | "A.shape" 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": null, 354 | "metadata": {}, 355 | "outputs": [], 356 | "source": [ 357 | "np.save(\"portraits/labels.npy\", A)" 358 | ] 359 | } 360 | ], 361 | "metadata": { 362 | "kernelspec": { 363 | "display_name": "Python 3", 364 | "language": "python", 365 | "name": "python3" 366 | }, 367 | "language_info": { 368 | "codemirror_mode": { 369 | "name": "ipython", 370 | "version": 3 371 | }, 372 | "file_extension": ".py", 373 | "mimetype": "text/x-python", 374 | "name": "python", 375 | "nbconvert_exporter": "python", 376 | "pygments_lexer": "ipython3", 377 | "version": "3.7.5" 378 | } 379 | }, 380 | "nbformat": 4, 381 | "nbformat_minor": 2 382 | } 383 | -------------------------------------------------------------------------------- /StyleGAN2 Network Interpolation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stderr", 10 | "output_type": "stream", 11 | "text": [ ] 12 | }, 13 | { 14 | "name": "stdout", 15 | "output_type": "stream", 16 | "text": [ 17 | "Setting up TensorFlow plugin \"fused_bias_act.cu\": Preprocessing... Loading... Done.\n", 18 | "Setting up TensorFlow plugin \"upfirdn_2d.cu\": Preprocessing... Loading... Done.\n" 19 | ] 20 | } 21 | ], 22 | "source": [ 23 | "import ipywidgets as widgets\n", 24 | "import pretrained_networks\n", 25 | "import PIL.Image\n", 26 | "import numpy as np\n", 27 | "src_model = '2020-01-11-skylion-stylegan2-animeportraits-networksnapshot-024664.pkl'\n", 28 | "dst_model = 'e621-network-snapshot-011573.pkl'\n", 29 | "_G, _D, Gs = pretrained_networks.load_networks(src_model)\n", 30 | "_Gd, _Dd, Gsd = pretrained_networks.load_networks(dst_model)\n", 31 | "bGs = Gs.clone()\n", 32 | "import dnnlib\n", 33 | "import dnnlib.tflib as tflib\n", 34 | "Gs_syn_kwargs = dnnlib.EasyDict()\n", 35 | "batch_size = 1\n", 36 | "Gs_syn_kwargs.output_transform = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)\n", 37 | "Gs_syn_kwargs.randomize_noise = True\n", 38 | "Gs_syn_kwargs.minibatch_size = batch_size\n", 39 | "\n", 40 | "noise_vars = [var for name, var in Gs.components.synthesis.vars.items() if name.startswith('noise')]" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 2, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "from dnnlib.tflib import tfutil\n", 50 | "def weighted_average(src_net, dst_net, t):\n", 51 | " names = []\n", 52 | " for name in src_net.trainables.keys():\n", 53 | " if name not in src_net.trainables:\n", 54 | " print(\"Not restoring (not present): {}\".format(name))\n", 55 | " elif dst_net.trainables[name].shape != src_net.trainables[name].shape:\n", 56 | " print(\"Not restoring (different shape): {}\".format(name))\n", 57 | "\n", 58 | " if name in src_net.trainables and dst_net.trainables[name].shape == src_net.trainables[name].shape:\n", 59 | " names.append(name)\n", 60 | "\n", 61 | " tfutil.set_vars(tfutil.run({bGs.vars[name]: (t*dst_net.vars[name] + (1-t)*src_net.vars[name]) for name in names}))" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 3, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "data": { 71 | "application/vnd.jupyter.widget-view+json": { 72 | "model_id": "2919b7365b6740dca1f1d73865ec8df0", 73 | "version_major": 2, 74 | "version_minor": 0 75 | }, 76 | "text/plain": [ 77 | "VBox(children=(HBox(children=(IntSlider(value=0, continuous_update=False, description='Seed: ', max=100000), F…" 78 | ] 79 | }, 80 | "metadata": {}, 81 | "output_type": "display_data" 82 | }, 83 | { 84 | "data": { 85 | "application/vnd.jupyter.widget-view+json": { 86 | "model_id": "1b97876f1cf04d818b86bd98467feae5", 87 | "version_major": 2, 88 | "version_minor": 0 89 | }, 90 | "text/plain": [ 91 | "Output()" 92 | ] 93 | }, 94 | "metadata": {}, 95 | "output_type": "display_data" 96 | } 97 | ], 98 | "source": [ 99 | "seed = widgets.IntSlider(min=0, max=100000, step=1, value=0, description='Seed: ', continuous_update=False)\n", 100 | "scale = widgets.FloatSlider(min=0, max=5, step=0.01, value=1, description='Scale: ', continuous_update=False)\n", 101 | "truncation = widgets.FloatSlider(min=-2, max=2, step=0.1, value=1, description='Truncation: ', continuous_update=False)\n", 102 | "blending = widgets.FloatSlider(min=0, max=1, step=0.01, value=0, description='Blending: ', continuous_update=False)\n", 103 | "\n", 104 | "bot_box = widgets.HBox([seed, scale, truncation, blending])\n", 105 | "ui = widgets.VBox([bot_box])\n", 106 | "\n", 107 | "def display_sample(seed, scale, truncation, blending):\n", 108 | " weighted_average(Gs, Gsd, blending)\n", 109 | " \n", 110 | " Gs_kwargs = dnnlib.EasyDict()\n", 111 | " Gs_kwargs.output_transform = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)\n", 112 | " Gs_kwargs.randomize_noise = False\n", 113 | " if truncation is not None:\n", 114 | " Gs_kwargs.truncation_psi = truncation\n", 115 | " rnd = np.random.RandomState(seed)\n", 116 | " tflib.set_vars({var: rnd.randn(*var.shape.as_list()) for var in noise_vars}) # [height, width]\n", 117 | " \n", 118 | " batch_size = 1\n", 119 | " all_seeds = [seed] * batch_size\n", 120 | " all_z = np.stack([np.random.RandomState(seed).randn(*bGs.input_shape[1:]) for seed in all_seeds]) # [minibatch, component]\n", 121 | " all_w = bGs.components.mapping.run(scale*all_z, None) # [minibatch, layer, component]\n", 122 | " if truncation != 1:\n", 123 | " w_avg = bGs.get_var('dlatent_avg')\n", 124 | " all_w = w_avg + (all_w - w_avg) * truncation # [minibatch, layer, component]\n", 125 | " all_images = bGs.components.synthesis.run(all_w, **Gs_syn_kwargs)\n", 126 | " display(PIL.Image.fromarray(np.median(all_images, axis=0).astype(np.uint8)))\n", 127 | "\n", 128 | "out = widgets.interactive_output(display_sample, {'seed': seed, 'scale': scale, 'truncation': truncation, 'blending': blending})\n", 129 | "\n", 130 | "display(ui, out)" 131 | ] 132 | } 133 | ], 134 | "metadata": { 135 | "kernelspec": { 136 | "display_name": "Python 3", 137 | "language": "python", 138 | "name": "python3" 139 | }, 140 | "language_info": { 141 | "codemirror_mode": { 142 | "name": "ipython", 143 | "version": 3 144 | }, 145 | "file_extension": ".py", 146 | "mimetype": "text/x-python", 147 | "name": "python", 148 | "nbconvert_exporter": "python", 149 | "pygments_lexer": "ipython3", 150 | "version": "3.7.5" 151 | } 152 | }, 153 | "nbformat": 4, 154 | "nbformat_minor": 2 155 | } 156 | -------------------------------------------------------------------------------- /TADNE_Editor.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "TADNE Editor.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [ 9 | "Vutcv21e5DMC", 10 | "RIW4gdO1cjnm", 11 | "lPgEF2KJdQVa" 12 | ], 13 | "toc_visible": true, 14 | "include_colab_link": true 15 | }, 16 | "kernelspec": { 17 | "name": "python3", 18 | "display_name": "Python 3" 19 | }, 20 | "accelerator": "TPU" 21 | }, 22 | "cells": [ 23 | { 24 | "cell_type": "markdown", 25 | "metadata": { 26 | "id": "view-in-github", 27 | "colab_type": "text" 28 | }, 29 | "source": [ 30 | "\"Open" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": { 36 | "id": "PtOVza7H9z3Y" 37 | }, 38 | "source": [ 39 | "# This Anime Does Not Exist - Ganspace Editor \n", 40 | "\n", 41 | "\n", 42 | "### To run:\n", 43 | "**Click \"Open in Playground\" above (if you see that option) and then Runtime > Run All and wait a few minutes for everything to load. (Takes about 4 minutes)**\n", 44 | "\n", 45 | "\n", 46 | "---\n", 47 | "\n", 48 | "\n", 49 | "### Credits\n", 50 | "\n", 51 | "Customizable anime images using [aydao](https://twitter.com/aydaoAI)'s anime StyleGAN2 model from [TADNE](https://thisanimedoesnotexist.ai/).\n", 52 | "\n", 53 | "Latent directions were discovered using [@harskish](https://twitter.com/harskish)'s [Ganspace](https://github.com/harskish/ganspace) [notebook](https://colab.research.google.com/github/harskish/ganspace/blob/master/notebooks/Ganspace_colab.ipynb) put together by [@realmeatyhuman](https://twitter.com/realmeatyhuman).\n", 54 | "\n", 55 | "\n", 56 | "Notebook by [arfa](https://twitter.com/arfafax)\n", 57 | "\n", 58 | "\n", 59 | "
\n", 60 | "\n", 61 | "\n", 62 | "\n", 63 | "
\n", 64 | "
\n" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "id": "Vutcv21e5DMC" 71 | }, 72 | "source": [ 73 | "## <- Click the triangle to view the code while you wait for it to load\n" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "metadata": { 79 | "id": "Ixs37iA-Mxf2", 80 | "colab": { 81 | "base_uri": "https://localhost:8080/" 82 | }, 83 | "outputId": "67690325-bd15-4dce-b3ca-fa308fbba5cf" 84 | }, 85 | "source": [ 86 | "!git clone https://github.com/shawwn/stylegan2 -b estimator /content/stylegan2" 87 | ], 88 | "execution_count": 25, 89 | "outputs": [ 90 | { 91 | "output_type": "stream", 92 | "text": [ 93 | "fatal: destination path '/content/stylegan2' already exists and is not an empty directory.\n" 94 | ], 95 | "name": "stdout" 96 | } 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "metadata": { 102 | "id": "pXcjXwwhzJOW", 103 | "colab": { 104 | "base_uri": "https://localhost:8080/", 105 | "height": 0 106 | }, 107 | "outputId": "b93096ca-f7d2-4347-9f6a-d719d4d43954" 108 | }, 109 | "source": [ 110 | "import gdown\n", 111 | "gdown.download('https://drive.google.com/uc?id=1qNhyusI0hwBLI-HOavkNP5I0J0-kcN4C', 'network-tadne.pkl', quiet=False)" 112 | ], 113 | "execution_count": 26, 114 | "outputs": [ 115 | { 116 | "output_type": "stream", 117 | "text": [ 118 | "Downloading...\n", 119 | "From: https://drive.google.com/uc?id=1qNhyusI0hwBLI-HOavkNP5I0J0-kcN4C\n", 120 | "To: /content/animations/network-tadne.pkl\n", 121 | "1.06GB [00:06, 171MB/s]\n" 122 | ], 123 | "name": "stderr" 124 | }, 125 | { 126 | "output_type": "execute_result", 127 | "data": { 128 | "application/vnd.google.colaboratory.intrinsic+json": { 129 | "type": "string" 130 | }, 131 | "text/plain": [ 132 | "'network-tadne.pkl'" 133 | ] 134 | }, 135 | "metadata": { 136 | "tags": [] 137 | }, 138 | "execution_count": 26 139 | } 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "metadata": { 145 | "colab": { 146 | "base_uri": "https://localhost:8080/" 147 | }, 148 | "id": "UB-om5xBcBMr", 149 | "outputId": "e189c4d1-1676-4882-821b-6047d970cf41" 150 | }, 151 | "source": [ 152 | "!wget -O /content/tadne-directions.zip https://www.thisponydoesnotexist.net/tadne-directions.zip" 153 | ], 154 | "execution_count": 27, 155 | "outputs": [ 156 | { 157 | "output_type": "stream", 158 | "text": [ 159 | "--2021-01-28 07:37:41-- https://www.thisponydoesnotexist.net/tadne-directions.zip\n", 160 | "Resolving www.thisponydoesnotexist.net (www.thisponydoesnotexist.net)... 172.67.145.125, 104.21.65.129, 2606:4700:3037::ac43:917d, ...\n", 161 | "Connecting to www.thisponydoesnotexist.net (www.thisponydoesnotexist.net)|172.67.145.125|:443... connected.\n", 162 | "HTTP request sent, awaiting response... 302 Moved Temporarily\n", 163 | "Location: https://thisponydoesnotexist.net/tadne-directions.zip [following]\n", 164 | "--2021-01-28 07:37:41-- https://thisponydoesnotexist.net/tadne-directions.zip\n", 165 | "Resolving thisponydoesnotexist.net (thisponydoesnotexist.net)... 172.67.145.125, 104.21.65.129, 2606:4700:3032::6815:4181, ...\n", 166 | "Connecting to thisponydoesnotexist.net (thisponydoesnotexist.net)|172.67.145.125|:443... connected.\n", 167 | "HTTP request sent, awaiting response... 200 OK\n", 168 | "Length: 1966529 (1.9M) [application/zip]\n", 169 | "Saving to: ‘/content/tadne-directions.zip’\n", 170 | "\n", 171 | "/content/tadne-dire 100%[===================>] 1.88M 2.32MB/s in 0.8s \n", 172 | "\n", 173 | "2021-01-28 07:37:42 (2.32 MB/s) - ‘/content/tadne-directions.zip’ saved [1966529/1966529]\n", 174 | "\n" 175 | ], 176 | "name": "stdout" 177 | } 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "metadata": { 183 | "id": "w_diRM7Fn1Pa", 184 | "colab": { 185 | "base_uri": "https://localhost:8080/" 186 | }, 187 | "outputId": "694c7ed7-6bd5-4186-b7f3-066b22fe2f55" 188 | }, 189 | "source": [ 190 | "%tensorflow_version 1.x\n", 191 | "%cd /content/stylegan2" 192 | ], 193 | "execution_count": 28, 194 | "outputs": [ 195 | { 196 | "output_type": "stream", 197 | "text": [ 198 | "/content/stylegan2\n" 199 | ], 200 | "name": "stdout" 201 | } 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "metadata": { 207 | "id": "Pt4kvzEM39oI" 208 | }, 209 | "source": [ 210 | "import os\n", 211 | "import pickle\n", 212 | "import numpy as np\n", 213 | "import PIL.Image\n", 214 | "import dnnlib\n", 215 | "import dnnlib.tflib as tflib\n", 216 | "import scipy\n", 217 | "import tensorflow as tf\n", 218 | "import tflex" 219 | ], 220 | "execution_count": 29, 221 | "outputs": [] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "metadata": { 226 | "id": "8coaz5KZeFum" 227 | }, 228 | "source": [ 229 | "if 'COLAB_TPU_ADDR' in os.environ:\n", 230 | " os.environ['TPU_NAME'] = 'grpc://' + os.environ['COLAB_TPU_ADDR']\n", 231 | " os.environ['NOISY'] = '1'" 232 | ], 233 | "execution_count": 30, 234 | "outputs": [] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "metadata": { 239 | "id": "Mg9DrxVNJ8am" 240 | }, 241 | "source": [ 242 | "tflib.init_tf()\n", 243 | "sess = tf.get_default_session()\n", 244 | "sess.list_devices()\n", 245 | "cores = tflex.get_cores()\n", 246 | "tflex.set_override_cores(cores)\n", 247 | "_G, _D, Gs = pickle.load(open(\"/content/network-tadne.pkl\", \"rb\"))\n", 248 | "# _G = Instantaneous snapshot of the generator. Mainly useful for resuming a previous training run.\n", 249 | "# _D = Instantaneous snapshot of the discriminator. Mainly useful for resuming a previous training run.\n", 250 | "# Gs = Long-term average of the generator. Yields higher-quality results than the instantaneous snapshot." 251 | ], 252 | "execution_count": 31, 253 | "outputs": [] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "metadata": { 258 | "id": "Zh5l7AqyI_7u" 259 | }, 260 | "source": [ 261 | " def generate_image_from_w(w, truncation_psi):\n", 262 | " with tflex.device('/gpu:0'):\n", 263 | " noise_vars = [var for name, var in Gs.components.synthesis.vars.items() if name.startswith('noise')]\n", 264 | " Gs_kwargs = dnnlib.EasyDict()\n", 265 | " Gs_kwargs.output_transform = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)\n", 266 | " Gs_kwargs.randomize_noise = False\n", 267 | " if truncation_psi is not None:\n", 268 | " Gs_kwargs.truncation_psi = truncation_psi\n", 269 | " synthesis_kwargs = dict(output_transform=Gs_kwargs.output_transform, truncation_psi=truncation_psi, minibatch_size=1)\n", 270 | " images = Gs.components.synthesis.run(w, randomize_noise=False, **synthesis_kwargs)\n", 271 | " display(PIL.Image.fromarray(images[0], 'RGB').resize((500,500),Image.LANCZOS))" 272 | ], 273 | "execution_count": 32, 274 | "outputs": [] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "metadata": { 279 | "id": "OnNwBLIBJnc2", 280 | "colab": { 281 | "base_uri": "https://localhost:8080/" 282 | }, 283 | "outputId": "ac990e32-b015-4387-b83f-e30daa05b02e" 284 | }, 285 | "source": [ 286 | "%cd \"/content\"" 287 | ], 288 | "execution_count": 33, 289 | "outputs": [ 290 | { 291 | "output_type": "stream", 292 | "text": [ 293 | "/content\n" 294 | ], 295 | "name": "stdout" 296 | } 297 | ] 298 | }, 299 | { 300 | "cell_type": "code", 301 | "metadata": { 302 | "id": "dYt6T-A5JqEB", 303 | "colab": { 304 | "base_uri": "https://localhost:8080/" 305 | }, 306 | "outputId": "c2cb7285-b00b-45ba-c414-96dae2d55c16" 307 | }, 308 | "source": [ 309 | "%mkdir directions\n", 310 | "%cd directions\n", 311 | "!unzip /content/tadne-directions.zip" 312 | ], 313 | "execution_count": null, 314 | "outputs": [ 315 | { 316 | "output_type": "stream", 317 | "text": [ 318 | "mkdir: cannot create directory ‘directions’: File exists\n", 319 | "/content/directions\n", 320 | "Archive: /content/tadne-directions.zip\n", 321 | "replace c47.2_layers_6_9.npy? [y]es, [n]o, [A]ll, [N]one, [r]ename: " 322 | ], 323 | "name": "stdout" 324 | } 325 | ] 326 | }, 327 | { 328 | "cell_type": "code", 329 | "metadata": { 330 | "id": "f7mSvjWbJvb0" 331 | }, 332 | "source": [ 333 | "!rm /content/directions/StyleGAN2-Light_direction-ffhq-ipca-w-style-comp15-range8-9.pkl\n", 334 | "#!rm -r /content/directions/.ipynb_checkpoints\n", 335 | "#!mv /content/directions/directions/* /content/ganspace/directions\n", 336 | "#!rm -r /content/directions/directions" 337 | ], 338 | "execution_count": null, 339 | "outputs": [] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "metadata": { 344 | "id": "K9oJWI1PJv7e" 345 | }, 346 | "source": [ 347 | "import os\n", 348 | "named_directions = {}\n", 349 | "latent_dirs = []\n", 350 | "starts = []\n", 351 | "ends = []\n", 352 | "# \n", 353 | "path_to_directions = \"/content/directions\"\n", 354 | "\n", 355 | "# This loads the directions in a dictionary in this format:\n", 356 | "# {'name' : [direction_num, start, end]}\n", 357 | "# and you load the direction by:\n", 358 | "# directions[direction_num]\n", 359 | "\n", 360 | "for i,file in enumerate(sorted(os.listdir(path_to_directions))):\n", 361 | " np_file = np.load(f'{path_to_directions}/{file}', allow_pickle=True)\n", 362 | " name = file.split(\"_layers_\")[0].split(\"/\")[-1]\n", 363 | " file = file.split('_')\n", 364 | " comp = int(name.split(\".\")[0][1:])\n", 365 | " \n", 366 | " named_directions[f'{name}'] = [comp, int(file[-2]), int(file[-1].split('.')[0]), f'{name}']\n", 367 | " if int(file[-2]) == 0:\n", 368 | " latent_dirs.append(np_file)\n" 369 | ], 370 | "execution_count": null, 371 | "outputs": [] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "metadata": { 376 | "id": "-OSkc-vFALMM" 377 | }, 378 | "source": [ 379 | "named_directions" 380 | ], 381 | "execution_count": null, 382 | "outputs": [] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "metadata": { 387 | "id": "6N_8gJsZiMxB" 388 | }, 389 | "source": [ 390 | "import yaml\n", 391 | "%mkdir /content/animations\n", 392 | "%cd /content/animations" 393 | ], 394 | "execution_count": null, 395 | "outputs": [] 396 | }, 397 | { 398 | "cell_type": "markdown", 399 | "metadata": { 400 | "id": "YtukNhESJ_b_" 401 | }, 402 | "source": [ 403 | "# UI" 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "metadata": { 409 | "id": "Jf1NZHlaKBGV", 410 | "cellView": "form" 411 | }, 412 | "source": [ 413 | "#@title Run UI (make sure you've done Runtime > Run All first or it won't work)\n", 414 | "from ipywidgets import fixed\n", 415 | "import PIL\n", 416 | "import numpy as np\n", 417 | "import ipywidgets as widgets\n", 418 | "from PIL import Image\n", 419 | "from IPython.display import clear_output\n", 420 | "from ipywidgets import Layout, Button, Box, VBox, Label\n", 421 | "\n", 422 | "box_layout = Layout(overflow='scroll hidden',\n", 423 | " border='3px solid black',\n", 424 | " width='',\n", 425 | " height=\"500px\")\n", 426 | "\n", 427 | "loaded_w = None\n", 428 | "def display_sample(seed, truncation, direction, distance, scale, start, end, update, disp=True, save=None, noise_spec=None, **args):\n", 429 | " global loaded_w\n", 430 | " if update == False:\n", 431 | " print(\"False\")\n", 432 | " # blockPrint()\n", 433 | " rng = np.random.RandomState(seed)\n", 434 | " z = rng.standard_normal(*Gs.input_shape[1:]).reshape(1, *Gs.input_shape[1:])\n", 435 | " #z = np.load(\"/content/drive/My Drive/latents/1006-0-0-9.npy\")\n", 436 | " noise_vars = [var for name, var in Gs.components.synthesis.vars.items() if name.startswith('noise')]\n", 437 | " Gs_kwargs = dnnlib.EasyDict()\n", 438 | " Gs_kwargs.randomize_noise = False\n", 439 | "\n", 440 | " all_w = Gs.components.mapping.run(z, None, **Gs_kwargs) # [minibatch, layer, component]\n", 441 | " if loaded_w is not None:\n", 442 | " all_w = loaded_w.copy()\n", 443 | " \n", 444 | " for i, item in enumerate(args):\n", 445 | " value = args[item]\n", 446 | " start_l = named_directions[item][1]\n", 447 | " end_l = min(16, named_directions[item][2])\n", 448 | " direction_l = latent_dirs[named_directions[item][0]]\n", 449 | " for l in range(start_l, end_l):\n", 450 | " all_w[0][l] = all_w[0][l] + direction_l * value * scale\n", 451 | "\n", 452 | " if truncation != 1:\n", 453 | " w_avg = Gs.get_var('dlatent_avg')\n", 454 | " all_w = w_avg + (all_w - w_avg) * truncation # [minibatch, layer, component]\n", 455 | "\n", 456 | " generate_image_from_w(all_w, truncation)\n", 457 | "\n", 458 | "seed = np.random.randint(0,100000)\n", 459 | "style = {'description_width': 'initial', 'width': '150px'}\n", 460 | "row_length = 6\n", 461 | "\n", 462 | "seed = widgets.IntSlider(min=0, max=100000, step=1, value=seed, description='Seed: ', continuous_update=False)\n", 463 | "truncation = widgets.FloatSlider(min=0, max=2, step=0.1, value=0.4, description='Truncation: ', continuous_update=False)\n", 464 | "distance = widgets.FloatSlider(min=-10, max=10, step=0.1, value=0, description='Distance: ', continuous_update=False, style=style)\n", 465 | "scale = widgets.FloatSlider(min=0, max=10, step=0.05, value=1, description='Scale: ', continuous_update=False)\n", 466 | "start_layer = widgets.IntSlider(min=0, max=18, step=1, value=18, description='start layer: ', continuous_update=False)\n", 467 | "end_layer = widgets.IntSlider(min=0, max=18, step=1, value=18, description='end layer: ', continuous_update=False)\n", 468 | "\n", 469 | "\n", 470 | "update = widgets.Checkbox(value=True, description=\"update\")\n", 471 | "\n", 472 | "directions_list = []\n", 473 | "params = {'seed': seed, 'truncation': truncation, 'direction': fixed(0), 'distance': distance, 'scale': scale, 'start': start_layer, 'end': end_layer, 'update' : update}\n", 474 | "\n", 475 | "for i, item in enumerate(named_directions):\n", 476 | " name = named_directions[item][3]\n", 477 | " widget = widgets.FloatSlider(min=-20, max=20, step=0.1, value=0, description=name + ': ', continuous_update=False, style=style, layout={'width' : 'auto'})\n", 478 | " directions_list.append(widget)\n", 479 | " params[item] = widget\n", 480 | "\n", 481 | "top_box = widgets.HBox([seed, truncation])\n", 482 | "rename_dropdown = widgets.Dropdown(options=named_directions.keys())\n", 483 | "rename_box = widgets.Text()\n", 484 | "rename = widgets.Button(description=\"Rename\")\n", 485 | "bot_box = widgets.HBox([rename_dropdown, rename_box, rename])\n", 486 | "\n", 487 | "ui = widgets.VBox([top_box, bot_box])\n", 488 | "\n", 489 | "grid = widgets.GridspecLayout(len(directions_list)//6, 6, width='90%', height=\"300px\")\n", 490 | "for i in range(len(directions_list)//6):\n", 491 | " for j in range(6):\n", 492 | " grid[i, j] = directions_list[6*i+j]\n", 493 | " \n", 494 | "ui2 = grid\n", 495 | "\n", 496 | "\n", 497 | "random = widgets.Button(description=\"Randomize Sliders\")\n", 498 | "reset = widgets.Button(description=\"Reset Sliders\")\n", 499 | "mobile = widgets.Button(description=\"Mobile Mode\")\n", 500 | "desktop = widgets.Button(description=\"Desktop Mode\")\n", 501 | "def reset_sliders(b):\n", 502 | " directions_list = []\n", 503 | " params_new = {'seed': seed, 'truncation': truncation, 'direction': fixed(0), 'distance': distance, 'scale': scale, 'start': start_layer, 'end': end_layer, 'update' : update}\n", 504 | " for i, item in enumerate(named_directions):\n", 505 | " name = named_directions[item][3]\n", 506 | " widget = widgets.FloatSlider(min=-20, max=20, step=0.1, value=0, description=name + ': ', continuous_update=False, style=style, layout={'width' : 'auto'})\n", 507 | " directions_list.append(widget)\n", 508 | " params_new[item] = widget\n", 509 | " params = params_new\n", 510 | " grid = widgets.GridspecLayout(len(directions_list)//6, 6, width='90%', height=\"300px\")\n", 511 | " for i in range(len(directions_list)//6):\n", 512 | " for j in range(6):\n", 513 | " grid[i, j] = directions_list[6*i+j]\n", 514 | " \n", 515 | " ui2 = grid\n", 516 | " clear_output()\n", 517 | " out = widgets.interactive_output(display_sample, params)\n", 518 | " last_button = mobile\n", 519 | " if row_length == 1:\n", 520 | " last_button = desktop\n", 521 | " display(ui, out, ui2, reset, random, last_button, widgets.HBox([save_name, save_btn]), widgets.HBox([load_name, load_btn]))\n", 522 | "\n", 523 | "def random_sliders(b):\n", 524 | " directions_list = []\n", 525 | " params_new = {'seed': seed, 'truncation': truncation, 'direction': fixed(0), 'distance': distance, 'scale': scale, 'start': start_layer, 'end': end_layer, 'update' : update}\n", 526 | " for i, item in enumerate(named_directions):\n", 527 | " name = named_directions[item][3]\n", 528 | " widget = widgets.FloatSlider(min=-20, max=20, step=0.1, value=np.random.normal(scale=2.5), description=name + ': ', continuous_update=False, style=style, layout={'width' : 'auto'})\n", 529 | " directions_list.append(widget)\n", 530 | " params_new[item] = widget\n", 531 | " params = params_new\n", 532 | " grid = widgets.GridspecLayout(len(directions_list)//6, 6, width='90%', height=\"300px\")\n", 533 | " for i in range(len(directions_list)//6):\n", 534 | " for j in range(6):\n", 535 | " grid[i, j] = directions_list[6*i+j]\n", 536 | " \n", 537 | " ui2 = grid\n", 538 | " clear_output()\n", 539 | " out = widgets.interactive_output(display_sample, params)\n", 540 | " last_button = mobile\n", 541 | " if row_length == 1:\n", 542 | " last_button = desktop\n", 543 | " display(ui, out, ui2, reset, random, last_button, widgets.HBox([save_name, save_btn]), widgets.HBox([load_name, load_btn]))\n", 544 | "\n", 545 | "def mobile_mode(b):\n", 546 | " global row_length\n", 547 | " global params\n", 548 | " row_length = 1\n", 549 | " directions_list = []\n", 550 | " params_new = {'seed': seed, 'truncation': truncation, 'direction': fixed(0), 'distance': distance, 'scale': scale, 'start': start_layer, 'end': end_layer, 'update' : update}\n", 551 | " for i, item in enumerate(named_directions):\n", 552 | " name = named_directions[item][3]\n", 553 | " widget = widgets.FloatSlider(min=-20, max=20, step=0.1, value=params[item].value, description=name + ': ', continuous_update=False, style=style, layout={'width' : 'auto'})\n", 554 | " directions_list.append(widget)\n", 555 | " params_new[item] = widget\n", 556 | " params = params_new\n", 557 | " row_list = []\n", 558 | " foo = []\n", 559 | " for i, item in enumerate(directions_list):\n", 560 | " row_list.append(item)\n", 561 | " if len(row_list) == row_length:\n", 562 | " bar = widgets.HBox(row_list)\n", 563 | " foo.append(bar)\n", 564 | " row_list = []\n", 565 | " bar = widgets.HBox(row_list)\n", 566 | " foo.append(bar)\n", 567 | "\n", 568 | " ui2 = widgets.VBox(foo)\n", 569 | " clear_output()\n", 570 | " out = widgets.interactive_output(display_sample, params)\n", 571 | " display(ui, out, ui2, reset, random, desktop, widgets.HBox([save_name, save_btn]), widgets.HBox([load_name, load_btn]))\n", 572 | "\n", 573 | "def desktop_mode(b):\n", 574 | " global row_length\n", 575 | " global params\n", 576 | " row_length = 6\n", 577 | " directions_list = []\n", 578 | " params_new = {'seed': seed, 'truncation': truncation, 'direction': fixed(0), 'distance': distance, 'scale': scale, 'start': start_layer, 'end': end_layer, 'update' : update}\n", 579 | " for i, item in enumerate(named_directions):\n", 580 | " name = named_directions[item][3]\n", 581 | " widget = widgets.FloatSlider(min=-20, max=20, step=0.1, value=params[item].value, description=name + ': ', continuous_update=False, style=style, layout={'width' : 'auto'})\n", 582 | " directions_list.append(widget)\n", 583 | " params_new[item] = widget\n", 584 | " params = params_new\n", 585 | " grid = widgets.GridspecLayout(len(directions_list)//6, 6, width='90%', height=\"300px\")\n", 586 | " for i in range(len(directions_list)//6):\n", 587 | " for j in range(6):\n", 588 | " grid[i, j] = directions_list[6*i+j]\n", 589 | " \n", 590 | " ui2 = grid\n", 591 | " clear_output()\n", 592 | " out = widgets.interactive_output(display_sample, params)\n", 593 | " display(ui, out, ui2, reset, random, mobile, widgets.HBox([save_name, save_btn]), widgets.HBox([load_name, load_btn]))\n", 594 | "\n", 595 | "def rename_slider(b):\n", 596 | " global row_length\n", 597 | " global params\n", 598 | " print(rename_dropdown.value, rename_box.value)\n", 599 | " named_directions[rename_dropdown.value][3] = rename_box.value\n", 600 | " #del named_directions[rename_dropdown.value]\n", 601 | " directions_list = []\n", 602 | " params_new = {'seed': seed, 'truncation': truncation, 'direction': fixed(0), 'distance': distance, 'scale': scale, 'start': start_layer, 'end': end_layer, 'update' : update}\n", 603 | " for i, item in enumerate(named_directions):\n", 604 | " name = named_directions[item][3]\n", 605 | " value_new = 0\n", 606 | " if item in params:\n", 607 | " value_new = params[item].value\n", 608 | " widget = widgets.FloatSlider(min=-20, max=20, step=0.1, value=value_new, description=name + ': ', continuous_update=False, style=style, layout={'width' : 'auto'})\n", 609 | " directions_list.append(widget)\n", 610 | " params_new[item] = widget\n", 611 | " params = params_new\n", 612 | " grid = widgets.GridspecLayout(len(directions_list)//6, 6, width='90%', height=\"300px\")\n", 613 | " for i in range(len(directions_list)//6):\n", 614 | " for j in range(6):\n", 615 | " grid[i, j] = directions_list[6*i+j]\n", 616 | " \n", 617 | " ui2 = grid\n", 618 | " clear_output()\n", 619 | " out = widgets.interactive_output(display_sample, params)\n", 620 | " display(ui, out, ui2, reset, random, mobile, widgets.HBox([save_name, save_btn]), widgets.HBox([load_name, load_btn]))\n", 621 | " \n", 622 | "save_name = widgets.Text()\n", 623 | "load_name = widgets.Text()\n", 624 | "save_btn = widgets.Button(description=\"Save\")\n", 625 | "load_btn = widgets.Button(description=\"Load\")\n", 626 | "\n", 627 | "def load_w(b):\n", 628 | " global loaded_w\n", 629 | " print(\"Loading \", load_name.value + \".npy\")\n", 630 | " loaded_w = np.load(load_name.value + \".npy\")\n", 631 | "\n", 632 | "def save_w(b):\n", 633 | " global loaded_w\n", 634 | " rng = np.random.RandomState(params['seed'].value)\n", 635 | " z = rng.standard_normal(*Gs.input_shape[1:]).reshape(1, *Gs.input_shape[1:])\n", 636 | "\n", 637 | " noise_vars = [var for name, var in Gs.components.synthesis.vars.items() if name.startswith('noise')]\n", 638 | " Gs_kwargs = dnnlib.EasyDict()\n", 639 | " Gs_kwargs.randomize_noise = False\n", 640 | "\n", 641 | " all_w = Gs.components.mapping.run(z, None, **Gs_kwargs) # [minibatch, layer, component]\n", 642 | " if loaded_w is not None:\n", 643 | " all_w = loaded_w.copy()\n", 644 | "\n", 645 | " for i, item in enumerate(params):\n", 646 | " if item not in ['seed', 'truncation', 'direction', 'distance', 'scale', 'start', 'end', 'update']:\n", 647 | " value = params[item].value\n", 648 | " start_l = named_directions[item][1]\n", 649 | " end_l = min(16, named_directions[item][2])\n", 650 | " direction_l = latent_dirs[named_directions[item][0]]\n", 651 | " for l in range(start_l, end_l):\n", 652 | " all_w[0][l] = all_w[0][l] + direction_l * value * params['scale'].value\n", 653 | "\n", 654 | " if truncation != 1:\n", 655 | " w_avg = Gs.get_var('dlatent_avg')\n", 656 | " all_w = w_avg + (all_w - w_avg) * params['truncation'].value # [minibatch, layer, component]\n", 657 | "\n", 658 | " from datetime import datetime\n", 659 | " now = datetime.now()\n", 660 | "\n", 661 | " out_name = now.isoformat()\n", 662 | " \n", 663 | " if save_name.value:\n", 664 | " out_name = save_name.value\n", 665 | " np.save(out_name + \".npy\", all_w)\n", 666 | " print(\"saved \", out_name + \".npy\")\n", 667 | "\n", 668 | "random.on_click(random_sliders)\n", 669 | "reset.on_click(reset_sliders)\n", 670 | "mobile.on_click(mobile_mode)\n", 671 | "desktop.on_click(desktop_mode)\n", 672 | "rename.on_click(rename_slider)\n", 673 | "save_btn.on_click(save_w)\n", 674 | "load_btn.on_click(load_w)\n", 675 | "out = widgets.interactive_output(display_sample, params)\n", 676 | "display(ui, out, ui2, reset, random, mobile, widgets.HBox([save_name, save_btn]), widgets.HBox([load_name, load_btn]))\n", 677 | "\n" 678 | ], 679 | "execution_count": null, 680 | "outputs": [] 681 | }, 682 | { 683 | "cell_type": "markdown", 684 | "metadata": { 685 | "id": "RIW4gdO1cjnm" 686 | }, 687 | "source": [ 688 | "# Animation stuff" 689 | ] 690 | }, 691 | { 692 | "cell_type": "code", 693 | "metadata": { 694 | "id": "dcOUM7ZnclE6" 695 | }, 696 | "source": [ 697 | "import math\n", 698 | "from PIL import ImageFont\n", 699 | "from PIL import ImageDraw\n", 700 | "def interpolate_between_ws(seed_array, truncation=0.5, duration_sec = 12.0, smoothing_sec = 1.0, mp4_fps = 20, filename=None, text=False):\n", 701 | " #_G, _D, Gs = pickle.load(open(\"/content/network-e621.pkl\", \"rb\"))\n", 702 | " Gs_kwargs = dnnlib.EasyDict()\n", 703 | " Gs_kwargs.output_transform = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)\n", 704 | " Gs_kwargs.randomize_noise = False\n", 705 | " synthesis_kwargs = dict(output_transform=Gs_kwargs.output_transform, truncation_psi=truncation, minibatch_size=8)\n", 706 | " noise_vars = [var for name, var in Gs.components.synthesis.vars.items() if name.startswith('noise')]\n", 707 | " #if seed_array[0] != seed_array[-1]:\n", 708 | " # seed_array.append(seed_array[0])\n", 709 | " \n", 710 | "\n", 711 | " all_w = seed_array\n", 712 | " \n", 713 | " num_frames = int(np.rint(duration_sec * mp4_fps))\n", 714 | " \n", 715 | " def make_frame(t):\n", 716 | " blend = ((len(seed_array)-1)*t/duration_sec)%1.0\n", 717 | " src_i = math.floor((t/duration_sec)*(len(seed_array)-1))\n", 718 | " dst_i = src_i + 1\n", 719 | " #print(t, blend, src_i, dst_i)\n", 720 | " all_w_new = (blend * all_w[dst_i]) + (1 - blend) * all_w[src_i]\n", 721 | " all_images_src = Gs.components.synthesis.run(all_w_new, randomize_noise=False, **synthesis_kwargs)\n", 722 | " #all_images_dst = Gs.components.synthesis.run(all_w_dst, randomize_noise=False, **synthesis_kwargs)\n", 723 | " if text:\n", 724 | " new_im = PIL.Image.new('RGB', (512, 600))\n", 725 | " new_im.paste(PIL.Image.fromarray(np.median(all_images_src, axis=0).astype(np.uint8)), (0, 0))\n", 726 | " draw = ImageDraw.Draw(new_im)\n", 727 | " font = ImageFont.truetype(\"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf\", size=16)\n", 728 | " draw.text((10, 512), \"{:0.2f}\".format((1-blend)), (255, 0, 0), font=font)\n", 729 | " draw.text((50, 512), str(seed_array[src_i]), (255, 255, 255), font=font)\n", 730 | " draw.text((10, 550), \"{:0.2f}\".format((blend)), (0, 255, 0), font=font)\n", 731 | " draw.text((50, 550), str(seed_array[dst_i]), (255, 255, 255), font=font)\n", 732 | " return np.array(new_im)\n", 733 | " else:\n", 734 | " return all_images_src[0]\n", 735 | "\n", 736 | " \n", 737 | " import moviepy.editor\n", 738 | " from datetime import datetime\n", 739 | " now = datetime.now()\n", 740 | "\n", 741 | " np.save(now.isoformat() + \".npy\", all_w)\n", 742 | " mp4_file = '%s.mp4' % (now)\n", 743 | " if filename:\n", 744 | " mp4_file = filename\n", 745 | " mp4_codec = 'libx264'\n", 746 | " mp4_bitrate = '5M'\n", 747 | "\n", 748 | " video_clip = moviepy.editor.VideoClip(make_frame, duration=duration_sec)\n", 749 | " video_clip.write_videofile(mp4_file, fps=mp4_fps, codec=mp4_codec, bitrate=mp4_bitrate)\n", 750 | " \n", 751 | " return mp4_file" 752 | ], 753 | "execution_count": null, 754 | "outputs": [] 755 | }, 756 | { 757 | "cell_type": "code", 758 | "metadata": { 759 | "id": "8DZJM9u8cuOa" 760 | }, 761 | "source": [ 762 | "import glob\n", 763 | "def preview_files():\n", 764 | " for file in sorted(glob.glob(\"*.npy\")):\n", 765 | " try:\n", 766 | " truncation = 1\n", 767 | " print(file)\n", 768 | " w = np.load(file)\n", 769 | " noise_vars = [var for name, var in Gs.components.synthesis.vars.items() if name.startswith('noise')]\n", 770 | " Gs_kwargs = dnnlib.EasyDict()\n", 771 | " Gs_kwargs.randomize_noise = False\n", 772 | "\n", 773 | "\n", 774 | " if truncation != 1:\n", 775 | " w_avg = Gs.get_var('dlatent_avg')\n", 776 | " all_w = w_avg + (all_w - w_avg) * truncation # [minibatch, layer, component]\n", 777 | "\n", 778 | " generate_image_from_w(w, truncation)\n", 779 | " except:\n", 780 | " print(\"Error\")" 781 | ], 782 | "execution_count": null, 783 | "outputs": [] 784 | }, 785 | { 786 | "cell_type": "markdown", 787 | "metadata": { 788 | "id": "lPgEF2KJdQVa" 789 | }, 790 | "source": [ 791 | "# Generate animation" 792 | ] 793 | }, 794 | { 795 | "cell_type": "code", 796 | "metadata": { 797 | "id": "5Odp38W4eiG9" 798 | }, 799 | "source": [ 800 | "!error Causing an error so the following cells are not run automatically...." 801 | ], 802 | "execution_count": null, 803 | "outputs": [] 804 | }, 805 | { 806 | "cell_type": "markdown", 807 | "metadata": { 808 | "id": "DRsRrdPOdTXB" 809 | }, 810 | "source": [ 811 | "Run this cell to preview all of the snapshots you've saved:" 812 | ] 813 | }, 814 | { 815 | "cell_type": "code", 816 | "metadata": { 817 | "id": "jSR8e6-vdZ1F" 818 | }, 819 | "source": [ 820 | "preview_files()" 821 | ], 822 | "execution_count": null, 823 | "outputs": [] 824 | }, 825 | { 826 | "cell_type": "markdown", 827 | "metadata": { 828 | "id": "1X0NR73xdbyF" 829 | }, 830 | "source": [ 831 | "List all of the files you want to animate between:" 832 | ] 833 | }, 834 | { 835 | "cell_type": "code", 836 | "metadata": { 837 | "id": "QzhiuZKrdSPD" 838 | }, 839 | "source": [ 840 | "ws = '''\n", 841 | "pose1.npy\n", 842 | "pose2.npy\n", 843 | "pose3.npy\n", 844 | "'''.split()\n", 845 | "ws\n" 846 | ], 847 | "execution_count": null, 848 | "outputs": [] 849 | }, 850 | { 851 | "cell_type": "markdown", 852 | "metadata": { 853 | "id": "sU9URd9ld1ag" 854 | }, 855 | "source": [ 856 | "Run this to generate the animation:" 857 | ] 858 | }, 859 | { 860 | "cell_type": "code", 861 | "metadata": { 862 | "id": "8_6bjmW4dqt5" 863 | }, 864 | "source": [ 865 | "w_arr = []\n", 866 | "for w in ws:\n", 867 | " w_val = np.load(w)\n", 868 | " w_arr.append(w_val)\n", 869 | "\n", 870 | "output_file = interpolate_between_ws(w_arr, duration_sec = 2.0, smoothing_sec = 1.0, mp4_fps = 30)" 871 | ], 872 | "execution_count": null, 873 | "outputs": [] 874 | }, 875 | { 876 | "cell_type": "markdown", 877 | "metadata": { 878 | "id": "IbQdPjyCd3xO" 879 | }, 880 | "source": [ 881 | "Run this to download the animation:" 882 | ] 883 | }, 884 | { 885 | "cell_type": "code", 886 | "metadata": { 887 | "id": "JK2cYFMwd5gK" 888 | }, 889 | "source": [ 890 | "from google.colab import files\n", 891 | "files.download(output_file) " 892 | ], 893 | "execution_count": null, 894 | "outputs": [] 895 | } 896 | ] 897 | } -------------------------------------------------------------------------------- /danbooru_to_csv.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "kernelspec": { 6 | "display_name": "Python 3", 7 | "language": "python", 8 | "name": "python3" 9 | }, 10 | "language_info": { 11 | "codemirror_mode": { 12 | "name": "ipython", 13 | "version": 3 14 | }, 15 | "file_extension": ".py", 16 | "mimetype": "text/x-python", 17 | "name": "python", 18 | "nbconvert_exporter": "python", 19 | "pygments_lexer": "ipython3", 20 | "version": "3.7.5" 21 | }, 22 | "colab": { 23 | "name": "danbooru_to_csv.ipynb", 24 | "provenance": [], 25 | "collapsed_sections": [], 26 | "include_colab_link": true 27 | }, 28 | "accelerator": "GPU" 29 | }, 30 | "cells": [ 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "id": "view-in-github", 35 | "colab_type": "text" 36 | }, 37 | "source": [ 38 | "\"Open" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "metadata": { 44 | "id": "iRexarvjiwkC" 45 | }, 46 | "source": [ 47 | "#import sqlite3\n", 48 | "import json\n", 49 | "import os\n", 50 | "import csv\n", 51 | "\n", 52 | "DATA_DIR = \"./metadata.json.tar/metadata.json/metadata/2019\"" 53 | ], 54 | "execution_count": null, 55 | "outputs": [] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "metadata": { 60 | "id": "aNTWbb9eiwkF", 61 | "outputId": "ec39efb7-c3a3-45d4-e11e-d3e4d83449d7" 62 | }, 63 | "source": [ 64 | "cf = csv.writer(open(\"danbooru2019.csv\", \"a\", newline='', encoding='utf-8'))\n", 65 | "'''cf.writerow([\"id\",\n", 66 | " \"tags\",\n", 67 | " \"created_at\",\n", 68 | " \"uploader_id\",\n", 69 | " \"source\",\n", 70 | " \"score\",\n", 71 | " \"up_score\",\n", 72 | " \"down_score\",\n", 73 | " \"favs\",\n", 74 | " \"md5\",\n", 75 | " \"file_size\",\n", 76 | "# \"file_url\",\n", 77 | " \"file_ext\",\n", 78 | " \"rating\",\n", 79 | " \"is_status_locked\",\n", 80 | " \"is_pending\",\n", 81 | " \"is_flagged\",\n", 82 | " \"is_deleted\",\n", 83 | " \"width\",\n", 84 | " \"height\",\n", 85 | " \"has_children\",\n", 86 | " \"parent_id\",\n", 87 | " \"pools\"\n", 88 | " #\"artist\",\n", 89 | " #\"sources\"\n", 90 | " ])\n", 91 | "'''\n", 92 | "for json_file in os.listdir(DATA_DIR):\n", 93 | " json_path = os.path.join(DATA_DIR, json_file)\n", 94 | " print(\"Processing\", json_path)\n", 95 | "\n", 96 | " with open(json_path, \"r\", encoding=\"UTF-8\") as f:\n", 97 | " raw_json_lines = f.readlines()\n", 98 | "\n", 99 | "\n", 100 | " for raw_json_line in raw_json_lines:\n", 101 | " json_line = json.loads(raw_json_line)\n", 102 | " image_id = json_line[\"id\"]\n", 103 | "\n", 104 | " tags_values = \" \".join(list(tag[\"category\"] + \":\" + tag[\"name\"]\n", 105 | " for tag in json_line[\"tags\"]))\n", 106 | "\n", 107 | " favs_values = \" \".join(list(faver_id for faver_id in json_line[\"favs\"]))\n", 108 | " pools_values = \" \".join(list(pool_id for pool_id in json_line[\"pools\"]))\n", 109 | " cf.writerow([json_line[\"id\"],\n", 110 | " tags_values,\n", 111 | " json_line[\"created_at\"],\n", 112 | " json_line[\"uploader_id\"],\n", 113 | " json_line[\"source\"],\n", 114 | " json_line[\"score\"],\n", 115 | " json_line[\"up_score\"],\n", 116 | " json_line[\"down_score\"],\n", 117 | " favs_values,\n", 118 | " json_line[\"md5\"],\n", 119 | " json_line[\"file_size\"],\n", 120 | " json_line[\"file_ext\"],\n", 121 | " json_line[\"rating\"],\n", 122 | " json_line[\"is_status_locked\"],\n", 123 | " json_line[\"is_pending\"],\n", 124 | " json_line[\"is_flagged\"],\n", 125 | " json_line[\"is_deleted\"],\n", 126 | " json_line[\"image_width\"],\n", 127 | " json_line[\"image_height\"],\n", 128 | " json_line[\"has_children\"],\n", 129 | " json_line[\"parent_id\"],\n", 130 | " pools_values\n", 131 | " ])\n" 132 | ], 133 | "execution_count": null, 134 | "outputs": [ 135 | { 136 | "output_type": "stream", 137 | "text": [ 138 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000000\n", 139 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000001\n", 140 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000002\n", 141 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000003\n", 142 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000004\n", 143 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000005\n", 144 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000006\n", 145 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000007\n", 146 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000008\n", 147 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000009\n", 148 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000010\n", 149 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000011\n", 150 | "Processing K:\\Danbooru\\metadata.json.tar\\metadata.json\\metadata\\2019\\2019000000000012\n" 151 | ], 152 | "name": "stdout" 153 | } 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "metadata": { 159 | "colab": { 160 | "base_uri": "https://localhost:8080/" 161 | }, 162 | "id": "rXPwcgSD3Dhl", 163 | "outputId": "5d3109ad-ede8-4541-8ab2-6e8f51237534" 164 | }, 165 | "source": [ 166 | "!pwd" 167 | ], 168 | "execution_count": null, 169 | "outputs": [ 170 | { 171 | "output_type": "stream", 172 | "text": [ 173 | "/root/twdne-ds\r\n" 174 | ], 175 | "name": "stdout" 176 | } 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "metadata": { 182 | "colab": { 183 | "base_uri": "https://localhost:8080/" 184 | }, 185 | "id": "n84fqX_diwkH", 186 | "outputId": "ca5c4e89-5071-442a-9c82-a289b8a00bae" 187 | }, 188 | "source": [ 189 | "!ls" 190 | ], 191 | "execution_count": null, 192 | "outputs": [ 193 | { 194 | "output_type": "stream", 195 | "text": [ 196 | "'=0.0.7' 750.jpg danbooru2019.csv portraits twdne.tar\r\n" 197 | ], 198 | "name": "stdout" 199 | } 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "metadata": { 205 | "colab": { 206 | "base_uri": "https://localhost:8080/" 207 | }, 208 | "id": "r8WIbKWH3PL-", 209 | "outputId": "4a9c3e49-23da-4645-cc25-075cd29ab6c3" 210 | }, 211 | "source": [ 212 | "!head -10 danbooru2019.csv" 213 | ], 214 | "execution_count": null, 215 | "outputs": [ 216 | { 217 | "output_type": "stream", 218 | "text": [ 219 | "id,tags,created_at,uploader_id,source,score,up_score,down_score,favs,md5,file_size,file_ext,rating,is_status_locked,is_pending,is_flagged,is_deleted,width,height,has_children,parent_id,pools\r\r\n", 220 | "263159,0:1girl 0:bangs 0:barefoot 0:blunt_bangs 0:brown_hair 0:hair_bun 0:hime_cut 0:japanese_clothes 1:kakinouchi_narumi 0:long_hair 4:miyu_(vampire_princess_miyu) 0:ribbon 0:solo 3:vampire_princess_miyu 0:yellow_eyes,2008-06-10 02:53:12.6256 UTC,65792,,0,0,0,89268 68238 117203 169955,c401bc0081a6952acfc1ad2f65d51b82,21258,jpg,s,False,False,False,False,363,575,False,0,\r\r\n", 221 | "3014643,1:0:00 0:1girl 0:bare_shoulders 0:bikini 0:blue_eyes 0:blush 0:braid 0:breasts 0:collarbone 5:commentary_request 3:girls_und_panzer 5:highres 0:legs 0:looking_at_viewer 0:navel 0:orange_hair 4:orange_pekoe_(girls_und_panzer) 0:solo 0:standing 0:swimsuit,2018-02-09 02:45:12.76396 UTC,526080,https://twitter.com/mayonaka_reiji/status/909418228849418240,2,2,0,467355 60223 352442,9e244e110b9f631dd031b376dcc53b0b,170749,jpg,s,False,False,False,True,1191,1684,False,0,\r\r\n", 222 | "2872205,0:1girl 0:alternate_costume 0:black_legwear 0:bunny 5:commentary 0:hair_ornament 5:highres 3:kantai_collection 1:ken_sogen 0:looking_at_viewer 0:pantyhose 0:pink_eyes 0:pink_hair 3:saturday_night_fever 4:sazanami_(kantai_collection) 0:shirt 0:shoes 0:shorts 0:simple_background 0:sneakers 0:striped 0:striped_shirt 5:translated 0:twintails 0:white_background,2017-09-29 02:47:20.1346 UTC,528640,https://i.pximg.net/img-original/img/2016/10/18/20/04/53/59529871_p0.jpg,5,5,0,486490 467363 512658 109835 467355 515301 60223,e8c6b832bac2e67ac2c3daa1077372ef,278218,jpg,s,False,False,False,False,992,1200,False,0,\r\r\n", 223 | "2875899,0:2girls 0:black_legwear 0:blue_eyes 0:blush 0:braid 0:brown_hair 0:chair 0:hair_flaps 0:hair_ornament 0:hand_kiss 0:heart 4:hibiki_(kantai_collection) 0:holding 0:holding_hand 3:kantai_collection 0:kiss 0:long_hair 0:long_sleeves 0:looking_at_another 1:mugicha_(mugitya912) 0:multiple_girls 0:neckerchief 0:no_gloves 0:no_hat 0:no_headwear 0:no_mouth 0:onomatopoeia 0:red_neckwear 0:remodel_(kantai_collection) 0:school_uniform 0:serafuku 4:shigure_(kantai_collection) 0:short_sleeves 0:side_braid 0:silver_hair 0:sitting 0:sitting_on_object 0:thighhighs 0:yuri,2017-10-02 06:15:04.59886 UTC,528640,https://i.pximg.net/img-original/img/2016/05/29/16/36/04/57125493_p4.png,6,6,0,72775 66907 60223 424873 467355 593735,dc182d8ea809d6f94391539339aa56fe,649765,png,s,False,False,False,True,800,1000,False,0,\r\r\n", 224 | "2874486,0:2girls 0:3koma 5:absurdres 4:atago_(kantai_collection) 0:blush 0:breast_press 0:breath 5:check_translation 0:comic 0:crying 0:crying_with_eyes_open 0:dress 0:hand_on_another's_shoulder 5:highres 0:hug 0:jacket 3:kantai_collection 0:kiss 0:long_sleeves 0:monochrome 0:multiple_girls 0:no_gloves 0:open_mouth 0:pink_theme 0:simple_background 1:sorimachi-doufu 0:symmetrical_docking 4:takao_(kantai_collection) 0:tears 5:translation_request 0:white_background 0:yuri,2017-10-01 03:12:48.2397 UTC,528640,https://i.pximg.net/img-original/img/2015/12/05/20/20/13/53894774_p2.jpg,6,6,0,497581 414276 367316 438160 516700 467355 336789 457124 108947 196099 478273 541192 533347 503093 593735,1d5163eb6a58c00dac9396e08425f564,2537127,jpg,s,False,False,False,False,1699,3401,False,0,\r\r\n", 225 | "2875904,0:2girls 0:ahoge 0:bed 0:bedroom 0:black_gloves 0:blue_eyes 0:blush 0:braid 0:brown_hair 0:chest_of_drawers 0:closed_eyes 0:fingerless_gloves 0:gloves 0:hair_ornament 0:hand_on_another's_head 4:hibiki_(kantai_collection) 0:holding 3:kantai_collection 0:long_hair 1:mugicha_(mugitya912) 0:multiple_girls 0:neckerchief 0:petting 0:pillow 0:red_neckwear 0:remodel_(kantai_collection) 0:school_uniform 0:serafuku 4:shigure_(kantai_collection) 0:side_braid 0:silver_hair 0:yuri,2017-10-02 06:20:20.62152 UTC,528640,https://i.pximg.net/img-original/img/2016/05/29/16/36/04/57125493_p7.png,7,7,0,505064 72775 438160 60223 463563 424873 481431 531481 467355 593735,7e5360871c6aaf7d7db8e7bda2c7a0c7,404786,png,s,False,False,False,True,750,563,False,0,\r\r\n", 226 | "2873159,0:1girl 0:bangs 0:black_hair 0:black_legwear 0:blunt_bangs 0:bow 0:braid 0:green_skirt 0:hair_bow 3:kantai_collection 1:ken_sogen 4:kitakami_(kantai_collection) 0:kneehighs 0:leaning_back 0:long_hair 0:neckerchief 0:no_shoes 0:open_mouth 0:pleated_skirt 0:school_uniform 0:serafuku 0:sidelocks 0:single_braid 0:skirt 0:skirt_hold 0:sweat 0:sweatdrop 5:translation_request,2017-09-30 02:40:25.95261 UTC,528640,https://i.pximg.net/img-original/img/2016/09/06/19/12/06/58848746_p2.jpg,11,11,0,486490 109333 66907 469777 521425 19831 95847 467355 32607 60223,c3c2c7f0f30ee6c5974c9c80537cbc51,344385,jpg,s,False,False,False,True,1052,744,False,0,\r\r\n", 227 | "2875864,0:2girls 0:alternate_costume 0:ass 0:bare_shoulders 0:beach 0:bikini 0:blush 0:brown_eyes 0:brown_hair 0:cloud 0:day 0:flower 0:folded_ponytail 0:frilled_bikini 0:frills 0:hair_flower 0:hair_ornament 0:hair_ribbon 0:hairclip 0:hand_on_own_chest 5:highres 0:holding 0:holding_clothes 4:ikazuchi_(kantai_collection) 4:inazuma_(kantai_collection) 0:innertube 3:kantai_collection 0:looking_at_viewer 0:looking_back 1:mitsuki_ponzu 0:multiple_girls 0:ocean 0:open_mouth 0:pink_bikini 0:red_bikini 0:red_flower 0:ribbon 0:short_hair 0:side-tie_bikini 0:star 0:swimsuit 0:wardrobe_malfunction 0:water_gun 0:yellow_innertube,2017-10-02 04:43:11.76278 UTC,528640,https://s.booth.pm/418bf358-c9a3-4149-aec4-ddcec1519dc1/i/623916/264788f5-2291-41af-90fb-7f4e9915ddb8.jpg,21,21,0,501346 533698 479628 469777 124147 267118 364643 449812 72775 22248 488864 385029 349233 499717 527326 66907 499450 526869 467709 60223 467355 509627 437683 511078 95847 59923 519585 499371 478797 451680 500158 556433 533699,2fa581cee5e2131e4f59311dd6c93d53,2173449,jpg,s,False,False,False,False,1354,1719,False,0,\r\r\n", 228 | "1900094,0:2girls 4:alice_margatroid 0:blonde_hair 0:blue_eyes 0:braid 0:breast_press 0:giantess 0:hat 5:highres 4:kirisame_marisa 1:kuro_oolong 0:long_hair 0:minigirl 0:multiple_girls 0:nude 0:open_mouth 0:short_hair 0:size_difference 0:smile 3:touhou 0:witch_hat,2015-01-12 01:08:34.12966 UTC,338432,http://i1.pixiv.net/img-original/img/2015/01/12/09/22/55/48132984_p1.jpg,0,0,0,449465 710328,b3a6a4bd9fe5048436a44bc982dff8ac,722525,jpg,q,False,False,False,True,1080,1528,False,1900057,\r\r\n" 229 | ], 230 | "name": "stdout" 231 | } 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "metadata": { 237 | "id": "c4vZ8Lep3cBl" 238 | }, 239 | "source": [ 240 | "import pandas as pd" 241 | ], 242 | "execution_count": null, 243 | "outputs": [] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "metadata": { 248 | "id": "H2bPpZzs41pd" 249 | }, 250 | "source": [ 251 | "df = pd.read_csv('danbooru2019.csv')\r\n", 252 | "df.head(3)" 253 | ], 254 | "execution_count": null, 255 | "outputs": [] 256 | } 257 | ] 258 | } --------------------------------------------------------------------------------