You can find the paper here: https://arxiv.org/abs/2102.11582.
Please cite us using:
@article{mukhoti2021deterministic,
title={Deterministic Neural Networks with Appropriate Inductive Biases Capture Epistemic and Aleatoric Uncertainty},
author={Mukhoti, Jishnu and Kirsch, Andreas and van Amersfoort, Joost and Torr, Philip HS and Gal, Yarin},
journal={arXiv preprint arXiv:2102.11582},
year={2021}
}
We create a new PyTorch VisionDataset
for Ambiguous-MNIST and then concatencate it with MNIST (using Joost van Amersfoort's FastMNIST, https://tinyurl.com/pytorch-fast-mnist) to build DirtyMNIST.
We export a constant MNIST_NORMALIZATION
in case you want to combine it with other transforms. All datasets take a normalize=True
(by default) parameter which normalizes the datasets without a transform, so the transform
and target_transform
can be empty.
MNIST_NORMALIZATION = Normalize((0.1307,), (0.3081,))
Let's look at the dataset:
dirty_mnist_train = DirtyMNIST(".", train=True, download=True)
This initializes DirtyMNIST and also normalizes the dataset (equivalent to MNIST_NORMALIZATION = Normalize((0.1307,), (0.3081,))
) by default---but faster. Use normalize=False
if you don't want to normalize the dataset.
normalize=True
(default) and num_workers=0, pin_memory=False
to the dataloader and use the device parameter to set the target device.!pip install tqdm
from tqdm.auto import tqdm
dirty_mnist_train = DirtyMNIST(".", train=True, download=True, device="cuda")
dirty_mnist_dataloader = torch.utils.data.DataLoader(
dirty_mnist_train,
batch_size=128,
shuffle=True,
num_workers=0,
pin_memory=False,
)
for image, label in tqdm(dirty_mnist_dataloader):
image.cuda()
label.cuda()
This achieves about 800it/s on a workstation compared to the default MNIST dataset which only achieves 40it/s. This insight is from Joost's https://tinyurl.com/pytorch-fast-mnist.
mnist_train = MNIST(
".",
train=True,
download=True,
transform=Compose([ToTensor(), MNIST_NORMALIZATION]),
)
mnist_dataloader = torch.utils.data.DataLoader(
mnist_train, batch_size=128, shuffle=True, num_workers=0, pin_memory=True
)
for image, label in tqdm(mnist_dataloader):
pass
import matplotlib.pyplot as plt
from torchvision.utils import make_grid
plt.imshow(
make_grid(dirty_mnist_train.datasets[1].data[: 64 * 10 : 10], nrow=8, normalize=True).permute(1, 2, 0).cpu().numpy()
)
plt.show()
plt.imshow(
make_grid(dirty_mnist_train.datasets[0].data[: 64 * 10 : 10], nrow=8, normalize=True).permute(1, 2, 0).cpu().numpy()
)
Let's look at the dataset:
train_dataset = DistributionalAmbiguousMNIST(".", train=True, download=True, device="cuda")
list(enumerate(train_dataset[3000][1].cpu().tolist()))
torch.multinomial(train_dataset[3000][1], 50, replacement=True)