Compare commits

...

4 commits

Author SHA1 Message Date
Ruben van de Ven
cb3fe0e197 Dockerignore 2023-01-12 15:55:19 +01:00
Ruben van de Ven
658e4c06f2 tweak helper scripts 2023-01-12 15:54:18 +01:00
Ruben van de Ven
35e9eb4193 cleanup snapshot notebook 2023-01-12 15:53:19 +01:00
Ruben van de Ven
1d40340e42 StyleGAN logbook generator and formatting 2023-01-12 15:51:16 +01:00
7 changed files with 335 additions and 339 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
training-runs
datasets

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,22 @@
{ {
"cells": [ "cells": [
{
"cell_type": "markdown",
"id": "c08a9c8e-bcce-4b45-94ad-b422ad60bea9",
"metadata": {},
"source": [
"# This Place Does Exists - Utilities for Stylegan3\n",
"\n",
"This notebook contains utility functions for working with the models created by StyleGAN3. \n",
"\n",
"## Usage\n",
"\n",
"Include it in any notebook using `%run ThisPlaceDoesExist.ipynb`. After which everything from this notebook becomes available. Including a `runs` variable which is a list containing all the `Run` objects."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": 1,
"id": "f4ee99c4-9c28-4fe4-9408-e130a0d446d3", "id": "f4ee99c4-9c28-4fe4-9408-e130a0d446d3",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -52,7 +66,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 4,
"id": "4c428611-8d75-4f9a-ae5a-7960e7b01470", "id": "4c428611-8d75-4f9a-ae5a-7960e7b01470",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -68,16 +82,6 @@
"See [Snapshot_images.ipynb](Snapshot_images.ipynb) for examples of each run/snapshot." "See [Snapshot_images.ipynb](Snapshot_images.ipynb) for examples of each run/snapshot."
] ]
}, },
{
"cell_type": "code",
"execution_count": 5,
"id": "9a5c4a18-0389-4d36-989e-7a120db590ab",
"metadata": {},
"outputs": [],
"source": [
"# snapshot = runs[3].snapshots[70]"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "c3aa8404-aeb0-4f63-b4b4-c278f0cf3766", "id": "c3aa8404-aeb0-4f63-b4b4-c278f0cf3766",
@ -90,7 +94,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 5,
"id": "c180db45-9bf1-4f0a-ab55-62b476a5897c", "id": "c180db45-9bf1-4f0a-ab55-62b476a5897c",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -115,22 +119,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 6,
"id": "22c74f41-65e7-461a-9094-f0b3d8738c82", "id": "22c74f41-65e7-461a-9094-f0b3d8738c82",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"ename": "NameError",
"evalue": "name 'runs' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_1/862876608.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# def is_main():\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mplot\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mplot_runs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mruns\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mplot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlegend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbbox_to_anchor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mloc\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"lower left\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mplot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'runs' is not defined"
]
}
],
"source": [ "source": [
"def is_main():\n", "def is_main():\n",
" plot = plot_runs(runs)\n", " plot = plot_runs(runs)\n",
@ -449,11 +441,11 @@
" runnr = snapshot.run.as_nr\n", " runnr = snapshot.run.as_nr\n",
" # !!python pbaylies_projector.py --network $snapshot_pkl --outdir out/projections/$runnr-$imagenr --target-image $image_filename --use-clip=False\n", " # !!python pbaylies_projector.py --network $snapshot_pkl --outdir out/projections/$runnr-$imagenr --target-image $image_filename --use-clip=False\n",
" \n", " \n",
" if replace_if_exists or not os.path.exists(f\"out/projections/{runnr}/{image_name}/proj.png\"):\n", " if replace_if_exists or not os.path.exists(f\"out/projections/{snapshot.id}/{image_name}/proj.png\"):\n",
" process = subprocess.Popen([\n", " process = subprocess.Popen([\n",
" \"python\", \"pbaylies_projector.py\",\n", " \"python\", \"pbaylies_projector.py\",\n",
" \"--network\" , snapshot.pkl_path,\n", " \"--network\" , snapshot.pkl_path,\n",
" \"--outdir\", f\"out/projections/{runnr}/{image_name}\",\n", " \"--outdir\", f\"out/projections/{snapshot.id}/{image_name}\",\n",
" \"--target-image\", image_filename,\n", " \"--target-image\", image_filename,\n",
" \"--use-clip\", \"False\",\n", " \"--use-clip\", \"False\",\n",
" \"--num-steps\", str(steps),\n", " \"--num-steps\", str(steps),\n",
@ -469,10 +461,10 @@
" loss, dist = (None, None)\n", " loss, dist = (None, None)\n",
"\n", "\n",
" return {\n", " return {\n",
" \"img\": f\"out/projections/{runnr}-{imagenr}/proj.png\",\n", " \"img\": f\"out/projections/{snapshot.id}/{image_name}/proj.png\",\n",
" \"src_img\": f\"out/projections/{runnr}-{imagenr}/target.png\",\n", " \"src_img\": f\"out/projections/{snapshot.id}/{image_name}/target.png\",\n",
" \"src\": image_filename,\n", " \"src\": image_filename,\n",
" \"npz\": f\"out/projections/{runnr}-{imagenr}/projected_w.npz\",\n", " \"npz\": f\"out/projections/{snapshot.id}/{image_name}/projected_w.npz\",\n",
" \"loss\": loss,\n", " \"loss\": loss,\n",
" \"dist\": dist\n", " \"dist\": dist\n",
" }\n", " }\n",
@ -568,43 +560,6 @@
" # output.release()\n", " # output.release()\n",
" writer.close()" " writer.close()"
] ]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "6ff4c6db-b48f-4ff4-b08c-e85138f0f307",
"metadata": {},
"outputs": [],
"source": [
"\n"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "d0661104-72a7-4320-980a-1a702388659f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e2aa2c98-cf1e-465a-9455-fe4a02f145ad",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {

View file

@ -90,7 +90,7 @@ def open_image_folder(source_dir, *, max_images: Optional[int]):
arch_fname = os.path.relpath(fname, source_dir) arch_fname = os.path.relpath(fname, source_dir)
arch_fname = arch_fname.replace('\\', '/') arch_fname = arch_fname.replace('\\', '/')
img = np.array(PIL.Image.open(fname)) img = np.array(PIL.Image.open(fname))
yield dict(img=img, label=labels.get(arch_fname)) yield dict(img=img, label=labels.get(arch_fname), filename=fname)
if idx >= max_idx-1: if idx >= max_idx-1:
break break
return max_idx, iterate_images() return max_idx, iterate_images()
@ -119,7 +119,7 @@ def open_image_zip(source, *, max_images: Optional[int]):
with z.open(fname, 'r') as file: with z.open(fname, 'r') as file:
img = PIL.Image.open(file) # type: ignore img = PIL.Image.open(file) # type: ignore
img = np.array(img) img = np.array(img)
yield dict(img=img, label=labels.get(fname)) yield dict(img=img, label=labels.get(fname), filename=fname)
if idx >= max_idx-1: if idx >= max_idx-1:
break break
return max_idx, iterate_images() return max_idx, iterate_images()

10
runs.py
View file

@ -1,13 +1,14 @@
import os import os
import datetime import datetime
import json import json
from typing import List from typing import List, Optional
from PIL import Image from PIL import Image
from enum import Enum from enum import Enum
import logging import logging
import numpy as np import numpy as np
import dnnlib import dnnlib
import legacy import legacy
from dataset_tool import open_dataset
logger = logging.getLogger('runs') logger = logging.getLogger('runs')
@ -131,6 +132,13 @@ class Run():
def dataset_is_conditional(self): def dataset_is_conditional(self):
return bool(self.training_options["training_set_kwargs"]["use_labels"]) return bool(self.training_options["training_set_kwargs"]["use_labels"])
def dataset_iterator(self, max_images: Optional[int] = None):
max_images, iterator = open_dataset(
self.training_options["training_set_kwargs"]["path"],
max_images=max_images
)
return iterator
@property @property
def resolution(self): def resolution(self):
return self.training_options["training_set_kwargs"]["resolution"] return self.training_options["training_set_kwargs"]["resolution"]

View file

@ -17,6 +17,11 @@
<section id='cover'> <section id='cover'>
<h1 class="title">This Place Does Exist</h1> <h1 class="title">This Place Does Exist</h1>
<h2>Stylegan 3 Snapshots</h2> <h2>Stylegan 3 Snapshots</h2>
<div class='authors'>Ward Goes & Ruben van de Ven</div>
</section>
<section id="introduction">
{{introduction}}
</section> </section>
<section id="toc"> <section id="toc">