# robustness.tools.folder module¶

robustness.tools.folder.has_file_allowed_extension(filename, extensions)

Checks if a file is an allowed extension.

Parameters: filename (string) – path to a file extensions (iterable of strings) – extensions to consider (lowercase) True if the filename ends with one of given extensions bool
robustness.tools.folder.is_image_file(filename)

Checks if a file is an allowed image extension.

Parameters: filename (string) – path to a file True if the filename ends with a known image extension bool
robustness.tools.folder.make_dataset(dir, class_to_idx, extensions)
class robustness.tools.folder.DatasetFolder(root, loader, extensions, transform=None, target_transform=None, label_mapping=None)

Bases: sphinx.ext.autodoc.importer._MockObject

A generic data loader where the samples are arranged in this way:

root/class_x/xxx.ext
root/class_x/xxy.ext
root/class_x/xxz.ext

root/class_y/123.ext
root/class_y/nsdf3.ext
root/class_y/asd932_.ext

Parameters: root (string) – Root directory path. loader (callable) – A function to load a sample given its path. extensions (list[string]) – A list of allowed extensions. transform (callable, optional) – A function/transform that takes in a sample and returns a transformed version. E.g, transforms.RandomCrop for images. target_transform – A function/transform that takes in the target and transforms it.
robustness.tools.folder.pil_loader(path)
robustness.tools.folder.accimage_loader(path)
robustness.tools.folder.default_loader(path)
class robustness.tools.folder.ImageFolder(root, transform=None, target_transform=None, loader=<function default_loader>, label_mapping=None)

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

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

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

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 – A function to load an image given its path.
class robustness.tools.folder.TensorDataset(*tensors, transform=None)

Bases: sphinx.ext.autodoc.importer._MockObject

Dataset wrapping tensors.

Each sample will be retrieved by indexing tensors along the first dimension.

Parameters: *tensors (Tensor) – tensors that have the same size of the first dimension.