Skip to content

dann

DANN

Bases: BaseGCDAdapter

Wraps DANNHook.

Container Required keys
models ["G", "C", "D"]
optimizers ["G", "C", "D"]
Source code in pytorch_adapt\adapters\dann.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class DANN(BaseGCDAdapter):
    """
    Wraps [DANNHook][pytorch_adapt.hooks.DANNHook].

    |Container|Required keys|
    |---|---|
    |models|```["G", "C", "D"]```|
    |optimizers|```["G", "C", "D"]```|
    """

    def init_hook(self, hook_kwargs):
        opts = with_opt(list(self.optimizers.keys()))
        self.hook = self.hook_cls(opts=opts, **hook_kwargs)

    @property
    def hook_cls(self):
        return DANNHook

GVB

Bases: DANN

Wraps GVBHook.

Container Required keys
models ["G", "C", "D"]
optimizers ["G", "C", "D"]

Models D and C must be of type ModelWithBridge. If not, they will be converted into instances of ModelWithBridge, with each bridge being a re-initialized copy of each model.

Source code in pytorch_adapt\adapters\dann.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class GVB(DANN):
    """
    Wraps [GVBHook][pytorch_adapt.hooks.GVBHook].

    |Container|Required keys|
    |---|---|
    |models|```["G", "C", "D"]```|
    |optimizers|```["G", "C", "D"]```|

    Models D and C must be of type [```ModelWithBridge```][pytorch_adapt.layers.ModelWithBridge].
    If not, they will be converted into instances of ```ModelWithBridge```,
    with each bridge being a re-initialized copy of each model.
    """

    @property
    def hook_cls(self):
        return GVBHook

    def init_containers_and_check_keys(self, containers):
        models = containers["models"]
        for k in ["D", "C"]:
            if not isinstance(models[k], ModelWithBridge):
                models[k] = ModelWithBridge(models[k])
        super().init_containers_and_check_keys(containers)