\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 | "

"
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 | }
--------------------------------------------------------------------------------