Functions and utilities to get representations of pytorch/fastai objects.
path = untar_data(URLs.MNIST_TINY)
dls = ImageDataLoaders.from_folder(path)
learn = cnn_learner(dls, resnet18, pretrained=False)

Model representation

First we want to represent any model as a graph. A graph consists of nodes and links, the nodes will be a collection of nn.Module's and nn.Parameter's, and the links will describe the connections between them.

class Representation[source]

Representation(data)

Representation of a Learn object.

class Node[source]

Node(name, idx, typ, obj=None, nodes=None, links=None, xtra=None)

Represents a Module or Parameter.

Module.to_representation[source]

Module.to_representation(name=None, idx=0, path=None, xtra=None)

Obtain information of the Module and stores it on a Node.

Learner.to_representation[source]

Learner.to_representation()

Gets a representation of the Learner to be passed to a web client.

r = learn.to_representation()
PrettyString(r.data)[:300]
"(Node): Learner, type: Learner, idx=0\nxtra: {'open': True, 'shape': None}\nnodes: [\n  (Node): Input, type: Input, idx=0\nxtra: {'shape': [64, 3, 28, 28]}\n  (Node): Sequential, type: Sequential, idx=0\nxtra: {'open': True, 'shape': torch.Size([64, 2])}\nnodes: [\n  (Node): 0_Sequential, type: Sequential, "

Node.get_dict[source]

Node.get_dict()

Gets the dictionary of the Node.

Representation.to_json[source]

Representation.to_json()

Gets the seriable json from the Leaner Representation.

r.to_json()[:300]
'{"name": "Learner", "type": "Learner", "index": 0, "nodes": [{"name": "Input", "type": "Input", "index": 0, "xtra": {"shape": [64, 3, 28, 28]}}, {"name": "Sequential", "type": "Sequential", "index": 0, "nodes": [{"name": "0_Sequential", "type": "Sequential", "index": 0, "nodes": [{"name": "0_Conv2d"'