[docs]classDTD(VisionDataset):"""`Describable Textures Dataset (DTD) <https://www.robots.ox.ac.uk/~vgg/data/dtd/>`_. Args: root (str or ``pathlib.Path``): Root directory of the dataset. split (string, optional): The dataset split, supports ``"train"`` (default), ``"val"``, or ``"test"``. partition (int, optional): The dataset partition. Should be ``1 <= partition <= 10``. Defaults to ``1``. .. note:: The partition only changes which split each image belongs to. Thus, regardless of the selected partition, combining all splits will result in all images. transform (callable, optional): A function/transform that takes in a 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. 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. Default is False. """_URL="https://www.robots.ox.ac.uk/~vgg/data/dtd/download/dtd-r1.0.1.tar.gz"_MD5="fff73e5086ae6bdbea199a49dfb8a4c1"def__init__(self,root:Union[str,pathlib.Path],split:str="train",partition:int=1,transform:Optional[Callable]=None,target_transform:Optional[Callable]=None,download:bool=False,)->None:self._split=verify_str_arg(split,"split",("train","val","test"))ifnotisinstance(partition,int)andnot(1<=partition<=10):raiseValueError(f"Parameter 'partition' should be an integer with `1 <= partition <= 10`, "f"but got {partition} instead")self._partition=partitionsuper().__init__(root,transform=transform,target_transform=target_transform)self._base_folder=pathlib.Path(self.root)/type(self).__name__.lower()self._data_folder=self._base_folder/"dtd"self._meta_folder=self._data_folder/"labels"self._images_folder=self._data_folder/"images"ifdownload:self._download()ifnotself._check_exists():raiseRuntimeError("Dataset not found. You can use download=True to download it")self._image_files=[]classes=[]withopen(self._meta_folder/f"{self._split}{self._partition}.txt")asfile:forlineinfile:cls,name=line.strip().split("/")self._image_files.append(self._images_folder.joinpath(cls,name))classes.append(cls)self.classes=sorted(set(classes))self.class_to_idx=dict(zip(self.classes,range(len(self.classes))))self._labels=[self.class_to_idx[cls]forclsinclasses]def__len__(self)->int:returnlen(self._image_files)
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.