Factories
ActivationsTypeFactory
Bases: AbstractFactory
This is a special factory for getting a type of the activation function by name. This factory does not instantiate a module, but rather return the type to be instantiated via call method.
Additionally, activation type factory supports already resolved types as input and fall-back to nop if the input is already a type that is subclass of nn.Module. This is done to support the case when the type is already resolved, which is the case when we're using CustomizableDetector.
Source code in common/factories/activations_type_factory.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
get(conf)
Get a type. :param conf: a configuration or a subclass of nn.Module (Type, not instance) if string - assumed to be a type name (not the real name, but a name defined in the Factory) a dictionary is not supported, since the actual instantiation takes place elsewhere
If provided value is not one of the three above, the value will be returned as is
Source code in common/factories/activations_type_factory.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
AbstractFactory
An abstract factory to generate an object from a string, a dictionary or a list
Source code in common/factories/base_factory.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
get(conf)
Get an instantiated object. :param conf: a configuration if string - assumed to be a type name (not the real name, but a name defined in the Factory) if dictionary - assumed to be {type_name(str): {parameters...}} (single item in dict) if list - assumed to be a list of the two options above
If provided value is not one of the three above, the value will be returned as is
Source code in common/factories/base_factory.py
12 13 14 15 16 17 18 19 20 21 22 |
|
BaseFactory
Bases: AbstractFactory
The basic factory fo a single object generation.
Source code in common/factories/base_factory.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
__init__(type_dict)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_dict |
Dict[str, type]
|
a dictionary mapping a name to a type |
required |
Source code in common/factories/base_factory.py
30 31 32 33 34 |
|
get(conf)
Get an instantiated object. :param conf: a configuration if string - assumed to be a type name (not the real name, but a name defined in the Factory) if dictionary - assumed to be {type_name(str): {parameters...}} (single item in dict)
If provided value is not one of the three above, the value will be returned as is
Source code in common/factories/base_factory.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
DetectionModulesFactory
Bases: BaseFactory
Source code in common/factories/detection_modules_factory.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
insert_module_param(conf, name, value)
staticmethod
Assign a new parameter for the module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
Union[str, dict, HpmStruct, DictConfig]
|
a module config, either {type_name(str): {parameters...}} or just type_name(str) |
required |
name |
str
|
parameter name |
required |
value |
Any
|
parameter value |
required |
Returns:
Type | Description |
---|---|
an update config {type_name(str): {name: value, parameters...}} |
Source code in common/factories/detection_modules_factory.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
OptimizersTypeFactory
Bases: TypeFactory
This is a special factory for torch.optim.Optimizer. This factory does not instantiate an object but rather return the type, since optimizer instantiation requires the model to be instantiated first
Source code in common/factories/optimizers_type_factory.py
5 6 7 8 9 10 11 12 13 |
|
TypeFactory
Bases: AbstractFactory
Factory to return class type from configuration string.
Source code in common/factories/type_factory.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
__init__(type_dict)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_dict |
Dict[str, type]
|
a dictionary mapping a name to a type |
required |
Source code in common/factories/type_factory.py
15 16 17 18 19 |
|
get(conf)
Get a type. :param conf: a configuration if string - assumed to be a type name (not the real name, but a name defined in the Factory) a dictionary is not supported, since the actual instantiation takes place elsewhere
If provided value is already a class type, the value will be returned as is.
Source code in common/factories/type_factory.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|