Path: blob/master/deprecated/notebooks/vae_latent_space.ipynb
1192 views
Kernel: Python 3
MMD-VAE, to create a more disentangled latent space
One way of making a more disentangled latent space besides beta-vae is to modify the KL term in the ELBO and replace it with a maximum mean discrepancy (MMD) term that always prefers maximising the mutual information in the latent code, resulting in a more disentangled latent space, as shown by Zhao et al. 17. This can be seen from the following image below comparing the latent space of a VAE trained on MNIST using the KL term vs the MMD term, which is more structured than the KL term.
In [1]:
In [ ]:
/usr/local/lib/python3.7/dist-packages/torchvision/datasets/mnist.py:498: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at /pytorch/torch/csrc/utils/tensor_numpy.cpp:180.)
return torch.from_numpy(parsed.astype(m[2], copy=False)).view(*s)
GPU available: True, used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/configuration_validator.py:101: UserWarning: you defined a validation_step but have no val_dataloader. Skipping val loop
rank_zero_warn(f"you defined a {step_name} but have no {loader_name}. Skipping {stage} loop")
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
| Name | Type | Params
--------------------------------------------------------
0 | model | VAE | 807 K
1 | model.encoder | Encoder | 403 K
2 | model.encoder.encoder | Sequential | 401 K
3 | model.encoder.encoder.0 | Linear | 401 K
4 | model.encoder.encoder.1 | ReLU | 0
5 | model.encoder.fc_mu | Linear | 1.0 K
6 | model.encoder.fc_var | Linear | 1.0 K
7 | model.decoder | Decoder | 403 K
8 | model.decoder.decoder | Sequential | 403 K
9 | model.decoder.decoder.0 | Linear | 1.5 K
10 | model.decoder.decoder.1 | ReLU | 0
11 | model.decoder.decoder.2 | Linear | 402 K
12 | model.decoder.decoder.3 | Sigmoid | 0
--------------------------------------------------------
807 K Trainable params
0 Non-trainable params
807 K Total params
3.231 Total estimated model params size (MB)
Validation sanity check: 0it [00:00, ?it/s]
Training: -1it [00:00, ?it/s]
GPU available: True, used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/configuration_validator.py:101: UserWarning: you defined a validation_step but have no val_dataloader. Skipping val loop
rank_zero_warn(f"you defined a {step_name} but have no {loader_name}. Skipping {stage} loop")
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
| Name | Type | Params
--------------------------------------------------------
0 | model | VAE | 807 K
1 | model.encoder | Encoder | 403 K
2 | model.encoder.encoder | Sequential | 401 K
3 | model.encoder.encoder.0 | Linear | 401 K
4 | model.encoder.encoder.1 | ReLU | 0
5 | model.encoder.fc_mu | Linear | 1.0 K
6 | model.encoder.fc_var | Linear | 1.0 K
7 | model.decoder | Decoder | 403 K
8 | model.decoder.decoder | Sequential | 403 K
9 | model.decoder.decoder.0 | Linear | 1.5 K
10 | model.decoder.decoder.1 | ReLU | 0
11 | model.decoder.decoder.2 | Linear | 402 K
12 | model.decoder.decoder.3 | Sigmoid | 0
--------------------------------------------------------
807 K Trainable params
0 Non-trainable params
807 K Total params
3.231 Total estimated model params size (MB)
Validation sanity check: 0it [00:00, ?it/s]
Training: -1it [00:00, ?it/s]
In [ ]:
In [ ]: