base_adapter
BaseAdapter
¶
Bases: ABC
Parent class of all adapters.
Source code in pytorch_adapt\adapters\base_adapter.py
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
__init__(models=None, optimizers=None, lr_schedulers=None, misc=None, default_containers=None, key_enforcer=None, inference_fn=None, before_training_starts=None, hook_kwargs=None)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
models |
Models
|
A |
None
|
optimizers |
Optimizers
|
An |
None
|
lr_schedulers |
LRSchedulers
|
An |
None
|
misc |
Misc
|
A |
None
|
default_containers |
MultipleContainers
|
The default set of containers to use, wrapped in a
|
None
|
key_enforcer |
KeyEnforcer
|
A |
None
|
inference_fn |
A function that takes in:
|
None
|
|
before_training_starts |
A function that takes in this adapter and returns another function that is optionally called by a framework wrapper before training starts. |
None
|
|
hook_kwargs |
Dict[str, Any]
|
A dictionary of keyword arguments that will be passed into the wrapped hook during initialization. |
None
|
Source code in pytorch_adapt\adapters\base_adapter.py
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
get_default_containers()
¶
Returns:
Type | Description |
---|---|
MultipleContainers
|
The default set of containers. Consists of an Optimizers container using the default of Adam with lr 0.0001. |
Source code in pytorch_adapt\adapters\base_adapter.py
127 128 129 130 131 132 133 134 135 136 |
|
get_key_enforcer()
abstractmethod
¶
Returns:
Type | Description |
---|---|
KeyEnforcer
|
The default KeyEnforcer. |
Source code in pytorch_adapt\adapters\base_adapter.py
138 139 140 141 142 143 144 |
|
inference(x, domain=None)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
torch.Tensor
|
The input to the model |
required |
domain |
int
|
An optional integer indicating the domain. |
None
|
Returns:
Type | Description |
---|---|
Tuple[torch.Tensor, torch.Tensor]
|
Features and logits |
Source code in pytorch_adapt\adapters\base_adapter.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
init_containers_and_check_keys(containers)
¶
Called in __init__
before
init_hook
.
Source code in pytorch_adapt\adapters\base_adapter.py
158 159 160 161 162 163 164 165 166 |
|
init_hook()
abstractmethod
¶
self.hook
is initialized here.
Source code in pytorch_adapt\adapters\base_adapter.py
146 147 148 149 150 151 |
|
training_step(batch, **kwargs)
¶
Calls the wrapped hook at each iteration during training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
Dict[str, Any]
|
A dictionary containing training data. |
required |
**kwargs |
Any other data that will be passed into the hook. |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, float]]
|
A two-level dictionary
|
Source code in pytorch_adapt\adapters\base_adapter.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
BaseGCAdapter
¶
Bases: BaseAdapter
Base class for adapters that use a Generator and Classifier.
Source code in pytorch_adapt\adapters\base_adapter.py
188 189 190 191 192 193 194 195 196 197 |
|
BaseGCDAdapter
¶
Bases: BaseAdapter
Base class for adapters that use a Generator, Classifier, and Discriminator.
Source code in pytorch_adapt\adapters\base_adapter.py
176 177 178 179 180 181 182 183 184 185 |
|