예제 #1
0
    def __init__(self, binary_features, continuous_features, z_dim, hidden_dim,
                 hidden_layers, optimizer, activation, cuda):
        pyro.clear_param_store()
        vae = VAE(binary_features, continuous_features, z_dim, hidden_dim,
                  hidden_layers, activation, cuda)
        vae = vae.double()
        self.vae = vae
        self.svi = SVI(vae.model, vae.guide, optimizer, loss=Trace_ELBO())
        self.cuda = cuda

        self.train_stats = Statistics()
        self.test_stats = Statistics()
mean_asian = np.mean(asian_points, axis=0)
mean_male = np.mean(male_points, axis=0)
mean_female = np.mean(female_points, axis=0)

var_white = np.cov(white_points, rowvar=False)
var_black = np.cov(black_points, rowvar=False)
var_asian = np.cov(asian_points, rowvar=False)
var_male = np.cov(male_points, rowvar=False)
var_female = np.cov(female_points, rowvar=False)

full_mean = np.mean(mu_points, axis=0)
full_var = np.cov(mu_points, rowvar=False)

# <codecell>
# TODO: redo VAE with permute instead of reshape
model = model.double()
with torch.no_grad():
    white_im = model.decode(torch.from_numpy(mean_white)).numpy()
    black_im = model.decode(torch.from_numpy(mean_black)).numpy()
    asian_im = model.decode(torch.from_numpy(mean_asian)).numpy()
    male_im = model.decode(torch.from_numpy(mean_male)).numpy()
    female_im = model.decode(torch.from_numpy(mean_female)).numpy()
    full_im = model.decode(torch.from_numpy(full_mean)).numpy()

white_im = np.squeeze(white_im).transpose(1, 2, 0)
plt.title('Average across White faces')
plt.imshow(white_im)
plt.savefig(save_path / 'white_mean.png')

black_im = np.squeeze(black_im).transpose(1, 2, 0)
plt.title('Average across Black faces')