Dive into Deep Learning
Table Of Contents
Dive into Deep Learning
Table Of Contents

15.7. d2l API Document

class d2l.Benchmark(prefix=None)

Benchmark programs.

class d2l.Decoder(**kwargs)

The base decoder interface for the encoder-decoder archtecture.

forward(X, state)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.DotProductAttention(dropout, **kwargs)
forward(query, key, value, valid_length=None)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.Encoder(**kwargs)

The base encoder interface for the encoder-decoder architecture.

forward(X)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.EncoderDecoder(encoder, decoder, **kwargs)

The base class for the encoder-decoder architecture.

forward(enc_X, dec_X, *args)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.MLPAttention(units, dropout, **kwargs)
forward(query, key, value, valid_length)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.MaskedSoftmaxCELoss(axis=-1, sparse_label=True, from_logits=False, weight=None, batch_axis=0, **kwargs)
forward(pred, label, valid_length)

Defines the forward computation. Arguments can be either NDArray or Symbol.

class d2l.RNNModel(rnn_layer, vocab_size, **kwargs)
forward(inputs, state)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.RNNModelScratch(vocab_size, num_hiddens, ctx, get_params, init_state, forward)

A RNN Model based on scratch implementations

class d2l.Residual(num_channels, use_1x1conv=False, strides=1, **kwargs)
forward(X)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.Seq2SeqDecoder(vocab_size, embed_size, num_hiddens, num_layers, dropout=0, **kwargs)
forward(X, state)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.Seq2SeqEncoder(vocab_size, embed_size, num_hiddens, num_layers, dropout=0, **kwargs)
forward(X, *args)

Overrides to implement forward computation using NDArray. Only accepts positional arguments.

*args : list of NDArray
Input tensors.
class d2l.SeqDataLoader(batch_size, num_steps, use_random_iter, max_tokens)

A iterator to load sequence data

class d2l.Timer

Record multiple running times.

avg()

Return the average time

cumsum()

Return the accumuated times

start()

Start the timer

stop()

Stop the timer and record the time in a list

sum()

Return the sum of time

class d2l.VOCSegDataset(is_train, crop_size, voc_dir)

A customized dataset to load VOC dataset.

d2l.bbox_to_rect(bbox, color)

Convert bounding box to matplotlib format.

d2l.build_colormap2label()

Build a RGB color to label mapping for segmentation.

d2l.corr2d(X, K)

Compute 2D cross-correlation.

d2l.download_voc_pascal(data_dir='../data')

Download the VOC2012 segmentation dataset.

d2l.evaluate_loss(net, data_iter, loss)

Evaluate the loss of a model on the given dataset

d2l.load_array(data_arrays, batch_size, is_train=True)

Construct a Gluon data loader

d2l.load_data_fashion_mnist(batch_size, resize=None)

Download the Fashion-MNIST dataset and then load into memory.

d2l.load_data_imdb(batch_size, max_len=500)

Download an IMDB dataset, return the vocabulary and iterators.

d2l.load_data_pikachu(batch_size, edge_size=256)

Load the pikachu dataset

d2l.load_data_voc(batch_size, crop_size)

Download and load the VOC2012 semantic dataset.

d2l.plot(X, Y=None, xlabel=None, ylabel=None, legend=[], xlim=None, ylim=None, xscale='linear', yscale='linear', fmts=None, figsize=(3.5, 2.5), axes=None)

Plot multiple lines

d2l.predict_sentiment(net, vocab, sentence)

Predict the sentiment of a given sentence.

d2l.read_time_machine()

Load the time machine book into a list of sentences.

d2l.read_voc_images(root='../data/VOCdevkit/VOC2012', is_train=True)

Read all VOC feature and label images.

d2l.resnet18(num_classes)

A slightly modified ResNet-18 model

d2l.semilogy(x_vals, y_vals, x_label, y_label, x2_vals=None, y2_vals=None, legend=None, figsize=(3.5, 2.5))

Plot x and log(y).

d2l.set_axes(axes, xlabel, ylabel, xlim, ylim, xscale, yscale, legend)

A utility function to set matplotlib axes

d2l.set_figsize(figsize=(3.5, 2.5))

Change the default figure size

d2l.show(obj)

Show a figure

d2l.show_bboxes(axes, bboxes, labels=None, colors=None)

Show bounding boxes.

d2l.show_images(imgs, num_rows, num_cols, titles=None, scale=1.5)

Plot a list of images.

d2l.show_trace_2d(f, results)

Show the trace of 2D variables during optimization.

d2l.split_batch(X, y, ctx_list)

Split X and y into multiple devices specified by ctx

d2l.synthetic_data(w, b, num_examples)

generate y = X w + b + noise

d2l.tokenize(lines, token='word')

Split sentences into word or char tokens

d2l.train_2d(trainer)

Optimize a 2-dim objective function with a customized trainer.

d2l.try_all_gpus()

Return all available GPUs, or [cpu(),] if no GPU exists.

d2l.try_gpu(i=0)

Return gpu(i) if exists, otherwise return cpu().

d2l.update_D(X, Z, net_D, net_G, loss, trainer_D)

Update discriminator

d2l.update_G(Z, net_D, net_G, loss, trainer_G)

Update generator

d2l.use_svg_display()

Use the svg format to display plot in jupyter.

d2l.voc_label_indices(colormap, colormap2label)

Map a RGB color to a label.

d2l.voc_rand_crop(feature, label, height, width)

Randomly crop for both feature and label images.