Skip to content

multiple_models

MultipleModels

Bases: torch.nn.Module

Wraps a list of models, and returns their outputs as a list of tensors

Source code in pytorch_adapt\layers\multiple_models.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class MultipleModels(torch.nn.Module):
    """
    Wraps a list of models, and returns their outputs as a list of tensors
    """

    def __init__(self, *models: torch.nn.Module):
        """
        Arguments:
            *models: The models to be wrapped.
        """
        super().__init__()
        self.models = torch.nn.ModuleList(models)

    def forward(self, x: torch.Tensor) -> List[Any]:
        """
        Arguments:
            x: the input to each model
        Returns:
            A list containing the output of each model.
        """
        outputs = []
        for m in self.models:
            outputs.append(m(x))
        return outputs

__init__(*models)

Parameters:

Name Type Description Default
*models torch.nn.Module

The models to be wrapped.

()
Source code in pytorch_adapt\layers\multiple_models.py
11
12
13
14
15
16
17
def __init__(self, *models: torch.nn.Module):
    """
    Arguments:
        *models: The models to be wrapped.
    """
    super().__init__()
    self.models = torch.nn.ModuleList(models)

forward(x)

Parameters:

Name Type Description Default
x torch.Tensor

the input to each model

required

Returns:

Type Description
List[Any]

A list containing the output of each model.

Source code in pytorch_adapt\layers\multiple_models.py
19
20
21
22
23
24
25
26
27
28
29
def forward(self, x: torch.Tensor) -> List[Any]:
    """
    Arguments:
        x: the input to each model
    Returns:
        A list containing the output of each model.
    """
    outputs = []
    for m in self.models:
        outputs.append(m(x))
    return outputs