Table of Contents
Shortcuts

# ImageFolder

class torchvision.datasets.ImageFolder(root: str, transform: ~typing.Optional[~typing.Callable] = None, target_transform: ~typing.Optional[~typing.Callable] = None, loader: ~typing.Callable[[str], ~typing.Any] = <function default_loader>, is_valid_file: ~typing.Optional[~typing.Callable[[str], bool]] = None)

  A generic data loader where the images are arranged in this way by default:

      root/dog/xxx.png
      root/dog/xxy.png
      root/dog/[...]/xxz.png

      root/cat/123.png
      root/cat/nsdf3.png
      root/cat/[...]/asd932_.png

  This class inherits from `DatasetFolder` so the same methods can be overridden to customize the dataset.

  Parameters:

    - root (string) – Root directory path.

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

    - loader (callable, optional) – A function to load an image given its path.

    - is_valid_file – A function that takes path of an Image file and check if the file is a valid file (used to check of corrupt files)

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.