backbone#

Module attributes and functions#

class backbone.MammothBackbone(**kwargs)[source]#

A backbone module for the Mammoth model.

Parameters:

**kwargs – additional keyword arguments

forward()[source]#

Compute a forward pass.

Return type:

Tensor

features()[source]#

Get the features of the input tensor (same as forward but with returnt=’features’).

Return type:

Tensor

get_params()[source]#

Returns all the parameters concatenated in a single tensor.

Return type:

Tensor

set_params()[source]#

Sets the parameters to a given value.

get_grads()[source]#

Returns all the gradients concatenated in a single tensor.

Return type:

Tensor

get_grads_list()#

Returns a list containing the gradients (a tensor for each layer).

features(x)[source]#

Compute the features of the input tensor.

Parameters:

x (Tensor) – input tensor

Returns:

features tensor

Return type:

Tensor

forward(x, returnt='out')[source]#

Compute a forward pass.

Parameters:
  • x (Tensor) – input tensor (batch_size, *input_shape)

  • returnt – return type (a string among out, features, both, or all)

Returns:

output tensor

Return type:

Tensor

get_grads()[source]#

Returns all the gradients concatenated in a single tensor.

Returns:

gradients tensor

Return type:

Tensor

get_params()[source]#

Returns all the parameters concatenated in a single tensor.

Returns:

parameters tensor

Return type:

Tensor

set_grads(new_grads)[source]#

Sets the gradients of all parameters.

Parameters:

new_params – concatenated values to be set

set_params(new_params)[source]#

Sets the parameters to a given value.

Parameters:

new_params (Tensor) – concatenated values to be set

to(device, *args, **kwargs)[source]#
backbone.get_backbone(args)[source]#

Build the backbone network from the registered networks.

Parameters:

args (Namespace) – the arguments which contains the –backbone attribute and the additional arguments required by the backbone network

Returns:

the backbone model

Return type:

MammothBackbone

backbone.get_backbone_class(name, return_args=False)[source]#

Get the backbone network class from the registered networks.

Parameters:
  • name (str) – the name of the backbone network

  • return_args – whether to return the parsable arguments of the backbone network

Returns:

the backbone class

Return type:

MammothBackbone

backbone.num_flat_features(x)[source]#

Computes the total number of items except the first (batch) dimension.

Parameters:

x (Tensor) – input tensor

Returns:

number of item from the second dimension onward

Return type:

int

backbone.register_backbone(name)[source]#

Decorator to register a backbone network for use in a Dataset. The decorator may be used on a class that inherits from MammothBackbone or on a function that returns a MammothBackbone instance. The registered model can be accessed using the get_backbone function and can include additional keyword arguments to be set during parsing.

The arguments can be inferred by the signature of the backbone network’s class. The value of the argument is the default value. If the default is set to Parameter.empty, the argument is required. If the default is set to None, the argument is optional. The type of the argument is inferred from the default value (default is str).

Parameters:

name (str) – the name of the backbone network

Return type:

Callable

backbone.xavier(m)[source]#

Applies Xavier initialization to linear modules.

Parameters:

m (Module) – the module to be initialized

Example::
>>> net = nn.Sequential(nn.Linear(10, 10), nn.ReLU())
>>> net.apply(xavier)