def show_fashion_mnist(images, labels): d2l.use_svg_display() # Here _ means that we ignore (not use) variables _, figs = d2l.plt.subplots(1, len(images), figsize=(12, 12)) for f, img, lbl in zip(figs, images, labels): f.imshow(img.reshape((28, 28)).numpy()) f.set_title(lbl) f.axes.get_xaxis().set_visible(False) f.axes.get_yaxis().set_visible(False)
def __init__(self, xlabel=None, ylabel=None, legend=[], xlim=None, ylim=None, xscale='linear', yscale='linear', fmts=None, nrows=1, ncols=1, figsize=(3.5, 2.5)): """Incrementally plot multiple lines.""" d2l.use_svg_display() self.fig, self.axes = d2l.plt.subplots(nrows, ncols, figsize=figsize) if nrows * ncols == 1: self.axes = [self.axes,] # use a lambda to capture arguments self.config_axes = lambda : d2l.set_axes( self.axes[0], xlabel, ylabel, xlim, ylim, xscale, yscale, legend) self.X, self.Y, self.fmts = None, None, fmts
import d2l from matplotlib import pyplot as plt from mxnet import npx, gluon npx.set_np() d2l.use_svg_display() mnist_train = gluon.data.vision.FashionMNIST(train=True) mnist_test = gluon.data.vision.FashionMNIST(train=False) print("train length : {}, test length: {}".format(len(mnist_train), len(mnist_test))) X, y = mnist_train[:18] # d2l.show_images(X.squeeze(axis=-1), 2, 9, titles=d2l.get_fashion_mnist_labels(y)) # plt.show() batch_size = 256 transformer = gluon.data.vision.transforms.ToTensor() train_iter = gluon.data.DataLoader(mnist_train.transform_first(transformer), batch_size, shuffle=True, num_workers=d2l.get_dataloader_workers()) timer = d2l.Timer() for X, y in train_iter: continue print("loading dada takes {:.2f} sec".format(timer.stop())) train_iter, test_iter = d2l.load_data_fashion_mnist(32, (64, 64))