models

Class

MLP

class gedml.core.models.mlp.MLP(layer_size_list, first_relu=True, last_relu=False, output_dim=None)[source]

Bases: gedml.core.modules.with_recorder.WithRecorder

Normal multi-layer perceptron.

Parameters
  • layer_size_list (list) – The numbers of neurals in each layer.

  • first_relu (bool) – Whether to set ReLU at the beginning of the MLP.

  • last_relu (bool) – Whether to set ReLU at the end of the MLP.

Example

>>> model = MLP(layer_size_list=[512, 100], first_relu=False)
forward(features)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

BatchNormMLP

class gedml.core.models.mlp.BatchNormMLP(layer_size_list, relu_list, bn_list, first_bn=False, **kwargs)[source]

Bases: gedml.core.modules.with_recorder.WithRecorder

Multi-layer perceptron with batch normalization.

Parameters
  • layer_size_list (list) – The numbers of neurals in each layer. (N + 1)

  • relu_list (list) – Whether relu is added.

  • bn_list (list) – Whether bn is added.

  • first_bn (bool) – Whether to set BN at the beginning of the MLP.

Example

>>> model = BatchNormMLP(
    layer_size_list=[512, 512, 1024],
    relu_list=[True, False],
    bn_list=[True, False],
    first_bn=False
)
forward(features)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Identity

class gedml.core.models.identity.Identity[source]

Bases: gedml.core.modules.with_recorder.WithRecorder

Do nothing.

forward(features)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

resnet50

class gedml.core.models.resnet50.resnet50(pretrained=True, list_style=False, no_norm=False)[source]

Bases: torch.nn.modules.module.Module

Container for ResNet50 s.t. it can be used for metric learning. The Network has been broken down to allow for higher modularity, if one wishes to target specific layers/blocks directly.

forward(x, is_init_cluster_generation=False)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.