Belle II Software development
pxd.background_generator.models Namespace Reference

basf2 (Belle II Analysis Software Framework) # Author: The Belle II Collaboration # # See git log for contributors and copyright holders. More...

Functions

Type _get_model_cls (str model)
 Helper function that imports and returns the class Model from the Python module named as model and assumed to be located in the package pxd.background_generator.models.
 
Callable _get_generate_func (str model)
 Helper function that imports and returns the function generate from the Python module named as model and assumed to be located in the package pxd.background_generator.models.
 

Variables

tuple MODELS
 Container for names of generator models that are available for selection.
 

Detailed Description

basf2 (Belle II Analysis Software Framework) # Author: The Belle II Collaboration # # See git log for contributors and copyright holders.

# This file is licensed under LGPL-3.0, see LICENSE.md. #

This package encapsulates different generator models that can be selected to generate digits in the PXD background generator module.

Function Documentation

◆ _get_generate_func()

Callable _get_generate_func ( str  model)
protected

Helper function that imports and returns the function generate from the Python module named as model and assumed to be located in the package pxd.background_generator.models.

An error is raised if the Python module named as model:

  • does not exist,
  • does not contain the function generate.
Parameters
modelModel name and the name of the corresponding Python module implementing the model

Definition at line 55 of file __init__.py.

55def _get_generate_func(model: str) -> Callable:
56 func = None
57 try:
58 func = import_module(f".{model}", __name__).generate
59 except AttributeError as exc:
60 exc.msg = f"please define the generation function for {model!r}"
61 raise
62 except ModuleNotFoundError as exc:
63 exc.msg = f"the selected model {model!r} is not implemented"
64 raise
65 return func
66
67

◆ _get_model_cls()

Type _get_model_cls ( str  model)
protected

Helper function that imports and returns the class Model from the Python module named as model and assumed to be located in the package pxd.background_generator.models.

An error is raised if the Python module named as model:

  • does not exist,
  • does not contain the class Model.
Parameters
modelModel name and the name of the corresponding Python module implementing the model

Definition at line 31 of file __init__.py.

31def _get_model_cls(model: str) -> Type:
32 cls = None
33 try:
34 cls = import_module(f".{model}", __name__).Model
35 except AttributeError as exc:
36 exc.msg = f"please define a model class for {model!r}"
37 raise
38 except ModuleNotFoundError as exc:
39 exc.msg = f"the selected model {model!r} is not implemented"
40 raise
41 return cls
42
43

Variable Documentation

◆ MODELS

tuple MODELS
Initial value:
1= (
2 "convnet",
3 "resnet",
4 "ieagan"
5)

Container for names of generator models that are available for selection.

Each model name is assumed to match a corresponding Python module that is located in the package pxd.background_generator.models and implements the specific model, i.e. defines a:

  • class Model,
  • function generate.

The class Model must inherit from the base class torch.nn.Module.

The generation function generate specific to a model is assumed to act on a model instance and produce an output of type torch.Tensor that is of shape (40, 250, 768) and contains values of type torch.uint8 in the interval $ [0, 255] $. Each index in the first axis of the output tensor is assumed to correspond to the PXD sensor specified by the VxdID arguments in pxd.background_generator.VXDID_ARGS at the same index.

Definition at line 86 of file __init__.py.