<jupyter_start><jupyter_text>Visualize training of static VAE on circle/Gaussian data- Input: circles on Gaussian-blob background (32x32)- Number of latents: 10- batch size: 64- 1M training batches- RMSprop w lr = 1e-05<jupyter_code>import torch
from torchvision import transforms

import pickle
from models import staticVAE32

import matplotlib.pyplot as plt
import numpy as np
vae = staticVAE32(n_latent = 10)
checkpoint = torch.load('trained/staticvae32_10latents_dsprites_circle_last_1M')
vae.load_state_dict(checkpoint['model_states']['net'])

training_stats = pickle.load(open('trained/staticvae32_10latents_dsprites_circle_1M.pkl', 'rb'))<jupyter_output><empty_output><jupyter_text>plot training loss<jupyter_code>plt.plot(training_stats['iter'], training_stats['recon_loss'])<jupyter_output><empty_output><jupyter_text>apparent difference in noise because logging interval was changed at 100Kpossibly problems with the optimizer (too high of a learning rate)  load some data and plot reconstructions<jupyter_code>import warnings
warnings.filterwarnings("ignore")

import sys
sys.path.append("..") # Adds higher directory to python modules path.
from data.dspritesb import dSpriteBackgroundDataset

ds = dSpriteBackgroundDataset(transform=transforms.Resize(32),shapetype = 'circle')

fig=plt.figure(figsize=(18, 16), dpi= 80, facecolor='w', edgecolor='k')
cnt = 0
for ii in range(12):
    x,label = ds.__getitem__(np.random.randint(1000))
    
    mu, _ = vae.encode(x.unsqueeze(0).float())
    recon = vae.decode(mu).detach().squeeze()
    
    x = x.squeeze()
    
    diff = x - recon
    
    cnt += 1
    plt.set_cmap('gray')
    ax = plt.subplot(6,6,cnt)
    ax.imshow(x, vmin=0, vmax=1)
    plt.title('true')
    plt.axis('off')
    
    cnt += 1
    ax = plt.subplot(6,6,cnt)    
    ax.imshow(recon, vmin=0, vmax=1)
    plt.title('recon')
    plt.axis('off')
    
    cnt += 1
    plt.set_cmap('bwr')
    ax = plt.subplot(6,6,cnt)    
    m = np.max(np.abs(diff.numpy()))
    ax.imshow(diff, vmin=-m, vmax=m)
    plt.title('diff')
    plt.axis('off')<jupyter_output><empty_output><jupyter_text>Visualize entanglement/disentanglementEach row is a sweep from -2 to 2 in one dimension while fixing the others at 0.<jupyter_code>fig=plt.figure(figsize=(18, 16), dpi= 80, facecolor='w', edgecolor='k')
z_points = np.linspace(-3,3, 15)
len(z_points)
for ii in range(10):
    for jj in range(len(z_points)):
        latent = torch.zeros(1,10)
        latent[0,ii] = z_points[jj]
        
        rec = vae.decode(latent)
        plt.set_cmap('gray')
        ax = plt.subplot(10,len(z_points),ii*len(z_points) + jj + 1)
        ax.imshow(rec.detach().numpy().squeeze(), vmin=0, vmax=1)
        plt.title('%0.2f' % z_points[jj])
        plt.axis('off')
        if jj == 0:
            plt.text(-5,16,'latent dimension = {}'.format(ii),horizontalalignment='right')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1386206896551724, 'fraction_numerical': 0.03103448275862069, 'mean_word_length': 4.208258527827648, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '315924', 'license': 'MIT', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1061, 'n_words': 216, 'path': 'src/staticvae/VisualizeStaticVAE32(circle)_10latents_training_04_12_2019.ipynb', 'repo_name': 'zahariaa/disentangled-dynamics', 'size': '2900'}