Registry

class deepreg.registry.Registry

Registry maintains a dictionary which maps (category, key) to value.

Multiple __init__.py files have been modified so that the classes are registered when executing:

from deepreg.registry import REGISTRY

References:

Init registry with empty dict.

_register(category: str, key: str, value: Callable, force: bool)

Registers the value with the registry.

Parameters
  • category – name of the class category

  • key – unique identity

  • value – class to be registered

  • force – if True, overwrite the existing value in case the key has been registered.

build_backbone(config: Dict, default_args: Optional[dict] = None)Any

Instantiate a registered backbone class.

Parameters
  • config – config having key name.

  • default_args – optionally some default arguments.

Returns

a backbone instance

build_data_augmentation(config: Dict, default_args: Optional[dict] = None)Callable

Instantiate a registered data augmentation class.

Parameters
  • config – config having key name.

  • default_args – optionally some default arguments.

Returns

a data augmentation instance

build_data_loader(config: Dict, default_args: Optional[dict] = None)Any

Instantiate a registered data loader class.

Parameters
  • config – config having key name.

  • default_args – optionally some default arguments.

Returns

a loss instance

build_from_config(category: str, config: Dict, default_args: Optional[dict] = None)Any

Build a class instance from config dict.

Parameters
  • category – category name.

  • config – a dict which must contain the key “name”.

  • default_args – optionally some default arguments.

Returns

the instantiated class.

build_loss(config: Dict, default_args: Optional[dict] = None)Callable

Instantiate a registered loss class.

Parameters
  • config – config having key name.

  • default_args – optionally some default arguments.

Returns

a loss instance

build_model(config: Dict, default_args: Optional[dict] = None)Any

Instantiate a registered model class.

Parameters
  • config – config having key name.

  • default_args – optionally some default arguments.

Returns

a model instance

contains(category: str, key: str)bool

Verify if the key has been registered for the category.

Parameters
  • category – category name.

  • key – value name.

Returns

True if registered.

copy()

Deep copy the registry.

get(category: str, key: str)Callable

Return the registered class.

Parameters
  • category – category name.

  • key – value name.

Returns

registered value.

register(category: str, name: str, cls: Optional[Callable] = None, force: bool = False)Callable

Register a py class. A record will be added to self._dict, whose key is the class name or the specified name, and value is the class itself. It can be used as a decorator or a normal function.

Parameters
  • category – The type of the category.

  • name – The class name to be registered. If not specified, the class name will be used.

  • force – Whether to override an existing class with the same name.

  • cls – Class to be registered.

Returns

The given class or a decorator.

register_backbone(name: str, cls: Optional[Callable] = None, force: bool = False)Callable

Register a backbone class.

Parameters
  • name – backbone name

  • cls – backbone class

  • force – whether overwrite if already registered

Returns

the registered class

register_data_augmentation(name: str, cls: Optional[Callable] = None, force: bool = False)Callable

Register a data augmentation class.

Parameters
  • name – data augmentation name

  • cls – data augmentation class

  • force – whether overwrite if already registered

Returns

the registered class

register_data_loader(name: str, cls: Optional[Callable] = None, force: bool = False)Callable

Register a data loader class.

Parameters
  • name – loss name

  • cls – loss class

  • force – whether overwrite if already registered

Returns

the registered class

register_file_loader(name: str, cls: Optional[Callable] = None, force: bool = False)Callable

Register a file loader class.

Parameters
  • name – loss name

  • cls – loss class

  • force – whether overwrite if already registered

Returns

the registered class

register_loss(name: str, cls: Optional[Callable] = None, force: bool = False)Callable

Register a loss class.

Parameters
  • name – loss name

  • cls – loss class

  • force – whether overwrite if already registered

Returns

the registered class

register_model(name: str, cls: Optional[Callable] = None, force: bool = False)Callable

Register a model class.

Parameters
  • name – model name

  • cls – model class

  • force – whether overwrite if already registered

Returns

the registered class