How to do it...

Run the following steps to implement a VAE with PyTorch:

  1. In this recipe, we will use the Fashion MNIST images as input. In order to download the training and test images and load these images, along with the ground-truth labels, to memory, the following functions need to be defined:
def download(filename, source='http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/'): print("Downloading %s" % filename) urlretrieve(source + filename, filename)def load_fashion_mnist_images(filename): if not os.path.exists(filename): download(filename) with gzip.open(filename, 'rb') as f:    data = np.frombuffer(f.read(), np.uint8, offset=16) data = data.reshape(-1,784) return datadef load_fashion_mnist_labels(filename): if not os.path.exists(filename): ...

Get Python Image Processing Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.