November 2018
Intermediate to advanced
492 pages
12h 19m
English
Let's start by downloading the MNIST dataset. The following Python code shows you how to download the training and test datasets:
# Function that downloads a specified MNIST data file from Yann Le Cun's websitedef download(filename, source='http://yann.lecun.com/exdb/mnist/'): print("Downloading %s" % filename) urlretrieve(source + filename, filename)# Invokes download() if necessary, then reads in imagesdef load_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_mnist_labels(filename): if not os.path.exists(filename): download(filename) ...Read now
Unlock full access