1.1 MiB
1.1 MiB
In [19]:
from runs import Run, Snapshot, get_runs_in_dir
import tabulate
import os
from IPython.display import Markdown as md
import matplotlib.pyplot as plt
import matplotlib
import shutil
import jinja2
from tqdm.notebook import trange, tqdm
Build an archive of the various runs & snapshots¶
This notebook can be used to generate a printable html archive, of all runs and their snapshots.
Configuration¶
In [2]:
outdir = os.path.abspath('out/html')
Output Run Index¶
In [3]:
palette = ["#c99ae0",
"#6bd154",
"#bb79f1",
"#c2d436",
"#ec68d3",
"#82d086",
"#e87fb7",
"#4dd7c4",
"#c7ba5c",
"#64a6e7"]
In [4]:
#see also https://github.com/matplotlib/matplotlib/blob/f6e0ee49c598f59c6e6cf4eefe473e4dc634a58a/lib/matplotlib/_cm.py#L859
palette = matplotlib.cm.datad['Accent']['listed']
palette = matplotlib.cm.datad['Set3']['listed']
In [5]:
def get_rgb_for_idx(i):
return f"rgb({palette[i][0]*255}, {palette[i][1]*255},{palette[i][2]*255})"
In [1]:
%run ThisPlaceDoesExist.ipynb
In [2]:
Out[2]:
In [ ]:
In [8]:
%matplotlib inline
plot = plot_runs(runs, dpi=300, palette=palette)
plot.legend(bbox_to_anchor=(1,0), loc="lower left")
# plot.show()
plt.xlabel('Iterations')
plt.ylabel('Fréchet inception distance (FID)')
plt.savefig(os.path.join(outdir, 'runs.png'), bbox_inches='tight', transparent=True)
In [26]:
plot = plot_stats([
'Loss/D/loss',
'Loss/G/loss',
], runs, palette=palette)
# plot.legend()
plt.savefig(os.path.join(outdir, 'run_losses.png'), bbox_inches='tight', transparent=True)
In [ ]:
In [10]:
index_html = tabulate.tabulate([
{
# "idx": i,
# "conditional": run.dataset_is_conditional(),
**run.get_summary(),
"nr": f"<a href='#run{run.as_nr}'>{run.as_nr}</a>",
"page": f"<span class='tocitem' style='color:{get_rgb_for_idx(i)}' data-ref='#run{run.as_nr}'>🮆</span>",
} for i, run in enumerate(runs)
], tablefmt='unsafehtml', headers="keys", colalign=("left","left")
)
In [11]:
index_html
Out[11]:
In [12]:
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader("templates"),
autoescape=jinja2.select_autoescape()
)
In [13]:
template = jinja_env.get_template("runs.j2")
In [21]:
template_vars = {
"runs_graph": "runs.png",
"runs_losses_graph": "run_losses.png",
"runs_table": index_html,
"runs": runs
}
In [23]:
with open(os.path.join(outdir, 'index.html'), 'w') as fp:
fp.write(template.render(**template_vars))
In [24]:
[run.id for run in runs]
Out[24]:
Copy necessary auxilary files to the output directory:
In [25]:
files = [
"templates/style.css",
"templates/pagedjs-interface.css",
]
for src in files:
shutil.copy(src, outdir)
In [20]:
for run in runs:
nr = 7 if run.resolution > 512 else 8
for snapshot in tqdm(run.snapshots):
filename = os.path.join(outdir, 'imgs', snapshot.id + ".jpg")
if not os.path.exists(filename):
img = snapshot.get_preview_img(nr,1)
img.save(filename)
In [ ]:
In [ ]: