[docs]classVisionDataset(data.Dataset):""" Base Class For making datasets which are compatible with torchvision. It is necessary to override the ``__getitem__`` and ``__len__`` method. Args: root (string, optional): Root directory of dataset. Only used for `__repr__`. transforms (callable, optional): A function/transforms that takes in an image and a label and returns the transformed versions of both. 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. .. note:: :attr:`transforms` and the combination of :attr:`transform` and :attr:`target_transform` are mutually exclusive. """_repr_indent=4def__init__(self,root:Union[str,Path]=None,# type: ignore[assignment]transforms:Optional[Callable]=None,transform:Optional[Callable]=None,target_transform:Optional[Callable]=None,)->None:_log_api_usage_once(self)ifisinstance(root,str):root=os.path.expanduser(root)self.root=roothas_transforms=transformsisnotNonehas_separate_transform=transformisnotNoneortarget_transformisnotNoneifhas_transformsandhas_separate_transform:raiseValueError("Only transforms or transform/target_transform can be passed as argument")# for backwards-compatibilityself.transform=transformself.target_transform=target_transformifhas_separate_transform:transforms=StandardTransform(transform,target_transform)self.transforms=transformsdef__getitem__(self,index:int)->Any:""" Args: index (int): Index Returns: (Any): Sample and meta data, optionally transformed by the respective transforms. """raiseNotImplementedErrordef__len__(self)->int:raiseNotImplementedErrordef__repr__(self)->str:head="Dataset "+self.__class__.__name__body=[f"Number of datapoints: {self.__len__()}"]ifself.rootisnotNone:body.append(f"Root location: {self.root}")body+=self.extra_repr().splitlines()ifhasattr(self,"transforms")andself.transformsisnotNone:body+=[repr(self.transforms)]lines=[head]+[" "*self._repr_indent+lineforlineinbody]return"\n".join(lines)def_format_transform_repr(self,transform:Callable,head:str)->List[str]:lines=transform.__repr__().splitlines()return[f"{head}{lines[0]}"]+["{}{}".format(" "*len(head),line)forlineinlines[1:]]defextra_repr(self)->str:return""
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.