<jupyter_start><jupyter_text>Compare GANs trained on CelebA in terms of sample quality<jupyter_code>#@title Setup for colab { display-mode: "form" }

%%capture
!sudo apt-get install subversion
!svn checkout https://github.com/probml/pyprobml/trunk/gan .
!pip install pytorch-lightning einops
!wget https://storage.googleapis.com/probml_data/gan_checkpoints/dcgan_celeba.ckpt
!wget https://storage.googleapis.com/probml_data/gan_checkpoints/sngan_celeba.ckpt
!wget https://storage.googleapis.com/probml_data/gan_checkpoints/gp_wgan_celeba.ckpt
!wget https://storage.googleapis.com/probml_data/gan_checkpoints/wgan_celeba.ckpt
!wget https://storage.googleapis.com/probml_data/gan_checkpoints/logan_celeba.ckpt
#@title Run Setup And Installation { display-mode: "form" }

from utils.plotting import sample_from_truncated_normal
from assembler import get_config, assembler

def make_model(model_name, use_gpu=False):
  fname = f"./configs/{model_name}.yaml"
  config = get_config(fname)
  vae = assembler(config)
  if use_gpu: vae = vae.to("cuda")
  return vae

def make_and_load_models(model_names: list, use_gpu=False):
  vaes = []
  for model_name in model_names:
    vae = make_model(model_name, use_gpu)
    vae.load_model()
    vaes.append(vae)
  return vaes<jupyter_output><empty_output><jupyter_text>Compare results<jupyter_code>import pytorch_lightning as pl
pl.seed_everything(99)

models_to_compare = ["dcgan","sngan", "logan"]
figsize_reconstruction = (10, 30)
figsize_samples = (10, 10)

gans = make_and_load_models(models_to_compare, use_gpu = True)
num = 16
sample_from_truncated_normal(gans, num)<jupyter_output><empty_output><jupyter_text>Save figures<jupyter_code>!ls figures
!rm /content/gan-figs.zip
!zip -r /content/gan-figs.zip /content/figures
from google.colab import files
files.download("/content/gan-figs.zip")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11379495437466453, 'fraction_numerical': 0.00644122383252818, 'mean_word_length': 6.485943775100401, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '25447', 'license': 'MIT', 'n_tokens_mistral': 720, 'n_tokens_neox': 684, 'n_words': 119, 'path': 'notebooks/gan_compare_results.ipynb', 'repo_name': 'Neoanarika/probml-notebooks', 'size': '1863'}