Skip to content

models

Models

Bases: BaseContainer

A container with some functions specific to models that have optimizable parameters.

Source code in pytorch_adapt\containers\models.py
 4
 5
 6
 7
 8
 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
class Models(BaseContainer):
    """
    A container with some functions specific to models
    that have optimizable parameters.
    """

    def train(self):
        """
        Sets all models to train mode.
        """
        for v in self.values():
            v.train()

    def eval(self):
        """
        Sets all models to eval mode.
        """
        for v in self.values():
            v.eval()

    def zero_grad(self):
        """
        Zeros the gradients in all models.
        """
        for v in self.values():
            v.zero_grad()

    def to(self, device):
        """
        Moves all models to ```device```.
        """
        for v in self.values():
            v.to(device)

eval()

Sets all models to eval mode.

Source code in pytorch_adapt\containers\models.py
17
18
19
20
21
22
def eval(self):
    """
    Sets all models to eval mode.
    """
    for v in self.values():
        v.eval()

to(device)

Moves all models to device.

Source code in pytorch_adapt\containers\models.py
31
32
33
34
35
36
def to(self, device):
    """
    Moves all models to ```device```.
    """
    for v in self.values():
        v.to(device)

train()

Sets all models to train mode.

Source code in pytorch_adapt\containers\models.py
10
11
12
13
14
15
def train(self):
    """
    Sets all models to train mode.
    """
    for v in self.values():
        v.train()

zero_grad()

Zeros the gradients in all models.

Source code in pytorch_adapt\containers\models.py
24
25
26
27
28
29
def zero_grad(self):
    """
    Zeros the gradients in all models.
    """
    for v in self.values():
        v.zero_grad()