Vision Datasets

ImageList

class dalib.vision.datasets.imagelist.ImageList(root: str, classes: List[str], data_list_file: str, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None)[source]

Bases: torchvision.datasets.vision.VisionDataset

A generic Dataset class for domain adaptation in image classification

Parameters:
  • root (str): Root directory of dataset
  • classes (List[str]): The names of all the classes
  • data_list_file (str): File to read the image list from.
  • transform (callable, optional): A function/transform that takes in an PIL image and returns a transformed version. E.g, transforms.RandomCrop.
  • target_transform (callable, optional): A function/transform that takes in the target and transforms it.

Note

In data_list_file, each line 2 values in the following format.

source_dir/dog_xxx.png 0
source_dir/cat_123.png 1
target_dir/dog_xxy.png 0
target_dir/cat_nsdf3.png 1

The first value is the relative path of an image, and the second value is the label of the corresponding image. If your data_list_file has different formats, please over-ride parse_data_file.

num_classes

Number of classes

parse_data_file(file_name: str) → List[Tuple[str, int]][source]

Parse file to data list

Parameters:
  • file_name (str): The path of data file
  • return (list): List of (image path, class_index) tuples

Office-31

class dalib.vision.datasets.office31.Office31(root: str, task: str, download: Optional[bool] = True, **kwargs)[source]

Bases: dalib.vision.datasets.imagelist.ImageList

Office31 Dataset.

Parameters:
  • root (str): Root directory of dataset
  • task (str): The task (domain) to create dataset. Choices include 'A': amazon, 'D': dslr and 'W': webcam.
  • download (bool, optional): If true, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again.
  • transform (callable, optional): A function/transform that takes in an PIL image and returns a transformed version. E.g, transforms.RandomCrop.
  • target_transform (callable, optional): A function/transform that takes in the target and transforms it.

Note

In root, there will exist following files after downloading.

amazon/
    images/
        backpack/
            *.jpg
            ...
dslr/
webcam/
image_list/
    amazon.txt
    dslr.txt
    webcam.txt

Office-Caltech

class dalib.vision.datasets.officecaltech.OfficeCaltech(root: str, task: str, download: Optional[bool] = False, **kwargs)[source]

Bases: torchvision.datasets.folder.DatasetFolder

Office+Caltech Dataset.

Parameters:
  • root (str): Root directory of dataset
  • task (str): The task (domain) to create dataset. Choices include 'A': amazon, 'D': dslr, 'W':webcam and 'C': caltech.
  • download (bool, optional): If true, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again.
  • transform (callable, optional): A function/transform that takes in an PIL image and returns a transformed version. E.g, transforms.RandomCrop.
  • target_transform (callable, optional): A function/transform that takes in the target and transforms it.

Note

In root, there will exist following files after downloading.

amazon/
    images/
        backpack/
            *.jpg
            ...
dslr/
webcam/
caltech/
image_list/
    amazon.txt
    dslr.txt
    webcam.txt
    caltech.txt
num_classes

Number of classes

Office-Home

class dalib.vision.datasets.officehome.OfficeHome(root: str, task: str, download: Optional[bool] = False, **kwargs)[source]

Bases: dalib.vision.datasets.imagelist.ImageList

OfficeHome Dataset.

Parameters:
  • root (str): Root directory of dataset
  • task (str): The task (domain) to create dataset. Choices include 'Ar': Art, 'Cl': Clipart, 'Pr': Product and 'Rw': Real_World.
  • download (bool, optional): If true, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again.
  • transform (callable, optional): A function/transform that takes in an PIL image and returns a transformed version. E.g, transforms.RandomCrop.
  • target_transform (callable, optional): A function/transform that takes in the target and transforms it.

Note

In root, there will exist following files after downloading.

Art/
    Alarm_Clock/*.jpg
    ...
Clipart/
Product/
Real_World/
image_list/
    Art.txt
    Clipart.txt
    Product.txt
    Real_World.txt

VisDA-2017

class dalib.vision.datasets.visda2017.VisDA2017(root: str, task: str, download: Optional[bool] = False, **kwargs)[source]

Bases: dalib.vision.datasets.imagelist.ImageList

VisDA-2017 Dataset

Parameters:
  • root (str): Root directory of dataset
  • task (str): The task (domain) to create dataset. Choices include 'T': training and 'V': validation.
  • download (bool, optional): If true, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again.
  • transform (callable, optional): A function/transform that takes in an PIL image and returns a transformed version. E.g, transforms.RandomCrop.
  • target_transform (callable, optional): A function/transform that takes in the target and transforms it.

Note

In root, there will exist following files after downloading.

train/
    aeroplance/
        *.png
        ...
validation/
image_list/
    train.txt
    validation.txt

DomainNet

class dalib.vision.datasets.domainnet.DomainNet(root: str, task: str, evaluate: Optional[bool] = False, download: Optional[float] = False, **kwargs)[source]

Bases: dalib.vision.datasets.imagelist.ImageList

DomainNet (cleaned version, recommended)

See Moment Matching for Multi-Source Domain Adaptation for details.

Parameters:
  • root (str): Root directory of dataset
  • task (str): The task (domain) to create dataset. Choices include 'c':clipart, 'i': infograph, 'p': painting, 'q': quickdraw, 'r': real, 's': sketch
  • evaluate (bool, optional): If true, use the test set. Otherwise, use the training set. Default: False
  • download (bool, optional): If true, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again.
  • transform (callable, optional): A function/transform that takes in an PIL image and returns a transformed version. E.g, transforms.RandomCrop.
  • target_transform (callable, optional): A function/transform that takes in the target and transforms it.

Note

In root, there will exist following files after downloading.

clipart/
infograph/
painting/
quickdraw/
real/
sketch/
image_list/
    clipart.txt
    ...