class torchvision.datasets.CelebA(root: Union[str, Path], split: str = 'train', target_type: Union[List[str], str] = 'attr', transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, download: bool = False)[source]

Large-scale CelebFaces Attributes (CelebA) Dataset Dataset.

  • root (str or pathlib.Path) – Root directory where images are downloaded to.

  • split (string) – One of {‘train’, ‘valid’, ‘test’, ‘all’}. Accordingly dataset is selected.

  • target_type (string or list, optional) –

    Type of target to use, attr, identity, bbox, or landmarks. Can also be a list to output a tuple with all specified target types. The targets represent:

    • attr (Tensor shape=(40,) dtype=int): binary (0, 1) labels for attributes

    • identity (int): label for each person (data points with the same identity are the same person)

    • bbox (Tensor shape=(4,) dtype=int): bounding box (x, y, width, height)

    • landmarks (Tensor shape=(10,) dtype=int): landmark points (lefteye_x, lefteye_y, righteye_x, righteye_y, nose_x, nose_y, leftmouth_x, leftmouth_y, rightmouth_x, rightmouth_y)

    Defaults to attr. If empty, None will be returned as target.

  • transform (callable, optional) – A function/transform that takes in a PIL image and returns a transformed version. E.g, transforms.PILToTensor

  • target_transform (callable, optional) – A function/transform that takes in the target and transforms it.

  • 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.


    To download the dataset gdown is required.


__getitem__(index: int) Tuple[Any, Any][source]

index (int) – Index


Sample and meta data, optionally transformed by the respective transforms.

Return type:



Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources