Skip to content

source_dataset

SourceDataset

Bases: DomainDataset

Wrap your source dataset with this. Your source dataset's __getitem__ function should return a tuple of (data, label).

Source code in pytorch_adapt\datasets\source_dataset.py
 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
37
38
39
40
41
42
class SourceDataset(DomainDataset):
    """
    Wrap your source dataset with this. Your source dataset's
    ```__getitem__``` function should return a tuple of ```(data, label)```.
    """

    def __init__(self, dataset: Dataset, domain: int = 0):
        """
        Arguments:
            dataset: The dataset to wrap
            domain: An integer representing the domain.
        """
        super().__init__(dataset, domain)

    def __getitem__(self, idx: int) -> Dict[str, Any]:
        """
        Returns:
            A dictionary with keys

                - "src_imgs" (the data)

                - "src_domain" (the integer representing the domain)

                - "src_labels" (the class label)

                - "src_sample_idx" (idx)
        """

        img, src_labels = self.dataset[idx]
        return {
            "src_imgs": img,
            "src_domain": self.domain,
            "src_labels": src_labels,
            "src_sample_idx": idx,
        }

__getitem__(idx)

Returns:

Type Description
Dict[str, Any]

A dictionary with keys

  • "src_imgs" (the data)

  • "src_domain" (the integer representing the domain)

  • "src_labels" (the class label)

  • "src_sample_idx" (idx)

Source code in pytorch_adapt\datasets\source_dataset.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def __getitem__(self, idx: int) -> Dict[str, Any]:
    """
    Returns:
        A dictionary with keys

            - "src_imgs" (the data)

            - "src_domain" (the integer representing the domain)

            - "src_labels" (the class label)

            - "src_sample_idx" (idx)
    """

    img, src_labels = self.dataset[idx]
    return {
        "src_imgs": img,
        "src_domain": self.domain,
        "src_labels": src_labels,
        "src_sample_idx": idx,
    }

__init__(dataset, domain=0)

Parameters:

Name Type Description Default
dataset Dataset

The dataset to wrap

required
domain int

An integer representing the domain.

0
Source code in pytorch_adapt\datasets\source_dataset.py
14
15
16
17
18
19
20
def __init__(self, dataset: Dataset, domain: int = 0):
    """
    Arguments:
        dataset: The dataset to wrap
        domain: An integer representing the domain.
    """
    super().__init__(dataset, domain)